From ee4e8d0323e83dc4f675459ebe6e4086609a5917 Mon Sep 17 00:00:00 2001 From: Jan Kelemen Date: Tue, 5 Mar 2024 22:31:27 +0100 Subject: [PATCH 1/2] Move gSamePriceThroughoutPark to GameState_t --- src/openrct2-ui/windows/Ride.cpp | 15 ++++++++------- src/openrct2/GameState.h | 1 + src/openrct2/actions/ParkSetParameterAction.cpp | 2 +- src/openrct2/park/ParkFile.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 4 ++-- src/openrct2/rct2/S6Importer.cpp | 3 ++- src/openrct2/ride/ShopItem.cpp | 7 ++++--- src/openrct2/ride/ShopItem.h | 2 -- 8 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 5fcacffb73..642b3b26a1 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -5914,23 +5914,24 @@ private: static void UpdateSamePriceThroughoutFlags(ShopItem shop_item) { + const auto& gameState = GetGameState(); + const auto existingFlags = gameState.SamePriceThroughoutPark; + + auto newFlags = existingFlags; if (GetShopItemDescriptor(shop_item).IsPhoto()) { - auto newFlags = gSamePriceThroughoutPark; - if (gSamePriceThroughoutPark & EnumToFlag(shop_item)) + if (existingFlags & EnumToFlag(shop_item)) newFlags &= ~EnumsToFlags(ShopItem::Photo, ShopItem::Photo2, ShopItem::Photo3, ShopItem::Photo4); else newFlags |= EnumsToFlags(ShopItem::Photo, ShopItem::Photo2, ShopItem::Photo3, ShopItem::Photo4); - auto parkSetParameter = ParkSetParameterAction(ParkParameter::SamePriceInPark, newFlags); - GameActions::Execute(&parkSetParameter); } else { - auto newFlags = gSamePriceThroughoutPark; newFlags ^= EnumToFlag(shop_item); - auto parkSetParameter = ParkSetParameterAction(ParkParameter::SamePriceInPark, newFlags); - GameActions::Execute(&parkSetParameter); } + + auto parkSetParameter = ParkSetParameterAction(ParkParameter::SamePriceInPark, newFlags); + GameActions::Execute(&parkSetParameter); } void IncomeTogglePrimaryPrice() diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 09034b7945..8018ef152e 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -101,6 +101,7 @@ namespace OpenRCT2 colour_t StaffHandymanColour; colour_t StaffMechanicColour; colour_t StaffSecurityColour; + uint64_t SamePriceThroughoutPark{}; uint8_t ResearchFundingLevel; uint8_t ResearchPriorities; diff --git a/src/openrct2/actions/ParkSetParameterAction.cpp b/src/openrct2/actions/ParkSetParameterAction.cpp index af35815c34..0da59e5072 100644 --- a/src/openrct2/actions/ParkSetParameterAction.cpp +++ b/src/openrct2/actions/ParkSetParameterAction.cpp @@ -73,7 +73,7 @@ GameActions::Result ParkSetParameterAction::Execute() const } break; case ParkParameter::SamePriceInPark: - gSamePriceThroughoutPark = _value; + gameState.SamePriceThroughoutPark = _value; WindowInvalidateByClass(WindowClass::Ride); break; default: diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index a71f89e5b0..6d609c902c 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -821,7 +821,7 @@ namespace OpenRCT2 cs.ReadWrite(gameState.StaffHandymanColour); cs.ReadWrite(gameState.StaffMechanicColour); cs.ReadWrite(gameState.StaffSecurityColour); - cs.ReadWrite(gSamePriceThroughoutPark); + cs.ReadWrite(gameState.SamePriceThroughoutPark); // Finances if (cs.GetMode() == OrcaStream::Mode::READING) diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 970d5ee818..4c4c21f2d0 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2236,10 +2236,10 @@ namespace RCT1 gameState.ParkSize = _s4.ParkSize; gameState.TotalRideValueForMoney = _s4.TotalRideValueForMoney; - gSamePriceThroughoutPark = 0; + gameState.SamePriceThroughoutPark = 0; if (_gameVersion == FILE_VERSION_RCT1_LL) { - gSamePriceThroughoutPark = _s4.SamePriceThroughout; + gameState.SamePriceThroughoutPark = _s4.SamePriceThroughout; } } diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 36f8b5e86a..0416d109e9 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -403,7 +403,8 @@ namespace RCT2 // Pad013587FC gParkRatingCasualtyPenalty = _s6.ParkRatingCasualtyPenalty; gameState.MapSize = { _s6.MapSize, _s6.MapSize }; - gSamePriceThroughoutPark = _s6.SamePriceThroughout | (static_cast(_s6.SamePriceThroughoutExtended) << 32); + gameState.SamePriceThroughoutPark = _s6.SamePriceThroughout + | (static_cast(_s6.SamePriceThroughoutExtended) << 32); gameState.SuggestedGuestMaximum = _s6.SuggestedMaxGuests; gameState.ScenarioParkRatingWarningDays = _s6.ParkRatingWarningDays; gLastEntranceStyle = _s6.LastEntranceStyle; diff --git a/src/openrct2/ride/ShopItem.cpp b/src/openrct2/ride/ShopItem.cpp index 1dd91d92ed..f85620c1a2 100644 --- a/src/openrct2/ride/ShopItem.cpp +++ b/src/openrct2/ride/ShopItem.cpp @@ -9,19 +9,20 @@ #include "ShopItem.h" +#include "../GameState.h" #include "../common.h" #include "../entity/Guest.h" #include "../localisation/StringIds.h" #include "../ride/RideEntry.h" #include "../sprites.h" +using namespace OpenRCT2; + ShopItem& operator++(ShopItem& d, int) { return d = (d == ShopItem::Count) ? ShopItem::Balloon : ShopItem(EnumValue(d) + 1); } -uint64_t gSamePriceThroughoutPark; - // clang-format off /** rct2: 0x00982164 (cost, base value, hot and cold value); 0x00982358 (default price) */ constexpr ShopItemDescriptor ShopItems[EnumValue(ShopItem::Count)] = { @@ -146,7 +147,7 @@ money64 ShopItemGetCommonPrice(Ride* forRide, const ShopItem shopItem) bool ShopItemHasCommonPrice(const ShopItem shopItem) { - return (gSamePriceThroughoutPark & EnumToFlag(shopItem)) != 0; + return (GetGameState().SamePriceThroughoutPark & EnumToFlag(shopItem)) != 0; } bool ShopItemDescriptor::IsFood() const diff --git a/src/openrct2/ride/ShopItem.h b/src/openrct2/ride/ShopItem.h index 241ecfae5f..9aa53277c5 100644 --- a/src/openrct2/ride/ShopItem.h +++ b/src/openrct2/ride/ShopItem.h @@ -128,8 +128,6 @@ enum SHOP_ITEM_FLAG_IS_RECOLOURABLE = (1 << 5), }; -extern uint64_t gSamePriceThroughoutPark; - money64 ShopItemGetCommonPrice(Ride* forRide, const ShopItem shopItem); bool ShopItemHasCommonPrice(const ShopItem shopItem); From 56df47a48d9ef6d85491af59a6164903cfe58899 Mon Sep 17 00:00:00 2001 From: Jan Kelemen Date: Tue, 5 Mar 2024 22:01:47 +0100 Subject: [PATCH 2/2] Move gRideRatingUpdateStates to GameState_t - Move gRideRatingUpdateStates variable to GameState_t - Remove RideRatingGetUpdateStates function --- src/openrct2/GameState.h | 2 ++ src/openrct2/park/ParkFile.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/ride/RideRatings.cpp | 15 +++++---------- src/openrct2/ride/RideRatings.h | 2 -- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 8018ef152e..66757b972e 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -17,6 +17,7 @@ #include "management/Finance.h" #include "management/NewsItem.h" #include "ride/Ride.h" +#include "ride/RideRatings.h" #include "scenario/Scenario.h" #include "world/Banner.h" #include "world/Climate.h" @@ -92,6 +93,7 @@ namespace OpenRCT2 std::vector Banners; // Ride storage for all the rides in the park, rides with RideId::Null are considered free. std::array Rides{}; + ::RideRatingUpdateStates RideRatingUpdateStates; std::vector TileElements; std::vector RestrictedScenery; diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 6d609c902c..2cc8c084c7 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -552,7 +552,7 @@ namespace OpenRCT2 cs.ReadWrite(gGrassSceneryTileLoopPosition); cs.ReadWrite(gWidePathTileLoopPosition); - auto& rideRatings = RideRatingGetUpdateStates(); + auto& rideRatings = gameState.RideRatingUpdateStates; if (os.GetHeader().TargetVersion >= 21) { cs.ReadWriteArray(rideRatings, [this, &cs](RideRatingUpdateState& calcData) { diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 0416d109e9..fd37bbd069 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1613,7 +1613,7 @@ namespace RCT2 const auto& src = _s6.RideRatingsCalcData; // S6 has only one state, ensure we reset all states before reading the first one. RideRatingResetUpdateStates(); - auto& rideRatingStates = RideRatingGetUpdateStates(); + auto& rideRatingStates = GetGameState().RideRatingUpdateStates; auto& dst = rideRatingStates[0]; dst = {}; dst.Proximity = { src.ProximityX, src.ProximityY, src.ProximityZ }; diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 340954cfed..55f2c96c8f 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -78,8 +78,6 @@ struct ShelteredEights uint8_t TotalShelteredEighths; }; -static RideRatingUpdateStates gRideRatingUpdateStates; - // Amount of updates allowed per updating state on the current tick. // The total amount would be MaxRideRatingSubSteps * RideRatingMaxUpdateStates which // would be currently 80, this is the worst case of sub-steps and may break out earlier. @@ -153,17 +151,13 @@ static void RideRatingsApplyRequirementStations(RatingTuple& ratings, const Ride static void RideRatingsApplyRequirementSplashdown(RatingTuple& ratings, const Ride& ride, RatingsModifier modifier); static void RideRatingsApplyPenaltyLateralGs(RatingTuple& ratings, const Ride& ride, RatingsModifier modifier); -RideRatingUpdateStates& RideRatingGetUpdateStates() -{ - return gRideRatingUpdateStates; -} - void RideRatingResetUpdateStates() { RideRatingUpdateState nullState{}; nullState.State = RIDE_RATINGS_STATE_FIND_NEXT_RIDE; - std::fill(gRideRatingUpdateStates.begin(), gRideRatingUpdateStates.end(), nullState); + auto& updateStates = GetGameState().RideRatingUpdateStates; + std::fill(updateStates.begin(), updateStates.end(), nullState); } /** @@ -197,7 +191,7 @@ void RideRatingsUpdateAll() if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) return; - for (auto& updateState : gRideRatingUpdateStates) + for (auto& updateState : GetGameState().RideRatingUpdateStates) { for (size_t i = 0; i < MaxRideRatingUpdateSubSteps; ++i) { @@ -237,7 +231,8 @@ static void ride_ratings_update_state(RideRatingUpdateState& state) static bool RideRatingIsUpdatingRide(RideId id) { - return std::any_of(gRideRatingUpdateStates.begin(), gRideRatingUpdateStates.end(), [id](auto& state) { + const auto& updateStates = GetGameState().RideRatingUpdateStates; + return std::any_of(updateStates.begin(), updateStates.end(), [id](auto& state) { return state.CurrentRide == id && state.State != RIDE_RATINGS_STATE_FIND_NEXT_RIDE; }); } diff --git a/src/openrct2/ride/RideRatings.h b/src/openrct2/ride/RideRatings.h index 82c8579d62..27c16bd617 100644 --- a/src/openrct2/ride/RideRatings.h +++ b/src/openrct2/ride/RideRatings.h @@ -55,10 +55,8 @@ struct RideRatingUpdateState }; static constexpr size_t RideRatingMaxUpdateStates = 4; - using RideRatingUpdateStates = std::array; -RideRatingUpdateStates& RideRatingGetUpdateStates(); void RideRatingResetUpdateStates(); void RideRatingsUpdateRide(const Ride& ride);