1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Move gExpenditureTable to GameState_t

This commit is contained in:
Harry Hopkinson
2024-03-04 14:24:29 +00:00
committed by GitHub
parent 4b6ba80a46
commit 9748038815
8 changed files with 19 additions and 20 deletions

View File

@@ -387,6 +387,7 @@ public:
screenCoords.y += TABLE_CELL_HEIGHT;
}
auto& gameState = GetGameState();
// Expenditure / Income values for each month
auto currentMonthYear = GetDate().GetMonthsElapsed();
for (int32_t i = SummaryMaxAvailableMonth(); i >= 0; i--)
@@ -409,7 +410,7 @@ public:
money64 profit = 0;
for (int32_t j = 0; j < static_cast<int32_t>(ExpenditureType::Count); j++)
{
auto expenditure = gExpenditureTable[i][j];
auto expenditure = gameState.ExpenditureTable[i][j];
if (expenditure != 0)
{
profit += expenditure;

View File

@@ -78,6 +78,7 @@ namespace OpenRCT2
money64 BankLoan;
uint8_t BankLoanInterestRate;
money64 MaxBankLoan;
money64 ExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][static_cast<int32_t>(ExpenditureType::Count)];
random_engine_t ScenarioRand;
TileCoordsXY MapSize;

View File

@@ -41,8 +41,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 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][static_cast<int32_t>(ExpenditureType::Count)];
/**
* Checks the condition if the game is required to use money.
* @param flags game command flags.
@@ -82,7 +80,7 @@ void FinancePayment(money64 amount, ExpenditureType type)
auto& gameState = GetGameState();
gameState.Cash = AddClamp_money64(gameState.Cash, -amount);
gExpenditureTable[0][static_cast<int32_t>(type)] -= amount;
gameState.ExpenditureTable[0][static_cast<int32_t>(type)] -= amount;
if (dword_988E60[static_cast<int32_t>(type)] & 1)
{
// Cumulative amount of money spent this day
@@ -199,7 +197,7 @@ void FinanceResetHistory()
{
for (uint32_t j = 0; j < static_cast<int32_t>(ExpenditureType::Count); ++j)
{
gExpenditureTable[i][j] = 0;
gameState.ExpenditureTable[i][j] = 0;
}
}
}
@@ -215,7 +213,7 @@ void FinanceInit()
// It only initialises the first month
for (uint32_t i = 0; i < static_cast<int32_t>(ExpenditureType::Count); i++)
{
gExpenditureTable[0][i] = 0;
gameState.ExpenditureTable[0][i] = 0;
}
gameState.CurrentExpenditure = 0;
@@ -319,12 +317,13 @@ money64 FinanceGetCurrentCash()
*/
void FinanceShiftExpenditureTable()
{
auto& gameState = GetGameState();
// If EXPENDITURE_TABLE_MONTH_COUNT months have passed then is full, sum the oldest month
if (GetDate().GetMonthsElapsed() >= EXPENDITURE_TABLE_MONTH_COUNT)
{
const money64 sum = std::accumulate(
std::cbegin(gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT - 1]),
std::cend(gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT - 1]), money64{});
std::cbegin(gameState.ExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT - 1]),
std::cend(gameState.ExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT - 1]), money64{});
GetGameState().HistoricalProfit += sum;
}
@@ -334,14 +333,14 @@ void FinanceShiftExpenditureTable()
{
for (size_t j = 0; j < static_cast<int32_t>(ExpenditureType::Count); j++)
{
gExpenditureTable[i][j] = gExpenditureTable[i - 1][j];
gameState.ExpenditureTable[i][j] = gameState.ExpenditureTable[i - 1][j];
}
}
// Zero the beginning of the table, which is the new month
for (uint32_t i = 0; i < static_cast<int32_t>(ExpenditureType::Count); i++)
{
gExpenditureTable[0][i] = 0;
gameState.ExpenditureTable[0][i] = 0;
}
WindowInvalidateByClass(WindowClass::Finances);
@@ -365,7 +364,7 @@ money64 FinanceGetLastMonthShopProfit()
money64 profit = 0;
if (GetDate().GetMonthsElapsed() != 0)
{
const auto* lastMonthExpenditure = gExpenditureTable[1];
const auto* lastMonthExpenditure = GetGameState().ExpenditureTable[1];
profit += lastMonthExpenditure[static_cast<int32_t>(ExpenditureType::ShopSales)];
profit += lastMonthExpenditure[static_cast<int32_t>(ExpenditureType::ShopStock)];
@@ -373,4 +372,4 @@ money64 FinanceGetLastMonthShopProfit()
profit += lastMonthExpenditure[static_cast<int32_t>(ExpenditureType::FoodDrinkStock)];
}
return profit;
}
}

