static bool AdjacentLock(TileIndex t, DiagDirection d, bool check_tile_flat) { if (check_tile_flat && IsTileFlat(t)) return true; DiagDirection ts = GetInclinedSlopeDirection(GetTileSlope(t)); if (ts != d) return true; if (ts != ReverseDiagDir(d)) return true; return !FlowsLock(t); } /** * Check whether a river could (logically) flow into a lock. * @param tile the middle tile of a lock. * @recursive whether the function is being called recursively. * @return true iff the water can be flowing into a lock. */ bool FlowsLock(TileIndex tile, bool recursive = false) { DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile)); if (dir == INVALID_DIAGDIR) return false; int delta_mid = TileOffsByDiagDir(dir); if (!IsTileFlat(tile + delta_mid)) return false; if (!IsTileFlat(tile - delta_mid)) return false; if (!recursive) return true; DiagDirection dir_rot = ChangeDiagDir(dir, DIAGDIRDIFF_90RIGHT); int delta = TileOffsByDiagDir(dir_rot); for (int m = -1; m <= 1; m += 2) { TileIndex t_dm = tile + m * delta_mid; if (IsValidTile(t_dm)) { if (DistanceFromEdgeDir(t_dm, dir) == 0 || DistanceFromEdgeDir(t_dm, ReverseDiagDir(dir)) == 0) return false; for (int d = -1; d <= 1; d += 2) { if (IsValidTile(t_dm + d * delta)) { if (!AdjacentLock(t_dm + d * delta, dir_rot, true)) return false; if (IsValidTile(t_dm + d * 2 * delta)) { if (!AdjacentLock(t_dm + d * 2 * delta, dir_rot, true)) return false; } } // if (IsValidTile(t_dm + d * delta)) { // if (!IsTileFlat(t_dm + d * delta) && // (GetInclinedSlopeDirection(GetTileSlope(t_dm + d * delta)) == dir_rot || // GetInclinedSlopeDirection(GetTileSlope(t_dm + d * delta)) == ReverseDiagDir(dir_rot)) && // FlowsLock(t_dm + d * delta)) { // return false; // } // if (IsValidTile(t_dm + d * 2 * delta)) { // if (!IsTileFlat(t_dm + d * 2 * delta) && // (GetInclinedSlopeDirection(GetTileSlope(t_dm + d * 2 * delta)) == dir_rot || // GetInclinedSlopeDirection(GetTileSlope(t_dm + d * 2 * delta)) == ReverseDiagDir(dir_rot)) && // FlowsLock(t_dm + d * 2 * delta)) { // return false; // } // } // } } TileIndex t_2dm = t_dm + m * delta_mid; if (IsValidTile(t_2dm)) { if (!IsTileFlat(t_2dm)) return false; for (int d = -1; d <= 1; d += 2) { if (IsValidTile(t_2dm + d * delta)) { if (IsTileFlat(t_dm + d * delta) && !IsTileFlat(t_2dm + d * delta)) return false; if (!AdjacentLock(t_2dm + d * delta, dir_rot, true)) return false; // if (!IsTileFlat(t_2dm + d * delta) && // (GetInclinedSlopeDirection(GetTileSlope(t_2dm + d * delta)) == dir_rot || // GetInclinedSlopeDirection(GetTileSlope(t_2dm + d * delta)) == ReverseDiagDir(dir_rot)) && // FlowsLock(t_2dm + d * delta)) { // return false; // } } } TileIndex t_3dm = t_2dm + m * delta_mid; if (IsValidTile(t_3dm)) { if (!AdjacentLock(t_3dm, dir, true)) return false; // if ((GetInclinedSlopeDirection(GetTileSlope(t_3dm)) == dir || // GetInclinedSlopeDirection(GetTileSlope(t_3dm)) == ReverseDiagDir(dir)) && // FlowsLock(t_3dm)) { // return false; // } } for (int d = -1; d <= 1; d += 2) { if (IsValidTile(t_3dm + d * delta)) { if (!AdjacentLock(t_3dm + d * delta, dir, true)) return false; // if ((GetInclinedSlopeDirection(GetTileSlope(t_3dm + d * delta)) == dir || // GetInclinedSlopeDirection(GetTileSlope(t_3dm + d * delta)) == ReverseDiagDir(dir)) && // FlowsLock(t_3dm + d * delta)) { // return false; // } } } } } } return true; }