src/tunnel_map.cpp
branchnoai
changeset 9723 eee46cb39750
parent 9694 e72987579514
child 10455 22c441f5adf9
equal deleted inserted replaced
9722:ebf0ece7d8f6 9723:eee46cb39750
     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 }
    50 	} while (z < height);
    51 	} while (z < height);
    51 
    52 
    52 	return
    53 	return
    53 		z == height &&
    54 		z == height &&
    54 		IsTunnelTile(tile) &&
    55 		IsTunnelTile(tile) &&
    55 		GetTunnelDirection(tile) == dir;
    56 		GetTunnelBridgeDirection(tile) == dir;
    56 }
    57 }
    57 
    58 
    58 /**
    59 /**
    59  * Is there a tunnel in the way in any direction?
    60  * Is there a tunnel in the way in any direction?
    60  * @param tile the tile to search from.
    61  * @param tile the tile to search from.