#21193: Move gInitialCash to GameState_t, refactor uses

This commit is contained in:
ζeh Matt 2024-01-20 17:13:57 +02:00
parent 7141fb4574
commit c493e22b9b
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0
11 changed files with 21 additions and 19 deletions

View File

@ -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>
@ -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;
@ -433,10 +436,10 @@ private:
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
@ -446,10 +449,10 @@ private:
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
@ -623,7 +626,7 @@ private:
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);
}

View File

@ -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);

View File

@ -25,6 +25,7 @@ namespace OpenRCT2
{
uint32_t CurrentTicks{};
money64 Cash;
money64 InitialCash;
};
GameState_t& GetGameState();

View File

@ -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;

View File

@ -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")
{

View File

@ -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;
@ -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;
@ -296,7 +295,7 @@ void FinanceUpdateDailyProfit()
money64 FinanceGetInitialCash()
{
return gInitialCash;
return GetGameState().InitialCash;
}
money64 FinanceGetCurrentLoan()
@ -356,7 +355,7 @@ void FinanceShiftExpenditureTable()
*/
void FinanceResetCashToInitial()
{
GetGameState().Cash = gInitialCash;
GetGameState().Cash = GetGameState().InitialCash;
}
/**

View File

@ -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;

View File

@ -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)

View File

@ -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);

View File

@ -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;

View File

@ -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];