Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move gWeekly* globals to GameState_t #21258

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/openrct2-ui/windows/Finances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ class FinancesWindow final : public Window

void OnDrawProfitGraph(DrawPixelInfo& dpi)
{
auto& gameState = GetGameState();
Widget* pageWidget = &_windowFinancesCashWidgets[WIDX_PAGE_BACKGROUND];
auto graphTopLeft = windowPos + ScreenCoordsXY{ pageWidget->left + 4, pageWidget->top + 15 };
auto graphBottomRight = windowPos + ScreenCoordsXY{ pageWidget->right - 4, pageWidget->bottom - 4 };
Expand All @@ -748,7 +749,7 @@ class FinancesWindow final : public Window
int32_t yAxisScale = 0;
for (int32_t i = 0; i < 64; i++)
{
auto balance = gWeeklyProfitHistory[i];
auto balance = gameState.WeeklyProfitHistory[i];
if (balance == MONEY64_UNDEFINED)
continue;

Expand Down Expand Up @@ -780,7 +781,7 @@ class FinancesWindow final : public Window

// X axis labels and values
screenPos = graphTopLeft + ScreenCoordsXY{ 98, 17 };
Graph::Draw(dpi, gWeeklyProfitHistory, 64, screenPos, yAxisScale, 128);
Graph::Draw(dpi, gameState.WeeklyProfitHistory, 64, screenPos, yAxisScale, 128);
}

#pragma endregion
Expand Down
4 changes: 4 additions & 0 deletions src/openrct2/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#pragma once

#include "Date.h"
#include "management/Finance.h"
#include "world/Climate.h"
#include "world/Location.hpp"

Expand All @@ -36,6 +37,9 @@ namespace OpenRCT2
uint8_t GuestInitialHappiness;
uint8_t GuestInitialHunger;
uint8_t GuestInitialThirst;
money64 WeeklyProfitAverageDividend;
uint16_t WeeklyProfitAverageDivisor;
money64 WeeklyProfitHistory[FINANCE_GRAPH_SIZE];
};

GameState_t& GetGameState();
Expand Down
17 changes: 8 additions & 9 deletions src/openrct2/management/Finance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ money64 gMaxBankLoan;
money64 gCurrentExpenditure;
money64 gCurrentProfit;
money64 gHistoricalProfit;
money64 gWeeklyProfitAverageDividend;
uint16_t gWeeklyProfitAverageDivisor;
money64 gCashHistory[FINANCE_GRAPH_SIZE];
money64 gWeeklyProfitHistory[FINANCE_GRAPH_SIZE];
money64 gParkValueHistory[FINANCE_GRAPH_SIZE];
money64 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][static_cast<int32_t>(ExpenditureType::Count)];

Expand Down Expand Up @@ -193,10 +190,11 @@ void FinancePayRideUpkeep()

void FinanceResetHistory()
{
auto& gameState = GetGameState();
for (int32_t i = 0; i < FINANCE_GRAPH_SIZE; i++)
{
gCashHistory[i] = MONEY64_UNDEFINED;
gWeeklyProfitHistory[i] = MONEY64_UNDEFINED;
gameState.WeeklyProfitHistory[i] = MONEY64_UNDEFINED;
gParkValueHistory[i] = MONEY64_UNDEFINED;
}

Expand Down Expand Up @@ -226,8 +224,8 @@ void FinanceInit()
gCurrentExpenditure = 0;
gCurrentProfit = 0;

gWeeklyProfitAverageDividend = 0;
gWeeklyProfitAverageDivisor = 0;
gameState.WeeklyProfitAverageDividend = 0;
gameState.WeeklyProfitAverageDivisor = 0;

gameState.InitialCash = 10000.00_GBP; // Cheat detection

Expand Down Expand Up @@ -258,8 +256,9 @@ void FinanceUpdateDailyProfit()
gCurrentExpenditure = 0; // Reset daily expenditure

money64 current_profit = 0;
auto& gameState = GetGameState();

if (!(GetGameState().ParkFlags & PARK_FLAGS_NO_MONEY))
if (!(gameState.ParkFlags & PARK_FLAGS_NO_MONEY))
{
// Staff costs
for (auto peep : EntityList<Staff>())
Expand Down Expand Up @@ -291,8 +290,8 @@ void FinanceUpdateDailyProfit()
gCurrentProfit += current_profit;

// These are related to weekly profit graph
gWeeklyProfitAverageDividend += gCurrentProfit;
gWeeklyProfitAverageDivisor += 1;
gameState.WeeklyProfitAverageDividend += gCurrentProfit;
gameState.WeeklyProfitAverageDivisor += 1;

WindowInvalidateByClass(WindowClass::Finances);
}
Expand Down
3 changes: 0 additions & 3 deletions src/openrct2/management/Finance.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ extern money64 gCurrentProfit;
*/
extern money64 gHistoricalProfit;

extern money64 gWeeklyProfitAverageDividend;
extern uint16_t gWeeklyProfitAverageDivisor;
extern money64 gCashHistory[FINANCE_GRAPH_SIZE];
extern money64 gWeeklyProfitHistory[FINANCE_GRAPH_SIZE];
extern money64 gParkValueHistory[FINANCE_GRAPH_SIZE];
extern money64 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][static_cast<int32_t>(ExpenditureType::Count)];

