/** * Is there a tunnel in the way in the given direction? * @param tile the tile to search from. * @param z the 'z' to search on. * @param dir the direction to start searching to. * @return true if and only if there is a tunnel. */ public static bool IsTunnelInWayDir(this TileIndex tile, int z, DiagDirection dir) { TileIndexDiff delta = TileOffsByDiagDir(dir); int height; do { tile -= delta; if (!TileMap.IsValidTile(tile)) { return(false); } height = TileMap.GetTileZ(tile); } while (z < height); return(z == height && IsTunnelTile(tile) && GetTunnelBridgeDirection(tile) == dir); }
/** * Gets the other end of the tunnel. Where a vehicle would reappear when it * enters at the given tile. * @param tile the tile to search from. * @return the tile of the other end of the tunnel. */ public static TileIndex GetOtherTunnelEnd(this TileIndex tile) { DiagDirection dir = GetTunnelBridgeDirection(tile); TileIndexDiff delta = TileOffsByDiagDir(dir); int z = TileMap.GetTileZ(tile); dir = ReverseDiagDir(dir); do { tile += delta; } while ( !IsTunnelTile(tile) || GetTunnelBridgeDirection(tile) != dir || TileMap.GetTileZ(tile) != z ); return(tile); }