#21193: Move gCash to GameState_t, refactor uses

This commit is contained in:
ζeh Matt 2024-01-20 15:46:35 +02:00
parent 2cb4eb950b
commit 3518a638bb
No known key found for this signature in database
GPG Key ID: 18CE582C71A225B0
15 changed files with 175 additions and 153 deletions

View File

@ -28,6 +28,8 @@
#include <openrct2/sprites.h> #include <openrct2/sprites.h>
#include <openrct2/world/Park.h> #include <openrct2/world/Park.h>
using namespace OpenRCT2;
enum enum
{ {
WINDOW_FINANCES_PAGE_SUMMARY, WINDOW_FINANCES_PAGE_SUMMARY,
@ -571,8 +573,8 @@ public:
// Current cash // Current cash
auto ft = Formatter(); auto ft = Formatter();
ft.Add<money64>(gCash); ft.Add<money64>(GetGameState().Cash);
StringId stringId = gCash >= 0 ? STR_CASH_LABEL : STR_CASH_NEGATIVE_LABEL; StringId stringId = GetGameState().Cash >= 0 ? STR_CASH_LABEL : STR_CASH_NEGATIVE_LABEL;
DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 8, 294 }, stringId, ft); DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 8, 294 }, stringId, ft);
// Objective related financial information // Objective related financial information
@ -612,7 +614,7 @@ public:
auto graphBottomRight = windowPos + ScreenCoordsXY{ pageWidget->right - 4, pageWidget->bottom - 4 }; auto graphBottomRight = windowPos + ScreenCoordsXY{ pageWidget->right - 4, pageWidget->bottom - 4 };
// Cash (less loan) // Cash (less loan)
auto cashLessLoan = gCash - gBankLoan; auto cashLessLoan = GetGameState().Cash - gBankLoan;
auto ft = Formatter(); auto ft = Formatter();
ft.Add<money64>(cashLessLoan); ft.Add<money64>(cashLessLoan);

View File

@ -14,6 +14,7 @@
#include <openrct2-ui/windows/Window.h> #include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h> #include <openrct2/Context.h>
#include <openrct2/Game.h> #include <openrct2/Game.h>
#include <openrct2/GameState.h>
#include <openrct2/Input.h> #include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h> #include <openrct2/OpenRCT2.h>
#include <openrct2/config/Config.h> #include <openrct2/config/Config.h>
@ -29,6 +30,8 @@
#include <openrct2/world/Climate.h> #include <openrct2/world/Climate.h>
#include <openrct2/world/Park.h> #include <openrct2/world/Park.h>
using namespace OpenRCT2;
// clang-format off // clang-format off
enum WindowGameBottomToolbarWidgetIdx enum WindowGameBottomToolbarWidgetIdx
{ {
@ -98,9 +101,9 @@ private:
= (gHoverWidget.window_classification == WindowClass::BottomToolbar && gHoverWidget.widget_index == WIDX_MONEY = (gHoverWidget.window_classification == WindowClass::BottomToolbar && gHoverWidget.widget_index == WIDX_MONEY
? COLOUR_WHITE ? COLOUR_WHITE
: NOT_TRANSLUCENT(colours[0])); : NOT_TRANSLUCENT(colours[0]));
StringId stringId = gCash < 0 ? STR_BOTTOM_TOOLBAR_CASH_NEGATIVE : STR_BOTTOM_TOOLBAR_CASH; StringId stringId = GetGameState().Cash < 0 ? STR_BOTTOM_TOOLBAR_CASH_NEGATIVE : STR_BOTTOM_TOOLBAR_CASH;
auto ft = Formatter(); auto ft = Formatter();
ft.Add<money64>(gCash); ft.Add<money64>(GetGameState().Cash);
DrawTextBasic(dpi, screenCoords, stringId, ft, { colour, TextAlignment::CENTRE }); DrawTextBasic(dpi, screenCoords, stringId, ft, { colour, TextAlignment::CENTRE });
} }

