mirror of https://github.com/OpenTTD/OpenTTD
(svn r4245) Simplify FindLengthOfTunnel()
parent
1c5c32dd60
commit
a6403bd50a
34
pathfind.c
34
pathfind.c
|
@ -221,39 +221,27 @@ continue_here:;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const int8 _get_tunlen_inc[5] = { -16, 0, 16, 0, -16 };
|
|
||||||
|
|
||||||
/* Returns the end tile and the length of a tunnel. The length does not
|
/* Returns the end tile and the length of a tunnel. The length does not
|
||||||
* include the starting tile (entry), it does include the end tile (exit).
|
* include the starting tile (entry), it does include the end tile (exit).
|
||||||
*/
|
*/
|
||||||
FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection direction)
|
FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection dir)
|
||||||
{
|
{
|
||||||
|
TileIndexDiff delta = TileOffsByDir(dir);
|
||||||
|
uint z = GetTileZ(tile);
|
||||||
FindLengthOfTunnelResult flotr;
|
FindLengthOfTunnelResult flotr;
|
||||||
int x,y;
|
|
||||||
byte z;
|
|
||||||
|
|
||||||
flotr.length = 0;
|
flotr.length = 0;
|
||||||
|
|
||||||
x = TileX(tile) * 16;
|
dir = ReverseDiagDir(dir);
|
||||||
y = TileY(tile) * 16;
|
do {
|
||||||
|
|
||||||
z = GetSlopeZ(x+8, y+8);
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
flotr.length++;
|
flotr.length++;
|
||||||
|
tile += delta;
|
||||||
x += _get_tunlen_inc[direction];
|
} while(
|
||||||
y += _get_tunlen_inc[direction+1];
|
!IsTunnelTile(tile) ||
|
||||||
|
GetTunnelDirection(tile) != dir ||
|
||||||
tile = TileVirtXY(x, y);
|
GetTileZ(tile) != z
|
||||||
|
);
|
||||||
if (IsTunnelTile(tile) &&
|
|
||||||
// GetTunnelTransportType(tile) == type && // rail/road-tunnel <-- This is not necesary to check, right?
|
|
||||||
ReverseDiagDir(GetTunnelDirection(tile)) == direction &&
|
|
||||||
GetSlopeZ(x + 8, y + 8) == z) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
flotr.tile = tile;
|
flotr.tile = tile;
|
||||||
return flotr;
|
return flotr;
|
||||||
|
|
Loading…
Reference in New Issue