summaryrefslogtreecommitdiff
path: root/tunnelbridge_cmd.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-08-15 01:28:07 +0000
committerDarkvater <darkvater@openttd.org>2006-08-15 01:28:07 +0000
commitd84a1dcf501227ec59a143e9d4b3d605aa8a3fcc (patch)
treeb76790c98ca93bd560b4214f3cc861fdd80c132d /tunnelbridge_cmd.c
parent8fc2664237f87e29bbc20103142ae4281c637a93 (diff)
downloadopenttd-d84a1dcf501227ec59a143e9d4b3d605aa8a3fcc.tar.xz
(svn r5906) -Fix [ 1203146 ]: GetVehicleOutOfTunnelTile always returned v->tile, now the exit-tile of the tunnel based on the vehicle's direction is correctly returned. Based on a patch by glx.
Diffstat (limited to 'tunnelbridge_cmd.c')
-rw-r--r--tunnelbridge_cmd.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 9d95de830..434f801b2 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -1425,15 +1425,27 @@ static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y
return 0;
}
+/** Retrieve the exit-tile of the vehicle from inside a tunnel
+ * Very similar to GetOtherTunnelEnd(), but we use the vehicle's
+ * direction for determining which end of the tunnel to find
+ * @param v the vehicle which is inside the tunnel and needs an exit
+ * @return the exit-tile of the tunnel based on the vehicle's direction */
TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v)
{
- TileIndex tile;
- TileIndexDiff delta = (v->direction & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
+ TileIndex tile = v->tile;
+ DiagDirection dir = DirToDiagDir(v->direction);
+ TileIndexDiff delta = TileOffsByDir(dir);
byte z = v->z_pos;
- for (tile = v->tile;; tile += delta) {
- if (IsTunnelTile(tile) && GetTileZ(tile) == z) break;
- }
+ dir = ReverseDiagDir(dir);
+ do {
+ tile += delta;
+ } while (
+ !IsTunnelTile(tile) ||
+ GetTunnelDirection(tile) != dir ||
+ GetTileZ(tile) != z
+ );
+
return tile;
}