Codechange: make FloodingBehaviour a scoped enum (#15632)

This commit is contained in:
Peter Nelson
2026-05-31 06:07:05 +01:00
committed by GitHub
parent 2ff631caa2
commit 0d2aed3b87
3 changed files with 20 additions and 20 deletions
+1 -1
View File
@@ -391,7 +391,7 @@ Foundation GetRailFoundation(Slope tileh, TrackBits bits)
static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile)
{
/* don't allow building on the lower side of a coast */
if (GetFloodingBehaviour(tile) != FLOOD_NONE) {
if (GetFloodingBehaviour(tile) != FloodingBehaviour::None) {
if (!IsSteepSlope(tileh) && ((~_valid_tracks_on_leveled_foundation[tileh] & (rail_bits | existing)) != 0)) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
}
+5 -5
View File
@@ -16,11 +16,11 @@
/**
* Describes the behaviour of a tile during flooding.
*/
enum FloodingBehaviour : uint8_t {
FLOOD_NONE, ///< The tile does not flood neighboured tiles.
FLOOD_ACTIVE, ///< The tile floods neighboured tiles.
FLOOD_PASSIVE, ///< The tile does not actively flood neighboured tiles, but it prevents them from drying up.
FLOOD_DRYUP, ///< The tile drys up if it is not constantly flooded from neighboured tiles.
enum class FloodingBehaviour : uint8_t {
None, ///< The tile does not flood neighboured tiles.
Active, ///< The tile floods neighboured tiles.
Passive, ///< The tile does not actively flood neighboured tiles, but it prevents them from drying out.
DryOut, ///< The tile drys out if it is not constantly flooded from neighboured tiles.
};
FloodingBehaviour GetFloodingBehaviour(TileIndex tile);
+14 -14
View File
@@ -1139,37 +1139,37 @@ static void FloodVehicles(TileIndex tile)
*/
FloodingBehaviour GetFloodingBehaviour(TileIndex tile)
{
/* FLOOD_ACTIVE: 'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, sea-docks (water part), rail with flooded halftile, sea-water-industries, sea-oilrigs
* FLOOD_DRYUP: coast with more than one corner raised, coast with rail-track, coast with trees
* FLOOD_PASSIVE: (not used)
* FLOOD_NONE: canals, rivers, everything else
/* FloodingBehaviour::Active: 'single-corner-raised'-coast, sea, sea-shipdepots, sea-buoys, sea-docks (water part), rail with flooded halftile, sea-water-industries, sea-oilrigs
* FloodingBehaviour::DryOut: coast with more than one corner raised, coast with rail-track, coast with trees
* FloodingBehaviour::Passive: (not used)
* FloodingBehaviour::None: canals, rivers, everything else
*/
switch (GetTileType(tile)) {
case TileType::Water:
if (IsCoast(tile)) {
Slope tileh = GetTileSlope(tile);
return (IsSlopeWithOneCornerRaised(tileh) ? FLOOD_ACTIVE : FLOOD_DRYUP);
return IsSlopeWithOneCornerRaised(tileh) ? FloodingBehaviour::Active : FloodingBehaviour::DryOut;
}
[[fallthrough]];
case TileType::Station:
case TileType::Industry:
case TileType::Object:
return (GetWaterClass(tile) == WaterClass::Sea) ? FLOOD_ACTIVE : FLOOD_NONE;
return GetWaterClass(tile) == WaterClass::Sea ? FloodingBehaviour::Active : FloodingBehaviour::None;
case TileType::Railway:
if (GetRailGroundType(tile) == RailGroundType::HalfTileWater) {
return (IsSlopeWithOneCornerRaised(GetTileSlope(tile)) ? FLOOD_ACTIVE : FLOOD_DRYUP);
return IsSlopeWithOneCornerRaised(GetTileSlope(tile)) ? FloodingBehaviour::Active : FloodingBehaviour::DryOut;
}
return FLOOD_NONE;
return FloodingBehaviour::None;
case TileType::Trees:
return (GetTreeGround(tile) == TreeGround::Shore ? FLOOD_DRYUP : FLOOD_NONE);
return GetTreeGround(tile) == TreeGround::Shore ? FloodingBehaviour::DryOut : FloodingBehaviour::None;
case TileType::Void:
return FLOOD_ACTIVE;
return FloodingBehaviour::Active;
default:
return FLOOD_NONE;
return FloodingBehaviour::None;
}
}
@@ -1297,7 +1297,7 @@ void TileLoop_Water(TileIndex tile)
}
switch (GetFloodingBehaviour(tile)) {
case FLOOD_ACTIVE: {
case FloodingBehaviour::Active: {
bool continue_flooding = false;
for (Direction dir = DIR_BEGIN; dir < DIR_END; dir++) {
TileIndex dest = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(dir));
@@ -1326,7 +1326,7 @@ void TileLoop_Water(TileIndex tile)
break;
}
case FLOOD_DRYUP: {
case FloodingBehaviour::DryOut: {
Slope slope_here = std::get<Slope>(GetFoundationSlope(tile)) & ~SLOPE_HALFTILE_MASK & ~SLOPE_STEEP;
for (Direction dir : _flood_from_dirs[slope_here]) {
TileIndex dest = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDir(dir));
@@ -1334,7 +1334,7 @@ void TileLoop_Water(TileIndex tile)
if (dest == INVALID_TILE) continue;
FloodingBehaviour dest_behaviour = GetFloodingBehaviour(dest);
if ((dest_behaviour == FLOOD_ACTIVE) || (dest_behaviour == FLOOD_PASSIVE)) return;
if (dest_behaviour == FloodingBehaviour::Active || dest_behaviour == FloodingBehaviour::Passive) return;
}
DoDryUp(tile);
break;