View File

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

View File

@ -39,6 +39,8 @@
#include "ParkSetLoanAction.h" #include "ParkSetLoanAction.h"
#include "ParkSetParameterAction.h" #include "ParkSetParameterAction.h"
using namespace OpenRCT2;
using ParametersRange = std::pair<std::pair<int64_t, int64_t>, std::pair<int64_t, int64_t>>; using ParametersRange = std::pair<std::pair<int64_t, int64_t>, std::pair<int64_t, int64_t>>;
CheatSetAction::CheatSetAction(CheatType cheatType, int64_t param1, int64_t param2) CheatSetAction::CheatSetAction(CheatType cheatType, int64_t param1, int64_t param2)
@ -565,7 +567,7 @@ void CheatSetAction::SetScenarioNoMoney(bool enabled) const
void CheatSetAction::SetMoney(money64 amount) const void CheatSetAction::SetMoney(money64 amount) const
{ {
gCash = amount; GetGameState().Cash = amount;
WindowInvalidateByClass(WindowClass::Finances); WindowInvalidateByClass(WindowClass::Finances);
WindowInvalidateByClass(WindowClass::BottomToolbar); WindowInvalidateByClass(WindowClass::BottomToolbar);
@ -573,7 +575,7 @@ void CheatSetAction::SetMoney(money64 amount) const
void CheatSetAction::AddMoney(money64 amount) const void CheatSetAction::AddMoney(money64 amount) const
{ {
gCash = AddClamp_money64(gCash, amount); GetGameState().Cash = AddClamp_money64(GetGameState().Cash, amount);
WindowInvalidateByClass(WindowClass::Finances); WindowInvalidateByClass(WindowClass::Finances);
WindowInvalidateByClass(WindowClass::BottomToolbar); WindowInvalidateByClass(WindowClass::BottomToolbar);

View File

@ -10,6 +10,7 @@
#include "ParkSetLoanAction.h" #include "ParkSetLoanAction.h"
#include "../Context.h" #include "../Context.h"
#include "../GameState.h"
#include "../core/MemoryStream.h" #include "../core/MemoryStream.h"
#include "../localisation/StringIds.h" #include "../localisation/StringIds.h"
#include "../management/Finance.h" #include "../management/Finance.h"
@ -17,6 +18,8 @@
#include "../ui/WindowManager.h" #include "../ui/WindowManager.h"
#include "../windows/Intent.h" #include "../windows/Intent.h"
using namespace OpenRCT2;
ParkSetLoanAction::ParkSetLoanAction(money64 value) ParkSetLoanAction::ParkSetLoanAction(money64 value)
: _value(value) : _value(value)
{ {
@ -52,7 +55,7 @@ GameActions::Result ParkSetLoanAction::Query() const
// The “isPayingBack” check is needed to allow increasing the loan when the player is in debt. // The “isPayingBack” check is needed to allow increasing the loan when the player is in debt.
const auto isPayingBack = gBankLoan > _value; const auto isPayingBack = gBankLoan > _value;
const auto amountToPayBack = gBankLoan - _value; const auto amountToPayBack = gBankLoan - _value;
if (isPayingBack && amountToPayBack > gCash) if (isPayingBack && amountToPayBack > GetGameState().Cash)
{ {
return GameActions::Result( return GameActions::Result(
GameActions::Status::InsufficientFunds, STR_CANT_PAY_BACK_LOAN, STR_NOT_ENOUGH_CASH_AVAILABLE); GameActions::Status::InsufficientFunds, STR_CANT_PAY_BACK_LOAN, STR_NOT_ENOUGH_CASH_AVAILABLE);
@ -62,7 +65,7 @@ GameActions::Result ParkSetLoanAction::Query() const
GameActions::Result ParkSetLoanAction::Execute() const GameActions::Result ParkSetLoanAction::Execute() const
{ {
gCash -= (gBankLoan - _value); GetGameState().Cash -= (gBankLoan - _value);
gBankLoan = _value; gBankLoan = _value;
auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager();

View File

@ -9,6 +9,7 @@
#include "ScenarioSetSettingAction.h" #include "ScenarioSetSettingAction.h"
#include "../GameState.h"
#include "../OpenRCT2.h" #include "../OpenRCT2.h"
#include "../entity/Peep.h" #include "../entity/Peep.h"
#include "../interface/Window.h" #include "../interface/Window.h"
@ -19,6 +20,8 @@
#include <algorithm> #include <algorithm>
using namespace OpenRCT2;
void ScenarioSetSettingAction::Serialise(DataSerialiser& stream) void ScenarioSetSettingAction::Serialise(DataSerialiser& stream)
{ {
GameAction::Serialise(stream); GameAction::Serialise(stream);
@ -80,7 +83,7 @@ GameActions::Result ScenarioSetSettingAction::Execute() const
break; break;
case ScenarioSetSetting::InitialCash: case ScenarioSetSetting::InitialCash:
gInitialCash = std::clamp<money64>(_value, 0.00_GBP, 1000000.00_GBP); gInitialCash = std::clamp<money64>(_value, 0.00_GBP, 1000000.00_GBP);
gCash = gInitialCash; GetGameState().Cash = gInitialCash;
WindowInvalidateByClass(WindowClass::Finances); WindowInvalidateByClass(WindowClass::Finances);
WindowInvalidateByClass(WindowClass::BottomToolbar); WindowInvalidateByClass(WindowClass::BottomToolbar);
break; break;

View File

@ -13,6 +13,7 @@
#include "../Date.h" #include "../Date.h"
#include "../EditorObjectSelectionSession.h" #include "../EditorObjectSelectionSession.h"
#include "../Game.h" #include "../Game.h"
#include "../GameState.h"
#include "../OpenRCT2.h" #include "../OpenRCT2.h"
#include "../PlatformEnvironment.h" #include "../PlatformEnvironment.h"
#include "../ReplayManager.h" #include "../ReplayManager.h"
@ -78,6 +79,8 @@
# include "../drawing/TTF.h" # include "../drawing/TTF.h"
#endif #endif
using namespace OpenRCT2;
using arguments_t = std::vector<std::string>; using arguments_t = std::vector<std::string>;
using OpenRCT2::Date; using OpenRCT2::Date;
@ -564,7 +567,7 @@ static int32_t ConsoleCommandGet(InteractiveConsole& console, const arguments_t&
} }
else if (argv[0] == "money") else if (argv[0] == "money")
{ {
console.WriteFormatLine("money %d.%d0", gCash / 10, gCash % 10); console.WriteFormatLine("money %d.%d0", GetGameState().Cash / 10, GetGameState().Cash % 10);
} }
else if (argv[0] == "scenario_initial_cash") else if (argv[0] == "scenario_initial_cash")
{ {
@ -767,7 +770,7 @@ static int32_t ConsoleCommandSet(InteractiveConsole& console, const arguments_t&
if (argv[0] == "money" && InvalidArguments(&invalidArgs, double_valid[0])) if (argv[0] == "money" && InvalidArguments(&invalidArgs, double_valid[0]))
{ {
money64 money = ToMoney64FromGBP(double_val[0]); money64 money = ToMoney64FromGBP(double_val[0]);
if (gCash != money) if (GetGameState().Cash != money)
{ {
auto cheatSetAction = CheatSetAction(CheatType::SetMoney, money); auto cheatSetAction = CheatSetAction(CheatType::SetMoney, money);
cheatSetAction.SetCallback([&console](const GameAction*, const GameActions::Result* res) { cheatSetAction.SetCallback([&console](const GameAction*, const GameActions::Result* res) {

View File

@ -11,6 +11,7 @@
#include "../Context.h" #include "../Context.h"
#include "../Game.h" #include "../Game.h"
#include "../GameState.h"
#include "../OpenRCT2.h" #include "../OpenRCT2.h"
#include "../entity/Peep.h" #include "../entity/Peep.h"
#include "../entity/Staff.h" #include "../entity/Staff.h"
@ -24,6 +25,8 @@
#include "../windows/Intent.h" #include "../windows/Intent.h"
#include "../world/Park.h" #include "../world/Park.h"
using namespace OpenRCT2;
// Monthly research funding costs // Monthly research funding costs
const money64 research_cost_table[RESEARCH_FUNDING_COUNT] = { const money64 research_cost_table[RESEARCH_FUNDING_COUNT] = {
0.00_GBP, // No funding 0.00_GBP, // No funding
@ -37,7 +40,6 @@ static constexpr int32_t dword_988E60[static_cast<int32_t>(ExpenditureType::Coun
}; };
money64 gInitialCash; money64 gInitialCash;
money64 gCash;
money64 gBankLoan; money64 gBankLoan;
uint8_t gBankLoanInterestRate; uint8_t gBankLoanInterestRate;
money64 gMaxBankLoan; money64 gMaxBankLoan;
@ -75,7 +77,7 @@ bool FinanceCheckMoneyRequired(uint32_t flags)
*/ */
bool FinanceCheckAffordability(money64 cost, uint32_t flags) bool FinanceCheckAffordability(money64 cost, uint32_t flags)
{ {
return !FinanceCheckMoneyRequired(flags) || cost <= 0 || cost <= gCash; return !FinanceCheckMoneyRequired(flags) || cost <= 0 || cost <= GetGameState().Cash;
} }
/** /**
@ -87,7 +89,7 @@ bool FinanceCheckAffordability(money64 cost, uint32_t flags)
void FinancePayment(money64 amount, ExpenditureType type) void FinancePayment(money64 amount, ExpenditureType type)
{ {
// overflow check // overflow check
gCash = AddClamp_money64(gCash, -amount); GetGameState().Cash = AddClamp_money64(GetGameState().Cash, -amount);
gExpenditureTable[0][static_cast<int32_t>(type)] -= amount; gExpenditureTable[0][static_cast<int32_t>(type)] -= amount;
if (dword_988E60[static_cast<int32_t>(type)] & 1) if (dword_988E60[static_cast<int32_t>(type)] & 1)
@ -226,7 +228,7 @@ void FinanceInit()
gInitialCash = 10000.00_GBP; // Cheat detection gInitialCash = 10000.00_GBP; // Cheat detection
gCash = 10000.00_GBP; GetGameState().Cash = 10000.00_GBP;
gBankLoan = 10000.00_GBP; gBankLoan = 10000.00_GBP;
gMaxBankLoan = 20000.00_GBP; gMaxBankLoan = 20000.00_GBP;
@ -309,7 +311,7 @@ money64 FinanceGetMaximumLoan()
money64 FinanceGetCurrentCash() money64 FinanceGetCurrentCash()
{ {
return gCash; return GetGameState().Cash;
} }
/** /**
@ -354,7 +356,7 @@ void FinanceShiftExpenditureTable()
*/ */
void FinanceResetCashToInitial() void FinanceResetCashToInitial()
{ {
gCash = gInitialCash; GetGameState().Cash = gInitialCash;
} }
/** /**

View File

@ -39,7 +39,6 @@ constexpr uint8_t MaxBankLoanInterestRate = 255;
extern const money64 research_cost_table[RESEARCH_FUNDING_COUNT]; extern const money64 research_cost_table[RESEARCH_FUNDING_COUNT];
extern money64 gInitialCash; extern money64 gInitialCash;
extern money64 gCash;
extern money64 gBankLoan; extern money64 gBankLoan;
extern uint8_t gBankLoanInterestRate; extern uint8_t gBankLoanInterestRate;
extern money64 gMaxBankLoan; extern money64 gMaxBankLoan;

View File

@ -11,6 +11,7 @@
# include "NetworkServerAdvertiser.h" # include "NetworkServerAdvertiser.h"
# include "../GameState.h"
# include "../config/Config.h" # include "../config/Config.h"
# include "../core/Console.hpp" # include "../core/Console.hpp"
# include "../core/Guard.hpp" # include "../core/Guard.hpp"
@ -33,6 +34,8 @@
# include <random> # include <random>
# include <string> # include <string>
using namespace OpenRCT2;
enum class MasterServerStatus enum class MasterServerStatus
{ {
Ok = 200, Ok = 200,
@ -306,7 +309,7 @@ private:
}; };
if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) if (!(gParkFlags & PARK_FLAGS_NO_MONEY))
{ {
gameInfo["cash"] = gCash; gameInfo["cash"] = GetGameState().Cash;
} }
root["gameInfo"] = gameInfo; root["gameInfo"] = gameInfo;

View File

@ -166,7 +166,7 @@ namespace OpenRCT2
} }
// Initial cash will eventually be removed // Initial cash will eventually be removed
gInitialCash = gCash; gInitialCash = gameState.Cash;
} }
void Save(GameState_t& gameState, IStream& stream) void Save(GameState_t& gameState, IStream& stream)
@ -797,148 +797,149 @@ namespace OpenRCT2
void ReadWriteParkChunk(GameState_t& gameState, OrcaStream& os) void ReadWriteParkChunk(GameState_t& gameState, OrcaStream& os)
{ {
os.ReadWriteChunk(ParkFileChunkType::PARK, [version = os.GetHeader().TargetVersion](OrcaStream::ChunkStream& cs) { os.ReadWriteChunk(
// TODO: Use the passed gameState instead of the global one. ParkFileChunkType::PARK, [version = os.GetHeader().TargetVersion, &gameState](OrcaStream::ChunkStream& cs) {
auto& park = GetContext()->GetGameState()->GetPark(); // TODO: Use the passed gameState instead of the global one.
cs.ReadWrite(park.Name); auto& park = GetContext()->GetGameState()->GetPark();
cs.ReadWrite(gCash); cs.ReadWrite(park.Name);
cs.ReadWrite(gBankLoan); cs.ReadWrite(gameState.Cash);
cs.ReadWrite(gMaxBankLoan); cs.ReadWrite(gBankLoan);
cs.ReadWrite(gBankLoanInterestRate); cs.ReadWrite(gMaxBankLoan);
cs.ReadWrite(gParkFlags); cs.ReadWrite(gBankLoanInterestRate);
if (version <= 18) cs.ReadWrite(gParkFlags);
{ if (version <= 18)
money16 tempParkEntranceFee{};
cs.ReadWrite(tempParkEntranceFee);
gParkEntranceFee = ToMoney64(tempParkEntranceFee);
}
else
{
cs.ReadWrite(gParkEntranceFee);
}
cs.ReadWrite(gStaffHandymanColour);
cs.ReadWrite(gStaffMechanicColour);
cs.ReadWrite(gStaffSecurityColour);
cs.ReadWrite(gSamePriceThroughoutPark);
// Finances
if (cs.GetMode() == OrcaStream::Mode::READING)
{
auto numMonths = std::min<uint32_t>(EXPENDITURE_TABLE_MONTH_COUNT, cs.Read<uint32_t>());
auto numTypes = std::min<uint32_t>(static_cast<uint32_t>(ExpenditureType::Count), cs.Read<uint32_t>());
for (uint32_t i = 0; i < numMonths; i++)
{ {
for (uint32_t j = 0; j < numTypes; j++) money16 tempParkEntranceFee{};
cs.ReadWrite(tempParkEntranceFee);
gParkEntranceFee = ToMoney64(tempParkEntranceFee);
}
else
{
cs.ReadWrite(gParkEntranceFee);
}
cs.ReadWrite(gStaffHandymanColour);
cs.ReadWrite(gStaffMechanicColour);
cs.ReadWrite(gStaffSecurityColour);
cs.ReadWrite(gSamePriceThroughoutPark);
// Finances
if (cs.GetMode() == OrcaStream::Mode::READING)
{
auto numMonths = std::min<uint32_t>(EXPENDITURE_TABLE_MONTH_COUNT, cs.Read<uint32_t>());
auto numTypes = std::min<uint32_t>(static_cast<uint32_t>(ExpenditureType::Count), cs.Read<uint32_t>());
for (uint32_t i = 0; i < numMonths; i++)
{ {
gExpenditureTable[i][j] = cs.Read<money64>(); for (uint32_t j = 0; j < numTypes; j++)
{
gExpenditureTable[i][j] = cs.Read<money64>();
}
} }
} }
} else
else
{
auto numMonths = static_cast<uint32_t>(EXPENDITURE_TABLE_MONTH_COUNT);
auto numTypes = static_cast<uint32_t>(ExpenditureType::Count);
cs.Write(numMonths);
cs.Write(numTypes);
for (uint32_t i = 0; i < numMonths; i++)
{ {
for (uint32_t j = 0; j < numTypes; j++) auto numMonths = static_cast<uint32_t>(EXPENDITURE_TABLE_MONTH_COUNT);
auto numTypes = static_cast<uint32_t>(ExpenditureType::Count);
cs.Write(numMonths);
cs.Write(numTypes);
for (uint32_t i = 0; i < numMonths; i++)
{ {
cs.Write(gExpenditureTable[i][j]); for (uint32_t j = 0; j < numTypes; j++)
{
cs.Write(gExpenditureTable[i][j]);
}
} }
} }
} cs.ReadWrite(gHistoricalProfit);
cs.ReadWrite(gHistoricalProfit);
// Marketing // Marketing
cs.ReadWriteVector(gMarketingCampaigns, [&cs](MarketingCampaign& campaign) { cs.ReadWriteVector(gMarketingCampaigns, [&cs](MarketingCampaign& campaign) {
cs.ReadWrite(campaign.Type); cs.ReadWrite(campaign.Type);
cs.ReadWrite(campaign.WeeksLeft); cs.ReadWrite(campaign.WeeksLeft);
cs.ReadWrite(campaign.Flags); cs.ReadWrite(campaign.Flags);
cs.ReadWrite(campaign.RideId); cs.ReadWrite(campaign.RideId);
}); });
// Awards // Awards
if (version <= 6) if (version <= 6)
{ {
Award awards[RCT2::Limits::MaxAwards]{}; Award awards[RCT2::Limits::MaxAwards]{};
cs.ReadWriteArray(awards, [&cs](Award& award) { cs.ReadWriteArray(awards, [&cs](Award& award) {
if (award.Time != 0) if (award.Time != 0)
{ {
cs.ReadWrite(award.Time);
cs.ReadWrite(award.Type);
GetAwards().push_back(award);
return true;
}
return false;
});
}
else
{
cs.ReadWriteVector(GetAwards(), [&cs](Award& award) {
cs.ReadWrite(award.Time); cs.ReadWrite(award.Time);
cs.ReadWrite(award.Type); cs.ReadWrite(award.Type);
GetAwards().push_back(award); });
return true; }
} cs.ReadWrite(gParkValue);
cs.ReadWrite(gCompanyValue);
cs.ReadWrite(gParkSize);
cs.ReadWrite(gNumGuestsInPark);
cs.ReadWrite(gNumGuestsHeadingForPark);
cs.ReadWrite(gParkRating);
cs.ReadWrite(gParkRatingCasualtyPenalty);
cs.ReadWrite(gCurrentExpenditure);
cs.ReadWrite(gCurrentProfit);
cs.ReadWrite(gWeeklyProfitAverageDividend);
cs.ReadWrite(gWeeklyProfitAverageDivisor);
cs.ReadWrite(gTotalAdmissions);
cs.ReadWrite(gTotalIncomeFromAdmissions);
if (version <= 16)
{
money16 legacyTotalRideValueForMoney = 0;
cs.ReadWrite(legacyTotalRideValueForMoney);
gTotalRideValueForMoney = legacyTotalRideValueForMoney;
}
else
{
cs.ReadWrite(gTotalRideValueForMoney);
}
cs.ReadWrite(gNumGuestsInParkLastWeek);
cs.ReadWrite(gGuestChangeModifier);
cs.ReadWrite(_guestGenerationProbability);
cs.ReadWrite(_suggestedGuestMaximum);
return false; cs.ReadWriteArray(gPeepWarningThrottle, [&cs](uint8_t& value) {
cs.ReadWrite(value);
return true;
}); });
}
else cs.ReadWriteArray(gParkRatingHistory, [&cs](uint8_t& value) {
{ cs.ReadWrite(value);
cs.ReadWriteVector(GetAwards(), [&cs](Award& award) { return true;
cs.ReadWrite(award.Time);
cs.ReadWrite(award.Type);
}); });
}
cs.ReadWrite(gParkValue);
cs.ReadWrite(gCompanyValue);
cs.ReadWrite(gParkSize);
cs.ReadWrite(gNumGuestsInPark);
cs.ReadWrite(gNumGuestsHeadingForPark);
cs.ReadWrite(gParkRating);
cs.ReadWrite(gParkRatingCasualtyPenalty);
cs.ReadWrite(gCurrentExpenditure);
cs.ReadWrite(gCurrentProfit);
cs.ReadWrite(gWeeklyProfitAverageDividend);
cs.ReadWrite(gWeeklyProfitAverageDivisor);
cs.ReadWrite(gTotalAdmissions);
cs.ReadWrite(gTotalIncomeFromAdmissions);
if (version <= 16)
{
money16 legacyTotalRideValueForMoney = 0;
cs.ReadWrite(legacyTotalRideValueForMoney);
gTotalRideValueForMoney = legacyTotalRideValueForMoney;
}
else
{
cs.ReadWrite(gTotalRideValueForMoney);
}
cs.ReadWrite(gNumGuestsInParkLastWeek);
cs.ReadWrite(gGuestChangeModifier);
cs.ReadWrite(_guestGenerationProbability);
cs.ReadWrite(_suggestedGuestMaximum);
cs.ReadWriteArray(gPeepWarningThrottle, [&cs](uint8_t& value) { cs.ReadWriteArray(gGuestsInParkHistory, [&cs](uint32_t& value) {
cs.ReadWrite(value); cs.ReadWrite(value);
return true; return true;
}); });
cs.ReadWriteArray(gParkRatingHistory, [&cs](uint8_t& value) { cs.ReadWriteArray(gCashHistory, [&cs](money64& value) {
cs.ReadWrite(value); cs.ReadWrite(value);
return true; return true;
});
cs.ReadWriteArray(gWeeklyProfitHistory, [&cs](money64& value) {
cs.ReadWrite(value);
return true;
});
cs.ReadWriteArray(gParkValueHistory, [&cs](money64& value) {
cs.ReadWrite(value);
return true;
});
}); });
cs.ReadWriteArray(gGuestsInParkHistory, [&cs](uint32_t& value) {
cs.ReadWrite(value);
return true;
});
cs.ReadWriteArray(gCashHistory, [&cs](money64& value) {
cs.ReadWrite(value);
return true;
});
cs.ReadWriteArray(gWeeklyProfitHistory, [&cs](money64& value) {
cs.ReadWrite(value);
return true;
});
cs.ReadWriteArray(gParkValueHistory, [&cs](money64& value) {
cs.ReadWrite(value);
return true;
});
});
} }
void ReadWriteResearchChunk(GameState_t& gameState, OrcaStream& os) void ReadWriteResearchChunk(GameState_t& gameState, OrcaStream& os)

View File

@ -180,7 +180,7 @@ namespace RCT1
ImportSprites(); ImportSprites();
ImportTileElements(); ImportTileElements();
ImportPeepSpawns(); ImportPeepSpawns();
ImportFinance(); ImportFinance(gameState);
ImportResearch(); ImportResearch();
ImportParkName(); ImportParkName();
ImportParkFlags(gameState); ImportParkFlags(gameState);
@ -1389,13 +1389,13 @@ namespace RCT1
} }
} }
void ImportFinance() void ImportFinance(GameState_t& gameState)
{ {
gParkEntranceFee = _s4.ParkEntranceFee; gParkEntranceFee = _s4.ParkEntranceFee;
gLandPrice = ToMoney64(_s4.LandPrice); gLandPrice = ToMoney64(_s4.LandPrice);
gConstructionRightsPrice = ToMoney64(_s4.ConstructionRightsPrice); gConstructionRightsPrice = ToMoney64(_s4.ConstructionRightsPrice);
gCash = ToMoney64(_s4.Cash); gameState.Cash = ToMoney64(_s4.Cash);
gBankLoan = ToMoney64(_s4.Loan); gBankLoan = ToMoney64(_s4.Loan);
gMaxBankLoan = ToMoney64(_s4.MaxLoan); 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. // It's more like 1.33%, but we can only use integers. Can be fixed once we have our own save format.

View File

@ -397,7 +397,7 @@ namespace RCT2
gHistoricalProfit = ToMoney64(_s6.HistoricalProfit); gHistoricalProfit = ToMoney64(_s6.HistoricalProfit);
// Pad013587D4 // Pad013587D4
gScenarioCompletedBy = std::string_view(_s6.ScenarioCompletedName, sizeof(_s6.ScenarioCompletedName)); gScenarioCompletedBy = std::string_view(_s6.ScenarioCompletedName, sizeof(_s6.ScenarioCompletedName));
gCash = ToMoney64(DECRYPT_MONEY(_s6.Cash)); gameState.Cash = ToMoney64(DECRYPT_MONEY(_s6.Cash));
// Pad013587FC // Pad013587FC
gParkRatingCasualtyPenalty = _s6.ParkRatingCasualtyPenalty; gParkRatingCasualtyPenalty = _s6.ParkRatingCasualtyPenalty;
gMapSize = { _s6.MapSize, _s6.MapSize }; gMapSize = { _s6.MapSize, _s6.MapSize };

View File

@ -115,7 +115,7 @@ void ScenarioReset()
gParkValue = park.CalculateParkValue(); gParkValue = park.CalculateParkValue();
gCompanyValue = park.CalculateCompanyValue(); gCompanyValue = park.CalculateCompanyValue();
gHistoricalProfit = gInitialCash - gBankLoan; gHistoricalProfit = gInitialCash - gBankLoan;
gCash = gInitialCash; GetGameState().Cash = gInitialCash;
{ {
utf8 normalisedName[64]; utf8 normalisedName[64];

View File

@ -51,15 +51,15 @@ namespace OpenRCT2::Scripting
money64 ScPark::cash_get() const money64 ScPark::cash_get() const
{ {
return gCash; return GetGameState().Cash;
} }
void ScPark::cash_set(money64 value) void ScPark::cash_set(money64 value)
{ {
ThrowIfGameStateNotMutable(); ThrowIfGameStateNotMutable();
if (gCash != value) if (GetGameState().Cash != value)
{ {
gCash = value; GetGameState().Cash = value;
auto intent = Intent(INTENT_ACTION_UPDATE_CASH); auto intent = Intent(INTENT_ACTION_UPDATE_CASH);
ContextBroadcastIntent(&intent); ContextBroadcastIntent(&intent);
} }