diff --git a/src/openrct2-ui/input/Shortcuts.cpp b/src/openrct2-ui/input/Shortcuts.cpp index 5228a9e4f2..aa65b1a1d3 100644 --- a/src/openrct2-ui/input/Shortcuts.cpp +++ b/src/openrct2-ui/input/Shortcuts.cpp @@ -609,7 +609,7 @@ static void ShortcutDecreaseElementHeight() static void ShortcutToggleClearanceChecks() { - auto cheatSetAction = CheatSetAction( + auto cheatSetAction = GameActions::CheatSetAction( CheatType::DisableClearanceChecks, getGameState().cheats.disableClearanceChecks ? 0 : 1); GameActions::Execute(&cheatSetAction); } diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 6e1e733d8d..da28743d22 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -649,7 +649,7 @@ namespace OpenRCT2::Ui { if (tileElement2->GetType() == TileElementType::Path && tileElement2->GetBaseZ() == z) { - auto action = FootpathRemoveAction({ mapCoords, z }); + auto action = GameActions::FootpathRemoveAction({ mapCoords, z }); GameActions::Execute(&action); break; } diff --git a/src/openrct2-ui/windows/Banner.cpp b/src/openrct2-ui/windows/Banner.cpp index 6c0cef0de6..e89363fda8 100644 --- a/src/openrct2-ui/windows/Banner.cpp +++ b/src/openrct2-ui/windows/Banner.cpp @@ -202,7 +202,7 @@ namespace OpenRCT2::Ui::Windows if (bannerElement == nullptr) break; - auto bannerRemoveAction = BannerRemoveAction( + auto bannerRemoveAction = GameActions::BannerRemoveAction( { banner->position.ToCoordsXY(), bannerElement->GetBaseZ(), bannerElement->GetPosition() }); GameActions::Execute(&bannerRemoveAction); break; @@ -214,8 +214,8 @@ namespace OpenRCT2::Ui::Windows case WIDX_BANNER_NO_ENTRY: { TextinputCancel(); - auto bannerSetStyle = BannerSetStyleAction( - BannerSetStyleType::NoEntry, GetBannerIndex(), !banner->flags.has(BannerFlag::noEntry)); + auto bannerSetStyle = GameActions::BannerSetStyleAction( + GameActions::BannerSetStyleType::NoEntry, GetBannerIndex(), !banner->flags.has(BannerFlag::noEntry)); GameActions::Execute(&bannerSetStyle); break; } @@ -231,8 +231,9 @@ namespace OpenRCT2::Ui::Windows if (dropdownIndex == -1) break; - auto bannerSetStyle = BannerSetStyleAction( - BannerSetStyleType::PrimaryColour, GetBannerIndex(), ColourDropDownIndexToColour(dropdownIndex)); + auto bannerSetStyle = GameActions::BannerSetStyleAction( + GameActions::BannerSetStyleType::PrimaryColour, GetBannerIndex(), + ColourDropDownIndexToColour(dropdownIndex)); GameActions::Execute(&bannerSetStyle); break; } @@ -240,8 +241,8 @@ namespace OpenRCT2::Ui::Windows { if (dropdownIndex == -1) break; - auto bannerSetStyle = BannerSetStyleAction( - BannerSetStyleType::TextColour, GetBannerIndex(), dropdownIndex + 1); + auto bannerSetStyle = GameActions::BannerSetStyleAction( + GameActions::BannerSetStyleType::TextColour, GetBannerIndex(), dropdownIndex + 1); GameActions::Execute(&bannerSetStyle); break; } @@ -252,7 +253,7 @@ namespace OpenRCT2::Ui::Windows { if (widgetIndex == WIDX_BANNER_TEXT) { - auto bannerSetNameAction = BannerSetNameAction(GetBannerIndex(), std::string(text)); + auto bannerSetNameAction = GameActions::BannerSetNameAction(GetBannerIndex(), std::string(text)); GameActions::Execute(&bannerSetNameAction); } } diff --git a/src/openrct2-ui/windows/Cheats.cpp b/src/openrct2-ui/windows/Cheats.cpp index 03d3f1b5fa..b6b59df291 100644 --- a/src/openrct2-ui/windows/Cheats.cpp +++ b/src/openrct2-ui/windows/Cheats.cpp @@ -965,7 +965,8 @@ static StringId window_cheats_page_titles[] = { InvalidateWidget(WIDX_PARK_RATING_SPINNER); if (Park::GetForcedRating() >= 0) { - auto cheatSetAction = CheatSetAction(CheatType::SetForcedParkRating, _parkRatingSpinnerValue); + auto cheatSetAction = GameActions::CheatSetAction( + CheatType::SetForcedParkRating, _parkRatingSpinnerValue); GameActions::Execute(&cheatSetAction); } break; diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 2b38d50a4f..c6b315914b 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -1320,7 +1320,7 @@ namespace OpenRCT2::Ui::Windows } gFootpathConstructFromPosition.z = tileElement->GetBaseZ(); - auto action = FootpathRemoveAction(gFootpathConstructFromPosition); + auto action = GameActions::FootpathRemoveAction(gFootpathConstructFromPosition); GameActions::Execute(&action); // Move selection @@ -1814,7 +1814,7 @@ namespace OpenRCT2::Ui::Windows { _provisionalFootpath.flags.unset(ProvisionalPathFlag::placed); - auto action = FootpathRemoveAction(_provisionalFootpath.position); + auto action = GameActions::FootpathRemoveAction(_provisionalFootpath.position); action.SetFlags(GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST); GameActions::Execute(&action); } diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 8b05b93a44..6656defb24 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -2297,7 +2297,7 @@ namespace OpenRCT2::Ui::Windows auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry(banner->type); if (bannerEntry->flags & BANNER_ENTRY_FLAG_HAS_PRIMARY_COLOUR) { - auto repaintScenery = BannerSetColourAction( + auto repaintScenery = GameActions::BannerSetColourAction( { info.Loc, info.Element->GetBaseZ(), info.Element->AsBanner()->GetPosition() }, _sceneryPrimaryColour); diff --git a/src/openrct2/Cheats.cpp b/src/openrct2/Cheats.cpp index a3a6f1865a..9321ac5333 100644 --- a/src/openrct2/Cheats.cpp +++ b/src/openrct2/Cheats.cpp @@ -61,7 +61,7 @@ void CheatsReset() void CheatsSet(CheatType cheatType, int64_t param1 /* = 0*/, int64_t param2 /* = 0*/) { - auto cheatSetAction = CheatSetAction(cheatType, param1, param2); + auto cheatSetAction = GameActions::CheatSetAction(cheatType, param1, param2); GameActions::Execute(&cheatSetAction); } diff --git a/src/openrct2/actions/BalloonPressAction.cpp b/src/openrct2/actions/BalloonPressAction.cpp index 5dd82179e2..c8a30f8b9d 100644 --- a/src/openrct2/actions/BalloonPressAction.cpp +++ b/src/openrct2/actions/BalloonPressAction.cpp @@ -37,30 +37,28 @@ namespace OpenRCT2::GameActions stream << DS_TAG(_spriteIndex); } - GameActions::Result BalloonPressAction::Query() const + Result BalloonPressAction::Query() const { auto balloon = TryGetEntity(_spriteIndex); if (balloon == nullptr) { LOG_ERROR("Balloon not found for spriteIndex %u", _spriteIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_BALLOON_NOT_FOUND); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_BALLOON_NOT_FOUND); } - return GameActions::Result(); + return Result(); } - GameActions::Result BalloonPressAction::Execute() const + Result BalloonPressAction::Execute() const { auto balloon = TryGetEntity(_spriteIndex); if (balloon == nullptr) { LOG_ERROR("Balloon not found for spriteIndex %u", _spriteIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_BALLOON_NOT_FOUND); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_BALLOON_NOT_FOUND); } balloon->Press(); - return GameActions::Result(); + return Result(); } } // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/BalloonPressAction.h b/src/openrct2/actions/BalloonPressAction.h index c3a2e6870d..f5c0f6279b 100644 --- a/src/openrct2/actions/BalloonPressAction.h +++ b/src/openrct2/actions/BalloonPressAction.h @@ -27,7 +27,7 @@ namespace OpenRCT2::GameActions uint16_t GetActionFlags() const override; void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; + Result Query() const override; + Result Execute() const override; }; } // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/BannerPlaceAction.cpp b/src/openrct2/actions/BannerPlaceAction.cpp index aeb17a5440..0cf7886df6 100644 --- a/src/openrct2/actions/BannerPlaceAction.cpp +++ b/src/openrct2/actions/BannerPlaceAction.cpp @@ -50,9 +50,9 @@ namespace OpenRCT2::GameActions stream << DS_TAG(_loc) << DS_TAG(_bannerType) << DS_TAG(_primaryColour); } - GameActions::Result BannerPlaceAction::Query() const + Result BannerPlaceAction::Query() const { - auto res = GameActions::Result(); + auto res = Result(); res.Position.x = _loc.x + 16; res.Position.y = _loc.y + 16; res.Position.z = _loc.z; @@ -61,51 +61,45 @@ namespace OpenRCT2::GameActions if (!LocationValid(_loc)) { - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_OFF_EDGE_OF_MAP); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_OFF_EDGE_OF_MAP); } if (!MapCheckCapacityAndReorganise(_loc)) { LOG_ERROR("No free map elements."); - return GameActions::Result( - GameActions::Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); + return Result(Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); } auto pathElement = GetValidPathElement(); if (pathElement == nullptr) { - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BE_BUILT_ACROSS_PATHS); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_CAN_ONLY_BE_BUILT_ACROSS_PATHS); } if (!MapCanBuildAt(_loc)) { - return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); + return Result(Status::NotOwned, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); } auto baseHeight = _loc.z + kPathHeightStep; BannerElement* existingBannerElement = MapGetBannerElementAt({ _loc.x, _loc.y, baseHeight }, _loc.direction); if (existingBannerElement != nullptr) { - return GameActions::Result( - GameActions::Status::ItemAlreadyPlaced, STR_CANT_POSITION_THIS_HERE, STR_BANNER_SIGN_IN_THE_WAY); + return Result(Status::ItemAlreadyPlaced, STR_CANT_POSITION_THIS_HERE, STR_BANNER_SIGN_IN_THE_WAY); } if (HasReachedBannerLimit()) { LOG_ERROR("No free banners available"); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME); } auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry(_bannerType); if (bannerEntry == nullptr) { LOG_ERROR("Banner entry not found for bannerType %u", _bannerType); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_BANNER_ELEMENT_NOT_FOUND); } res.Cost = bannerEntry->price; res.SetData(BannerPlaceActionResult{}); @@ -113,9 +107,9 @@ namespace OpenRCT2::GameActions return res; } - GameActions::Result BannerPlaceAction::Execute() const + Result BannerPlaceAction::Execute() const { - auto res = GameActions::Result(); + auto res = Result(); res.Position.x = _loc.x + 16; res.Position.y = _loc.y + 16; res.Position.z = _loc.z; @@ -125,24 +119,21 @@ namespace OpenRCT2::GameActions if (!MapCheckCapacityAndReorganise(_loc)) { LOG_ERROR("No free map elements."); - return GameActions::Result( - GameActions::Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); + return Result(Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE, STR_TILE_ELEMENT_LIMIT_REACHED); } auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry(_bannerType); if (bannerEntry == nullptr) { LOG_ERROR("Banner entry not found for bannerType %u", _bannerType); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_ERR_BANNER_ELEMENT_NOT_FOUND); } auto banner = CreateBanner(); if (banner == nullptr) { LOG_ERROR("No free banners available"); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME); + return Result(Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_TOO_MANY_BANNERS_IN_GAME); } banner->flags = {}; banner->text = {}; diff --git a/src/openrct2/actions/BannerPlaceAction.h b/src/openrct2/actions/BannerPlaceAction.h index ae7915a1c5..9c75a204ba 100644 --- a/src/openrct2/actions/BannerPlaceAction.h +++ b/src/openrct2/actions/BannerPlaceAction.h @@ -22,22 +22,22 @@ namespace OpenRCT2::GameActions { private: CoordsXYZD _loc; - OpenRCT2::ObjectEntryIndex _bannerType{ kBannerNull }; + ObjectEntryIndex _bannerType{ kBannerNull }; uint8_t _primaryColour{}; public: BannerPlaceAction() = default; - BannerPlaceAction(const CoordsXYZD& loc, OpenRCT2::ObjectEntryIndex bannerType, colour_t primaryColour); + BannerPlaceAction(const CoordsXYZD& loc, ObjectEntryIndex bannerType, colour_t primaryColour); void AcceptParameters(GameActionParameterVisitor& visitor) override; uint16_t GetActionFlags() const override; void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; + Result Query() const override; + Result Execute() const override; private: - OpenRCT2::PathElement* GetValidPathElement() const; + PathElement* GetValidPathElement() const; }; } // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/BannerRemoveAction.cpp b/src/openrct2/actions/BannerRemoveAction.cpp index 1320a4fbfa..201677beed 100644 --- a/src/openrct2/actions/BannerRemoveAction.cpp +++ b/src/openrct2/actions/BannerRemoveAction.cpp @@ -19,135 +19,138 @@ #include "../world/tile_element/BannerElement.h" #include "GameAction.h" -using namespace OpenRCT2; - -BannerRemoveAction::BannerRemoveAction(const CoordsXYZD& loc) - : _loc(loc) +namespace OpenRCT2::GameActions { -} - -void BannerRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); -} - -uint16_t BannerRemoveAction::GetActionFlags() const -{ - return GameAction::GetActionFlags(); -} - -void BannerRemoveAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_loc); -} - -GameActions::Result BannerRemoveAction::Query() const -{ - auto res = GameActions::Result(); - res.Expenditure = ExpenditureType::landscaping; - res.Position.x = _loc.x + 16; - res.Position.y = _loc.y + 16; - res.Position.z = _loc.z; - res.ErrorTitle = STR_CANT_REMOVE_THIS; - - if (!LocationValid(_loc)) + BannerRemoveAction::BannerRemoveAction(const CoordsXYZD& loc) + : _loc(loc) { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP); - } - if (!MapCanBuildAt({ _loc.x, _loc.y, _loc.z - 16 })) - { - return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); } - BannerElement* bannerElement = GetBannerElementAt(); - if (bannerElement == nullptr) + void BannerRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR("Invalid banner location, x = %d, y = %d, z = %d, direction = %d", _loc.x, _loc.y, _loc.z, _loc.direction); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); + visitor.Visit(_loc); } - auto bannerIndex = bannerElement->GetIndex(); - if (bannerIndex == BannerIndex::GetNull()) + uint16_t BannerRemoveAction::GetActionFlags() const { - LOG_ERROR("Invalid banner index %u", bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); + return GameAction::GetActionFlags(); } - auto banner = bannerElement->GetBanner(); - if (banner == nullptr) + void BannerRemoveAction::Serialise(DataSerialiser& stream) { - LOG_ERROR("Invalid banner index %u", bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); + GameAction::Serialise(stream); + + stream << DS_TAG(_loc); } - auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry(banner->type); - if (bannerEntry != nullptr) + Result BannerRemoveAction::Query() const { - res.Cost = -((bannerEntry->price * 3) / 4); + auto res = Result(); + res.Expenditure = ExpenditureType::landscaping; + res.Position.x = _loc.x + 16; + res.Position.y = _loc.y + 16; + res.Position.z = _loc.z; + res.ErrorTitle = STR_CANT_REMOVE_THIS; + + if (!LocationValid(_loc)) + { + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP); + } + if (!MapCanBuildAt({ _loc.x, _loc.y, _loc.z - 16 })) + { + return Result(Status::NotOwned, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); + } + + BannerElement* bannerElement = GetBannerElementAt(); + if (bannerElement == nullptr) + { + LOG_ERROR( + "Invalid banner location, x = %d, y = %d, z = %d, direction = %d", _loc.x, _loc.y, _loc.z, _loc.direction); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); + } + + auto bannerIndex = bannerElement->GetIndex(); + if (bannerIndex == BannerIndex::GetNull()) + { + LOG_ERROR("Invalid banner index %u", bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); + } + + auto banner = bannerElement->GetBanner(); + if (banner == nullptr) + { + LOG_ERROR("Invalid banner index %u", bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); + } + + auto* bannerEntry = ObjectManager::GetObjectEntry(banner->type); + if (bannerEntry != nullptr) + { + res.Cost = -((bannerEntry->price * 3) / 4); + } + + return res; } - return res; -} - -GameActions::Result BannerRemoveAction::Execute() const -{ - auto res = GameActions::Result(); - res.Expenditure = ExpenditureType::landscaping; - res.Position.x = _loc.x + 16; - res.Position.y = _loc.y + 16; - res.Position.z = _loc.z; - res.ErrorTitle = STR_CANT_REMOVE_THIS; - - BannerElement* bannerElement = GetBannerElementAt(); - if (bannerElement == nullptr) + Result BannerRemoveAction::Execute() const { - LOG_ERROR("Invalid banner location, x = %d, y = %d, z = %d, direction = %d", _loc.x, _loc.y, _loc.z, _loc.direction); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); + auto res = Result(); + res.Expenditure = ExpenditureType::landscaping; + res.Position.x = _loc.x + 16; + res.Position.y = _loc.y + 16; + res.Position.z = _loc.z; + res.ErrorTitle = STR_CANT_REMOVE_THIS; + + BannerElement* bannerElement = GetBannerElementAt(); + if (bannerElement == nullptr) + { + LOG_ERROR( + "Invalid banner location, x = %d, y = %d, z = %d, direction = %d", _loc.x, _loc.y, _loc.z, _loc.direction); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); + } + + auto bannerIndex = bannerElement->GetIndex(); + if (bannerIndex == BannerIndex::GetNull()) + { + LOG_ERROR("Invalid banner index %u", bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); + } + + auto banner = bannerElement->GetBanner(); + if (banner == nullptr) + { + LOG_ERROR("Invalid banner index %u", bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); + } + + auto* bannerEntry = ObjectManager::GetObjectEntry(banner->type); + if (bannerEntry != nullptr) + { + res.Cost = -((bannerEntry->price * 3) / 4); + } + + reinterpret_cast(bannerElement)->RemoveBannerEntry(); + MapInvalidateTileZoom1({ _loc, _loc.z, _loc.z + 32 }); + bannerElement->Remove(); + + return res; } - auto bannerIndex = bannerElement->GetIndex(); - if (bannerIndex == BannerIndex::GetNull()) + BannerElement* BannerRemoveAction::GetBannerElementAt() const { - LOG_ERROR("Invalid banner index %u", bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); + // Find the banner element at known z and position + for (auto* bannerElement : TileElementsView(_loc)) + { + if (bannerElement->GetBaseZ() != _loc.z) + continue; + if (bannerElement->IsGhost() && !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) + continue; + if (bannerElement->GetPosition() != _loc.direction) + continue; + + return bannerElement; + } + + return nullptr; } - - auto banner = bannerElement->GetBanner(); - if (banner == nullptr) - { - LOG_ERROR("Invalid banner index %u", bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, kStringIdNone); - } - - auto* bannerEntry = OpenRCT2::ObjectManager::GetObjectEntry(banner->type); - if (bannerEntry != nullptr) - { - res.Cost = -((bannerEntry->price * 3) / 4); - } - - reinterpret_cast(bannerElement)->RemoveBannerEntry(); - MapInvalidateTileZoom1({ _loc, _loc.z, _loc.z + 32 }); - bannerElement->Remove(); - - return res; -} - -BannerElement* BannerRemoveAction::GetBannerElementAt() const -{ - // Find the banner element at known z and position - for (auto* bannerElement : TileElementsView(_loc)) - { - if (bannerElement->GetBaseZ() != _loc.z) - continue; - if (bannerElement->IsGhost() && !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) - continue; - if (bannerElement->GetPosition() != _loc.direction) - continue; - - return bannerElement; - } - - return nullptr; -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/BannerRemoveAction.h b/src/openrct2/actions/BannerRemoveAction.h index 67100f9109..6108212809 100644 --- a/src/openrct2/actions/BannerRemoveAction.h +++ b/src/openrct2/actions/BannerRemoveAction.h @@ -11,23 +11,26 @@ #include "GameAction.h" -class BannerRemoveAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZD _loc; + class BannerRemoveAction final : public GameActionBase + { + private: + CoordsXYZD _loc; -public: - BannerRemoveAction() = default; - BannerRemoveAction(const CoordsXYZD& loc); + public: + BannerRemoveAction() = default; + BannerRemoveAction(const CoordsXYZD& loc); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; -private: - OpenRCT2::BannerElement* GetBannerElementAt() const; -}; + private: + BannerElement* GetBannerElementAt() const; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/BannerSetColourAction.cpp b/src/openrct2/actions/BannerSetColourAction.cpp index 8a3d7c4125..579e22c661 100644 --- a/src/openrct2/actions/BannerSetColourAction.cpp +++ b/src/openrct2/actions/BannerSetColourAction.cpp @@ -17,93 +17,94 @@ #include "../world/tile_element/BannerElement.h" #include "GameAction.h" -using namespace OpenRCT2; - -BannerSetColourAction::BannerSetColourAction(const CoordsXYZD& loc, uint8_t primaryColour) - : _loc(loc) - , _primaryColour(primaryColour) +namespace OpenRCT2::GameActions { -} - -void BannerSetColourAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); - visitor.Visit("primaryColour", _primaryColour); -} - -uint16_t BannerSetColourAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void BannerSetColourAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_loc) << DS_TAG(_primaryColour); -} - -GameActions::Result BannerSetColourAction::Query() const -{ - return QueryExecute(false); -} - -GameActions::Result BannerSetColourAction::Execute() const -{ - return QueryExecute(true); -} - -GameActions::Result BannerSetColourAction::QueryExecute(bool isExecuting) const -{ - auto res = GameActions::Result(); - res.Expenditure = ExpenditureType::landscaping; - res.Position.x = _loc.x + 16; - res.Position.y = _loc.y + 16; - res.Position.z = _loc.z; - res.ErrorTitle = STR_CANT_REPAINT_THIS; - - if (!LocationValid(_loc)) + BannerSetColourAction::BannerSetColourAction(const CoordsXYZD& loc, uint8_t primaryColour) + : _loc(loc) + , _primaryColour(primaryColour) { - LOG_ERROR("Invalid x / y coordinates: x = %d, y = %d", _loc.x, _loc.y); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP); } - if (_primaryColour > 31) + void BannerSetColourAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR("Invalid primary colour %u", _primaryColour); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); + visitor.Visit(_loc); + visitor.Visit("primaryColour", _primaryColour); } - if (!MapCanBuildAt({ _loc.x, _loc.y, _loc.z - 16 })) + uint16_t BannerSetColourAction::GetActionFlags() const { - return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK); + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; } - auto bannerElement = MapGetBannerElementAt(_loc, _loc.direction); - - if (bannerElement == nullptr) + void BannerSetColourAction::Serialise(DataSerialiser& stream) { - LOG_ERROR("No banner at x = %d, y = %d, z = %d, direction = %u", _loc.x, _loc.y, _loc.z, _loc.direction); - return GameActions::Result(GameActions::Status::Unknown, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + GameAction::Serialise(stream); + + stream << DS_TAG(_loc) << DS_TAG(_primaryColour); } - auto index = bannerElement->GetIndex(); - auto banner = GetBanner(index); - if (banner == nullptr) + Result BannerSetColourAction::Query() const { - LOG_ERROR("Invalid banner index %u", index); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + return QueryExecute(false); } - if (isExecuting) + Result BannerSetColourAction::Execute() const { - auto intent = Intent(INTENT_ACTION_UPDATE_BANNER); - intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, index); - ContextBroadcastIntent(&intent); - - banner->colour = _primaryColour; - MapInvalidateTileZoom1({ _loc, _loc.z, _loc.z + 32 }); + return QueryExecute(true); } - return res; -} + Result BannerSetColourAction::QueryExecute(bool isExecuting) const + { + auto res = Result(); + res.Expenditure = ExpenditureType::landscaping; + res.Position.x = _loc.x + 16; + res.Position.y = _loc.y + 16; + res.Position.z = _loc.z; + res.ErrorTitle = STR_CANT_REPAINT_THIS; + + if (!LocationValid(_loc)) + { + LOG_ERROR("Invalid x / y coordinates: x = %d, y = %d", _loc.x, _loc.y); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP); + } + + if (_primaryColour > 31) + { + LOG_ERROR("Invalid primary colour %u", _primaryColour); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); + } + + if (!MapCanBuildAt({ _loc.x, _loc.y, _loc.z - 16 })) + { + return Result(Status::NotOwned, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK); + } + + auto bannerElement = MapGetBannerElementAt(_loc, _loc.direction); + + if (bannerElement == nullptr) + { + LOG_ERROR("No banner at x = %d, y = %d, z = %d, direction = %u", _loc.x, _loc.y, _loc.z, _loc.direction); + return Result(Status::Unknown, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + } + + auto index = bannerElement->GetIndex(); + auto banner = GetBanner(index); + if (banner == nullptr) + { + LOG_ERROR("Invalid banner index %u", index); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + } + + if (isExecuting) + { + auto intent = Intent(INTENT_ACTION_UPDATE_BANNER); + intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, index); + ContextBroadcastIntent(&intent); + + banner->colour = _primaryColour; + MapInvalidateTileZoom1({ _loc, _loc.z, _loc.z + 32 }); + } + + return res; + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/BannerSetColourAction.h b/src/openrct2/actions/BannerSetColourAction.h index 5a1a663476..546c1dd68a 100644 --- a/src/openrct2/actions/BannerSetColourAction.h +++ b/src/openrct2/actions/BannerSetColourAction.h @@ -11,24 +11,27 @@ #include "GameAction.h" -class BannerSetColourAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZD _loc; - uint8_t _primaryColour{}; + class BannerSetColourAction final : public GameActionBase + { + private: + CoordsXYZD _loc; + uint8_t _primaryColour{}; -public: - BannerSetColourAction() = default; - BannerSetColourAction(const CoordsXYZD& loc, uint8_t primaryColour); + public: + BannerSetColourAction() = default; + BannerSetColourAction(const CoordsXYZD& loc, uint8_t primaryColour); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; -private: - OpenRCT2::GameActions::Result QueryExecute(bool isExecuting) const; -}; + private: + Result QueryExecute(bool isExecuting) const; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/BannerSetNameAction.cpp b/src/openrct2/actions/BannerSetNameAction.cpp index 1b069ee941..7cd2caf795 100644 --- a/src/openrct2/actions/BannerSetNameAction.cpp +++ b/src/openrct2/actions/BannerSetNameAction.cpp @@ -19,83 +19,81 @@ #include "../world/tile_element/BannerElement.h" #include "GameAction.h" -using namespace OpenRCT2; - -BannerSetNameAction::BannerSetNameAction(BannerIndex bannerIndex, const std::string& name) - : _bannerIndex(bannerIndex) - , _name(name) +namespace OpenRCT2::GameActions { -} - -void BannerSetNameAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("id", _bannerIndex); - visitor.Visit("name", _name); -} - -uint16_t BannerSetNameAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void BannerSetNameAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - stream << DS_TAG(_bannerIndex) << DS_TAG(_name); -} - -GameActions::Result BannerSetNameAction::Query() const -{ - auto banner = GetBanner(_bannerIndex); - if (banner == nullptr) + BannerSetNameAction::BannerSetNameAction(BannerIndex bannerIndex, const std::string& name) + : _bannerIndex(bannerIndex) + , _name(name) { - LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND); } - TileElement* tileElement = BannerGetTileElement(_bannerIndex); - - if (tileElement == nullptr) + void BannerSetNameAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR("Banner tile element not found for bannerIndex %d", _bannerIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + visitor.Visit("id", _bannerIndex); + visitor.Visit("name", _name); } - BannerElement* bannerElement = tileElement->AsBanner(); - CoordsXYZD loc = { banner->position.ToCoordsXY(), bannerElement->GetBaseZ(), bannerElement->GetPosition() }; - - if (!LocationValid(loc)) + uint16_t BannerSetNameAction::GetActionFlags() const { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_OFF_EDGE_OF_MAP); - } - if (!MapCanBuildAt({ loc.x, loc.y, loc.z - 16 })) - { - return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_RENAME_BANNER, STR_LAND_NOT_OWNED_BY_PARK); + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; } - return GameActions::Result(); -} - -GameActions::Result BannerSetNameAction::Execute() const -{ - auto banner = GetBanner(_bannerIndex); - if (banner == nullptr) + void BannerSetNameAction::Serialise(DataSerialiser& stream) { - LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + GameAction::Serialise(stream); + stream << DS_TAG(_bannerIndex) << DS_TAG(_name); } - banner->text = _name; + Result BannerSetNameAction::Query() const + { + auto banner = GetBanner(_bannerIndex); + if (banner == nullptr) + { + LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + } - auto intent = Intent(INTENT_ACTION_UPDATE_BANNER); - intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, _bannerIndex); - ContextBroadcastIntent(&intent); + TileElement* tileElement = BannerGetTileElement(_bannerIndex); - ScrollingTextInvalidate(); - GfxInvalidateScreen(); + if (tileElement == nullptr) + { + LOG_ERROR("Banner tile element not found for bannerIndex %d", _bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + } - return GameActions::Result(); -} + BannerElement* bannerElement = tileElement->AsBanner(); + CoordsXYZD loc = { banner->position.ToCoordsXY(), bannerElement->GetBaseZ(), bannerElement->GetPosition() }; + + if (!LocationValid(loc)) + { + return Result(Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_OFF_EDGE_OF_MAP); + } + if (!MapCanBuildAt({ loc.x, loc.y, loc.z - 16 })) + { + return Result(Status::NotOwned, STR_CANT_RENAME_BANNER, STR_LAND_NOT_OWNED_BY_PARK); + } + + return Result(); + } + + Result BannerSetNameAction::Execute() const + { + auto banner = GetBanner(_bannerIndex); + if (banner == nullptr) + { + LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_RENAME_BANNER, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + } + + banner->text = _name; + + auto intent = Intent(INTENT_ACTION_UPDATE_BANNER); + intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, _bannerIndex); + ContextBroadcastIntent(&intent); + + ScrollingTextInvalidate(); + GfxInvalidateScreen(); + + return Result(); + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/BannerSetNameAction.h b/src/openrct2/actions/BannerSetNameAction.h index 01e09fd8dc..212feea9c4 100644 --- a/src/openrct2/actions/BannerSetNameAction.h +++ b/src/openrct2/actions/BannerSetNameAction.h @@ -11,21 +11,24 @@ #include "GameAction.h" -class BannerSetNameAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - BannerIndex _bannerIndex{ BannerIndex::GetNull() }; - std::string _name; + class BannerSetNameAction final : public GameActionBase + { + private: + BannerIndex _bannerIndex{ BannerIndex::GetNull() }; + std::string _name; -public: - BannerSetNameAction() = default; - BannerSetNameAction(BannerIndex bannerIndex, const std::string& name); + public: + BannerSetNameAction() = default; + BannerSetNameAction(BannerIndex bannerIndex, const std::string& name); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; -}; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/BannerSetStyleAction.cpp b/src/openrct2/actions/BannerSetStyleAction.cpp index e6d3e00319..13755265b2 100644 --- a/src/openrct2/actions/BannerSetStyleAction.cpp +++ b/src/openrct2/actions/BannerSetStyleAction.cpp @@ -18,172 +18,167 @@ #include "../world/tile_element/BannerElement.h" #include "GameAction.h" -using namespace OpenRCT2; - -BannerSetStyleAction::BannerSetStyleAction(BannerSetStyleType type, BannerIndex bannerIndex, uint8_t parameter) - : _type(type) - , _bannerIndex(bannerIndex) - , _parameter(parameter) +namespace OpenRCT2::GameActions { -} - -void BannerSetStyleAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("id", _bannerIndex); - visitor.Visit("type", _type); - visitor.Visit("parameter", _parameter); -} - -uint16_t BannerSetStyleAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void BannerSetStyleAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_type) << DS_TAG(_bannerIndex) << DS_TAG(_parameter); -} - -GameActions::Result BannerSetStyleAction::Query() const -{ - StringId errorTitle = STR_CANT_REPAINT_THIS; - if (_type == BannerSetStyleType::NoEntry) + BannerSetStyleAction::BannerSetStyleAction(BannerSetStyleType type, BannerIndex bannerIndex, uint8_t parameter) + : _type(type) + , _bannerIndex(bannerIndex) + , _parameter(parameter) { - errorTitle = STR_CANT_RENAME_BANNER; } - auto res = GameActions::Result(); - - auto banner = GetBanner(_bannerIndex); - if (banner == nullptr) + void BannerSetStyleAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, errorTitle, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + visitor.Visit("id", _bannerIndex); + visitor.Visit("type", _type); + visitor.Visit("parameter", _parameter); } - res.Expenditure = ExpenditureType::landscaping; - auto location = banner->position.ToCoordsXY().ToTileCentre(); - res.Position = { location, TileElementHeight(location) }; - - TileElement* tileElement = BannerGetTileElement(_bannerIndex); - - if (tileElement == nullptr) + uint16_t BannerSetStyleAction::GetActionFlags() const { - LOG_ERROR("Banner tile element not found for bannerIndex %d", _bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, errorTitle, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; } - BannerElement* bannerElement = tileElement->AsBanner(); - CoordsXYZ loc = { banner->position.ToCoordsXY(), bannerElement->GetBaseZ() }; + void BannerSetStyleAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); - if (!LocationValid(loc)) - { - return GameActions::Result(GameActions::Status::InvalidParameters, errorTitle, STR_OFF_EDGE_OF_MAP); - } - if (!MapCanBuildAt({ loc.x, loc.y, loc.z - 16 })) - { - return GameActions::Result(GameActions::Status::NotOwned, errorTitle, STR_LAND_NOT_OWNED_BY_PARK); + stream << DS_TAG(_type) << DS_TAG(_bannerIndex) << DS_TAG(_parameter); } - switch (_type) + Result BannerSetStyleAction::Query() const { - case BannerSetStyleType::PrimaryColour: - if (_parameter > COLOUR_COUNT) - { - LOG_ERROR("Invalid primary colour %u", _parameter); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); - } - break; - - case BannerSetStyleType::TextColour: - if (_parameter > 13) - { - LOG_ERROR("Invalid text colour %u", _parameter); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); - } - break; - case BannerSetStyleType::NoEntry: - if (tileElement->AsBanner() == nullptr) - { - LOG_ERROR("Tile element was not a banner."); - return GameActions::Result(GameActions::Status::Unknown, STR_CANT_RENAME_BANNER, kStringIdNone); - } - break; - default: - LOG_ERROR("Invalid banner style type %u", _type); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_VALUE_OUT_OF_RANGE); - } - return res; -} - -GameActions::Result BannerSetStyleAction::Execute() const -{ - auto res = GameActions::Result(); - - auto banner = GetBanner(_bannerIndex); - if (banner == nullptr) - { - LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND); - } - - res.Expenditure = ExpenditureType::landscaping; - auto location = banner->position.ToCoordsXY().ToTileCentre(); - res.Position = { location, TileElementHeight(location) }; - - TileElement* tileElement = BannerGetTileElement(_bannerIndex); - - if (tileElement == nullptr) - { - LOG_ERROR("Banner tile element not found for bannerIndex &u", _bannerIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); - } - - switch (_type) - { - case BannerSetStyleType::PrimaryColour: - banner->colour = _parameter; - break; - case BannerSetStyleType::TextColour: - banner->textColour = static_cast(_parameter); - break; - case BannerSetStyleType::NoEntry: + StringId errorTitle = STR_CANT_REPAINT_THIS; + if (_type == BannerSetStyleType::NoEntry) { - BannerElement* bannerElement = tileElement->AsBanner(); - if (bannerElement == nullptr) - { - LOG_ERROR("Tile element was not a banner."); - return GameActions::Result( - GameActions::Status::Unknown, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND); - } - - banner->flags.set(BannerFlag::noEntry, (_parameter != 0)); - uint8_t allowedEdges = 0xF; - if (banner->flags.has(BannerFlag::noEntry)) - { - allowedEdges &= ~(1 << bannerElement->GetPosition()); - } - bannerElement->SetAllowedEdges(allowedEdges); - break; + errorTitle = STR_CANT_RENAME_BANNER; } - default: - LOG_ERROR("Invalid banner style type %u", _type); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_VALUE_OUT_OF_RANGE); + + auto res = Result(); + + auto banner = GetBanner(_bannerIndex); + if (banner == nullptr) + { + LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex); + return Result(Status::InvalidParameters, errorTitle, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + } + + res.Expenditure = ExpenditureType::landscaping; + auto location = banner->position.ToCoordsXY().ToTileCentre(); + res.Position = { location, TileElementHeight(location) }; + + TileElement* tileElement = BannerGetTileElement(_bannerIndex); + + if (tileElement == nullptr) + { + LOG_ERROR("Banner tile element not found for bannerIndex %d", _bannerIndex); + return Result(Status::InvalidParameters, errorTitle, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + } + + BannerElement* bannerElement = tileElement->AsBanner(); + CoordsXYZ loc = { banner->position.ToCoordsXY(), bannerElement->GetBaseZ() }; + + if (!LocationValid(loc)) + { + return Result(Status::InvalidParameters, errorTitle, STR_OFF_EDGE_OF_MAP); + } + if (!MapCanBuildAt({ loc.x, loc.y, loc.z - 16 })) + { + return Result(Status::NotOwned, errorTitle, STR_LAND_NOT_OWNED_BY_PARK); + } + + switch (_type) + { + case BannerSetStyleType::PrimaryColour: + if (_parameter > COLOUR_COUNT) + { + LOG_ERROR("Invalid primary colour %u", _parameter); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); + } + break; + + case BannerSetStyleType::TextColour: + if (_parameter > 13) + { + LOG_ERROR("Invalid text colour %u", _parameter); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR); + } + break; + case BannerSetStyleType::NoEntry: + if (tileElement->AsBanner() == nullptr) + { + LOG_ERROR("Tile element was not a banner."); + return Result(Status::Unknown, STR_CANT_RENAME_BANNER, kStringIdNone); + } + break; + default: + LOG_ERROR("Invalid banner style type %u", _type); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_VALUE_OUT_OF_RANGE); + } + return res; } - auto intent = Intent(INTENT_ACTION_UPDATE_BANNER); - intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, _bannerIndex); - ContextBroadcastIntent(&intent); + Result BannerSetStyleAction::Execute() const + { + auto res = Result(); - ScrollingTextInvalidate(); - GfxInvalidateScreen(); + auto banner = GetBanner(_bannerIndex); + if (banner == nullptr) + { + LOG_ERROR("Banner not found for bannerIndex %d", _bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + } - return res; -} + res.Expenditure = ExpenditureType::landscaping; + auto location = banner->position.ToCoordsXY().ToTileCentre(); + res.Position = { location, TileElementHeight(location) }; + + TileElement* tileElement = BannerGetTileElement(_bannerIndex); + + if (tileElement == nullptr) + { + LOG_ERROR("Banner tile element not found for bannerIndex &u", _bannerIndex); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone); + } + + switch (_type) + { + case BannerSetStyleType::PrimaryColour: + banner->colour = _parameter; + break; + case BannerSetStyleType::TextColour: + banner->textColour = static_cast(_parameter); + break; + case BannerSetStyleType::NoEntry: + { + BannerElement* bannerElement = tileElement->AsBanner(); + if (bannerElement == nullptr) + { + LOG_ERROR("Tile element was not a banner."); + return Result(Status::Unknown, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND); + } + + banner->flags.set(BannerFlag::noEntry, (_parameter != 0)); + uint8_t allowedEdges = 0xF; + if (banner->flags.has(BannerFlag::noEntry)) + { + allowedEdges &= ~(1 << bannerElement->GetPosition()); + } + bannerElement->SetAllowedEdges(allowedEdges); + break; + } + default: + LOG_ERROR("Invalid banner style type %u", _type); + return Result(Status::InvalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_VALUE_OUT_OF_RANGE); + } + + auto intent = Intent(INTENT_ACTION_UPDATE_BANNER); + intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, _bannerIndex); + ContextBroadcastIntent(&intent); + + ScrollingTextInvalidate(); + GfxInvalidateScreen(); + + return res; + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/BannerSetStyleAction.h b/src/openrct2/actions/BannerSetStyleAction.h index 20de773ba6..bca3226911 100644 --- a/src/openrct2/actions/BannerSetStyleAction.h +++ b/src/openrct2/actions/BannerSetStyleAction.h @@ -11,32 +11,35 @@ #include "GameAction.h" -// There is also the BannerSetColourAction that sets primary colour but this action takes banner index rather than x, y, z, -// direction -enum class BannerSetStyleType : uint8_t +namespace OpenRCT2::GameActions { - PrimaryColour, - TextColour, - NoEntry, - Count -}; + // There is also the BannerSetColourAction that sets primary colour but this action takes banner index rather than x, y, z, + // direction + enum class BannerSetStyleType : uint8_t + { + PrimaryColour, + TextColour, + NoEntry, + Count + }; -class BannerSetStyleAction final : public GameActionBase -{ -private: - BannerSetStyleType _type{ BannerSetStyleType::Count }; - BannerIndex _bannerIndex{ BannerIndex::GetNull() }; - uint8_t _parameter{}; + class BannerSetStyleAction final : public GameActionBase + { + private: + BannerSetStyleType _type{ BannerSetStyleType::Count }; + BannerIndex _bannerIndex{ BannerIndex::GetNull() }; + uint8_t _parameter{}; -public: - BannerSetStyleAction() = default; - BannerSetStyleAction(BannerSetStyleType type, BannerIndex bannerIndex, uint8_t parameter); + public: + BannerSetStyleAction() = default; + BannerSetStyleAction(BannerSetStyleType type, BannerIndex bannerIndex, uint8_t parameter); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; -}; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/CheatSetAction.cpp b/src/openrct2/actions/CheatSetAction.cpp index 068bebf66b..3147d11d64 100644 --- a/src/openrct2/actions/CheatSetAction.cpp +++ b/src/openrct2/actions/CheatSetAction.cpp @@ -45,823 +45,826 @@ #include "ParkSetLoanAction.h" #include "ParkSetParameterAction.h" -using namespace OpenRCT2; - -using ParametersRange = std::pair, std::pair>; - -CheatSetAction::CheatSetAction(CheatType cheatType, int64_t param1, int64_t param2) - : _cheatType(static_cast(cheatType)) - , _param1(param1) - , _param2(param2) +namespace OpenRCT2::GameActions { -} + using ParametersRange = std::pair, std::pair>; -void CheatSetAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("type", _cheatType); - visitor.Visit("param1", _param1); - visitor.Visit("param2", _param2); -} - -uint16_t CheatSetAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void CheatSetAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - stream << DS_TAG(_cheatType) << DS_TAG(_param1) << DS_TAG(_param2); -} - -GameActions::Result CheatSetAction::Query() const -{ - if (static_cast(_cheatType) >= static_cast(CheatType::Count)) + CheatSetAction::CheatSetAction(CheatType cheatType, int64_t param1, int64_t param2) + : _cheatType(static_cast(cheatType)) + , _param1(param1) + , _param2(param2) { - LOG_ERROR("Invalid cheat type %u", _cheatType); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); } - ParametersRange validRange = GetParameterRange(static_cast(_cheatType.id)); - - if (_param1 < validRange.first.first || _param1 > validRange.first.second) + void CheatSetAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR( - "The first cheat parameter is out of range. Value = %d, min = %d, max = %d", _param1, validRange.first.first, - validRange.first.second); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); - } - if (_param2 < validRange.second.first || _param2 > validRange.second.second) - { - LOG_ERROR( - "The second cheat parameter is out of range. Value = %d, min = %d, max = %d", _param2, validRange.second.first, - validRange.second.second); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); + visitor.Visit("type", _cheatType); + visitor.Visit("param1", _param1); + visitor.Visit("param2", _param2); } - return GameActions::Result(); -} - -GameActions::Result CheatSetAction::Execute() const -{ - auto& gameState = getGameState(); - auto* windowMgr = Ui::GetWindowManager(); - - switch (static_cast(_cheatType.id)) + uint16_t CheatSetAction::GetActionFlags() const { - case CheatType::SandboxMode: - gameState.cheats.sandboxMode = _param1 != 0; - windowMgr->InvalidateByClass(WindowClass::Map); - windowMgr->InvalidateByClass(WindowClass::Footpath); - break; - case CheatType::DisableClearanceChecks: - gameState.cheats.disableClearanceChecks = _param1 != 0; - // Required to update the clearance checks overlay on the Cheats button. - windowMgr->InvalidateByClass(WindowClass::TopToolbar); - break; - case CheatType::DisableSupportLimits: - gameState.cheats.disableSupportLimits = _param1 != 0; - break; - case CheatType::ShowAllOperatingModes: - gameState.cheats.showAllOperatingModes = _param1 != 0; - break; - case CheatType::ShowVehiclesFromOtherTrackTypes: - gameState.cheats.showVehiclesFromOtherTrackTypes = _param1 != 0; - break; - case CheatType::FastLiftHill: - gameState.cheats.unlockOperatingLimits = _param1 != 0; - break; - case CheatType::DisableBrakesFailure: - gameState.cheats.disableBrakesFailure = _param1 != 0; - break; - case CheatType::DisableAllBreakdowns: - gameState.cheats.disableAllBreakdowns = _param1 != 0; - break; - case CheatType::DisableTrainLengthLimit: - gameState.cheats.disableTrainLengthLimit = _param1 != 0; - break; - case CheatType::EnableChainLiftOnAllTrack: - gameState.cheats.enableChainLiftOnAllTrack = _param1 != 0; - break; - case CheatType::BuildInPauseMode: - gameState.cheats.buildInPauseMode = _param1 != 0; - break; - case CheatType::IgnoreRideIntensity: - gameState.cheats.ignoreRideIntensity = _param1 != 0; - break; - case CheatType::IgnorePrice: - gameState.cheats.ignorePrice = _param1 != 0; - break; - case CheatType::DisableVandalism: - gameState.cheats.disableVandalism = _param1 != 0; - break; - case CheatType::DisableLittering: - gameState.cheats.disableLittering = _param1 != 0; - break; - case CheatType::NoMoney: - SetScenarioNoMoney(_param1 != 0); - break; - case CheatType::AddMoney: - AddMoney(_param1); - break; - case CheatType::SetMoney: - SetMoney(_param1); - break; - case CheatType::ClearLoan: - ClearLoan(); - break; - case CheatType::SetGuestParameter: - SetGuestParameter(_param1, _param2); - break; - case CheatType::GenerateGuests: - GenerateGuests(_param1); - break; - case CheatType::RemoveAllGuests: - RemoveAllGuests(); - break; - case CheatType::GiveAllGuests: - GiveObjectToGuests(_param1); - break; - case CheatType::SetGrassLength: - SetGrassLength(_param1); - break; - case CheatType::WaterPlants: - WaterPlants(); - break; - case CheatType::FixVandalism: - FixVandalism(); - break; - case CheatType::RemoveLitter: - RemoveLitter(); - break; - case CheatType::DisablePlantAging: - gameState.cheats.disablePlantAging = _param1 != 0; - break; - case CheatType::SetStaffSpeed: - SetStaffSpeed(_param1); - break; - case CheatType::RenewRides: - RenewRides(); - break; - case CheatType::MakeDestructible: - gameState.cheats.makeAllDestructible = _param1 != 0; - windowMgr->InvalidateByClass(WindowClass::Ride); - break; - case CheatType::FixRides: - FixBrokenRides(); - break; - case CheatType::ResetCrashStatus: - ResetRideCrashStatus(); - break; - case CheatType::TenMinuteInspections: - Set10MinuteInspection(); - break; - case CheatType::WinScenario: - ScenarioSuccess(gameState); - break; - case CheatType::ForceWeather: - // Todo - make sure this is safe - ClimateForceWeather(WeatherType{ static_cast(_param1) }); - break; - case CheatType::FreezeWeather: - gameState.cheats.freezeWeather = _param1 != 0; - break; - case CheatType::NeverendingMarketing: - gameState.cheats.neverendingMarketing = _param1 != 0; - break; - case CheatType::OpenClosePark: - ParkSetOpen(!Park::IsOpen(gameState.park)); - break; - case CheatType::HaveFun: - gameState.scenarioOptions.objective.Type = Scenario::ObjectiveType::haveFun; - break; - case CheatType::SetForcedParkRating: - Park::SetForcedRating(_param1); - break; - case CheatType::AllowArbitraryRideTypeChanges: - gameState.cheats.allowArbitraryRideTypeChanges = _param1 != 0; - windowMgr->InvalidateByClass(WindowClass::Ride); - break; - case CheatType::OwnAllLand: - OwnAllLand(); - break; - case CheatType::DisableRideValueAging: - gameState.cheats.disableRideValueAging = _param1 != 0; - break; - case CheatType::IgnoreResearchStatus: - gameState.cheats.ignoreResearchStatus = _param1 != 0; - break; - case CheatType::EnableAllDrawableTrackPieces: - gameState.cheats.enableAllDrawableTrackPieces = _param1 != 0; - break; - case CheatType::CreateDucks: - CreateDucks(_param1); - break; - case CheatType::RemoveDucks: - Duck::RemoveAll(); - break; - case CheatType::AllowTrackPlaceInvalidHeights: - gameState.cheats.allowTrackPlaceInvalidHeights = _param1 != 0; - break; - case CheatType::AllowRegularPathAsQueue: - gameState.cheats.allowRegularPathAsQueue = _param1 != 0; - break; - case CheatType::AllowSpecialColourSchemes: - gameState.cheats.allowSpecialColourSchemes = static_cast(_param1); - break; - case CheatType::RemoveParkFences: - RemoveParkFences(); - break; - default: + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; + } + + void CheatSetAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); + stream << DS_TAG(_cheatType) << DS_TAG(_param1) << DS_TAG(_param2); + } + + Result CheatSetAction::Query() const + { + if (static_cast(_cheatType) >= static_cast(CheatType::Count)) { - LOG_ERROR("Invalid cheat type %d", _cheatType.id); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); + LOG_ERROR("Invalid cheat type %u", _cheatType); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); + } + + ParametersRange validRange = GetParameterRange(static_cast(_cheatType.id)); + + if (_param1 < validRange.first.first || _param1 > validRange.first.second) + { + LOG_ERROR( + "The first cheat parameter is out of range. Value = %d, min = %d, max = %d", _param1, validRange.first.first, + validRange.first.second); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); + } + if (_param2 < validRange.second.first || _param2 > validRange.second.second) + { + LOG_ERROR( + "The second cheat parameter is out of range. Value = %d, min = %d, max = %d", _param2, validRange.second.first, + validRange.second.second); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); + } + + return Result(); + } + + Result CheatSetAction::Execute() const + { + auto& gameState = getGameState(); + auto* windowMgr = Ui::GetWindowManager(); + + switch (static_cast(_cheatType.id)) + { + case CheatType::SandboxMode: + gameState.cheats.sandboxMode = _param1 != 0; + windowMgr->InvalidateByClass(WindowClass::Map); + windowMgr->InvalidateByClass(WindowClass::Footpath); + break; + case CheatType::DisableClearanceChecks: + gameState.cheats.disableClearanceChecks = _param1 != 0; + // Required to update the clearance checks overlay on the Cheats button. + windowMgr->InvalidateByClass(WindowClass::TopToolbar); + break; + case CheatType::DisableSupportLimits: + gameState.cheats.disableSupportLimits = _param1 != 0; + break; + case CheatType::ShowAllOperatingModes: + gameState.cheats.showAllOperatingModes = _param1 != 0; + break; + case CheatType::ShowVehiclesFromOtherTrackTypes: + gameState.cheats.showVehiclesFromOtherTrackTypes = _param1 != 0; + break; + case CheatType::FastLiftHill: + gameState.cheats.unlockOperatingLimits = _param1 != 0; + break; + case CheatType::DisableBrakesFailure: + gameState.cheats.disableBrakesFailure = _param1 != 0; + break; + case CheatType::DisableAllBreakdowns: + gameState.cheats.disableAllBreakdowns = _param1 != 0; + break; + case CheatType::DisableTrainLengthLimit: + gameState.cheats.disableTrainLengthLimit = _param1 != 0; + break; + case CheatType::EnableChainLiftOnAllTrack: + gameState.cheats.enableChainLiftOnAllTrack = _param1 != 0; + break; + case CheatType::BuildInPauseMode: + gameState.cheats.buildInPauseMode = _param1 != 0; + break; + case CheatType::IgnoreRideIntensity: + gameState.cheats.ignoreRideIntensity = _param1 != 0; + break; + case CheatType::IgnorePrice: + gameState.cheats.ignorePrice = _param1 != 0; + break; + case CheatType::DisableVandalism: + gameState.cheats.disableVandalism = _param1 != 0; + break; + case CheatType::DisableLittering: + gameState.cheats.disableLittering = _param1 != 0; + break; + case CheatType::NoMoney: + SetScenarioNoMoney(_param1 != 0); + break; + case CheatType::AddMoney: + AddMoney(_param1); + break; + case CheatType::SetMoney: + SetMoney(_param1); + break; + case CheatType::ClearLoan: + ClearLoan(); + break; + case CheatType::SetGuestParameter: + SetGuestParameter(_param1, _param2); + break; + case CheatType::GenerateGuests: + GenerateGuests(_param1); + break; + case CheatType::RemoveAllGuests: + RemoveAllGuests(); + break; + case CheatType::GiveAllGuests: + GiveObjectToGuests(_param1); + break; + case CheatType::SetGrassLength: + SetGrassLength(_param1); + break; + case CheatType::WaterPlants: + WaterPlants(); + break; + case CheatType::FixVandalism: + FixVandalism(); + break; + case CheatType::RemoveLitter: + RemoveLitter(); + break; + case CheatType::DisablePlantAging: + gameState.cheats.disablePlantAging = _param1 != 0; + break; + case CheatType::SetStaffSpeed: + SetStaffSpeed(_param1); + break; + case CheatType::RenewRides: + RenewRides(); + break; + case CheatType::MakeDestructible: + gameState.cheats.makeAllDestructible = _param1 != 0; + windowMgr->InvalidateByClass(WindowClass::Ride); + break; + case CheatType::FixRides: + FixBrokenRides(); + break; + case CheatType::ResetCrashStatus: + ResetRideCrashStatus(); + break; + case CheatType::TenMinuteInspections: + Set10MinuteInspection(); + break; + case CheatType::WinScenario: + ScenarioSuccess(gameState); + break; + case CheatType::ForceWeather: + // Todo - make sure this is safe + ClimateForceWeather(WeatherType{ static_cast(_param1) }); + break; + case CheatType::FreezeWeather: + gameState.cheats.freezeWeather = _param1 != 0; + break; + case CheatType::NeverendingMarketing: + gameState.cheats.neverendingMarketing = _param1 != 0; + break; + case CheatType::OpenClosePark: + ParkSetOpen(!Park::IsOpen(gameState.park)); + break; + case CheatType::HaveFun: + gameState.scenarioOptions.objective.Type = Scenario::ObjectiveType::haveFun; + break; + case CheatType::SetForcedParkRating: + Park::SetForcedRating(_param1); + break; + case CheatType::AllowArbitraryRideTypeChanges: + gameState.cheats.allowArbitraryRideTypeChanges = _param1 != 0; + windowMgr->InvalidateByClass(WindowClass::Ride); + break; + case CheatType::OwnAllLand: + OwnAllLand(); + break; + case CheatType::DisableRideValueAging: + gameState.cheats.disableRideValueAging = _param1 != 0; + break; + case CheatType::IgnoreResearchStatus: + gameState.cheats.ignoreResearchStatus = _param1 != 0; + break; + case CheatType::EnableAllDrawableTrackPieces: + gameState.cheats.enableAllDrawableTrackPieces = _param1 != 0; + break; + case CheatType::CreateDucks: + CreateDucks(_param1); + break; + case CheatType::RemoveDucks: + Duck::RemoveAll(); + break; + case CheatType::AllowTrackPlaceInvalidHeights: + gameState.cheats.allowTrackPlaceInvalidHeights = _param1 != 0; + break; + case CheatType::AllowRegularPathAsQueue: + gameState.cheats.allowRegularPathAsQueue = _param1 != 0; + break; + case CheatType::AllowSpecialColourSchemes: + gameState.cheats.allowSpecialColourSchemes = static_cast(_param1); + break; + case CheatType::RemoveParkFences: + RemoveParkFences(); + break; + default: + { + LOG_ERROR("Invalid cheat type %d", _cheatType.id); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); + } + } + + if (NetworkGetMode() == NETWORK_MODE_NONE) + { + Config::Save(); + } + + windowMgr->InvalidateByClass(WindowClass::Cheats); + return Result(); + } + + ParametersRange CheatSetAction::GetParameterRange(CheatType cheatType) const + { + switch (static_cast(_cheatType.id)) + { + case CheatType::SandboxMode: + [[fallthrough]]; + case CheatType::DisableClearanceChecks: + [[fallthrough]]; + case CheatType::DisableSupportLimits: + [[fallthrough]]; + case CheatType::ShowAllOperatingModes: + [[fallthrough]]; + case CheatType::ShowVehiclesFromOtherTrackTypes: + [[fallthrough]]; + case CheatType::FastLiftHill: + [[fallthrough]]; + case CheatType::DisableBrakesFailure: + [[fallthrough]]; + case CheatType::DisableAllBreakdowns: + [[fallthrough]]; + case CheatType::DisableTrainLengthLimit: + [[fallthrough]]; + case CheatType::EnableChainLiftOnAllTrack: + [[fallthrough]]; + case CheatType::BuildInPauseMode: + [[fallthrough]]; + case CheatType::IgnoreRideIntensity: + [[fallthrough]]; + case CheatType::IgnorePrice: + [[fallthrough]]; + case CheatType::DisableVandalism: + [[fallthrough]]; + case CheatType::DisableLittering: + [[fallthrough]]; + case CheatType::NoMoney: + [[fallthrough]]; + case CheatType::DisablePlantAging: + [[fallthrough]]; + case CheatType::FreezeWeather: + [[fallthrough]]; + case CheatType::NeverendingMarketing: + [[fallthrough]]; + case CheatType::AllowArbitraryRideTypeChanges: + [[fallthrough]]; + case CheatType::DisableRideValueAging: + [[fallthrough]]; + case CheatType::IgnoreResearchStatus: + [[fallthrough]]; + case CheatType::EnableAllDrawableTrackPieces: + [[fallthrough]]; + case CheatType::AllowRegularPathAsQueue: + [[fallthrough]]; + case CheatType::UnlockAllPrices: + [[fallthrough]]; + case CheatType::MakeDestructible: + [[fallthrough]]; + case CheatType::AllowSpecialColourSchemes: + [[fallthrough]]; + case CheatType::AllowTrackPlaceInvalidHeights: + [[fallthrough]]; + case CheatType::OpenClosePark: + return { { 0, 1 }, { 0, 0 } }; + case CheatType::AddMoney: + [[fallthrough]]; + case CheatType::SetMoney: + return { { std::numeric_limits::min(), std::numeric_limits::max() }, { 0, 0 } }; + case CheatType::SetGuestParameter: + switch (_param1) + { + case GUEST_PARAMETER_HAPPINESS: + return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, + { 0, kPeepMaxHappiness } }; + case GUEST_PARAMETER_ENERGY: + return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, + { kPeepMinEnergy, kPeepMaxEnergy } }; + case GUEST_PARAMETER_HUNGER: + return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, + { 0, kPeepMaxHunger } }; + case GUEST_PARAMETER_THIRST: + return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, + { 0, kPeepMaxThirst } }; + case GUEST_PARAMETER_NAUSEA: + return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, + { 0, kPeepMaxNausea } }; + case GUEST_PARAMETER_NAUSEA_TOLERANCE: + return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, + { EnumValue(PeepNauseaTolerance::None), EnumValue(PeepNauseaTolerance::High) } }; + case GUEST_PARAMETER_TOILET: + return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, + { 0, kPeepMaxToilet } }; + case GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY: + return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, { 0, 255 } }; + default: + return { { 0, 0 }, { 0, 0 } }; + } + case CheatType::GenerateGuests: + return { { 1, 10000 }, { 0, 0 } }; + case CheatType::GiveAllGuests: + return { { OBJECT_MONEY, OBJECT_UMBRELLA }, { 0, 0 } }; + case CheatType::SetGrassLength: + return { { 0, 7 }, { 0, 0 } }; + case CheatType::SetStaffSpeed: + return { { 0, 255 }, { 0, 0 } }; + case CheatType::ForceWeather: + return { { 0, EnumValue(WeatherType::Count) - 1 }, { 0, 0 } }; + case CheatType::SetForcedParkRating: + return { { -1, 999 }, { 0, 0 } }; + case CheatType::CreateDucks: + return { { 0, 100 }, { 0, 0 } }; + case CheatType::RemoveDucks: + [[fallthrough]]; + case CheatType::ClearLoan: + [[fallthrough]]; + case CheatType::RemoveAllGuests: + [[fallthrough]]; + case CheatType::OwnAllLand: + [[fallthrough]]; + case CheatType::WinScenario: + [[fallthrough]]; + case CheatType::HaveFun: + [[fallthrough]]; + case CheatType::FixVandalism: + [[fallthrough]]; + case CheatType::WaterPlants: + [[fallthrough]]; + case CheatType::FixRides: + [[fallthrough]]; + case CheatType::RenewRides: + [[fallthrough]]; + case CheatType::TenMinuteInspections: + [[fallthrough]]; + case CheatType::ResetCrashStatus: + [[fallthrough]]; + case CheatType::NoCapOnQueueLengthDummy: + [[fallthrough]]; + case CheatType::RemoveLitter: + [[fallthrough]]; + case CheatType::RemoveParkFences: + return { { 0, 0 }, { 0, 0 } }; + case CheatType::Count: + break; + } + + // Should be unreachable unless new cheats are added, still have to return something + // to avoid compiler warnings. + Guard::Assert(false, "Missing validation parameter for cheat: %d", _cheatType.id); + return { { 0, 0 }, { 0, 0 } }; + } + + void CheatSetAction::SetGrassLength(int32_t length) const + { + auto& gameState = getGameState(); + for (int32_t y = 0; y < gameState.mapSize.y; y++) + { + for (int32_t x = 0; x < gameState.mapSize.x; x++) + { + auto surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y }); + if (surfaceElement == nullptr) + continue; + + if (surfaceElement != nullptr && (surfaceElement->GetOwnership() & OWNERSHIP_OWNED) + && surfaceElement->GetWaterHeight() == 0 && surfaceElement->CanGrassGrow()) + { + surfaceElement->SetGrassLength(length); + } + } + } + + GfxInvalidateScreen(); + } + + void CheatSetAction::WaterPlants() const + { + TileElementIterator it; + + TileElementIteratorBegin(&it); + do + { + if (it.element->GetType() == TileElementType::SmallScenery) + { + it.element->AsSmallScenery()->SetAge(0); + } + } while (TileElementIteratorNext(&it)); + + GfxInvalidateScreen(); + } + + void CheatSetAction::FixVandalism() const + { + TileElementIterator it; + + TileElementIteratorBegin(&it); + do + { + if (it.element->GetType() != TileElementType::Path) + continue; + + if (!(it.element)->AsPath()->HasAddition()) + continue; + + it.element->AsPath()->SetIsBroken(false); + } while (TileElementIteratorNext(&it)); + + GfxInvalidateScreen(); + } + + void CheatSetAction::RemoveLitter() const + { + for (auto litter : EntityList()) + { + EntityRemove(litter); + } + + TileElementIterator it{}; + TileElementIteratorBegin(&it); + do + { + if (it.element->GetType() != TileElementType::Path) + continue; + + auto* path = it.element->AsPath(); + if (!path->HasAddition()) + continue; + + auto* pathAdditionEntry = path->GetAdditionEntry(); + if (pathAdditionEntry != nullptr && pathAdditionEntry->flags & PATH_ADDITION_FLAG_IS_BIN) + path->SetAdditionStatus(0xFF); + + } while (TileElementIteratorNext(&it)); + + GfxInvalidateScreen(); + } + + void CheatSetAction::FixBrokenRides() const + { + for (auto& ride : GetRideManager()) + { + if (ride.lifecycleFlags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)) + { + auto mechanic = RideGetAssignedMechanic(ride); + + if (mechanic != nullptr) + { + if (ride.mechanicStatus == RIDE_MECHANIC_STATUS_FIXING) + { + mechanic->RideSubState = PeepRideSubState::ApproachExit; + } + else if ( + ride.mechanicStatus == RIDE_MECHANIC_STATUS_CALLING + || ride.mechanicStatus == RIDE_MECHANIC_STATUS_HEADING) + { + mechanic->RemoveFromRide(); + } + } + + RideFixBreakdown(ride, 0); + ride.windowInvalidateFlags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST; + } } } - if (NetworkGetMode() == NETWORK_MODE_NONE) + void CheatSetAction::RenewRides() const { - Config::Save(); + for (auto& ride : GetRideManager()) + { + ride.renew(); + } + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->InvalidateByClass(WindowClass::Ride); } - windowMgr->InvalidateByClass(WindowClass::Cheats); - return GameActions::Result(); -} - -ParametersRange CheatSetAction::GetParameterRange(CheatType cheatType) const -{ - switch (static_cast(_cheatType.id)) + void CheatSetAction::ResetRideCrashStatus() const { - case CheatType::SandboxMode: - [[fallthrough]]; - case CheatType::DisableClearanceChecks: - [[fallthrough]]; - case CheatType::DisableSupportLimits: - [[fallthrough]]; - case CheatType::ShowAllOperatingModes: - [[fallthrough]]; - case CheatType::ShowVehiclesFromOtherTrackTypes: - [[fallthrough]]; - case CheatType::FastLiftHill: - [[fallthrough]]; - case CheatType::DisableBrakesFailure: - [[fallthrough]]; - case CheatType::DisableAllBreakdowns: - [[fallthrough]]; - case CheatType::DisableTrainLengthLimit: - [[fallthrough]]; - case CheatType::EnableChainLiftOnAllTrack: - [[fallthrough]]; - case CheatType::BuildInPauseMode: - [[fallthrough]]; - case CheatType::IgnoreRideIntensity: - [[fallthrough]]; - case CheatType::IgnorePrice: - [[fallthrough]]; - case CheatType::DisableVandalism: - [[fallthrough]]; - case CheatType::DisableLittering: - [[fallthrough]]; - case CheatType::NoMoney: - [[fallthrough]]; - case CheatType::DisablePlantAging: - [[fallthrough]]; - case CheatType::FreezeWeather: - [[fallthrough]]; - case CheatType::NeverendingMarketing: - [[fallthrough]]; - case CheatType::AllowArbitraryRideTypeChanges: - [[fallthrough]]; - case CheatType::DisableRideValueAging: - [[fallthrough]]; - case CheatType::IgnoreResearchStatus: - [[fallthrough]]; - case CheatType::EnableAllDrawableTrackPieces: - [[fallthrough]]; - case CheatType::AllowRegularPathAsQueue: - [[fallthrough]]; - case CheatType::UnlockAllPrices: - [[fallthrough]]; - case CheatType::MakeDestructible: - [[fallthrough]]; - case CheatType::AllowSpecialColourSchemes: - [[fallthrough]]; - case CheatType::AllowTrackPlaceInvalidHeights: - [[fallthrough]]; - case CheatType::OpenClosePark: - return { { 0, 1 }, { 0, 0 } }; - case CheatType::AddMoney: - [[fallthrough]]; - case CheatType::SetMoney: - return { { std::numeric_limits::min(), std::numeric_limits::max() }, { 0, 0 } }; - case CheatType::SetGuestParameter: - switch (_param1) + for (auto& ride : GetRideManager()) + { + // Reset crash status and history + ride.lifecycleFlags &= ~RIDE_LIFECYCLE_CRASHED; + ride.lastCrashType = RIDE_CRASH_TYPE_NONE; + } + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->InvalidateByClass(WindowClass::Ride); + } + + void CheatSetAction::Set10MinuteInspection() const + { + for (auto& ride : GetRideManager()) + { + // Set inspection interval to 10 minutes + ride.inspectionInterval = RIDE_INSPECTION_EVERY_10_MINUTES; + } + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->InvalidateByClass(WindowClass::Ride); + } + + void CheatSetAction::SetScenarioNoMoney(bool enabled) const + { + auto& park = getGameState().park; + if (enabled) + { + park.flags |= PARK_FLAGS_NO_MONEY; + } + else + { + park.flags &= ~PARK_FLAGS_NO_MONEY; + } + + // Invalidate all windows that have anything to do with finance + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->InvalidateByClass(WindowClass::Ride); + windowMgr->InvalidateByClass(WindowClass::Peep); + windowMgr->InvalidateByClass(WindowClass::ParkInformation); + windowMgr->InvalidateByClass(WindowClass::Finances); + windowMgr->InvalidateByClass(WindowClass::BottomToolbar); + windowMgr->InvalidateByClass(WindowClass::TopToolbar); + windowMgr->InvalidateByClass(WindowClass::Cheats); + } + + void CheatSetAction::SetMoney(money64 amount) const + { + getGameState().park.cash = amount; + + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->InvalidateByClass(WindowClass::Finances); + windowMgr->InvalidateByClass(WindowClass::BottomToolbar); + } + + void CheatSetAction::AddMoney(money64 amount) const + { + auto& park = getGameState().park; + park.cash = AddClamp(park.cash, amount); + + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->InvalidateByClass(WindowClass::Finances); + windowMgr->InvalidateByClass(WindowClass::BottomToolbar); + } + + void CheatSetAction::ClearLoan() const + { + // First give money + AddMoney(getGameState().park.bankLoan); + + // Then pay the loan + auto gameAction = ParkSetLoanAction(0.00_GBP); + ExecuteNested(&gameAction); + } + + void CheatSetAction::GenerateGuests(int32_t count) const + { + for (int32_t i = 0; i < count; i++) + { + Park::GenerateGuest(); + } + + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->InvalidateByClass(WindowClass::BottomToolbar); + } + + void CheatSetAction::SetGuestParameter(int32_t parameter, int32_t value) const + { + for (auto peep : EntityList()) + { + switch (parameter) { case GUEST_PARAMETER_HAPPINESS: - return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, - { 0, kPeepMaxHappiness } }; - case GUEST_PARAMETER_ENERGY: - return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, - { kPeepMinEnergy, kPeepMaxEnergy } }; - case GUEST_PARAMETER_HUNGER: - return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, { 0, kPeepMaxHunger } }; - case GUEST_PARAMETER_THIRST: - return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, { 0, kPeepMaxThirst } }; - case GUEST_PARAMETER_NAUSEA: - return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, { 0, kPeepMaxNausea } }; - case GUEST_PARAMETER_NAUSEA_TOLERANCE: - return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, - { EnumValue(PeepNauseaTolerance::None), EnumValue(PeepNauseaTolerance::High) } }; - case GUEST_PARAMETER_TOILET: - return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, { 0, kPeepMaxToilet } }; - case GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY: - return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, { 0, 255 } }; - default: - return { { 0, 0 }, { 0, 0 } }; - } - case CheatType::GenerateGuests: - return { { 1, 10000 }, { 0, 0 } }; - case CheatType::GiveAllGuests: - return { { OBJECT_MONEY, OBJECT_UMBRELLA }, { 0, 0 } }; - case CheatType::SetGrassLength: - return { { 0, 7 }, { 0, 0 } }; - case CheatType::SetStaffSpeed: - return { { 0, 255 }, { 0, 0 } }; - case CheatType::ForceWeather: - return { { 0, EnumValue(WeatherType::Count) - 1 }, { 0, 0 } }; - case CheatType::SetForcedParkRating: - return { { -1, 999 }, { 0, 0 } }; - case CheatType::CreateDucks: - return { { 0, 100 }, { 0, 0 } }; - case CheatType::RemoveDucks: - [[fallthrough]]; - case CheatType::ClearLoan: - [[fallthrough]]; - case CheatType::RemoveAllGuests: - [[fallthrough]]; - case CheatType::OwnAllLand: - [[fallthrough]]; - case CheatType::WinScenario: - [[fallthrough]]; - case CheatType::HaveFun: - [[fallthrough]]; - case CheatType::FixVandalism: - [[fallthrough]]; - case CheatType::WaterPlants: - [[fallthrough]]; - case CheatType::FixRides: - [[fallthrough]]; - case CheatType::RenewRides: - [[fallthrough]]; - case CheatType::TenMinuteInspections: - [[fallthrough]]; - case CheatType::ResetCrashStatus: - [[fallthrough]]; - case CheatType::NoCapOnQueueLengthDummy: - [[fallthrough]]; - case CheatType::RemoveLitter: - [[fallthrough]]; - case CheatType::RemoveParkFences: - return { { 0, 0 }, { 0, 0 } }; - case CheatType::Count: - break; - } - - // Should be unreachable unless new cheats are added, still have to return something - // to avoid compiler warnings. - Guard::Assert(false, "Missing validation parameter for cheat: %d", _cheatType.id); - return { { 0, 0 }, { 0, 0 } }; -} - -void CheatSetAction::SetGrassLength(int32_t length) const -{ - auto& gameState = getGameState(); - for (int32_t y = 0; y < gameState.mapSize.y; y++) - { - for (int32_t x = 0; x < gameState.mapSize.x; x++) - { - auto surfaceElement = MapGetSurfaceElementAt(TileCoordsXY{ x, y }); - if (surfaceElement == nullptr) - continue; - - if (surfaceElement != nullptr && (surfaceElement->GetOwnership() & OWNERSHIP_OWNED) - && surfaceElement->GetWaterHeight() == 0 && surfaceElement->CanGrassGrow()) - { - surfaceElement->SetGrassLength(length); - } - } - } - - GfxInvalidateScreen(); -} - -void CheatSetAction::WaterPlants() const -{ - TileElementIterator it; - - TileElementIteratorBegin(&it); - do - { - if (it.element->GetType() == TileElementType::SmallScenery) - { - it.element->AsSmallScenery()->SetAge(0); - } - } while (TileElementIteratorNext(&it)); - - GfxInvalidateScreen(); -} - -void CheatSetAction::FixVandalism() const -{ - TileElementIterator it; - - TileElementIteratorBegin(&it); - do - { - if (it.element->GetType() != TileElementType::Path) - continue; - - if (!(it.element)->AsPath()->HasAddition()) - continue; - - it.element->AsPath()->SetIsBroken(false); - } while (TileElementIteratorNext(&it)); - - GfxInvalidateScreen(); -} - -void CheatSetAction::RemoveLitter() const -{ - for (auto litter : EntityList()) - { - EntityRemove(litter); - } - - TileElementIterator it{}; - TileElementIteratorBegin(&it); - do - { - if (it.element->GetType() != TileElementType::Path) - continue; - - auto* path = it.element->AsPath(); - if (!path->HasAddition()) - continue; - - auto* pathAdditionEntry = path->GetAdditionEntry(); - if (pathAdditionEntry != nullptr && pathAdditionEntry->flags & PATH_ADDITION_FLAG_IS_BIN) - path->SetAdditionStatus(0xFF); - - } while (TileElementIteratorNext(&it)); - - GfxInvalidateScreen(); -} - -void CheatSetAction::FixBrokenRides() const -{ - for (auto& ride : GetRideManager()) - { - if (ride.lifecycleFlags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)) - { - auto mechanic = RideGetAssignedMechanic(ride); - - if (mechanic != nullptr) - { - if (ride.mechanicStatus == RIDE_MECHANIC_STATUS_FIXING) - { - mechanic->RideSubState = PeepRideSubState::ApproachExit; - } - else if ( - ride.mechanicStatus == RIDE_MECHANIC_STATUS_CALLING || ride.mechanicStatus == RIDE_MECHANIC_STATUS_HEADING) - { - mechanic->RemoveFromRide(); - } - } - - RideFixBreakdown(ride, 0); - ride.windowInvalidateFlags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST; - } - } -} - -void CheatSetAction::RenewRides() const -{ - for (auto& ride : GetRideManager()) - { - ride.renew(); - } - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByClass(WindowClass::Ride); -} - -void CheatSetAction::ResetRideCrashStatus() const -{ - for (auto& ride : GetRideManager()) - { - // Reset crash status and history - ride.lifecycleFlags &= ~RIDE_LIFECYCLE_CRASHED; - ride.lastCrashType = RIDE_CRASH_TYPE_NONE; - } - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByClass(WindowClass::Ride); -} - -void CheatSetAction::Set10MinuteInspection() const -{ - for (auto& ride : GetRideManager()) - { - // Set inspection interval to 10 minutes - ride.inspectionInterval = RIDE_INSPECTION_EVERY_10_MINUTES; - } - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByClass(WindowClass::Ride); -} - -void CheatSetAction::SetScenarioNoMoney(bool enabled) const -{ - auto& park = getGameState().park; - if (enabled) - { - park.flags |= PARK_FLAGS_NO_MONEY; - } - else - { - park.flags &= ~PARK_FLAGS_NO_MONEY; - } - - // Invalidate all windows that have anything to do with finance - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByClass(WindowClass::Ride); - windowMgr->InvalidateByClass(WindowClass::Peep); - windowMgr->InvalidateByClass(WindowClass::ParkInformation); - windowMgr->InvalidateByClass(WindowClass::Finances); - windowMgr->InvalidateByClass(WindowClass::BottomToolbar); - windowMgr->InvalidateByClass(WindowClass::TopToolbar); - windowMgr->InvalidateByClass(WindowClass::Cheats); -} - -void CheatSetAction::SetMoney(money64 amount) const -{ - getGameState().park.cash = amount; - - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByClass(WindowClass::Finances); - windowMgr->InvalidateByClass(WindowClass::BottomToolbar); -} - -void CheatSetAction::AddMoney(money64 amount) const -{ - auto& park = getGameState().park; - park.cash = AddClamp(park.cash, amount); - - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByClass(WindowClass::Finances); - windowMgr->InvalidateByClass(WindowClass::BottomToolbar); -} - -void CheatSetAction::ClearLoan() const -{ - // First give money - AddMoney(getGameState().park.bankLoan); - - // Then pay the loan - auto gameAction = ParkSetLoanAction(0.00_GBP); - GameActions::ExecuteNested(&gameAction); -} - -void CheatSetAction::GenerateGuests(int32_t count) const -{ - for (int32_t i = 0; i < count; i++) - { - Park::GenerateGuest(); - } - - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByClass(WindowClass::BottomToolbar); -} - -void CheatSetAction::SetGuestParameter(int32_t parameter, int32_t value) const -{ - for (auto peep : EntityList()) - { - switch (parameter) - { - case GUEST_PARAMETER_HAPPINESS: - peep->Happiness = value; - peep->HappinessTarget = value; - // Clear the 'red-faced with anger' status if we're making the guest happy - if (value > 0) - { - peep->PeepFlags &= ~PEEP_FLAGS_ANGRY; - peep->Angriness = 0; - } - break; - case GUEST_PARAMETER_ENERGY: - peep->Energy = value; - peep->EnergyTarget = value; - break; - case GUEST_PARAMETER_HUNGER: - peep->Hunger = value; - break; - case GUEST_PARAMETER_THIRST: - peep->Thirst = value; - break; - case GUEST_PARAMETER_NAUSEA: - peep->Nausea = value; - peep->NauseaTarget = value; - break; - case GUEST_PARAMETER_NAUSEA_TOLERANCE: - peep->NauseaTolerance = static_cast(value); - break; - case GUEST_PARAMETER_TOILET: - peep->Toilet = value; - break; - case GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY: - peep->Intensity = IntensityRange(value, 15); - break; - } - peep->UpdateAnimationGroup(); - } -} - -void CheatSetAction::GiveObjectToGuests(int32_t object) const -{ - for (auto peep : EntityList()) - { - switch (object) - { - case OBJECT_MONEY: - peep->CashInPocket = 1000.00_GBP; - break; - case OBJECT_PARK_MAP: - peep->GiveItem(ShopItem::Map); - break; - case OBJECT_BALLOON: - peep->GiveItem(ShopItem::Balloon); - peep->BalloonColour = ScenarioRandMax(kColourNumNormal); - peep->UpdateAnimationGroup(); - break; - case OBJECT_UMBRELLA: - peep->GiveItem(ShopItem::Umbrella); - peep->UmbrellaColour = ScenarioRandMax(kColourNumOriginal); - peep->UpdateAnimationGroup(); - break; - } - } - - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByClass(WindowClass::Peep); -} - -void CheatSetAction::RemoveAllGuests() const -{ - for (auto& ride : GetRideManager()) - { - ride.numRiders = 0; - - for (auto& station : ride.getStations()) - { - station.QueueLength = 0; - station.LastPeepInQueue = EntityId::GetNull(); - } - - for (auto trainIndex : ride.vehicles) - { - for (Vehicle* vehicle = TryGetEntity(trainIndex); vehicle != nullptr; - vehicle = TryGetEntity(vehicle->next_vehicle_on_train)) - { - auto i = 0; - for (auto& peepInTrainIndex : vehicle->peep) - { - if (i >= vehicle->num_peeps) - break; - - auto peep = TryGetEntity(peepInTrainIndex); - if (peep != nullptr && peep->CurrentRide == ride.id) + peep->Happiness = value; + peep->HappinessTarget = value; + // Clear the 'red-faced with anger' status if we're making the guest happy + if (value > 0) { - if ((peep->State == PeepState::OnRide && peep->RideSubState == PeepRideSubState::OnRide) - || (peep->State == PeepState::LeavingRide && peep->RideSubState == PeepRideSubState::LeaveVehicle)) - { - vehicle->ApplyMass(-peep->Mass); - } + peep->PeepFlags &= ~PEEP_FLAGS_ANGRY; + peep->Angriness = 0; } - peepInTrainIndex = EntityId::GetNull(); - i++; - } - - vehicle->num_peeps = 0; - vehicle->next_free_seat = 0; + break; + case GUEST_PARAMETER_ENERGY: + peep->Energy = value; + peep->EnergyTarget = value; + break; + case GUEST_PARAMETER_HUNGER: + peep->Hunger = value; + break; + case GUEST_PARAMETER_THIRST: + peep->Thirst = value; + break; + case GUEST_PARAMETER_NAUSEA: + peep->Nausea = value; + peep->NauseaTarget = value; + break; + case GUEST_PARAMETER_NAUSEA_TOLERANCE: + peep->NauseaTolerance = static_cast(value); + break; + case GUEST_PARAMETER_TOILET: + peep->Toilet = value; + break; + case GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY: + peep->Intensity = IntensityRange(value, 15); + break; } + peep->UpdateAnimationGroup(); } } - // Do not use the FOR_ALL_PEEPS macro for this as next sprite index - // will be fetched on a deleted guest. - for (auto guest : EntityList()) + void CheatSetAction::GiveObjectToGuests(int32_t object) const { - // Frozen peeps are usually placed and tweaked for artistic purposes, - // so exempt them from being removed. - if (guest->PeepFlags & PEEP_FLAGS_POSITION_FROZEN) - continue; - - guest->Remove(); - } - - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByClass(WindowClass::Ride); - GfxInvalidateScreen(); -} - -void CheatSetAction::SetStaffSpeed(uint8_t value) const -{ - for (auto peep : EntityList()) - { - peep->Energy = value; - peep->EnergyTarget = value; - } -} - -void CheatSetAction::OwnAllLand() const -{ - const auto min = CoordsXY{ kCoordsXYStep, kCoordsXYStep }; - const auto max = GetMapSizeUnits() - CoordsXY{ kCoordsXYStep, kCoordsXYStep }; - - for (CoordsXY coords = min; coords.y <= max.y; coords.y += kCoordsXYStep) - { - for (coords.x = min.x; coords.x <= max.x; coords.x += kCoordsXYStep) + for (auto peep : EntityList()) { - auto* surfaceElement = MapGetSurfaceElementAt(coords); - if (surfaceElement == nullptr) - continue; - - // Ignore already owned tiles. - if (surfaceElement->GetOwnership() & OWNERSHIP_OWNED) - continue; - - int32_t baseZ = surfaceElement->GetBaseZ(); - int32_t destOwnership = CheckMaxAllowableLandRightsForTile({ coords, baseZ }); - - // only own tiles that were not set to 0 - if (destOwnership != OWNERSHIP_UNOWNED) + switch (object) { - surfaceElement->SetOwnership(destOwnership); - Park::UpdateFencesAroundTile(coords); - MapInvalidateTile({ coords, baseZ, baseZ + 16 }); + case OBJECT_MONEY: + peep->CashInPocket = 1000.00_GBP; + break; + case OBJECT_PARK_MAP: + peep->GiveItem(ShopItem::Map); + break; + case OBJECT_BALLOON: + peep->GiveItem(ShopItem::Balloon); + peep->BalloonColour = ScenarioRandMax(kColourNumNormal); + peep->UpdateAnimationGroup(); + break; + case OBJECT_UMBRELLA: + peep->GiveItem(ShopItem::Umbrella); + peep->UmbrellaColour = ScenarioRandMax(kColourNumOriginal); + peep->UpdateAnimationGroup(); + break; + } + } + + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->InvalidateByClass(WindowClass::Peep); + } + + void CheatSetAction::RemoveAllGuests() const + { + for (auto& ride : GetRideManager()) + { + ride.numRiders = 0; + + for (auto& station : ride.getStations()) + { + station.QueueLength = 0; + station.LastPeepInQueue = EntityId::GetNull(); + } + + for (auto trainIndex : ride.vehicles) + { + for (Vehicle* vehicle = TryGetEntity(trainIndex); vehicle != nullptr; + vehicle = TryGetEntity(vehicle->next_vehicle_on_train)) + { + auto i = 0; + for (auto& peepInTrainIndex : vehicle->peep) + { + if (i >= vehicle->num_peeps) + break; + + auto peep = TryGetEntity(peepInTrainIndex); + if (peep != nullptr && peep->CurrentRide == ride.id) + { + if ((peep->State == PeepState::OnRide && peep->RideSubState == PeepRideSubState::OnRide) + || (peep->State == PeepState::LeavingRide + && peep->RideSubState == PeepRideSubState::LeaveVehicle)) + { + vehicle->ApplyMass(-peep->Mass); + } + } + peepInTrainIndex = EntityId::GetNull(); + i++; + } + + vehicle->num_peeps = 0; + vehicle->next_free_seat = 0; + } + } + } + + // Do not use the FOR_ALL_PEEPS macro for this as next sprite index + // will be fetched on a deleted guest. + for (auto guest : EntityList()) + { + // Frozen peeps are usually placed and tweaked for artistic purposes, + // so exempt them from being removed. + if (guest->PeepFlags & PEEP_FLAGS_POSITION_FROZEN) + continue; + + guest->Remove(); + } + + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->InvalidateByClass(WindowClass::Ride); + GfxInvalidateScreen(); + } + + void CheatSetAction::SetStaffSpeed(uint8_t value) const + { + for (auto peep : EntityList()) + { + peep->Energy = value; + peep->EnergyTarget = value; + } + } + + void CheatSetAction::OwnAllLand() const + { + const auto min = CoordsXY{ kCoordsXYStep, kCoordsXYStep }; + const auto max = GetMapSizeUnits() - CoordsXY{ kCoordsXYStep, kCoordsXYStep }; + + for (CoordsXY coords = min; coords.y <= max.y; coords.y += kCoordsXYStep) + { + for (coords.x = min.x; coords.x <= max.x; coords.x += kCoordsXYStep) + { + auto* surfaceElement = MapGetSurfaceElementAt(coords); + if (surfaceElement == nullptr) + continue; + + // Ignore already owned tiles. + if (surfaceElement->GetOwnership() & OWNERSHIP_OWNED) + continue; + + int32_t baseZ = surfaceElement->GetBaseZ(); + int32_t destOwnership = CheckMaxAllowableLandRightsForTile({ coords, baseZ }); + + // only own tiles that were not set to 0 + if (destOwnership != OWNERSHIP_UNOWNED) + { + surfaceElement->SetOwnership(destOwnership); + Park::UpdateFencesAroundTile(coords); + MapInvalidateTile({ coords, baseZ, baseZ + 16 }); + } + } + } + + // Completely unown peep spawn points + for (const auto& spawn : getGameState().peepSpawns) + { + auto* surfaceElement = MapGetSurfaceElementAt(spawn); + if (surfaceElement != nullptr) + { + surfaceElement->SetOwnership(OWNERSHIP_UNOWNED); + Park::UpdateFencesAroundTile(spawn); + uint16_t baseZ = surfaceElement->GetBaseZ(); + MapInvalidateTile({ spawn, baseZ, baseZ + 16 }); + } + } + + MapCountRemainingLandRights(); + } + + void CheatSetAction::ParkSetOpen(bool isOpen) const + { + auto parkSetParameter = ParkSetParameterAction(isOpen ? ParkParameter::Open : ParkParameter::Close); + ExecuteNested(&parkSetParameter); + } + + void CheatSetAction::CreateDucks(int count) const + { + for (int i = 0; i < count; i++) + { + // 100 attempts at finding some water to create a few ducks at + for (int32_t attempts = 0; attempts < 100; attempts++) + { + if (ScenarioCreateDucks()) + break; } } } - // Completely unown peep spawn points - for (const auto& spawn : getGameState().peepSpawns) + void CheatSetAction::RemoveParkFences() const { - auto* surfaceElement = MapGetSurfaceElementAt(spawn); - if (surfaceElement != nullptr) + TileElementIterator it; + TileElementIteratorBegin(&it); + do { - surfaceElement->SetOwnership(OWNERSHIP_UNOWNED); - Park::UpdateFencesAroundTile(spawn); - uint16_t baseZ = surfaceElement->GetBaseZ(); - MapInvalidateTile({ spawn, baseZ, baseZ + 16 }); - } + if (it.element->GetType() == TileElementType::Surface) + { + // Remove all park fence flags + it.element->AsSurface()->SetParkFences(0); + } + } while (TileElementIteratorNext(&it)); + + GfxInvalidateScreen(); } - - MapCountRemainingLandRights(); -} - -void CheatSetAction::ParkSetOpen(bool isOpen) const -{ - auto parkSetParameter = ParkSetParameterAction(isOpen ? ParkParameter::Open : ParkParameter::Close); - GameActions::ExecuteNested(&parkSetParameter); -} - -void CheatSetAction::CreateDucks(int count) const -{ - for (int i = 0; i < count; i++) - { - // 100 attempts at finding some water to create a few ducks at - for (int32_t attempts = 0; attempts < 100; attempts++) - { - if (ScenarioCreateDucks()) - break; - } - } -} - -void CheatSetAction::RemoveParkFences() const -{ - TileElementIterator it; - TileElementIteratorBegin(&it); - do - { - if (it.element->GetType() == TileElementType::Surface) - { - // Remove all park fence flags - it.element->AsSurface()->SetParkFences(0); - } - } while (TileElementIteratorNext(&it)); - - GfxInvalidateScreen(); -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/CheatSetAction.h b/src/openrct2/actions/CheatSetAction.h index fe387771b6..89f7947ff3 100644 --- a/src/openrct2/actions/CheatSetAction.h +++ b/src/openrct2/actions/CheatSetAction.h @@ -11,48 +11,51 @@ #include "GameAction.h" -class CheatSetAction final : public GameActionBase +namespace OpenRCT2::GameActions { - using ParametersRange = std::pair, std::pair>; + class CheatSetAction final : public GameActionBase + { + using ParametersRange = std::pair, std::pair>; -private: - NetworkCheatType_t _cheatType{ EnumValue(CheatType::Count) }; - int64_t _param1{}; - int64_t _param2{}; + private: + NetworkCheatType_t _cheatType{ EnumValue(CheatType::Count) }; + int64_t _param1{}; + int64_t _param2{}; -public: - CheatSetAction() = default; - CheatSetAction(CheatType cheatType, int64_t param1 = 0, int64_t param2 = 0); + public: + CheatSetAction() = default; + CheatSetAction(CheatType cheatType, int64_t param1 = 0, int64_t param2 = 0); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; -private: - ParametersRange GetParameterRange(CheatType cheatType) const; - void SetGrassLength(int32_t length) const; - void WaterPlants() const; - void FixVandalism() const; - void RemoveLitter() const; - void FixBrokenRides() const; - void RenewRides() const; - void ResetRideCrashStatus() const; - void Set10MinuteInspection() const; - void SetScenarioNoMoney(bool enabled) const; - void SetMoney(money64 amount) const; - void AddMoney(money64 amount) const; - void ClearLoan() const; - void GenerateGuests(int32_t count) const; - void SetGuestParameter(int32_t parameter, int32_t value) const; - void GiveObjectToGuests(int32_t object) const; - void RemoveAllGuests() const; - void SetStaffSpeed(uint8_t value) const; - void OwnAllLand() const; - void ParkSetOpen(bool isOpen) const; - void CreateDucks(int count) const; - void RemoveParkFences() const; -}; + private: + ParametersRange GetParameterRange(CheatType cheatType) const; + void SetGrassLength(int32_t length) const; + void WaterPlants() const; + void FixVandalism() const; + void RemoveLitter() const; + void FixBrokenRides() const; + void RenewRides() const; + void ResetRideCrashStatus() const; + void Set10MinuteInspection() const; + void SetScenarioNoMoney(bool enabled) const; + void SetMoney(money64 amount) const; + void AddMoney(money64 amount) const; + void ClearLoan() const; + void GenerateGuests(int32_t count) const; + void SetGuestParameter(int32_t parameter, int32_t value) const; + void GiveObjectToGuests(int32_t object) const; + void RemoveAllGuests() const; + void SetStaffSpeed(uint8_t value) const; + void OwnAllLand() const; + void ParkSetOpen(bool isOpen) const; + void CreateDucks(int count) const; + void RemoveParkFences() const; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/ClearAction.cpp b/src/openrct2/actions/ClearAction.cpp index d1a19d3e64..4c754f39f3 100644 --- a/src/openrct2/actions/ClearAction.cpp +++ b/src/openrct2/actions/ClearAction.cpp @@ -143,7 +143,7 @@ money64 ClearAction::ClearSceneryFromTile(const CoordsXY& tilePos, bool executin case TileElementType::Path: if (_itemsToClear & CLEARABLE_ITEMS::kSceneryFootpath) { - auto footpathRemoveAction = FootpathRemoveAction({ tilePos, tileElement->GetBaseZ() }); + auto footpathRemoveAction = GameActions::FootpathRemoveAction({ tilePos, tileElement->GetBaseZ() }); footpathRemoveAction.SetFlags(GetFlags()); auto res = executing ? GameActions::ExecuteNested(&footpathRemoveAction) diff --git a/src/openrct2/actions/FootpathRemoveAction.cpp b/src/openrct2/actions/FootpathRemoveAction.cpp index b8f633833c..7e644f6777 100644 --- a/src/openrct2/actions/FootpathRemoveAction.cpp +++ b/src/openrct2/actions/FootpathRemoveAction.cpp @@ -22,172 +22,171 @@ #include "../world/tile_element/PathElement.h" #include "BannerRemoveAction.h" -using namespace OpenRCT2; - -FootpathRemoveAction::FootpathRemoveAction(const CoordsXYZ& location) - : _loc(location) +namespace OpenRCT2::GameActions { -} - -void FootpathRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit(_loc); -} - -uint16_t FootpathRemoveAction::GetActionFlags() const -{ - return GameAction::GetActionFlags(); -} - -void FootpathRemoveAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_loc); -} - -GameActions::Result FootpathRemoveAction::Query() const -{ - auto res = GameActions::Result(); - res.Cost = 0; - res.Expenditure = ExpenditureType::landscaping; - res.Position = { _loc.x + 16, _loc.y + 16, _loc.z }; - - if (!LocationValid(_loc)) + FootpathRemoveAction::FootpathRemoveAction(const CoordsXYZ& location) + : _loc(location) { - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_OFF_EDGE_OF_MAP); } - if (!(gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode) && !MapIsLocationOwned(_loc)) + void FootpathRemoveAction::AcceptParameters(GameActionParameterVisitor& visitor) { - return GameActions::Result( - GameActions::Status::NotOwned, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_LAND_NOT_OWNED_BY_PARK); + visitor.Visit(_loc); } - TileElement* footpathElement = GetFootpathElement(); - if (footpathElement == nullptr) + uint16_t FootpathRemoveAction::GetActionFlags() const { - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_ERR_PATH_ELEMENT_NOT_FOUND); + return GameAction::GetActionFlags(); } - res.Cost = GetRefundPrice(footpathElement); - - return res; -} - -GameActions::Result FootpathRemoveAction::Execute() const -{ - auto res = GameActions::Result(); - res.Cost = 0; - res.Expenditure = ExpenditureType::landscaping; - res.Position = { _loc.x + 16, _loc.y + 16, _loc.z }; - - if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) + void FootpathRemoveAction::Serialise(DataSerialiser& stream) { - FootpathInterruptPeeps(_loc); - FootpathRemoveLitter(_loc); + GameAction::Serialise(stream); + + stream << DS_TAG(_loc); } - TileElement* footpathElement = GetFootpathElement(); - if (footpathElement != nullptr) + Result FootpathRemoveAction::Query() const { - FootpathQueueChainReset(); - auto bannerRes = RemoveBannersAtElement(_loc, footpathElement); - if (bannerRes.Error == GameActions::Status::Ok) + auto res = Result(); + res.Cost = 0; + res.Expenditure = ExpenditureType::landscaping; + res.Position = { _loc.x + 16, _loc.y + 16, _loc.z }; + + if (!LocationValid(_loc)) { - res.Cost += bannerRes.Cost; + return Result(Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_OFF_EDGE_OF_MAP); } - FootpathRemoveEdgesAt(_loc, footpathElement); - MapInvalidateTileFull(_loc); - TileElementRemove(footpathElement); - FootpathUpdateQueueChains(); - auto& gameState = getGameState(); - // Remove the spawn point (if there is one in the current tile) - gameState.peepSpawns.erase( - std::remove_if( - gameState.peepSpawns.begin(), gameState.peepSpawns.end(), - [this](const CoordsXYZ& spawn) { - { - return spawn.ToTileStart() == _loc.ToTileStart(); - } - }), - gameState.peepSpawns.end()); - } - else - { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, kStringIdNone); - } - - res.Cost += GetRefundPrice(footpathElement); - - return res; -} - -TileElement* FootpathRemoveAction::GetFootpathElement() const -{ - bool getGhostPath = GetFlags() & GAME_COMMAND_FLAG_GHOST; - - // FIXME: This is a hack to get the footpath element. It should be done in a better way. - TileElement* tileElement = MapGetFootpathElement(_loc)->as(); - TileElement* footpathElement = nullptr; - if (tileElement != nullptr) - { - if (getGhostPath && !tileElement->IsGhost()) + if (!(gLegacyScene == LegacyScene::scenarioEditor || getGameState().cheats.sandboxMode) && !MapIsLocationOwned(_loc)) { - while (!(tileElement++)->IsLastForTile()) + return Result(Status::NotOwned, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_LAND_NOT_OWNED_BY_PARK); + } + + TileElement* footpathElement = GetFootpathElement(); + if (footpathElement == nullptr) + { + return Result(Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, STR_ERR_PATH_ELEMENT_NOT_FOUND); + } + + res.Cost = GetRefundPrice(footpathElement); + + return res; + } + + Result FootpathRemoveAction::Execute() const + { + auto res = Result(); + res.Cost = 0; + res.Expenditure = ExpenditureType::landscaping; + res.Position = { _loc.x + 16, _loc.y + 16, _loc.z }; + + if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) + { + FootpathInterruptPeeps(_loc); + FootpathRemoveLitter(_loc); + } + + TileElement* footpathElement = GetFootpathElement(); + if (footpathElement != nullptr) + { + FootpathQueueChainReset(); + auto bannerRes = RemoveBannersAtElement(_loc, footpathElement); + if (bannerRes.Error == Status::Ok) { - if (tileElement->GetType() != TileElementType::Path && !tileElement->IsGhost()) - { - continue; - } - footpathElement = tileElement; - break; + res.Cost += bannerRes.Cost; } + FootpathRemoveEdgesAt(_loc, footpathElement); + MapInvalidateTileFull(_loc); + TileElementRemove(footpathElement); + FootpathUpdateQueueChains(); + + auto& gameState = getGameState(); + // Remove the spawn point (if there is one in the current tile) + gameState.peepSpawns.erase( + std::remove_if( + gameState.peepSpawns.begin(), gameState.peepSpawns.end(), + [this](const CoordsXYZ& spawn) { + { + return spawn.ToTileStart() == _loc.ToTileStart(); + } + }), + gameState.peepSpawns.end()); } else { - footpathElement = tileElement; + return Result(Status::InvalidParameters, STR_CANT_REMOVE_FOOTPATH_FROM_HERE, kStringIdNone); } + + res.Cost += GetRefundPrice(footpathElement); + + return res; } - return footpathElement; -} - -money64 FootpathRemoveAction::GetRefundPrice(TileElement* footpathElement) const -{ - money64 cost = -10.00_GBP; - return cost; -} - -/** - * - * rct2: 0x006BA23E - */ -GameActions::Result FootpathRemoveAction::RemoveBannersAtElement(const CoordsXY& loc, TileElement* tileElement) const -{ - auto result = GameActions::Result(); - while (!(tileElement++)->IsLastForTile()) + TileElement* FootpathRemoveAction::GetFootpathElement() const { - if (tileElement->GetType() == TileElementType::Path) - return result; + bool getGhostPath = GetFlags() & GAME_COMMAND_FLAG_GHOST; - if (tileElement->GetType() != TileElementType::Banner) - continue; - - auto bannerRemoveAction = BannerRemoveAction({ loc, tileElement->GetBaseZ(), tileElement->AsBanner()->GetPosition() }); - bool isGhost = tileElement->IsGhost(); - auto bannerFlags = GetFlags() | (isGhost ? static_cast(GAME_COMMAND_FLAG_GHOST) : 0); - bannerRemoveAction.SetFlags(bannerFlags); - auto res = GameActions::ExecuteNested(&bannerRemoveAction); - // Ghost removal is free - if (res.Error == GameActions::Status::Ok && !isGhost) + // FIXME: This is a hack to get the footpath element. It should be done in a better way. + TileElement* tileElement = MapGetFootpathElement(_loc)->as(); + TileElement* footpathElement = nullptr; + if (tileElement != nullptr) { - result.Cost += res.Cost; + if (getGhostPath && !tileElement->IsGhost()) + { + while (!(tileElement++)->IsLastForTile()) + { + if (tileElement->GetType() != TileElementType::Path && !tileElement->IsGhost()) + { + continue; + } + footpathElement = tileElement; + break; + } + } + else + { + footpathElement = tileElement; + } } - tileElement--; + + return footpathElement; } - return result; -} + + money64 FootpathRemoveAction::GetRefundPrice(TileElement* footpathElement) const + { + money64 cost = -10.00_GBP; + return cost; + } + + /** + * + * rct2: 0x006BA23E + */ + Result FootpathRemoveAction::RemoveBannersAtElement(const CoordsXY& loc, TileElement* tileElement) const + { + auto result = Result(); + while (!(tileElement++)->IsLastForTile()) + { + if (tileElement->GetType() == TileElementType::Path) + return result; + + if (tileElement->GetType() != TileElementType::Banner) + continue; + + auto bannerRemoveAction = BannerRemoveAction( + { loc, tileElement->GetBaseZ(), tileElement->AsBanner()->GetPosition() }); + bool isGhost = tileElement->IsGhost(); + auto bannerFlags = GetFlags() | (isGhost ? static_cast(GAME_COMMAND_FLAG_GHOST) : 0); + bannerRemoveAction.SetFlags(bannerFlags); + auto res = ExecuteNested(&bannerRemoveAction); + // Ghost removal is free + if (res.Error == Status::Ok && !isGhost) + { + result.Cost += res.Cost; + } + tileElement--; + } + return result; + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/FootpathRemoveAction.h b/src/openrct2/actions/FootpathRemoveAction.h index ab2c83f00e..2398de32dc 100644 --- a/src/openrct2/actions/FootpathRemoveAction.h +++ b/src/openrct2/actions/FootpathRemoveAction.h @@ -12,25 +12,28 @@ #include "../management/Finance.h" #include "GameAction.h" -class FootpathRemoveAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - CoordsXYZ _loc; + class FootpathRemoveAction final : public GameActionBase + { + private: + CoordsXYZ _loc; -public: - FootpathRemoveAction() = default; - FootpathRemoveAction(const CoordsXYZ& location); + public: + FootpathRemoveAction() = default; + FootpathRemoveAction(const CoordsXYZ& location); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; -private: - OpenRCT2::TileElement* GetFootpathElement() const; - money64 GetRefundPrice(OpenRCT2::TileElement* footpathElement) const; - OpenRCT2::GameActions::Result RemoveBannersAtElement(const CoordsXY& loc, OpenRCT2::TileElement* tileElement) const; -}; + private: + TileElement* GetFootpathElement() const; + money64 GetRefundPrice(TileElement* footpathElement) const; + Result RemoveBannersAtElement(const CoordsXY& loc, TileElement* tileElement) const; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/GameAction.cpp b/src/openrct2/actions/GameAction.cpp index 6ac0b5355d..361b2ebb97 100644 --- a/src/openrct2/actions/GameAction.cpp +++ b/src/openrct2/actions/GameAction.cpp @@ -31,8 +31,6 @@ #include -using namespace OpenRCT2; - namespace OpenRCT2::GameActions { struct QueuedGameAction @@ -143,8 +141,8 @@ namespace OpenRCT2::GameActions Guard::Assert(action != nullptr); - GameActions::Result result = Execute(action); - if (result.Error == GameActions::Status::Ok && NetworkGetMode() == NETWORK_MODE_SERVER) + Result result = Execute(action); + if (result.Error == Status::Ok && NetworkGetMode() == NETWORK_MODE_SERVER) { // Relay this action to all other clients. NetworkSendGameAction(action); @@ -161,7 +159,7 @@ namespace OpenRCT2::GameActions GameAction::Ptr Clone(const GameAction* action) { - std::unique_ptr ga = GameActions::Create(action->GetType()); + std::unique_ptr ga = Create(action->GetType()); ga->SetCallback(action->GetCallback()); // Serialise action data into stream. @@ -184,21 +182,21 @@ namespace OpenRCT2::GameActions return true; if (getGameState().cheats.buildInPauseMode) return true; - if (actionFlags & GameActions::Flags::AllowWhilePaused) + if (actionFlags & Flags::AllowWhilePaused) return true; return false; } - static GameActions::Result QueryInternal(const GameAction* action, bool topLevel) + static Result QueryInternal(const GameAction* action, bool topLevel) { Guard::ArgumentNotNull(action); uint16_t actionFlags = action->GetActionFlags(); if (topLevel && !CheckActionInPausedMode(actionFlags)) { - GameActions::Result result = GameActions::Result(); + Result result = Result(); - result.Error = GameActions::Status::GamePaused; + result.Error = Status::GamePaused; result.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; result.ErrorMessage = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED; @@ -207,11 +205,11 @@ namespace OpenRCT2::GameActions auto result = action->Query(); - if (result.Error == GameActions::Status::Ok) + if (result.Error == Status::Ok) { if (!FinanceCheckAffordability(result.Cost, action->GetFlags())) { - result.Error = GameActions::Status::InsufficientFunds; + result.Error = Status::InsufficientFunds; result.ErrorTitle = STR_CANT_DO_THIS; result.ErrorMessage = STR_NOT_ENOUGH_CASH_REQUIRES; Formatter(result.ErrorMessageArgs.data()).Add(result.Cost); @@ -220,12 +218,12 @@ namespace OpenRCT2::GameActions return result; } - GameActions::Result Query(const GameAction* action) + Result Query(const GameAction* action) { return QueryInternal(action, true); } - GameActions::Result QueryNested(const GameAction* action) + Result QueryNested(const GameAction* action) { return QueryInternal(action, false); } @@ -261,13 +259,13 @@ namespace OpenRCT2::GameActions action->Serialise(ds); } - static void LogActionFinish(ActionLogContext& ctx, const GameAction* action, const GameActions::Result& result) + static void LogActionFinish(ActionLogContext& ctx, const GameAction* action, const Result& result) { MemoryStream& output = ctx.output; char temp[128] = {}; - if (result.Error != GameActions::Status::Ok) + if (result.Error != Status::Ok) { snprintf(temp, sizeof(temp), ") Failed, %u", static_cast(result.Error)); } @@ -284,7 +282,7 @@ namespace OpenRCT2::GameActions NetworkAppendServerLog(text); } - static GameActions::Result ExecuteInternal(const GameAction* action, bool topLevel) + static Result ExecuteInternal(const GameAction* action, bool topLevel) { Guard::ArgumentNotNull(action); @@ -292,7 +290,7 @@ namespace OpenRCT2::GameActions uint32_t flags = action->GetFlags(); // Some actions are not recorded in the replay. - const auto ignoreForReplays = (actionFlags & GameActions::Flags::IgnoreForReplays) != 0; + const auto ignoreForReplays = (actionFlags & Flags::IgnoreForReplays) != 0; auto* replayManager = OpenRCT2::GetContext()->GetReplayManager(); if (replayManager != nullptr && (replayManager->IsReplaying() || replayManager->IsNormalising())) @@ -301,8 +299,8 @@ namespace OpenRCT2::GameActions if ((flags & GAME_COMMAND_FLAG_REPLAY) == 0 && !ignoreForReplays) { // TODO: Introduce proper error. - auto result = GameActions::Result(); - result.Error = GameActions::Status::GamePaused; + auto result = Result(); + result.Error = Status::GamePaused; result.ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; result.ErrorMessage = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED; @@ -310,17 +308,16 @@ namespace OpenRCT2::GameActions } } - GameActions::Result result = QueryInternal(action, topLevel); + Result result = QueryInternal(action, topLevel); #ifdef ENABLE_SCRIPTING - if (result.Error == GameActions::Status::Ok - && ((NetworkGetMode() == NETWORK_MODE_NONE) || (flags & GAME_COMMAND_FLAG_NETWORKED))) + if (result.Error == Status::Ok && ((NetworkGetMode() == NETWORK_MODE_NONE) || (flags & GAME_COMMAND_FLAG_NETWORKED))) { auto& scriptEngine = GetContext()->GetScriptEngine(); scriptEngine.RunGameActionHooks(*action, result, false); // Script hooks may now have changed the game action result... } #endif - if (result.Error == GameActions::Status::Ok) + if (result.Error == Status::Ok) { if (topLevel) { @@ -328,7 +325,7 @@ namespace OpenRCT2::GameActions if (NetworkGetMode() == NETWORK_MODE_CLIENT) { // As a client we have to wait or send it first. - if (!(actionFlags & GameActions::Flags::ClientOnly) && !(flags & GAME_COMMAND_FLAG_NETWORKED)) + if (!(actionFlags & Flags::ClientOnly) && !(flags & GAME_COMMAND_FLAG_NETWORKED)) { LOG_VERBOSE("[%s] GameAction::Execute %s (Out)", GetRealm(), action->GetName()); NetworkSendGameAction(action); @@ -341,7 +338,7 @@ namespace OpenRCT2::GameActions // If player is the server it would execute right away as where clients execute the commands // at the beginning of the frame, so we have to put them into the queue. // This is also the case when its executed from the UI update. - if (!(actionFlags & GameActions::Flags::ClientOnly) && !(flags & GAME_COMMAND_FLAG_NETWORKED)) + if (!(actionFlags & Flags::ClientOnly) && !(flags & GAME_COMMAND_FLAG_NETWORKED)) { LOG_VERBOSE("[%s] GameAction::Execute %s (Queue)", GetRealm(), action->GetName()); Enqueue(action, getGameState().currentTicks); @@ -357,7 +354,7 @@ namespace OpenRCT2::GameActions // Execute the action, changing the game state result = action->Execute(); #ifdef ENABLE_SCRIPTING - if (result.Error == GameActions::Status::Ok) + if (result.Error == Status::Ok) { auto& scriptEngine = GetContext()->GetScriptEngine(); scriptEngine.RunGameActionHooks(*action, result, true); @@ -372,13 +369,13 @@ namespace OpenRCT2::GameActions return result; // Update money balance - if (result.Error == GameActions::Status::Ok && FinanceCheckMoneyRequired(flags) && result.Cost != 0) + if (result.Error == Status::Ok && FinanceCheckMoneyRequired(flags) && result.Cost != 0) { FinancePayment(result.Cost, result.Expenditure); MoneyEffect::Create(result.Cost, result.Position); } - if (!(actionFlags & GameActions::Flags::ClientOnly) && result.Error == GameActions::Status::Ok) + if (!(actionFlags & Flags::ClientOnly) && result.Error == Status::Ok) { if (NetworkGetMode() != NETWORK_MODE_NONE) { @@ -448,7 +445,7 @@ namespace OpenRCT2::GameActions } } - if (result.Error != GameActions::Status::Ok && shouldShowError) + if (result.Error != Status::Ok && shouldShowError) { auto windowManager = Ui::GetWindowManager(); windowManager->ShowError(result.GetErrorTitle(), result.GetErrorMessage()); @@ -457,12 +454,12 @@ namespace OpenRCT2::GameActions return result; } - GameActions::Result Execute(const GameAction* action) + Result Execute(const GameAction* action) { return ExecuteInternal(action, true); } - GameActions::Result ExecuteNested(const GameAction* action) + Result ExecuteNested(const GameAction* action) { return ExecuteInternal(action, false); } @@ -470,7 +467,7 @@ namespace OpenRCT2::GameActions const char* GameAction::GetName() const { - return GameActions::GetName(_type); + return OpenRCT2::GameActions::GetName(_type); } bool GameAction::LocationValid(const CoordsXY& coords) const @@ -479,10 +476,10 @@ bool GameAction::LocationValid(const CoordsXY& coords) const if (!result) return false; #ifdef ENABLE_SCRIPTING - auto& hookEngine = GetContext()->GetScriptEngine().GetHookEngine(); + auto& hookEngine = OpenRCT2::GetContext()->GetScriptEngine().GetHookEngine(); if (hookEngine.HasSubscriptions(OpenRCT2::Scripting::HookType::actionLocation)) { - auto ctx = GetContext()->GetScriptEngine().GetContext(); + auto ctx = OpenRCT2::GetContext()->GetScriptEngine().GetContext(); // Create event args object auto obj = OpenRCT2::Scripting::DukObject(ctx); @@ -492,7 +489,7 @@ bool GameAction::LocationValid(const CoordsXY& coords) const obj.Set("type", EnumValue(_type)); auto flags = GetActionFlags(); - obj.Set("isClientOnly", (flags & GameActions::Flags::ClientOnly) != 0); + obj.Set("isClientOnly", (flags & OpenRCT2::GameActions::Flags::ClientOnly) != 0); obj.Set("result", true); // Call the subscriptions diff --git a/src/openrct2/actions/GameAction.h b/src/openrct2/actions/GameAction.h index 124972bef4..0e200d3143 100644 --- a/src/openrct2/actions/GameAction.h +++ b/src/openrct2/actions/GameAction.h @@ -288,11 +288,11 @@ namespace OpenRCT2::GameActions GameAction::Ptr Clone(const GameAction* action); // This should be used if a round trip is to be expected. - OpenRCT2::GameActions::Result Query(const GameAction* action); - OpenRCT2::GameActions::Result Execute(const GameAction* action); + Result Query(const GameAction* action); + Result Execute(const GameAction* action); // This should be used from within game actions. - OpenRCT2::GameActions::Result QueryNested(const GameAction* action); - OpenRCT2::GameActions::Result ExecuteNested(const GameAction* action); + Result QueryNested(const GameAction* action); + Result ExecuteNested(const GameAction* action); } // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/GameActionRegistry.cpp b/src/openrct2/actions/GameActionRegistry.cpp index 8a566732df..de3bb35168 100644 --- a/src/openrct2/actions/GameActionRegistry.cpp +++ b/src/openrct2/actions/GameActionRegistry.cpp @@ -94,8 +94,6 @@ #include -using namespace OpenRCT2; - namespace OpenRCT2::GameActions { struct GameActionEntry diff --git a/src/openrct2/actions/GameActionResult.cpp b/src/openrct2/actions/GameActionResult.cpp index cf1b4cb3af..bb53ea1010 100644 --- a/src/openrct2/actions/GameActionResult.cpp +++ b/src/openrct2/actions/GameActionResult.cpp @@ -8,7 +8,7 @@ using namespace OpenRCT2; namespace OpenRCT2::GameActions { - Result::Result(GameActions::Status error, StringId title, StringId message, uint8_t* args /*= nullptr*/) + Result::Result(Status error, StringId title, StringId message, uint8_t* args /*= nullptr*/) : Error(error) , ErrorTitle(title) , ErrorMessage(message) @@ -33,12 +33,12 @@ namespace OpenRCT2::GameActions } }; - std::string GameActions::Result::GetErrorTitle() const + std::string Result::GetErrorTitle() const { return std::visit(StringVariantVisitor{ ErrorMessageArgs.data() }, ErrorTitle); } - std::string GameActions::Result::GetErrorMessage() const + std::string Result::GetErrorMessage() const { return std::visit(StringVariantVisitor{ ErrorMessageArgs.data() }, ErrorMessage); } diff --git a/src/openrct2/actions/GameActionResult.h b/src/openrct2/actions/GameActionResult.h index 3fbabc2c16..f40d2b311f 100644 --- a/src/openrct2/actions/GameActionResult.h +++ b/src/openrct2/actions/GameActionResult.h @@ -6,6 +6,7 @@ * * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ + #pragma once #include "../management/Finance.h" @@ -56,7 +57,7 @@ namespace OpenRCT2::GameActions public: using StringVariant = std::variant; - OpenRCT2::GameActions::Status Error = OpenRCT2::GameActions::Status::Ok; + Status Error = Status::Ok; StringVariant ErrorTitle = kStringIdNone; StringVariant ErrorMessage = kStringIdNone; std::array ErrorMessageArgs{}; @@ -74,7 +75,7 @@ namespace OpenRCT2::GameActions #endif Result() = default; - Result(OpenRCT2::GameActions::Status error, StringId title, StringId message, uint8_t* args = nullptr); + Result(Status error, StringId title, StringId message, uint8_t* args = nullptr); std::string GetErrorTitle() const; std::string GetErrorMessage() const; diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 43ff25f3a0..e88ac0e7ca 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -790,7 +790,7 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar money64 money = ToMoney64FromGBP(double_val[0]); if (gameState.park.cash != money) { - ConsoleSetVariableAction(console, varName, CheatType::SetMoney, money); + ConsoleSetVariableAction(console, varName, CheatType::SetMoney, money); } else { @@ -876,7 +876,7 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar } else if (varName == "no_money" && InvalidArguments(&invalidArgs, int_valid[0])) { - ConsoleSetVariableAction(console, varName, CheatType::NoMoney, int_val[0] != 0); + ConsoleSetVariableAction(console, varName, CheatType::NoMoney, int_val[0] != 0); } else if (varName == "difficult_park_rating" && InvalidArguments(&invalidArgs, int_valid[0])) { @@ -957,7 +957,8 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar { if (getGameState().cheats.sandboxMode != (int_val[0] != 0)) { - ConsoleSetVariableAction(console, varName, CheatType::SandboxMode, int_val[0] != 0); + ConsoleSetVariableAction( + console, varName, CheatType::SandboxMode, int_val[0] != 0); } else { @@ -968,7 +969,8 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar { if (getGameState().cheats.disableClearanceChecks != (int_val[0] != 0)) { - ConsoleSetVariableAction(console, varName, CheatType::DisableClearanceChecks, int_val[0] != 0); + ConsoleSetVariableAction( + console, varName, CheatType::DisableClearanceChecks, int_val[0] != 0); } else { @@ -979,7 +981,8 @@ static void ConsoleCommandSet(InteractiveConsole& console, const arguments_t& ar { if (getGameState().cheats.disableSupportLimits != (int_val[0] != 0)) { - ConsoleSetVariableAction(console, varName, CheatType::DisableSupportLimits, int_val[0] != 0); + ConsoleSetVariableAction( + console, varName, CheatType::DisableSupportLimits, int_val[0] != 0); } else { diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index bea573dd9f..bada10e428 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -980,7 +980,7 @@ static GameActions::Result TrackDesignPlaceSceneryElementRemoveGhost( break; case ObjectType::paths: case ObjectType::footpathSurface: - ga = std::make_unique(CoordsXYZ{ mapCoord.x, mapCoord.y, z }); + ga = std::make_unique(CoordsXYZ{ mapCoord.x, mapCoord.y, z }); break; default: return GameActions::Result(); diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index f56a4f9b15..a8034fca4f 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1525,7 +1525,7 @@ void ClearElementAt(const CoordsXY& loc, TileElement** elementPtr) break; case TileElementType::Banner: { - auto bannerRemoveAction = BannerRemoveAction( + auto bannerRemoveAction = GameActions::BannerRemoveAction( { loc.x, loc.y, element->GetBaseZ(), element->AsBanner()->GetPosition() }); auto result = GameActions::ExecuteNested(&bannerRemoveAction); // If asking nicely did not work, forcibly remove this to avoid an infinite loop. diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index 456ed9ece4..199140f4ef 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -292,7 +292,7 @@ void SceneryRemoveGhostToolPlacement() { gSceneryGhostType &= ~SCENERY_GHOST_FLAG_4; - auto removeSceneryAction = BannerRemoveAction({ gSceneryGhostPosition, gSceneryPlaceRotation }); + auto removeSceneryAction = GameActions::BannerRemoveAction({ gSceneryGhostPosition, gSceneryPlaceRotation }); removeSceneryAction.SetFlags( GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_NO_SPEND | GAME_COMMAND_FLAG_GHOST); GameActions::Execute(&removeSceneryAction);