From 11bf58dceb588ec4e1d04fa2e247b55979cbb0bc Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 8 Aug 2026 10:55:06 +0200 Subject: [PATCH] Refactor CLEARABLE_ITEMS into enum class+FlagHolder --- src/openrct2-ui/windows/ClearScenery.cpp | 12 ++++++------ src/openrct2/actions/terraform/ClearAction.cpp | 16 ++++++++-------- src/openrct2/actions/terraform/ClearAction.h | 18 +++++++++--------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/openrct2-ui/windows/ClearScenery.cpp b/src/openrct2-ui/windows/ClearScenery.cpp index a1e4335348..576feaf34d 100644 --- a/src/openrct2-ui/windows/ClearScenery.cpp +++ b/src/openrct2-ui/windows/ClearScenery.cpp @@ -226,18 +226,18 @@ namespace OpenRCT2::Ui::Windows { auto range = MapRange(gMapSelectPositionA.x, gMapSelectPositionA.y, gMapSelectPositionB.x, gMapSelectPositionB.y); - GameActions::ClearableItems itemsToClear = 0; + GameActions::ClearableItems itemsToClear{}; if (_clearSmallScenery) - itemsToClear |= GameActions::CLEARABLE_ITEMS::kScenerySmall; + itemsToClear.set(GameActions::ClearableItem::smallScenery); if (_clearLargeScenery) - itemsToClear |= GameActions::CLEARABLE_ITEMS::kSceneryLarge; + itemsToClear.set(GameActions::ClearableItem::largeScenery); if (_clearFootpath) - itemsToClear |= GameActions::CLEARABLE_ITEMS::kSceneryFootpath; + itemsToClear.set(GameActions::ClearableItem::footpaths); if (_clearWalls) - itemsToClear |= GameActions::CLEARABLE_ITEMS::kSceneryWall; + itemsToClear.set(GameActions::ClearableItem::walls); if (_clearFootpathAdditions) - itemsToClear |= GameActions::CLEARABLE_ITEMS::kPathAddition; + itemsToClear.set(GameActions::ClearableItem::pathAdditions); return GameActions::ClearAction(range, itemsToClear); } diff --git a/src/openrct2/actions/terraform/ClearAction.cpp b/src/openrct2/actions/terraform/ClearAction.cpp index 00844d0b78..c02f1cefca 100644 --- a/src/openrct2/actions/terraform/ClearAction.cpp +++ b/src/openrct2/actions/terraform/ClearAction.cpp @@ -36,7 +36,7 @@ namespace OpenRCT2::GameActions void ClearAction::AcceptParameters(GameActionParameterVisitor& visitor) { visitor.Visit(_range); - visitor.Visit("itemsToClear", _itemsToClear); + visitor.Visit("itemsToClear", _itemsToClear.holder); } uint16_t ClearAction::GetActionFlags() const @@ -48,7 +48,7 @@ namespace OpenRCT2::GameActions { GameAction::Serialise(stream); - stream << DS_TAG(_range) << DS_TAG(_itemsToClear); + stream << DS_TAG(_range) << DS_TAG(_itemsToClear.holder); } Result ClearAction::Query(GameState_t& gameState, Park::ParkData& park) const @@ -106,7 +106,7 @@ namespace OpenRCT2::GameActions } } - if (_itemsToClear & CLEARABLE_ITEMS::kSceneryLarge) + if (_itemsToClear.has(ClearableItem::largeScenery)) { ResetClearLargeSceneryFlag(gameState); } @@ -141,7 +141,7 @@ namespace OpenRCT2::GameActions switch (tileElement->getType()) { case TileElementType::path: - if (_itemsToClear & CLEARABLE_ITEMS::kSceneryFootpath) + if (_itemsToClear.has(ClearableItem::footpaths)) { auto footpathRemoveAction = FootpathRemoveAction({ tilePos, tileElement->getBaseZ() }); footpathRemoveAction.SetFlags(GetFlags()); @@ -159,7 +159,7 @@ namespace OpenRCT2::GameActions totalCost += res.cost; } } - if (!tileEdited && _itemsToClear & CLEARABLE_ITEMS::kPathAddition) + if (!tileEdited && _itemsToClear.has(ClearableItem::pathAdditions)) { auto additionRemoveAction = FootpathAdditionRemoveAction({ tilePos, tileElement->getBaseZ() }); additionRemoveAction.SetFlags(GetFlags()); @@ -178,7 +178,7 @@ namespace OpenRCT2::GameActions } break; case TileElementType::smallScenery: - if (_itemsToClear & CLEARABLE_ITEMS::kScenerySmall) + if (_itemsToClear.has(ClearableItem::smallScenery)) { auto removeSceneryAction = SmallSceneryRemoveAction( { tilePos, tileElement->getBaseZ() }, tileElement->asSmallScenery()->GetSceneryQuadrant(), @@ -200,7 +200,7 @@ namespace OpenRCT2::GameActions } break; case TileElementType::wall: - if (_itemsToClear & CLEARABLE_ITEMS::kSceneryWall) + if (_itemsToClear.has(ClearableItem::walls)) { CoordsXYZD wallLocation = { tilePos, tileElement->getBaseZ(), tileElement->getDirection() }; auto wallRemoveAction = WallRemoveAction(wallLocation); @@ -221,7 +221,7 @@ namespace OpenRCT2::GameActions } break; case TileElementType::largeScenery: - if (_itemsToClear & CLEARABLE_ITEMS::kSceneryLarge) + if (_itemsToClear.has(ClearableItem::largeScenery)) { auto removeSceneryAction = LargeSceneryRemoveAction( { tilePos, tileElement->getBaseZ(), tileElement->getDirection() }, diff --git a/src/openrct2/actions/terraform/ClearAction.h b/src/openrct2/actions/terraform/ClearAction.h index 98d26e8b7a..191ffbd6ac 100644 --- a/src/openrct2/actions/terraform/ClearAction.h +++ b/src/openrct2/actions/terraform/ClearAction.h @@ -9,20 +9,20 @@ #pragma once +#include "../../core/FlagHolder.hpp" #include "../GameAction.hpp" namespace OpenRCT2::GameActions { - using ClearableItems = uint8_t; - - namespace CLEARABLE_ITEMS + enum class ClearableItem : uint8_t { - constexpr ClearableItems kScenerySmall = 1 << 0; - constexpr ClearableItems kSceneryLarge = 1 << 1; - constexpr ClearableItems kSceneryFootpath = 1 << 2; - constexpr ClearableItems kSceneryWall = 1 << 3; - constexpr ClearableItems kPathAddition = 1 << 4; - } // namespace CLEARABLE_ITEMS + smallScenery, + largeScenery, + footpaths, + walls, + pathAdditions, + }; + using ClearableItems = FlagHolder; class ClearAction final : public GameActionBase {