2 |
2 |
3 /** @file tunnel_map.cpp */ |
3 /** @file tunnel_map.cpp */ |
4 |
4 |
5 #include "stdafx.h" |
5 #include "stdafx.h" |
6 #include "openttd.h" |
6 #include "openttd.h" |
7 #include "tile.h" |
|
8 #include "tunnel_map.h" |
7 #include "tunnel_map.h" |
|
8 #include "tunnelbridge_map.h" |
|
9 |
9 |
10 |
10 /** |
11 /** |
11 * Gets the other end of the tunnel. Where a vehicle would reappear when it |
12 * Gets the other end of the tunnel. Where a vehicle would reappear when it |
12 * enters at the given tile. |
13 * enters at the given tile. |
13 * @param tile the tile to search from. |
14 * @param tile the tile to search from. |
14 * @return the tile of the other end of the tunnel. |
15 * @return the tile of the other end of the tunnel. |
15 */ |
16 */ |
16 TileIndex GetOtherTunnelEnd(TileIndex tile) |
17 TileIndex GetOtherTunnelEnd(TileIndex tile) |
17 { |
18 { |
18 DiagDirection dir = GetTunnelDirection(tile); |
19 DiagDirection dir = GetTunnelBridgeDirection(tile); |
19 TileIndexDiff delta = TileOffsByDiagDir(dir); |
20 TileIndexDiff delta = TileOffsByDiagDir(dir); |
20 uint z = GetTileZ(tile); |
21 uint z = GetTileZ(tile); |
21 |
22 |
22 dir = ReverseDiagDir(dir); |
23 dir = ReverseDiagDir(dir); |
23 do { |
24 do { |
24 tile += delta; |
25 tile += delta; |
25 } while ( |
26 } while ( |
26 !IsTunnelTile(tile) || |
27 !IsTunnelTile(tile) || |
27 GetTunnelDirection(tile) != dir || |
28 GetTunnelBridgeDirection(tile) != dir || |
28 GetTileZ(tile) != z |
29 GetTileZ(tile) != z |
29 ); |
30 ); |
30 |
31 |
31 return tile; |
32 return tile; |
32 } |
33 } |