Changeset - r3225:c5b1dafc46ed
[Not reviewed]
master
0 3 0
tron - 18 years ago 2006-03-16 05:28:15
tron@openttd.org
(svn r3898) Add functions to find a bridge end starting at a middle tile
3 files changed with 46 insertions and 15 deletions:
0 comments (0 inline, 0 general)
bridge_map.c
Show inline comments
 
@@ -5,6 +5,26 @@
 
#include "bridge_map.h"
 

	
 

	
 
TileIndex GetBridgeEnd(TileIndex tile, DiagDirection dir)
 
{
 
	TileIndexDiff delta = TileOffsByDir(dir);
 

	
 
	assert(DiagDirToAxis(dir) == GetBridgeAxis(tile));
 

	
 
	do {
 
		tile += delta;
 
	} while (!IsBridgeRamp(tile));
 

	
 
	return tile;
 
}
 

	
 

	
 
TileIndex GetSouthernBridgeEnd(TileIndex t)
 
{
 
	return GetBridgeEnd(t, AxisToDiagDir(GetBridgeAxis(t)));
 
}
 

	
 

	
 
TileIndex GetOtherBridgeEnd(TileIndex tile)
 
{
 
	TileIndexDiff delta = TileOffsByDir(GetBridgeRampDirection(tile));
bridge_map.h
Show inline comments
 
@@ -15,6 +15,12 @@ static inline bool IsBridgeRamp(TileInde
 
	return !HASBIT(_m[t].m5, 6);
 
}
 

	
 
static inline bool IsBridgeMiddle(TileIndex t)
 
{
 
	return HASBIT(_m[t].m5, 6);
 
}
 

	
 

	
 

	
 
/**
 
 * Get the direction pointing onto the bridge
 
@@ -28,6 +34,12 @@ static inline DiagDirection GetBridgeRam
 
}
 

	
 

	
 
static inline Axis GetBridgeAxis(TileIndex t)
 
{
 
	return (Axis)GB(_m[t].m5, 0, 1);
 
}
 

	
 

	
 
static inline bool IsClearUnderBridge(TileIndex t)
 
{
 
	return GB(_m[t].m5, 3, 3) == 0;
 
@@ -46,6 +58,17 @@ static inline TransportType GetTransport
 

	
 

	
 
/**
 
 * Finds the end of a bridge in the specified direction starting at a middle tile
 
 */
 
TileIndex GetBridgeEnd(TileIndex, DiagDirection);
 

	
 
/**
 
 * Finds the southern end of a bridge starting at a middle tile
 
 */
 
TileIndex GetSouthernBridgeEnd(TileIndex t);
 

	
 

	
 
/**
 
 * Starting at one bridge end finds the other bridge end
 
 */
 
TileIndex GetOtherBridgeEnd(TileIndex);
tunnelbridge_cmd.c
Show inline comments
 
@@ -846,15 +846,7 @@ int32 DoConvertTunnelBridgeRail(TileInde
 
// fast routine for getting the height of a middle bridge tile. 'tile' MUST be a middle bridge tile.
 
static uint GetBridgeHeight(const TileInfo *ti)
 
{
 
	TileIndexDiff delta;
 
	TileIndex tile = ti->tile;
 

	
 
	// find the end tile of the bridge.
 
	delta = GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
 
	do {
 
		assert((_m[tile].m5 & 0xC0) == 0xC0);	// bridge and middle part
 
		tile += delta;
 
	} while (_m[tile].m5 & 0x40);	// while bridge middle parts
 
	TileIndex tile = GetSouthernBridgeEnd(ti->tile);
 

	
 
	/* Return the height there (the height of the NORTH CORNER)
 
	 * If the end of the bridge is on a tileh 7 (all raised, except north corner),
 
@@ -1240,12 +1232,8 @@ static void GetTileDesc_TunnelBridge(Til
 
	} else {
 
		td->str = _bridge_tile_str[GB(_m[tile].m5, 1, 2) << 4 | GB(_m[tile].m2, 4, 4)];
 

	
 
		/* scan to the end of the bridge, that's where the owner is stored */
 
		if (_m[tile].m5 & 0x40) {
 
			TileIndexDiff delta = GB(_m[tile].m5, 0, 1) ? TileDiffXY(0, -1) : TileDiffXY(-1, 0);
 

	
 
			do tile += delta; while (_m[tile].m5 & 0x40);
 
		}
 
		// the owner is stored at the end of the bridge
 
		if (IsBridgeMiddle(tile)) tile = GetSouthernBridgeEnd(tile);
 
	}
 
	td->owner = GetTileOwner(tile);
 
}
0 comments (0 inline, 0 general)