View File

@@ -38,8 +38,6 @@ constexpr uint8_t MaxBankLoanInterestRate = 255;
extern const money64 research_cost_table[RESEARCH_FUNDING_COUNT];
extern money64 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][static_cast<int32_t>(ExpenditureType::Count)];
bool FinanceCheckMoneyRequired(uint32_t flags);
bool FinanceCheckAffordability(money64 cost, uint32_t flags);
void FinancePayment(money64 amount, ExpenditureType type);

View File

@@ -832,7 +832,7 @@ namespace OpenRCT2
{
for (uint32_t j = 0; j < numTypes; j++)
{
gExpenditureTable[i][j] = cs.Read<money64>();
gameState.ExpenditureTable[i][j] = cs.Read<money64>();
}
}
}
@@ -847,7 +847,7 @@ namespace OpenRCT2
{
for (uint32_t j = 0; j < numTypes; j++)
{
cs.Write(gExpenditureTable[i][j]);
cs.Write(gameState.ExpenditureTable[i][j]);
}
}
}

View File

@@ -1450,7 +1450,7 @@ namespace RCT1
{
for (size_t j = 0; j < Limits::ExpenditureTypeCount; j++)
{
gExpenditureTable[i][j] = ToMoney64(_s4.Expenditure[i][j]);
gameState.ExpenditureTable[i][j] = ToMoney64(_s4.Expenditure[i][j]);
}
}
gameState.CurrentExpenditure = ToMoney64(_s4.TotalExpenditure);

View File

@@ -295,7 +295,7 @@ namespace RCT2
{
for (size_t j = 0; j < Limits::ExpenditureTypeCount; j++)
{
gExpenditureTable[i][j] = ToMoney64(_s6.ExpenditureTable[i][j]);
gameState.ExpenditureTable[i][j] = ToMoney64(_s6.ExpenditureTable[i][j]);
}
}

View File

@@ -743,7 +743,7 @@ ObjectiveStatus Objective::CheckGuestsAndRating() const
ObjectiveStatus Objective::CheckMonthlyRideIncome() const
{
money64 lastMonthRideIncome = gExpenditureTable[1][static_cast<int32_t>(ExpenditureType::ParkRideTickets)];
money64 lastMonthRideIncome = GetGameState().ExpenditureTable[1][static_cast<int32_t>(ExpenditureType::ParkRideTickets)];
if (lastMonthRideIncome >= Currency)
{
return ObjectiveStatus::Success;
@@ -831,7 +831,7 @@ ObjectiveStatus Objective::CheckRepayLoanAndParkValue() const
ObjectiveStatus Objective::CheckMonthlyFoodIncome() const
{
const auto* lastMonthExpenditure = gExpenditureTable[1];
const auto* lastMonthExpenditure = GetGameState().ExpenditureTable[1];
auto lastMonthProfit = lastMonthExpenditure[static_cast<int32_t>(ExpenditureType::ShopSales)]
+ lastMonthExpenditure[static_cast<int32_t>(ExpenditureType::ShopStock)]
+ lastMonthExpenditure[static_cast<int32_t>(ExpenditureType::FoodDrinkSales)]