tron@3154: /* $Id$ */ tron@3154: rubidium@10429: /** @file tunnel_map.cpp Map accessors for tunnels. */ belugas@6918: tron@3154: #include "stdafx.h" tron@3154: #include "openttd.h" tron@3154: #include "tunnel_map.h" smatz@8579: #include "tunnelbridge_map.h" smatz@8579: tron@3154: rubidium@6985: /** rubidium@6985: * Gets the other end of the tunnel. Where a vehicle would reappear when it rubidium@6985: * enters at the given tile. rubidium@6985: * @param tile the tile to search from. rubidium@6985: * @return the tile of the other end of the tunnel. rubidium@6985: */ tron@3154: TileIndex GetOtherTunnelEnd(TileIndex tile) tron@3154: { smatz@8579: 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) || smatz@8579: GetTunnelBridgeDirection(tile) != dir || tron@3154: GetTileZ(tile) != z tron@3154: ); tron@3154: tron@3154: return tile; tron@3154: } tron@3156: tron@3156: rubidium@6985: /** rubidium@6985: * Is there a tunnel in the way in the given direction? rubidium@6985: * @param tile the tile to search from. rubidium@6985: * @param z the 'z' to search on. rubidium@6985: * @param dir the direction to start searching to. rubidium@6985: * @return true if and only if there is a tunnel. rubidium@6985: */ rubidium@7498: 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) && smatz@8579: GetTunnelBridgeDirection(tile) == dir; tron@3156: } tron@3156: rubidium@6985: /** rubidium@6985: * Is there a tunnel in the way in any direction? rubidium@6985: * @param tile the tile to search from. rubidium@6985: * @param z the 'z' to search on. rubidium@6985: * @return true if and only if there is a tunnel. rubidium@6985: */ tron@3156: bool IsTunnelInWay(TileIndex tile, uint z) tron@3156: { tron@3156: return rubidium@7819: IsTunnelInWayDir(tile, z, (TileX(tile) > (MapMaxX() / 2)) ? DIAGDIR_NE : DIAGDIR_SW) || rubidium@7819: IsTunnelInWayDir(tile, z, (TileY(tile) > (MapMaxY() / 2)) ? DIAGDIR_NW : DIAGDIR_SE); tron@3156: }