pathfind.c
changeset 3420 85a5201aeb14
parent 3355 a653b8e47f27
child 3618 dc8cebe5ffd3
--- a/pathfind.c	Sun Apr 02 14:36:51 2006 +0000
+++ b/pathfind.c	Sun Apr 02 18:03:48 2006 +0000
@@ -221,39 +221,27 @@
 
 }
 
-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;