From cc57ac0eff1fbff6060b4cbda5cd6ea08a20124c Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 17 Aug 2023 14:40:07 +0100 Subject: [PATCH] Add pre-check to auxiliary tile loop flooding test --- src/landscape.cpp | 2 +- src/water_map.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/landscape.cpp b/src/landscape.cpp index cb1b9f3890..65384b6fe0 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -887,7 +887,7 @@ void RunAuxiliaryTileLoop() TileIndex tile = _aux_tileloop_tile; while (count--) { - if (!IsNonFloodingWaterTile(tile)) { + if (IsFloodingTypeTile(tile) && !IsNonFloodingWaterTile(tile)) { FloodingBehaviour fb = GetFloodingBehaviour(tile); if (fb != FLOOD_NONE) TileLoopWaterFlooding(fb, tile); } diff --git a/src/water_map.h b/src/water_map.h index 9674d59916..eaba56ebe3 100644 --- a/src/water_map.h +++ b/src/water_map.h @@ -524,4 +524,14 @@ static inline bool IsNonFloodingWaterTile(TileIndex t) return IsTileType(t, MP_WATER) && HasBit(_m[t].m3, 0); } +/** + * Checks whether the tile type could have flooding behaviour + * @return true iff the tile type is one where GetFloodingBehaviour could return a value other than FLOOD_NONE. + */ +static inline bool IsFloodingTypeTile(TileIndex t) +{ + static const uint16 mask = (1 << MP_WATER) | (1 << MP_STATION) | (1 << MP_INDUSTRY) | (1 << MP_RAILWAY) | (1 << MP_TREES) | (1 << MP_OBJECT) | (1 << MP_VOID); + return HasBit(mask, GetTileType(t)); +} + #endif /* WATER_MAP_H */