tron@3154: /* $Id$ */ tron@3154: tron@3154: #include "stdafx.h" tron@3154: #include "openttd.h" tron@3154: #include "tile.h" tron@3154: #include "tunnel_map.h" tron@3154: tron@3154: TileIndex GetOtherTunnelEnd(TileIndex tile) tron@3154: { tron@3154: DiagDirection dir = GetTunnelDirection(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) || tron@3154: GetTunnelDirection(tile) != dir || tron@3154: GetTileZ(tile) != z tron@3154: ); tron@3154: tron@3154: return tile; tron@3154: } tron@3156: tron@3156: tron@3156: static 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) && tron@3156: GetTunnelDirection(tile) == dir; tron@3156: } tron@3156: tron@3156: bool IsTunnelInWay(TileIndex tile, uint z) tron@3156: { tron@3156: return tron@3156: IsTunnelInWayDir(tile, z, DIAGDIR_NE) || tron@3156: IsTunnelInWayDir(tile, z, DIAGDIR_SE) || tron@3156: IsTunnelInWayDir(tile, z, DIAGDIR_SW) || tron@3156: IsTunnelInWayDir(tile, z, DIAGDIR_NW); tron@3156: }