Expand Down
6 changes: 3 additions & 3 deletions src/openrct2/park/ParkFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,8 @@ namespace OpenRCT2
cs.ReadWrite(gParkRatingCasualtyPenalty);
cs.ReadWrite(gCurrentExpenditure);
cs.ReadWrite(gCurrentProfit);
cs.ReadWrite(gWeeklyProfitAverageDividend);
cs.ReadWrite(gWeeklyProfitAverageDivisor);
cs.ReadWrite(gameState.WeeklyProfitAverageDividend);
cs.ReadWrite(gameState.WeeklyProfitAverageDivisor);
cs.ReadWrite(gTotalAdmissions);
cs.ReadWrite(gTotalIncomeFromAdmissions);
if (version <= 16)
Expand Down Expand Up @@ -931,7 +931,7 @@ namespace OpenRCT2
cs.ReadWrite(value);
return true;
});
cs.ReadWriteArray(gWeeklyProfitHistory, [&cs](money64& value) {
cs.ReadWriteArray(gameState.WeeklyProfitHistory, [&cs](money64& value) {
cs.ReadWrite(value);
return true;
});
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/rct1/S4Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ namespace RCT1
{
gCashHistory[i] = ToMoney64(_s4.CashHistory[i]);
gParkValueHistory[i] = CorrectRCT1ParkValue(_s4.ParkValueHistory[i]);
gWeeklyProfitHistory[i] = ToMoney64(_s4.WeeklyProfitHistory[i]);
gameState.WeeklyProfitHistory[i] = ToMoney64(_s4.WeeklyProfitHistory[i]);
}

for (size_t i = 0; i < Limits::ExpenditureTableMonthCount; i++)
Expand Down
6 changes: 3 additions & 3 deletions src/openrct2/rct2/S6Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,16 @@ namespace RCT2

gCurrentExpenditure = ToMoney64(_s6.CurrentExpenditure);
gCurrentProfit = ToMoney64(_s6.CurrentProfit);
gWeeklyProfitAverageDividend = ToMoney64(_s6.WeeklyProfitAverageDividend);
gWeeklyProfitAverageDivisor = _s6.WeeklyProfitAverageDivisor;
gameState.WeeklyProfitAverageDividend = ToMoney64(_s6.WeeklyProfitAverageDividend);
gameState.WeeklyProfitAverageDivisor = _s6.WeeklyProfitAverageDivisor;
// Pad0135833A

gParkValue = ToMoney64(_s6.ParkValue);

for (size_t i = 0; i < Limits::FinanceGraphSize; i++)
{
gCashHistory[i] = ToMoney64(_s6.BalanceHistory[i]);
gWeeklyProfitHistory[i] = ToMoney64(_s6.WeeklyProfitHistory[i]);
gameState.WeeklyProfitHistory[i] = ToMoney64(_s6.WeeklyProfitHistory[i]);
gParkValueHistory[i] = ToMoney64(_s6.ParkValueHistory[i]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/scenario/Scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ void ScenarioReset()

gCurrentExpenditure = 0;
gCurrentProfit = 0;
gWeeklyProfitAverageDividend = 0;
gWeeklyProfitAverageDivisor = 0;
gameState.WeeklyProfitAverageDividend = 0;
gameState.WeeklyProfitAverageDivisor = 0;
gTotalAdmissions = 0;
gTotalIncomeFromAdmissions = 0;

Expand Down
12 changes: 6 additions & 6 deletions src/openrct2/world/Park.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,14 +768,14 @@ void Park::UpdateHistories()
HistoryPushRecord<money64, std::size(gCashHistory)>(gCashHistory, FinanceGetCurrentCash() - gBankLoan);

// Update weekly profit history
auto currentWeeklyProfit = gWeeklyProfitAverageDividend;
if (gWeeklyProfitAverageDivisor != 0)
auto currentWeeklyProfit = gameState.WeeklyProfitAverageDividend;
if (gameState.WeeklyProfitAverageDivisor != 0)
{
currentWeeklyProfit /= gWeeklyProfitAverageDivisor;
currentWeeklyProfit /= gameState.WeeklyProfitAverageDivisor;
}
HistoryPushRecord<money64, std::size(gWeeklyProfitHistory)>(gWeeklyProfitHistory, currentWeeklyProfit);
gWeeklyProfitAverageDividend = 0;
gWeeklyProfitAverageDivisor = 0;
HistoryPushRecord<money64, FINANCE_GRAPH_SIZE>(gameState.WeeklyProfitHistory, currentWeeklyProfit);
gameState.WeeklyProfitAverageDividend = 0;
gameState.WeeklyProfitAverageDivisor = 0;

// Update park value history
HistoryPushRecord<money64, std::size(gParkValueHistory)>(gParkValueHistory, gParkValue);
Expand Down
Loading