summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-04-02 18:03:48 +0000
committertron <tron@openttd.org>2006-04-02 18:03:48 +0000
commit16c721237bc2ac93b80bb1a22fae1340158b7d71 (patch)
treebde05a65da743facbe4a4997adef137abc4522eb
parent7549e674b3b88b1b6885bc2d9cb2db867937b2ee (diff)
downloadopenttd-16c721237bc2ac93b80bb1a22fae1340158b7d71.tar.xz
(svn r4245) Simplify FindLengthOfTunnel()
-rw-r--r--pathfind.c34
1 files changed, 11 insertions, 23 deletions
diff --git a/pathfind.c b/pathfind.c
index b6c268938..e3a21398d 100644
--- a/pathfind.c
+++ b/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
* 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;
- int x,y;
- byte z;
flotr.length = 0;
- x = TileX(tile) * 16;
- y = TileY(tile) * 16;
-
- z = GetSlopeZ(x+8, y+8);
-
- for (;;) {
+ dir = ReverseDiagDir(dir);
+ do {
flotr.length++;
-
- x += _get_tunlen_inc[direction];
- y += _get_tunlen_inc[direction+1];
-
- tile = TileVirtXY(x, y);
-
- 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;
- }
- }
+ tile += delta;
+ } while(
+ !IsTunnelTile(tile) ||
+ GetTunnelDirection(tile) != dir ||
+ GetTileZ(tile) != z
+ );
flotr.tile = tile;
return flotr;