diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index d612e9a3d7..ad2e3aad5e 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -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(ExpenditureType::Count); j++) { - auto expenditure = gExpenditureTable[i][j]; + auto expenditure = gameState.ExpenditureTable[i][j]; if (expenditure != 0) { profit += expenditure; diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 9b048aa6c8..09034b7945 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -78,6 +78,7 @@ namespace OpenRCT2 money64 BankLoan; uint8_t BankLoanInterestRate; money64 MaxBankLoan; + money64 ExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][static_cast(ExpenditureType::Count)]; random_engine_t ScenarioRand; TileCoordsXY MapSize; diff --git a/src/openrct2/management/Finance.cpp b/src/openrct2/management/Finance.cpp index 9a99a987f0..b7afabef08 100644 --- a/src/openrct2/management/Finance.cpp +++ b/src/openrct2/management/Finance.cpp @@ -41,8 +41,6 @@ static constexpr int32_t dword_988E60[static_cast(ExpenditureType::Coun 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, }; -money64 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][static_cast(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(type)] -= amount; + gameState.ExpenditureTable[0][static_cast(type)] -= amount; if (dword_988E60[static_cast(type)] & 1) { // Cumulative amount of money spent this day @@ -199,7 +197,7 @@ void FinanceResetHistory() { for (uint32_t j = 0; j < static_cast(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(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(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(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(ExpenditureType::ShopSales)]; profit += lastMonthExpenditure[static_cast(ExpenditureType::ShopStock)]; @@ -373,4 +372,4 @@ money64 FinanceGetLastMonthShopProfit() profit += lastMonthExpenditure[static_cast(ExpenditureType::FoodDrinkStock)]; } return profit; -} +} \ No newline at end of file diff --git a/src/openrct2/management/Finance.h b/src/openrct2/management/Finance.h index 7666f3e818..33375b8966 100644 --- a/src/openrct2/management/Finance.h +++ b/src/openrct2/management/Finance.h @@ -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(ExpenditureType::Count)]; - bool FinanceCheckMoneyRequired(uint32_t flags); bool FinanceCheckAffordability(money64 cost, uint32_t flags); void FinancePayment(money64 amount, ExpenditureType type); diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 26c4dea608..a71f89e5b0 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -832,7 +832,7 @@ namespace OpenRCT2 { for (uint32_t j = 0; j < numTypes; j++) { - gExpenditureTable[i][j] = cs.Read(); + gameState.ExpenditureTable[i][j] = cs.Read(); } } } @@ -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]); } } } diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index fc326b7f94..970d5ee818 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -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); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 82ebc8e647..36f8b5e86a 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -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]); } } diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index d6c055c9f4..239f233a1b 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -743,7 +743,7 @@ ObjectiveStatus Objective::CheckGuestsAndRating() const ObjectiveStatus Objective::CheckMonthlyRideIncome() const { - money64 lastMonthRideIncome = gExpenditureTable[1][static_cast(ExpenditureType::ParkRideTickets)]; + money64 lastMonthRideIncome = GetGameState().ExpenditureTable[1][static_cast(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(ExpenditureType::ShopSales)] + lastMonthExpenditure[static_cast(ExpenditureType::ShopStock)] + lastMonthExpenditure[static_cast(ExpenditureType::FoodDrinkSales)]