static bool IsPossibleLockLocation(TileIndex tile) { DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile)); if (!IsValidDiagDirection(dir)) return false; TileIndexDiff delta_mid = TileOffsByDiagDir(dir); if (!IsTileFlat(tile + delta_mid)) return false; if (!IsTileFlat(tile - delta_mid)) return false; return true; } /** * Tests whether a tile is suitable for a lock for the provided diagonal direction (axis). * @param tile The middle tile of a lock * @param dir Any diagonal direction belonging to the same axis * @param check_tile_flat If set to true, check whether the tile is flat * @return true if a lock can be placed in the given direction */ bool IsPossibleLockLocationOnDiagDir(TileIndex tile, DiagDirection dir, bool check_tile_flat) { if (check_tile_flat && IsTileFlat(tile)) return false; DiagDirection tdir = GetInclinedSlopeDirection(GetTileSlope(tile)); return (tdir == dir || tdir == ReverseDiagDir(dir)) && IsPossibleLockLocation(tile); } /** * Determine if a player could possibly build a ship lock that would cover this tile. * * @param bridge_tile The tile to possibly outrule a bridge position * @param bridge_dir The bridge direction * @return true if a player could possibly build a ship lock on this tile. * @see GrowTownWithBridge */ static bool IsPossibleLockLocationOnTownBridgeTile(const TileIndex bridge_tile, const DiagDirection bridge_dir) { const DiagDirection dir_side = ChangeDiagDir(bridge_dir, DIAGDIRDIFF_90LEFT); const TileIndexDiff delta_side = TileOffsByDiagDir(dir_side); if (IsValidTile(bridge_tile) && IsPossibleLockLocationOnDiagDir(bridge_tile, bridge_dir, true) && IsWaterTile(bridge_tile) || IsValidTile(bridge_tile + delta_side) && IsPossibleLockLocationOnDiagDir(bridge_tile + delta_side, dir_side, true) && IsWaterTile(bridge_tile + delta_side) || IsValidTile(bridge_tile - delta_side) && IsPossibleLockLocationOnDiagDir(bridge_tile - delta_side, ReverseDiagDir(dir_side), true) && IsWaterTile(bridge_tile - delta_side)) { return true; } return false; }