diff --git a/src/landscape.cpp b/src/landscape.cpp index 478bf6964d..6e02264f79 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -460,7 +460,7 @@ void DrawFoundation(TileInfo *ti, Foundation f) if (!IsNonContinuousFoundation(f)) { /* Lower part of foundation */ static constexpr SpriteBounds bounds{{}, {TILE_SIZE, TILE_SIZE, TILE_HEIGHT - 1}, {}}; - AddSortableSpriteToDraw(leveled_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, *ti, bounds); + AddSortableSpriteToDraw(leveled_base + RemoveSteepSlope(ti->tileh), PAL_NONE, *ti, bounds); } Corner highest_corner = GetHighestSlopeCorner(ti->tileh); diff --git a/src/slope_func.h b/src/slope_func.h index eaa3d0c762..38695c65d9 100644 --- a/src/slope_func.h +++ b/src/slope_func.h @@ -38,6 +38,16 @@ static constexpr inline bool IsSteepSlope(Slope s) return (s & SLOPE_STEEP) != 0; } +/** + * Removes a steep flag from a slope + * @param s A #Slope to get modified version of. + * @return The slope s without the steep flag. + */ +static constexpr Slope RemoveSteepSlope(Slope s) +{ + return s & ~SLOPE_STEEP; +} + /** * Checks for non-continuous slope on halftile foundations. * diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 832f9f36ee..a3d81bd2f8 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1074,9 +1074,8 @@ static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir) if (Chance16(1, 8)) { CommandCost res = CMD_ERROR; if (!_generating_world && Chance16(1, 10)) { - /* Note: Do not replace "^ SLOPE_ELEVATED" with ComplementSlope(). The slope might be steep. */ res = ExtractCommandCost(Command::Do({DoCommandFlag::Execute, DoCommandFlag::Auto, DoCommandFlag::NoWater}, - tile, Chance16(1, 16) ? cur_slope : cur_slope ^ SLOPE_ELEVATED, false)); + tile, Chance16(1, 16) ? cur_slope : ComplementSlope(RemoveSteepSlope(RemoveHalftileSlope(cur_slope))), false)); } if (res.Failed() && Chance16(1, 3)) { /* We can consider building on the slope, though. */ diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 240cb2d69e..1681605dc3 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -1318,7 +1318,7 @@ void TileLoop_Water(TileIndex tile) auto [slope_dest, z_dest] = GetFoundationSlope(dest); if (z_dest > 0) continue; - if (!_flood_from_dirs[slope_dest & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP].Test(ReverseDir(dir))) continue; + if (!_flood_from_dirs[RemoveSteepSlope(RemoveHalftileSlope(slope_dest))].Test(ReverseDir(dir))) continue; DoFloodTile(dest); } @@ -1327,7 +1327,7 @@ void TileLoop_Water(TileIndex tile) } case FloodingBehaviour::DryOut: { - Slope slope_here = std::get(GetFoundationSlope(tile)) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP; + Slope slope_here = RemoveHalftileSlope(RemoveSteepSlope(std::get(GetFoundationSlope(tile)))); for (Direction dir : _flood_from_dirs[slope_here]) { TileIndex dest = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(dir)); /* Contrary to flooding, drying up does consider TileType::Void tiles. */ @@ -1365,9 +1365,9 @@ void ConvertGroundTilesIntoWaterTiles() break; default: - for (Direction dir : _flood_from_dirs[slope & ~SLOPE_STEEP]) { + for (Direction dir : _flood_from_dirs[RemoveSteepSlope(slope)]) { TileIndex dest = TileAddByDir(tile, dir); - Slope slope_dest = GetTileSlope(dest) & ~SLOPE_STEEP; + Slope slope_dest = RemoveSteepSlope(GetTileSlope(dest)); if (slope_dest == SLOPE_FLAT || IsSlopeWithOneCornerRaised(slope_dest) || IsTileType(dest, TileType::Void)) { MakeShore(tile); break;