tunnel_map.c
changeset 4290 2d6895dc84eb
parent 3184 7405329343ce
child 4291 c0e769957f8b
equal deleted inserted replaced
4289:ff1b2b915cab 4290:2d6895dc84eb
     2 
     2 
     3 #include "stdafx.h"
     3 #include "stdafx.h"
     4 #include "openttd.h"
     4 #include "openttd.h"
     5 #include "tile.h"
     5 #include "tile.h"
     6 #include "tunnel_map.h"
     6 #include "tunnel_map.h"
       
     7 #include "vehicle.h"
     7 
     8 
     8 TileIndex GetOtherTunnelEnd(TileIndex tile)
     9 TileIndex GetOtherTunnelEnd(TileIndex tile)
     9 {
    10 {
    10 	DiagDirection dir = GetTunnelDirection(tile);
    11 	DiagDirection dir = GetTunnelDirection(tile);
    11 	TileIndexDiff delta = TileOffsByDir(dir);
    12 	TileIndexDiff delta = TileOffsByDir(dir);
    17 	} while (
    18 	} while (
    18 		!IsTunnelTile(tile) ||
    19 		!IsTunnelTile(tile) ||
    19 		GetTunnelDirection(tile) != dir ||
    20 		GetTunnelDirection(tile) != dir ||
    20 		GetTileZ(tile) != z
    21 		GetTileZ(tile) != z
    21 	);
    22 	);
       
    23 
       
    24 	return tile;
       
    25 }
       
    26 
       
    27 
       
    28 /** Retrieve the exit-tile of the vehicle from inside a tunnel
       
    29  * Very similar to GetOtherTunnelEnd(), but we use the vehicle's
       
    30  * direction for determining which end of the tunnel to find
       
    31  * @param v the vehicle which is inside the tunnel and needs an exit
       
    32  * @return the exit-tile of the tunnel based on the vehicle's direction */
       
    33 TileIndex GetVehicleOutOfTunnelTile(const Vehicle *v)
       
    34 {
       
    35 	TileIndex tile = TileVirtXY(v->x_pos, v->y_pos);
       
    36 	DiagDirection dir = DirToDiagDir(v->direction);
       
    37 	TileIndexDiff delta = TileOffsByDir(dir);
       
    38 	uint z = v->z_pos;
       
    39 
       
    40 	dir = ReverseDiagDir(dir);
       
    41 	while (
       
    42 		!IsTunnelTile(tile) ||
       
    43 		GetTunnelDirection(tile) != dir ||
       
    44 		GetTileZ(tile) != z
       
    45 	) {
       
    46 		tile += delta;
       
    47 	}
    22 
    48 
    23 	return tile;
    49 	return tile;
    24 }
    50 }
    25 
    51 
    26 
    52