From 57a4c83f80a475a7a234941667c9b653f89ba22c Mon Sep 17 00:00:00 2001 From: Harry Hopkinson <63599884+Harry-Hopkinson@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:20:11 +0000 Subject: [PATCH] Move gConstructionRightsPrice to GameState_t (#21467) * Move gConstructionRightsPrice to GameState_t * Add OpenRCT2 namespace --- src/openrct2-ui/windows/EditorScenarioOptions.cpp | 10 +++++----- src/openrct2/GameState.h | 1 + src/openrct2/actions/LandBuyRightsAction.cpp | 5 ++++- src/openrct2/actions/ScenarioSetSettingAction.cpp | 2 +- src/openrct2/interface/InteractiveConsole.cpp | 3 ++- src/openrct2/park/ParkFile.cpp | 4 ++-- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/scripting/bindings/world/ScPark.cpp | 4 ++-- src/openrct2/world/Park.cpp | 3 +-- src/openrct2/world/Park.h | 1 - 11 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/openrct2-ui/windows/EditorScenarioOptions.cpp b/src/openrct2-ui/windows/EditorScenarioOptions.cpp index 287594f52c..47cd8b969d 100644 --- a/src/openrct2-ui/windows/EditorScenarioOptions.cpp +++ b/src/openrct2-ui/windows/EditorScenarioOptions.cpp @@ -1031,10 +1031,10 @@ private: Invalidate(); break; case WIDX_CONSTRUCTION_RIGHTS_COST_INCREASE: - if (gConstructionRightsPrice < 200.00_GBP) + if (gameState.ConstructionRightsPrice < 200.00_GBP) { auto scenarioSetSetting = ScenarioSetSettingAction( - ScenarioSetSetting::CostToBuyConstructionRights, gConstructionRightsPrice + 1.00_GBP); + ScenarioSetSetting::CostToBuyConstructionRights, gameState.ConstructionRightsPrice + 1.00_GBP); GameActions::Execute(&scenarioSetSetting); } else @@ -1044,10 +1044,10 @@ private: Invalidate(); break; case WIDX_CONSTRUCTION_RIGHTS_COST_DECREASE: - if (gConstructionRightsPrice > 5.00_GBP) + if (gameState.ConstructionRightsPrice > 5.00_GBP) { auto scenarioSetSetting = ScenarioSetSettingAction( - ScenarioSetSetting::CostToBuyConstructionRights, gConstructionRightsPrice - 1.00_GBP); + ScenarioSetSetting::CostToBuyConstructionRights, gameState.ConstructionRightsPrice - 1.00_GBP); GameActions::Execute(&scenarioSetSetting); } else @@ -1230,7 +1230,7 @@ private: screenCoords = windowPos + ScreenCoordsXY{ constructionRightsCostWidget.left + 1, constructionRightsCostWidget.top }; auto ft = Formatter(); - ft.Add(gConstructionRightsPrice); + ft.Add(gameState.ConstructionRightsPrice); DrawTextBasic(dpi, screenCoords, STR_CURRENCY_FORMAT_LABEL, ft); } diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index a9f200ddb6..64c31a0949 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -41,6 +41,7 @@ namespace OpenRCT2 money64 ParkValue; money64 ParkValueHistory[FINANCE_GRAPH_SIZE]; money64 CompanyValue; + money64 ConstructionRightsPrice; uint8_t ParkRatingHistory[32]; ClimateType Climate; ClimateState ClimateCurrent; diff --git a/src/openrct2/actions/LandBuyRightsAction.cpp b/src/openrct2/actions/LandBuyRightsAction.cpp index 993fcaf1e7..74a025e6a5 100644 --- a/src/openrct2/actions/LandBuyRightsAction.cpp +++ b/src/openrct2/actions/LandBuyRightsAction.cpp @@ -10,6 +10,7 @@ #include "LandBuyRightsAction.h" #include "../Context.h" +#include "../GameState.h" #include "../OpenRCT2.h" #include "../actions/LandSetHeightAction.h" #include "../audio/audio.h" @@ -24,6 +25,8 @@ #include "../world/Scenery.h" #include "../world/Surface.h" +using namespace OpenRCT2; + LandBuyRightsAction::LandBuyRightsAction(const MapRange& range, LandBuyRightSetting setting) : _range(range) , _setting(setting) @@ -163,7 +166,7 @@ GameActions::Result LandBuyRightsAction::MapBuyLandRightsForTile(const CoordsXY& uint16_t baseZ = surfaceElement->GetBaseZ(); MapInvalidateTile({ loc, baseZ, baseZ + 16 }); } - res.Cost = gConstructionRightsPrice; + res.Cost = GetGameState().ConstructionRightsPrice; return res; default: diff --git a/src/openrct2/actions/ScenarioSetSettingAction.cpp b/src/openrct2/actions/ScenarioSetSettingAction.cpp index 75befc3f70..60a2fb773f 100644 --- a/src/openrct2/actions/ScenarioSetSettingAction.cpp +++ b/src/openrct2/actions/ScenarioSetSettingAction.cpp @@ -149,7 +149,7 @@ GameActions::Result ScenarioSetSettingAction::Execute() const gLandPrice = std::clamp(_value, 5.00_GBP, 200.00_GBP); break; case ScenarioSetSetting::CostToBuyConstructionRights: - gConstructionRightsPrice = std::clamp(_value, 5.00_GBP, 200.00_GBP); + gameState.ConstructionRightsPrice = std::clamp(_value, 5.00_GBP, 200.00_GBP); break; case ScenarioSetSetting::ParkChargeMethod: if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 3b36cefa3d..4781474621 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -673,7 +673,8 @@ static int32_t ConsoleCommandGet(InteractiveConsole& console, const arguments_t& else if (argv[0] == "construction_rights_cost") { console.WriteFormatLine( - "construction_rights_cost %d.%d0", gConstructionRightsPrice / 10, gConstructionRightsPrice % 10); + "construction_rights_cost %d.%d0", gameState.ConstructionRightsPrice / 10, + gameState.ConstructionRightsPrice % 10); } else if (argv[0] == "climate") { diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index ee4abbb3bf..c6cf4d78fe 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -542,12 +542,12 @@ namespace OpenRCT2 cs.ReadWrite(tempLandPrice); cs.ReadWrite(tempConstructionRightPrice); gLandPrice = ToMoney64(tempLandPrice); - gConstructionRightsPrice = ToMoney64(tempConstructionRightPrice); + gameState.ConstructionRightsPrice = ToMoney64(tempConstructionRightPrice); } else { cs.ReadWrite(gLandPrice); - cs.ReadWrite(gConstructionRightsPrice); + cs.ReadWrite(gameState.ConstructionRightsPrice); } cs.ReadWrite(gGrassSceneryTileLoopPosition); cs.ReadWrite(gWidePathTileLoopPosition); diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 640c14fdb4..6257f30f4c 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1393,7 +1393,7 @@ namespace RCT1 { gameState.ParkEntranceFee = _s4.ParkEntranceFee; gLandPrice = ToMoney64(_s4.LandPrice); - gConstructionRightsPrice = ToMoney64(_s4.ConstructionRightsPrice); + gameState.ConstructionRightsPrice = ToMoney64(_s4.ConstructionRightsPrice); gameState.Cash = ToMoney64(_s4.Cash); gameState.BankLoan = ToMoney64(_s4.Loan); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 2b98bd888f..7a89c5b07e 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -388,7 +388,7 @@ namespace RCT2 } gLandPrice = ToMoney64(_s6.LandPrice); - gConstructionRightsPrice = ToMoney64(_s6.ConstructionRightsPrice); + gameState.ConstructionRightsPrice = ToMoney64(_s6.ConstructionRightsPrice); // unk_01358774 // Pad01358776 // _s6.CdKey diff --git a/src/openrct2/scripting/bindings/world/ScPark.cpp b/src/openrct2/scripting/bindings/world/ScPark.cpp index 910ac173e6..58b7e59cea 100644 --- a/src/openrct2/scripting/bindings/world/ScPark.cpp +++ b/src/openrct2/scripting/bindings/world/ScPark.cpp @@ -253,12 +253,12 @@ namespace OpenRCT2::Scripting money64 ScPark::constructionRightsPrice_get() const { - return gConstructionRightsPrice; + return GetGameState().ConstructionRightsPrice; } void ScPark::constructionRightsPrice_set(money64 value) { ThrowIfGameStateNotMutable(); - gConstructionRightsPrice = value; + GetGameState().ConstructionRightsPrice = value; } int16_t ScPark::casualtyPenalty_get() const diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index b6b189e6a8..652c65fdb7 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -48,7 +48,6 @@ using namespace OpenRCT2; money64 gLandPrice; -money64 gConstructionRightsPrice; int16_t gParkRatingCasualtyPenalty; uint32_t gGuestsInParkHistory[32]; @@ -275,7 +274,7 @@ void Park::Initialise() gameState.ScenarioObjective.Year = 4; gameState.ScenarioObjective.NumGuests = 1000; gLandPrice = 90.00_GBP; - gConstructionRightsPrice = 40.00_GBP; + gameState.ConstructionRightsPrice = 40.00_GBP; gameState.ParkFlags = PARK_FLAGS_NO_MONEY | PARK_FLAGS_SHOW_REAL_GUEST_NAMES; ResetHistories(); FinanceResetHistory(); diff --git a/src/openrct2/world/Park.h b/src/openrct2/world/Park.h index b14062829c..c0858ff0fe 100644 --- a/src/openrct2/world/Park.h +++ b/src/openrct2/world/Park.h @@ -93,7 +93,6 @@ namespace OpenRCT2 } // namespace OpenRCT2 extern money64 gLandPrice; -extern money64 gConstructionRightsPrice; extern int16_t gParkRatingCasualtyPenalty; extern uint32_t gGuestsInParkHistory[32];