mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-15 15:19:52 +00:00
Codechange: Use more helper functions for slopes. (#15722)
This commit is contained in:
committed by
GitHub
parent
8ca99f96ee
commit
dc87cd3d7a
+1
-1
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
+1
-2
@@ -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<Commands::TerraformLand>::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. */
|
||||
|
||||
+4
-4
@@ -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<Slope>(GetFoundationSlope(tile)) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP;
|
||||
Slope slope_here = RemoveHalftileSlope(RemoveSteepSlope(std::get<Slope>(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;
|
||||
|
||||
Reference in New Issue
Block a user