Skip to content

Commit

Permalink
Move gConstructionRightsPrice to GameState_t (OpenRCT2#21467)
Browse files Browse the repository at this point in the history
* Move gConstructionRightsPrice to GameState_t

* Add OpenRCT2 namespace
  • Loading branch information
Harry-Hopkinson authored Feb 27, 2024
1 parent b2639ad commit 57a4c83
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/openrct2-ui/windows/EditorScenarioOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,10 +1031,10 @@ class EditorScenarioOptionsWindow final : public Window
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
Expand All @@ -1044,10 +1044,10 @@ class EditorScenarioOptionsWindow final : public Window
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
Expand Down Expand Up @@ -1230,7 +1230,7 @@ class EditorScenarioOptionsWindow final : public Window
screenCoords = windowPos
+ ScreenCoordsXY{ constructionRightsCostWidget.left + 1, constructionRightsCostWidget.top };
auto ft = Formatter();
ft.Add<money64>(gConstructionRightsPrice);
ft.Add<money64>(gameState.ConstructionRightsPrice);
DrawTextBasic(dpi, screenCoords, STR_CURRENCY_FORMAT_LABEL, ft);
}

Expand Down
1 change: 1 addition & 0 deletions src/openrct2/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/openrct2/actions/LandBuyRightsAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "LandBuyRightsAction.h"

#include "../Context.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../actions/LandSetHeightAction.h"
#include "../audio/audio.h"
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/actions/ScenarioSetSettingAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ GameActions::Result ScenarioSetSettingAction::Execute() const
gLandPrice = std::clamp<money64>(_value, 5.00_GBP, 200.00_GBP);
break;
case ScenarioSetSetting::CostToBuyConstructionRights:
gConstructionRightsPrice = std::clamp<money64>(_value, 5.00_GBP, 200.00_GBP);
gameState.ConstructionRightsPrice = std::clamp<money64>(_value, 5.00_GBP, 200.00_GBP);
break;
case ScenarioSetSetting::ParkChargeMethod:
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
Expand Down
3 changes: 2 additions & 1 deletion src/openrct2/interface/InteractiveConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/park/ParkFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/rct1/S4Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/rct2/S6Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ namespace RCT2
}

gLandPrice = ToMoney64(_s6.LandPrice);
gConstructionRightsPrice = ToMoney64(_s6.ConstructionRightsPrice);
gameState.ConstructionRightsPrice = ToMoney64(_s6.ConstructionRightsPrice);
// unk_01358774
// Pad01358776
// _s6.CdKey
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/scripting/bindings/world/ScPark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/openrct2/world/Park.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
using namespace OpenRCT2;

money64 gLandPrice;
money64 gConstructionRightsPrice;

int16_t gParkRatingCasualtyPenalty;
uint32_t gGuestsInParkHistory[32];
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/openrct2/world/Park.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ namespace OpenRCT2
} // namespace OpenRCT2

extern money64 gLandPrice;
extern money64 gConstructionRightsPrice;

extern int16_t gParkRatingCasualtyPenalty;
extern uint32_t gGuestsInParkHistory[32];
Expand Down

0 comments on commit 57a4c83

Please sign in to comment.