From 42844d1667bbbdc31825c27e68a9c6e8a8d6ce28 Mon Sep 17 00:00:00 2001 From: Harry Hopkinson <63599884+Harry-Hopkinson@users.noreply.github.com> Date: Fri, 1 Mar 2024 08:47:30 +0000 Subject: [PATCH] Move gCurrentProfit to GameState_t (#21485) --- src/openrct2-ui/windows/Finances.cpp | 4 ++-- src/openrct2-ui/windows/GameBottomToolbar.cpp | 2 +- src/openrct2/GameState.h | 1 + src/openrct2/management/Finance.cpp | 9 ++++----- src/openrct2/management/Finance.h | 2 -- src/openrct2/park/ParkFile.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/scenario/Scenario.cpp | 2 +- 9 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index 757878c02f..b94f1fed68 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -742,10 +742,10 @@ public: // Weekly profit auto ft = Formatter(); - ft.Add(gCurrentProfit); + ft.Add(gameState.CurrentProfit); DrawTextBasic( dpi, graphTopLeft - ScreenCoordsXY{ 0, 11 }, - gCurrentProfit >= 0 ? STR_FINANCES_WEEKLY_PROFIT_POSITIVE : STR_FINANCES_WEEKLY_PROFIT_LOSS, ft); + gameState.CurrentProfit >= 0 ? STR_FINANCES_WEEKLY_PROFIT_POSITIVE : STR_FINANCES_WEEKLY_PROFIT_LOSS, ft); // Graph GfxFillRectInset(dpi, { graphTopLeft, graphBottomRight }, colours[1], INSET_RECT_F_30); diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index 496f775b7a..12fa470ae5 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -475,7 +475,7 @@ public: switch (widgetIndex) { case WIDX_MONEY: - ft.Add(gCurrentProfit); + ft.Add(gameState.CurrentProfit); ft.Add(gameState.ParkValue); break; case WIDX_PARK_RATING: diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 021377f16e..b944d83113 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -43,6 +43,7 @@ namespace OpenRCT2 money64 CompanyValue; money64 ConstructionRightsPrice; money64 CurrentExpenditure; + money64 CurrentProfit; uint8_t ParkRatingHistory[32]; ClimateType Climate; ClimateState ClimateCurrent; diff --git a/src/openrct2/management/Finance.cpp b/src/openrct2/management/Finance.cpp index 0297384ee7..292fbe97e8 100644 --- a/src/openrct2/management/Finance.cpp +++ b/src/openrct2/management/Finance.cpp @@ -39,7 +39,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 gCurrentProfit; money64 gHistoricalProfit; money64 gCashHistory[FINANCE_GRAPH_SIZE]; money64 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][static_cast(ExpenditureType::Count)]; @@ -220,7 +219,7 @@ void FinanceInit() } gameState.CurrentExpenditure = 0; - gCurrentProfit = 0; + gameState.CurrentProfit = 0; gameState.WeeklyProfitAverageDividend = 0; gameState.WeeklyProfitAverageDivisor = 0; @@ -251,7 +250,7 @@ void FinanceUpdateDailyProfit() PROFILED_FUNCTION(); auto& gameState = GetGameState(); - gCurrentProfit = 7 * gameState.CurrentExpenditure; + gameState.CurrentProfit = 7 * gameState.CurrentExpenditure; gameState.CurrentExpenditure = 0; // Reset daily expenditure money64 current_profit = 0; @@ -285,10 +284,10 @@ void FinanceUpdateDailyProfit() // This is not equivalent to / 4 due to rounding of negative numbers current_profit = current_profit >> 2; - gCurrentProfit += current_profit; + gameState.CurrentProfit += current_profit; // These are related to weekly profit graph - gameState.WeeklyProfitAverageDividend += gCurrentProfit; + gameState.WeeklyProfitAverageDividend += gameState.CurrentProfit; gameState.WeeklyProfitAverageDivisor += 1; WindowInvalidateByClass(WindowClass::Finances); diff --git a/src/openrct2/management/Finance.h b/src/openrct2/management/Finance.h index 60bf6249c4..bc8b028871 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 gCurrentProfit; - /** * The total profit for the entire scenario that precedes * the current financial table. diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index f430cec855..fc9650c133 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -892,7 +892,7 @@ namespace OpenRCT2 cs.ReadWrite(gameState.ParkRating); cs.ReadWrite(gParkRatingCasualtyPenalty); cs.ReadWrite(gameState.CurrentExpenditure); - cs.ReadWrite(gCurrentProfit); + cs.ReadWrite(gameState.CurrentProfit); cs.ReadWrite(gameState.WeeklyProfitAverageDividend); cs.ReadWrite(gameState.WeeklyProfitAverageDivisor); cs.ReadWrite(gameState.TotalAdmissions); diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 54f480ac76..6ca90e9a33 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1404,7 +1404,7 @@ namespace RCT1 gameState.CompanyValue = ToMoney64(_s4.CompanyValue); gameState.ParkValue = CorrectRCT1ParkValue(_s4.ParkValue); - gCurrentProfit = ToMoney64(_s4.Profit); + gameState.CurrentProfit = ToMoney64(_s4.Profit); for (size_t i = 0; i < Limits::FinanceGraphSize; i++) { diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 4f3d4581fb..8cc31513f8 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -357,7 +357,7 @@ namespace RCT2 ImportMarketingCampaigns(); gameState.CurrentExpenditure = ToMoney64(_s6.CurrentExpenditure); - gCurrentProfit = ToMoney64(_s6.CurrentProfit); + gameState.CurrentProfit = ToMoney64(_s6.CurrentProfit); gameState.WeeklyProfitAverageDividend = ToMoney64(_s6.WeeklyProfitAverageDividend); gameState.WeeklyProfitAverageDivisor = _s6.WeeklyProfitAverageDivisor; // Pad0135833A diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index 8389365d3d..1c141a8bbb 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -135,7 +135,7 @@ void ScenarioReset(GameState_t& gameState) gScenarioSavePath = Path::Combine(savePath, park.Name + u8".park"); gameState.CurrentExpenditure = 0; - gCurrentProfit = 0; + gameState.CurrentProfit = 0; gameState.WeeklyProfitAverageDividend = 0; gameState.WeeklyProfitAverageDivisor = 0; gameState.TotalAdmissions = 0;