bridge_map.c
author peter1138
Sat, 03 Jun 2006 19:23:14 +0000
changeset 3943 d3d5f7b3d3d0
parent 3933 231ae3c419f4
child 3977 513433ebd092
permissions -rw-r--r--
(svn r5088) - Add another set of parentheses, missed in r5085, somehow... (thanks ASM)
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"
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
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
{
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    11
	TileIndexDiff delta = TileOffsByDir(dir);
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    12
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    13
	do { tile += delta; } while (IsBridgeAbove(tile) && IsBridgeOfAxis(tile, DiagDirToAxis(dir)));
3225
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    14
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    15
	return tile;
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    16
}
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
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    19
TileIndex GetNorthernBridgeEnd(TileIndex t)
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    20
{
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    21
	return GetBridgeEnd(t, ReverseDiagDir(AxisToDiagDir(GetBridgeAxis(t))));
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    22
}
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    23
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    24
3225
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    25
TileIndex GetSouthernBridgeEnd(TileIndex t)
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    26
{
3a3e35bd39a6 (svn r3898) Add functions to find a bridge end starting at a middle tile
tron
parents: 3214
diff changeset
    27
	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
    28
}
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
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    31
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
    32
{
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    33
	assert(IsBridgeTile(tile));
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    34
	return GetBridgeEnd(tile, GetBridgeRampDirection(tile));
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    35
}
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    36
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    37
uint GetBridgeHeight(TileIndex tile, Axis a)
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    38
{
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    39
	uint h, f;
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    40
	uint tileh = GetTileSlope(tile, &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
    41
3933
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    42
	f = GetBridgeFoundation(tileh, a);
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    43
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    44
	if (f) {
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    45
		if (f < 15) {
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    46
			h += TILE_HEIGHT;
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    47
			tileh = SLOPE_FLAT;
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    48
		} else {
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    49
			tileh = _inclined_tileh[f - 15];
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    50
		}
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    51
	}
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    52
231ae3c419f4 (svn r5070) Merged the bridge branch
celestar
parents: 3225
diff changeset
    53
	return h + TILE_HEIGHT;
3214
dd744119dfac (svn r3887) Add a function to get the other bridge end when you're at a bridge ramp
tron
parents:
diff changeset
    54
}