From 6fb525e90616fc7fafcf576d88f16995dc026e76 Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Fri, 18 Sep 2026 15:10:26 -0400 Subject: [PATCH] Close #27126: Refactor PATH_ADDITION_FLAG_* to enum class + FlagHolder (#27149) --- .../actions/cheats/CheatSetAction.cpp | 2 +- .../footpath/FootpathAdditionPlaceAction.cpp | 12 ++++---- .../actions/footpath/FootpathPlaceAction.cpp | 4 +-- src/openrct2/entity/Guest.cpp | 16 +++++----- src/openrct2/entity/JumpingFountain.cpp | 7 +++-- src/openrct2/entity/Staff.cpp | 4 +-- src/openrct2/object/PathAdditionEntry.h | 16 ++-------- src/openrct2/object/PathAdditionFlags.h | 29 +++++++++++++++++++ src/openrct2/object/PathAdditionObject.cpp | 22 +++++++------- .../paint/tile_element/Paint.PathAddition.cpp | 2 +- .../bindings/world/ScTileElement.cpp | 2 +- src/openrct2/world/Scenery.cpp | 4 +-- 12 files changed, 69 insertions(+), 51 deletions(-) create mode 100644 src/openrct2/object/PathAdditionFlags.h diff --git a/src/openrct2/actions/cheats/CheatSetAction.cpp b/src/openrct2/actions/cheats/CheatSetAction.cpp index caf94687b3..c50ccb6f49 100644 --- a/src/openrct2/actions/cheats/CheatSetAction.cpp +++ b/src/openrct2/actions/cheats/CheatSetAction.cpp @@ -514,7 +514,7 @@ namespace OpenRCT2::GameActions continue; auto* pathAdditionEntry = path->getAdditionEntry(); - if (pathAdditionEntry != nullptr && pathAdditionEntry->flags & PATH_ADDITION_FLAG_IS_BIN) + if (pathAdditionEntry != nullptr && pathAdditionEntry->flags.has(PathAdditionFlag::isBin)) path->setAdditionStatus(0xFF); } while (TileElementIteratorNext(&it)); diff --git a/src/openrct2/actions/footpath/FootpathAdditionPlaceAction.cpp b/src/openrct2/actions/footpath/FootpathAdditionPlaceAction.cpp index 322139cea8..2bb698c527 100644 --- a/src/openrct2/actions/footpath/FootpathAdditionPlaceAction.cpp +++ b/src/openrct2/actions/footpath/FootpathAdditionPlaceAction.cpp @@ -100,25 +100,25 @@ namespace OpenRCT2::GameActions LOG_ERROR("Unknown footpath addition entry for entryIndex %d", _entryIndex); return Result(Status::invalidParameters, STR_CANT_POSITION_THIS_HERE, STR_UNKNOWN_OBJECT_TYPE); } - uint16_t sceneryFlags = pathAdditionEntry->flags; + PathAdditionFlags sceneryFlags = pathAdditionEntry->flags; - if ((sceneryFlags & PATH_ADDITION_FLAG_DONT_ALLOW_ON_SLOPE) && pathElement->isSloped()) + if (sceneryFlags.has(PathAdditionFlag::dontAllowOnSlope) && pathElement->isSloped()) { return Result(Status::invalidParameters, STR_CANT_POSITION_THIS_HERE, STR_CANT_BUILD_THIS_ON_SLOPED_FOOTPATH); } - if ((sceneryFlags & PATH_ADDITION_FLAG_DONT_ALLOW_ON_QUEUE) && pathElement->isQueue()) + if (sceneryFlags.has(PathAdditionFlag::dontAllowOnQueue) && pathElement->isQueue()) { return Result(Status::invalidParameters, STR_CANT_POSITION_THIS_HERE, STR_CANNOT_PLACE_THESE_ON_QUEUE_LINE_AREA); } - if (!(sceneryFlags & (PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_WATER | PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_SNOW)) + if (!sceneryFlags.hasAny(PathAdditionFlag::jumpingFountainWater, PathAdditionFlag::jumpingFountainSnow) && (pathElement->getEdges()) == 0x0F) { return Result(Status::invalidParameters, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BE_PLACED_ON_PATH_EDGES); } - if ((sceneryFlags & PATH_ADDITION_FLAG_IS_QUEUE_SCREEN) && !pathElement->isQueue()) + if (sceneryFlags.has(PathAdditionFlag::isQueueScreen) && !pathElement->isQueue()) { return Result(Status::invalidParameters, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_PLACE_THESE_ON_QUEUE_AREA); } @@ -180,7 +180,7 @@ namespace OpenRCT2::GameActions pathElement->setAdditionEntryIndex(_entryIndex); pathElement->setIsBroken(false); - if (pathAdditionEntry->flags & PATH_ADDITION_FLAG_IS_BIN) + if (pathAdditionEntry->flags.has(PathAdditionFlag::isBin)) { pathElement->setAdditionStatus(255); } diff --git a/src/openrct2/actions/footpath/FootpathPlaceAction.cpp b/src/openrct2/actions/footpath/FootpathPlaceAction.cpp index c9f4fe186f..e18245fc04 100644 --- a/src/openrct2/actions/footpath/FootpathPlaceAction.cpp +++ b/src/openrct2/actions/footpath/FootpathPlaceAction.cpp @@ -258,7 +258,7 @@ namespace OpenRCT2::GameActions if (_constructFlags & PathConstructFlag::IsQueue) { // remove any addition that isn't a TV or a lamp - if ((elem->flags & PATH_ADDITION_FLAG_IS_QUEUE_SCREEN) == 0 && (elem->flags & PATH_ADDITION_FLAG_LAMP) == 0) + if (!elem->flags.hasAny(PathAdditionFlag::isQueueScreen, PathAdditionFlag::lamp)) { pathElement->setIsBroken(false); pathElement->setAddition(0); @@ -267,7 +267,7 @@ namespace OpenRCT2::GameActions else { // remove all TVs - if ((elem->flags & PATH_ADDITION_FLAG_IS_QUEUE_SCREEN) != 0) + if (elem->flags.has(PathAdditionFlag::isQueueScreen)) { pathElement->setIsBroken(false); pathElement->setAddition(0); diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index a0b4e19890..e6530acc4e 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -1120,7 +1120,7 @@ namespace OpenRCT2 if (pathElement->hasAddition() && !pathElement->additionIsGhost()) { auto* pathAddEntry = pathElement->getAdditionEntry(); - if (pathAddEntry != nullptr && (pathAddEntry->flags & PATH_ADDITION_FLAG_IS_QUEUE_SCREEN)) + if (pathAddEntry != nullptr && pathAddEntry->flags.has(PathAdditionFlag::isQueueScreen)) { found = true; } @@ -2909,8 +2909,8 @@ namespace OpenRCT2 if (tileElement->asPath()->additionIsGhost()) break; - if (pathAddEntry->flags - & (PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_WATER | PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_SNOW)) + if (pathAddEntry->flags.hasAny( + PathAdditionFlag::jumpingFountainWater, PathAdditionFlag::jumpingFountainSnow)) { num_fountains++; break; @@ -5556,7 +5556,7 @@ namespace OpenRCT2 return; } - if ((pathAddEntry->flags & PATH_ADDITION_FLAG_IS_BENCH)) + if (pathAddEntry->flags.has(PathAdditionFlag::isBench)) positions_free = 9; } } @@ -5939,7 +5939,7 @@ namespace OpenRCT2 break; auto* pathAddEntry = pathElement->getAdditionEntry(); - if (!(pathAddEntry->flags & PATH_ADDITION_FLAG_IS_BIN)) + if (!pathAddEntry->flags.has(PathAdditionFlag::isBin)) break; if (pathElement->isBroken()) @@ -6051,7 +6051,7 @@ namespace OpenRCT2 continue; auto* pathAddEntry = pathElement->getAdditionEntry(); - if (pathAddEntry == nullptr || !(pathAddEntry->flags & PATH_ADDITION_FLAG_IS_BENCH)) + if (pathAddEntry == nullptr || !pathAddEntry->flags.has(PathAdditionFlag::isBench)) continue; if (pathElement->isBroken()) @@ -6140,7 +6140,7 @@ namespace OpenRCT2 continue; auto* pathAddEntry = pathElement->getAdditionEntry(); - if (pathAddEntry == nullptr || !(pathAddEntry->flags & PATH_ADDITION_FLAG_IS_BIN)) + if (pathAddEntry == nullptr || !pathAddEntry->flags.has(PathAdditionFlag::isBin)) continue; if (pathElement->isBroken()) @@ -6218,7 +6218,7 @@ namespace OpenRCT2 continue; auto* pathAddEntry = pathElement->getAdditionEntry(); - if (pathAddEntry == nullptr || !(pathAddEntry->flags & PATH_ADDITION_FLAG_BREAKABLE)) + if (pathAddEntry == nullptr || !pathAddEntry->flags.has(PathAdditionFlag::breakable)) continue; if (pathElement->isBroken()) diff --git a/src/openrct2/entity/JumpingFountain.cpp b/src/openrct2/entity/JumpingFountain.cpp index 65424f5d9f..43fbf85cd2 100644 --- a/src/openrct2/entity/JumpingFountain.cpp +++ b/src/openrct2/entity/JumpingFountain.cpp @@ -252,8 +252,9 @@ namespace OpenRCT2 bool JumpingFountain::isJumpingFountain(const JumpingFountainType newType, const CoordsXYZ& newLoc) { - const int32_t pathAdditionFlagMask = newType == JumpingFountainType::snow ? PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_SNOW - : PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_WATER; + const PathAdditionFlag jumpingFountainFlag = newType == JumpingFountainType::snow + ? PathAdditionFlag::jumpingFountainSnow + : PathAdditionFlag::jumpingFountainWater; TileElement* tileElement = MapGetFirstElementAt(newLoc); if (tileElement == nullptr) @@ -270,7 +271,7 @@ namespace OpenRCT2 continue; auto* pathAdditionEntry = tileElement->asPath()->getAdditionEntry(); - if (pathAdditionEntry != nullptr && pathAdditionEntry->flags & pathAdditionFlagMask) + if (pathAdditionEntry != nullptr && pathAdditionEntry->flags.has(jumpingFountainFlag)) { return true; } diff --git a/src/openrct2/entity/Staff.cpp b/src/openrct2/entity/Staff.cpp index 8a520b3f63..732d73db52 100644 --- a/src/openrct2/entity/Staff.cpp +++ b/src/openrct2/entity/Staff.cpp @@ -1204,7 +1204,7 @@ namespace OpenRCT2 } auto* pathAddEntry = tile_element->asPath()->getAdditionEntry(); - if (!(pathAddEntry->flags & PATH_ADDITION_FLAG_IS_BIN) || tile_element->asPath()->isBroken() + if (!pathAddEntry->flags.has(PathAdditionFlag::isBin) || tile_element->asPath()->isBroken() || tile_element->asPath()->additionIsGhost()) { stateReset(); @@ -1574,7 +1574,7 @@ namespace OpenRCT2 if (pathAddEntry == nullptr) return false; - if (!(pathAddEntry->flags & PATH_ADDITION_FLAG_IS_BIN)) + if (!pathAddEntry->flags.has(PathAdditionFlag::isBin)) return false; if (tileElement->asPath()->isBroken()) diff --git a/src/openrct2/object/PathAdditionEntry.h b/src/openrct2/object/PathAdditionEntry.h index 0a8af8a5aa..ac6dd3c564 100644 --- a/src/openrct2/object/PathAdditionEntry.h +++ b/src/openrct2/object/PathAdditionEntry.h @@ -11,6 +11,7 @@ #include "../core/Money.hpp" #include "../localisation/StringIdType.h" +#include "../object/PathAdditionFlags.h" #include "ObjectTypes.h" enum class CursorID : uint8_t; @@ -25,26 +26,13 @@ namespace OpenRCT2 jumpingFountain, }; - enum - { - PATH_ADDITION_FLAG_IS_BIN = 1 << 0, - PATH_ADDITION_FLAG_IS_BENCH = 1 << 1, - PATH_ADDITION_FLAG_BREAKABLE = 1 << 2, - PATH_ADDITION_FLAG_LAMP = 1 << 3, - PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_WATER = 1 << 4, - PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_SNOW = 1 << 5, - PATH_ADDITION_FLAG_DONT_ALLOW_ON_QUEUE = 1 << 6, - PATH_ADDITION_FLAG_DONT_ALLOW_ON_SLOPE = 1 << 7, - PATH_ADDITION_FLAG_IS_QUEUE_SCREEN = 1 << 8 - }; - struct PathAdditionEntry { static constexpr auto kObjectType = ObjectType::pathAdditions; StringId name; uint32_t image; - uint16_t flags; + PathAdditionFlags flags; PathAdditionDrawType draw_type; CursorID tool_id; money64 price; diff --git a/src/openrct2/object/PathAdditionFlags.h b/src/openrct2/object/PathAdditionFlags.h new file mode 100644 index 0000000000..882e567082 --- /dev/null +++ b/src/openrct2/object/PathAdditionFlags.h @@ -0,0 +1,29 @@ +/***************************************************************************** + * Copyright (c) 2014-2026 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "../core/FlagHolder.hpp" + +namespace OpenRCT2 +{ + enum class PathAdditionFlag + { + isBin = 0, + isBench = 1, + breakable = 2, + lamp = 3, + jumpingFountainWater = 4, + jumpingFountainSnow = 5, + dontAllowOnQueue = 6, + dontAllowOnSlope = 7, + isQueueScreen = 8 + }; + using PathAdditionFlags = FlagHolder; +} // namespace OpenRCT2 diff --git a/src/openrct2/object/PathAdditionObject.cpp b/src/openrct2/object/PathAdditionObject.cpp index ef7ab4261c..f0c7acd2e5 100644 --- a/src/openrct2/object/PathAdditionObject.cpp +++ b/src/openrct2/object/PathAdditionObject.cpp @@ -21,7 +21,7 @@ namespace OpenRCT2 void PathAdditionObject::ReadLegacy(IReadObjectContext* context, IStream* stream) { stream->Seek(6, STREAM_SEEK_CURRENT); - _legacyType.flags = stream->ReadValue(); + _legacyType.flags = stream->ReadValue(); _legacyType.draw_type = static_cast(stream->ReadValue()); _legacyType.tool_id = static_cast(stream->ReadValue()); _legacyType.price = stream->ReadValue(); @@ -103,18 +103,18 @@ namespace OpenRCT2 SetPrimarySceneryGroup(ObjectEntryDescriptor(Json::GetString(properties["sceneryGroup"]))); // clang-format off - _legacyType.flags = Json::GetFlags( + _legacyType.flags = Json::GetFlagHolder( properties, { - { "isBin", PATH_ADDITION_FLAG_IS_BIN, Json::FlagType::normal }, - { "isBench", PATH_ADDITION_FLAG_IS_BENCH, Json::FlagType::normal }, - { "isBreakable", PATH_ADDITION_FLAG_BREAKABLE, Json::FlagType::normal }, - { "isLamp", PATH_ADDITION_FLAG_LAMP, Json::FlagType::normal }, - { "isJumpingFountainWater", PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_WATER, Json::FlagType::normal }, - { "isJumpingFountainSnow", PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_SNOW, Json::FlagType::normal }, - { "isAllowedOnQueue", PATH_ADDITION_FLAG_DONT_ALLOW_ON_QUEUE, Json::FlagType::inverted }, - { "isAllowedOnSlope", PATH_ADDITION_FLAG_DONT_ALLOW_ON_SLOPE, Json::FlagType::inverted }, - { "isTelevision", PATH_ADDITION_FLAG_IS_QUEUE_SCREEN, Json::FlagType::normal }, + { "isBin", PathAdditionFlag::isBin, Json::FlagType::normal }, + { "isBench", PathAdditionFlag::isBench, Json::FlagType::normal }, + { "isBreakable", PathAdditionFlag::breakable, Json::FlagType::normal }, + { "isLamp", PathAdditionFlag::lamp, Json::FlagType::normal }, + { "isJumpingFountainWater", PathAdditionFlag::jumpingFountainWater, Json::FlagType::normal }, + { "isJumpingFountainSnow", PathAdditionFlag::jumpingFountainSnow, Json::FlagType::normal }, + { "isAllowedOnQueue", PathAdditionFlag::dontAllowOnQueue, Json::FlagType::inverted }, + { "isAllowedOnSlope", PathAdditionFlag::dontAllowOnSlope, Json::FlagType::inverted }, + { "isTelevision", PathAdditionFlag::isQueueScreen, Json::FlagType::normal }, }); // clang-format on } diff --git a/src/openrct2/paint/tile_element/Paint.PathAddition.cpp b/src/openrct2/paint/tile_element/Paint.PathAddition.cpp index 06eb7eba97..e9b15a67e5 100644 --- a/src/openrct2/paint/tile_element/Paint.PathAddition.cpp +++ b/src/openrct2/paint/tile_element/Paint.PathAddition.cpp @@ -278,7 +278,7 @@ void PaintLampLightEffects(PaintSession& session, const PathElement& pathEl, uin if (pathEl.hasAddition() && !(pathEl.isBroken())) { auto* pathAddEntry = pathEl.getAdditionEntry(); - if (pathAddEntry != nullptr && pathAddEntry->flags & PATH_ADDITION_FLAG_LAMP) + if (pathAddEntry != nullptr && pathAddEntry->flags.has(PathAdditionFlag::lamp)) { if (!(pathEl.getEdges() & EDGE_NE)) { diff --git a/src/openrct2/scripting/bindings/world/ScTileElement.cpp b/src/openrct2/scripting/bindings/world/ScTileElement.cpp index 2803d4d870..d38955c468 100644 --- a/src/openrct2/scripting/bindings/world/ScTileElement.cpp +++ b/src/openrct2/scripting/bindings/world/ScTileElement.cpp @@ -2092,7 +2092,7 @@ namespace OpenRCT2::Scripting return JS_NULL; const auto* additionEntry = el->getAdditionEntry(); - if (additionEntry == nullptr || !(additionEntry->flags & PATH_ADDITION_FLAG_IS_BIN)) + if (additionEntry == nullptr || !additionEntry->flags.has(PathAdditionFlag::isBin)) return JS_NULL; // Each path edge has a 2-bit slot (0 = full, 3 = empty); a bin is only "full" once a diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index 1f3d7b2010..9036872469 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -145,11 +145,11 @@ void SceneryUpdateTile(const CoordsXY& sceneryPos) auto* pathAddEntry = tileElement->asPath()->getAdditionEntry(); if (pathAddEntry != nullptr) { - if (pathAddEntry->flags & PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_WATER) + if (pathAddEntry->flags.has(PathAdditionFlag::jumpingFountainWater)) { JumpingFountain::startAnimation(JumpingFountainType::water, sceneryPos, tileElement); } - else if (pathAddEntry->flags & PATH_ADDITION_FLAG_JUMPING_FOUNTAIN_SNOW) + else if (pathAddEntry->flags.has(PathAdditionFlag::jumpingFountainSnow)) { JumpingFountain::startAnimation(JumpingFountainType::snow, sceneryPos, tileElement); }