tron@3154: /* $Id$ */ tron@3154: richk@6719: /** @file tunnel_map.cpp */ richk@6719: tron@3154: #include "stdafx.h" tron@3154: #include "openttd.h" tron@3154: #include "tunnel_map.h" rubidium@6872: #include "tunnelbridge_map.h" rubidium@6872: tron@3154: richk@6719: /** richk@6719: * Gets the other end of the tunnel. Where a vehicle would reappear when it richk@6719: * enters at the given tile. richk@6719: * @param tile the tile to search from. richk@6719: * @return the tile of the other end of the tunnel. richk@6719: */ tron@3154: TileIndex GetOtherTunnelEnd(TileIndex tile) tron@3154: { rubidium@6872: DiagDirection dir = GetTunnelBridgeDirection(tile); Darkvater@4559: TileIndexDiff delta = TileOffsByDiagDir(dir); tron@3154: uint z = GetTileZ(tile); tron@3154: tron@3154: dir = ReverseDiagDir(dir); tron@3154: do { tron@3154: tile += delta; tron@3154: } while ( tron@3184: !IsTunnelTile(tile) || rubidium@6872: GetTunnelBridgeDirection(tile) != dir || tron@3154: GetTileZ(tile) != z tron@3154: ); tron@3154: tron@3154: return tile; tron@3154: } tron@3156: tron@3156: richk@6719: /** richk@6719: * Is there a tunnel in the way in the given direction? richk@6719: * @param tile the tile to search from. richk@6719: * @param z the 'z' to search on. richk@6719: * @param dir the direction to start searching to. richk@6719: * @return true if and only if there is a tunnel. richk@6719: */ richk@6720: bool IsTunnelInWayDir(TileIndex tile, uint z, DiagDirection dir) tron@3156: { Darkvater@4559: TileIndexDiff delta = TileOffsByDiagDir(dir); tron@3156: uint height; tron@3156: tron@3156: do { tron@3156: tile -= delta; tron@3156: height = GetTileZ(tile); tron@3156: } while (z < height); tron@3156: tron@3156: return tron@3156: z == height && tron@3184: IsTunnelTile(tile) && rubidium@6872: GetTunnelBridgeDirection(tile) == dir; tron@3156: } tron@3156: richk@6719: /** richk@6719: * Is there a tunnel in the way in any direction? richk@6719: * @param tile the tile to search from. richk@6719: * @param z the 'z' to search on. richk@6719: * @return true if and only if there is a tunnel. richk@6719: */ tron@3156: bool IsTunnelInWay(TileIndex tile, uint z) tron@3156: { tron@3156: return richk@6743: IsTunnelInWayDir(tile, z, (TileX(tile) > (MapMaxX() / 2)) ? DIAGDIR_NE : DIAGDIR_SW) || richk@6743: IsTunnelInWayDir(tile, z, (TileY(tile) > (MapMaxY() / 2)) ? DIAGDIR_NW : DIAGDIR_SE); tron@3156: }