Skip to content

Commit

Permalink
OpenRCT2#21193: Move gInitialCash to GameState_t, refactor uses
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Jan 20, 2024
1 parent 7141fb4 commit c493e22
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 19 deletions.
13 changes: 8 additions & 5 deletions src/openrct2-ui/windows/EditorScenarioOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <openrct2/Context.h>
#include <openrct2/Editor.h>
#include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/ClimateSetAction.h>
#include <openrct2/actions/ScenarioSetSettingAction.h>
Expand All @@ -29,6 +30,8 @@
#include <openrct2/world/Climate.h>
#include <openrct2/world/Park.h>

using namespace OpenRCT2;

static constexpr int32_t WW_FINANCIAL = 280;
static constexpr int32_t WH_FINANCIAL = 149;

Expand Down Expand Up @@ -433,10 +436,10 @@ class EditorScenarioOptionsWindow final : public Window
switch (widgetIndex)
{
case WIDX_INITIAL_CASH_INCREASE:
if (gInitialCash < 1000000.00_GBP)
if (GetGameState().InitialCash < 1000000.00_GBP)
{
auto scenarioSetSetting = ScenarioSetSettingAction(
ScenarioSetSetting::InitialCash, gInitialCash + 500.00_GBP);
ScenarioSetSetting::InitialCash, GetGameState().InitialCash + 500.00_GBP);
GameActions::Execute(&scenarioSetSetting);
}
else
Expand All @@ -446,10 +449,10 @@ class EditorScenarioOptionsWindow final : public Window
Invalidate();
break;
case WIDX_INITIAL_CASH_DECREASE:
if (gInitialCash > 0.00_GBP)
if (GetGameState().InitialCash > 0.00_GBP)
{
auto scenarioSetSetting = ScenarioSetSettingAction(
ScenarioSetSetting::InitialCash, gInitialCash - 500.00_GBP);
ScenarioSetSetting::InitialCash, GetGameState().InitialCash - 500.00_GBP);
GameActions::Execute(&scenarioSetSetting);
}
else
Expand Down Expand Up @@ -623,7 +626,7 @@ class EditorScenarioOptionsWindow final : public Window

screenCoords = windowPos + ScreenCoordsXY{ initialCashWidget.left + 1, initialCashWidget.top };
auto ft = Formatter();
ft.Add<money64>(gInitialCash);
ft.Add<money64>(GetGameState().InitialCash);
DrawTextBasic(dpi, screenCoords, STR_CURRENCY_FORMAT_LABEL, ft);
}

Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ namespace Editor

gGuestInitialCash = std::clamp(gGuestInitialCash, 10.00_GBP, MAX_ENTRANCE_FEE);

gInitialCash = std::min<money64>(gInitialCash, 100000);
GetGameState().InitialCash = std::min<money64>(GetGameState().InitialCash, 100000);
FinanceResetCashToInitial();

gBankLoan = std::clamp<money64>(gBankLoan, 0.00_GBP, 5000000.00_GBP);
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace OpenRCT2
{
uint32_t CurrentTicks{};
money64 Cash;
money64 InitialCash;
};

GameState_t& GetGameState();
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/actions/ScenarioSetSettingAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ GameActions::Result ScenarioSetSettingAction::Execute() const
}
break;
case ScenarioSetSetting::InitialCash:
gInitialCash = std::clamp<money64>(_value, 0.00_GBP, 1000000.00_GBP);
GetGameState().Cash = gInitialCash;
GetGameState().InitialCash = std::clamp<money64>(_value, 0.00_GBP, 1000000.00_GBP);
GetGameState().Cash = GetGameState().InitialCash;
WindowInvalidateByClass(WindowClass::Finances);
WindowInvalidateByClass(WindowClass::BottomToolbar);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/interface/InteractiveConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ static int32_t ConsoleCommandGet(InteractiveConsole& console, const arguments_t&
}
else if (argv[0] == "scenario_initial_cash")
{
console.WriteFormatLine("scenario_initial_cash %d", gInitialCash / 10);
console.WriteFormatLine("scenario_initial_cash %d", GetGameState().InitialCash / 10);
}
else if (argv[0] == "current_loan")
{
Expand Down
7 changes: 3 additions & 4 deletions src/openrct2/management/Finance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ static constexpr int32_t dword_988E60[static_cast<int32_t>(ExpenditureType::Coun
1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0,
};

money64 gInitialCash;
money64 gBankLoan;
uint8_t gBankLoanInterestRate;
money64 gMaxBankLoan;
Expand Down Expand Up @@ -226,7 +225,7 @@ void FinanceInit()
gWeeklyProfitAverageDividend = 0;
gWeeklyProfitAverageDivisor = 0;

gInitialCash = 10000.00_GBP; // Cheat detection
GetGameState().InitialCash = 10000.00_GBP; // Cheat detection

GetGameState().Cash = 10000.00_GBP;
gBankLoan = 10000.00_GBP;
Expand Down Expand Up @@ -296,7 +295,7 @@ void FinanceUpdateDailyProfit()

money64 FinanceGetInitialCash()
{
return gInitialCash;
return GetGameState().InitialCash;
}

money64 FinanceGetCurrentLoan()
Expand Down Expand Up @@ -356,7 +355,7 @@ void FinanceShiftExpenditureTable()
*/
void FinanceResetCashToInitial()
{
GetGameState().Cash = gInitialCash;
GetGameState().Cash = GetGameState().InitialCash;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/openrct2/management/Finance.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ constexpr uint8_t MaxBankLoanInterestRate = 255;

extern const money64 research_cost_table[RESEARCH_FUNDING_COUNT];

extern money64 gInitialCash;
extern money64 gBankLoan;
extern uint8_t gBankLoanInterestRate;
extern money64 gMaxBankLoan;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/park/ParkFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace OpenRCT2
}

// Initial cash will eventually be removed
gInitialCash = gameState.Cash;
gameState.InitialCash = gameState.Cash;
}

void Save(GameState_t& gameState, IStream& stream)
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 @@ -1400,7 +1400,7 @@ namespace RCT1
gMaxBankLoan = ToMoney64(_s4.MaxLoan);
// It's more like 1.33%, but we can only use integers. Can be fixed once we have our own save format.
gBankLoanInterestRate = 1;
gInitialCash = ToMoney64(_s4.Cash);
gameState.InitialCash = ToMoney64(_s4.Cash);

gCompanyValue = ToMoney64(_s4.CompanyValue);
gParkValue = CorrectRCT1ParkValue(_s4.ParkValue);
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 @@ -260,7 +260,7 @@ namespace RCT2
ImportTileElements();
ImportEntities();

gInitialCash = ToMoney64(_s6.InitialCash);
gameState.InitialCash = ToMoney64(_s6.InitialCash);
gBankLoan = ToMoney64(_s6.CurrentLoan);

gParkFlags = _s6.ParkFlags & ~PARK_FLAGS_NO_MONEY_SCENARIO;
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/scenario/Scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ void ScenarioReset()
gParkRating = park.CalculateParkRating();
gParkValue = park.CalculateParkValue();
gCompanyValue = park.CalculateCompanyValue();
gHistoricalProfit = gInitialCash - gBankLoan;
GetGameState().Cash = gInitialCash;
gHistoricalProfit = GetGameState().InitialCash - gBankLoan;
GetGameState().Cash = GetGameState().InitialCash;

{
utf8 normalisedName[64];
Expand Down

0 comments on commit c493e22

Please sign in to comment.