bridge_map.c
author rubidium
Mon, 01 Jan 2007 22:00:54 +0000
changeset 5462 ebb6fe93a23a
parent 5385 3868f2e6db9b
permissions -rw-r--r--
(svn r7731) -Fix (r5999): off-by-one error in the date to YMD calculation for first 4 years of a century that was not divisable by 400.
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     1
/* $Id$ */
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     2
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     3
#include "stdafx.h"
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     4
#include "openttd.h"
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     5
#include "bridge_map.h"
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
     6
#include "variables.h"
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     7
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
     8
3225
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
     9
TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    10
{
4559
aa0c13e39840 (svn r6406) -Codechange: Rename TileOffsByDir to TileOffsByDiagDir because it accepts
Darkvater
parents: 3977
diff changeset
    11
	TileIndexDiff delta = TileOffsByDiagDir(dir);
3225
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    12
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    13
	dir = ReverseDiagDir(dir);
3977
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
    14
	do {
513433ebd092 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
    15
		tile += delta;
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    16
	} while (!IsBridgeTile(tile) || GetBridgeRampDirection(tile) != dir);
3225
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    17
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    18
	return tile;
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    19
}
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    20
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    21
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    22
TileIndex GetNorthernBridgeEnd(TileIndex t)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    23
{
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    24
	return GetBridgeEnd(t, ReverseDiagDir(AxisToDiagDir(GetBridgeAxis(t))));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    25
}
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    26
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    27
3225
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    28
TileIndex GetSouthernBridgeEnd(TileIndex t)
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    29
{
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    30
	return GetBridgeEnd(t, AxisToDiagDir(GetBridgeAxis(t)));
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    31
}
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    32
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    33
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    34
TileIndex GetOtherBridgeEnd(TileIndex tile)
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    35
{
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    36
	assert(IsBridgeTile(tile));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    37
	return GetBridgeEnd(tile, GetBridgeRampDirection(tile));
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    38
}
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    39
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    40
uint GetBridgeHeight(TileIndex t)
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    41
{
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    42
	uint h;
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    43
	uint tileh = GetTileSlope(t, &h);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    44
	uint f = GetBridgeFoundation(tileh, DiagDirToAxis(GetBridgeRampDirection(t)));
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    45
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    46
	// one height level extra if the ramp is on a flat foundation
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    47
	return
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    48
		h + TILE_HEIGHT +
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    49
		(IS_INT_INSIDE(f, 1, 15) ? TILE_HEIGHT : 0) +
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4559
diff changeset
    50
		(IsSteepSlope(tileh) ? TILE_HEIGHT : 0);
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    51
}