1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-18 13:32:32 +01:00

Merge pull request #21271 from Broxzier/refactor/global-park-value

#21193: Move gParkValue and gParkValueHistory to GameState_t
This commit is contained in:
Hielke Morsink
2024-01-25 16:14:23 +01:00
committed by GitHub
15 changed files with 49 additions and 43 deletions

View File

@@ -591,7 +591,7 @@ public:
{
// Park value and company value
ft = Formatter();
ft.Add<money64>(gParkValue);
ft.Add<money64>(gameState.ParkValue);
DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ 280, 279 }, STR_PARK_VALUE_LABEL, ft);
ft = Formatter();
ft.Add<money64>(gCompanyValue);
@@ -677,9 +677,11 @@ public:
auto graphTopLeft = windowPos + ScreenCoordsXY{ pageWidget->left + 4, pageWidget->top + 15 };
auto graphBottomRight = windowPos + ScreenCoordsXY{ pageWidget->right - 4, pageWidget->bottom - 4 };
const auto& gameState = GetGameState();
// Park value
auto ft = Formatter();
ft.Add<money64>(gParkValue);
ft.Add<money64>(gameState.ParkValue);
DrawTextBasic(dpi, graphTopLeft - ScreenCoordsXY{ 0, 11 }, STR_FINANCES_PARK_VALUE, ft);
// Graph
@@ -689,7 +691,7 @@ public:
int32_t yAxisScale = 0;
for (int32_t i = 0; i < 64; i++)
{
auto balance = gParkValueHistory[i];
auto balance = gameState.ParkValueHistory[i];
if (balance == MONEY64_UNDEFINED)
continue;
@@ -721,7 +723,7 @@ public:
// X axis labels and values
coords = graphTopLeft + ScreenCoordsXY{ 98, 17 };
Graph::Draw(dpi, gParkValueHistory, 64, coords, yAxisScale, 0);
Graph::Draw(dpi, gameState.ParkValueHistory, 64, coords, yAxisScale, 0);
}
#pragma endregion

View File

@@ -469,18 +469,19 @@ public:
OpenRCT2String OnTooltip(WidgetIndex widgetIndex, StringId fallback) override
{
const auto& gameState = GetGameState();
auto ft = Formatter();
switch (widgetIndex)
{
case WIDX_MONEY:
ft.Add<money64>(gCurrentProfit);
ft.Add<money64>(gParkValue);
break;
case WIDX_PARK_RATING:
ft.Add<int16_t>(GetGameState().ParkRating);
break;
}
switch (widgetIndex)
{
case WIDX_MONEY:
ft.Add<money64>(gCurrentProfit);
ft.Add<money64>(gameState.ParkValue);
break;
case WIDX_PARK_RATING:
ft.Add<int16_t>(gameState.ParkRating);
break;
}
return { fallback, ft };
}

View File

@@ -34,6 +34,8 @@ namespace OpenRCT2
money64 ParkEntranceFee;
std::vector<CoordsXYZD> ParkEntrances;
uint32_t ParkSize;
money64 ParkValue;
money64 ParkValueHistory[FINANCE_GRAPH_SIZE];
ClimateType Climate;
ClimateState ClimateCurrent;
ClimateState ClimateNext;

View File

@@ -155,7 +155,7 @@ GameActions::Result RideDemolishAction::DemolishRide(Ride& ride) const
}
ride.Delete();
gParkValue = GetContext()->GetGameState()->GetPark().CalculateParkValue();
GetGameState().ParkValue = GetContext()->GetGameState()->GetPark().CalculateParkValue();
// Close windows related to the demolished ride
WindowCloseByNumber(WindowClass::RideConstruction, rideId.ToUnderlying());

View File

@@ -561,7 +561,7 @@ static int32_t ConsoleCommandGet(InteractiveConsole& console, const arguments_t&
}
else if (argv[0] == "park_value")
{
console.WriteFormatLine("park_value %d", gParkValue / 10);
console.WriteFormatLine("park_value %d", gameState.ParkValue / 10);
}
else if (argv[0] == "company_value")
{

View File

@@ -46,7 +46,6 @@ money64 gCurrentExpenditure;
money64 gCurrentProfit;
money64 gHistoricalProfit;
money64 gCashHistory[FINANCE_GRAPH_SIZE];
money64 gParkValueHistory[FINANCE_GRAPH_SIZE];
money64 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][static_cast<int32_t>(ExpenditureType::Count)];
/**
@@ -195,7 +194,7 @@ void FinanceResetHistory()
{
gCashHistory[i] = MONEY64_UNDEFINED;
gameState.WeeklyProfitHistory[i] = MONEY64_UNDEFINED;
gParkValueHistory[i] = MONEY64_UNDEFINED;
gameState.ParkValueHistory[i] = MONEY64_UNDEFINED;
}
for (uint32_t i = 0; i < EXPENDITURE_TABLE_MONTH_COUNT; ++i)
@@ -236,7 +235,7 @@ void FinanceInit()
gHistoricalProfit = 0;
gBankLoanInterestRate = 10;
gParkValue = 0;
gameState.ParkValue = 0;
gCompanyValue = 0;
gameState.ScenarioCompletedCompanyValue = MONEY64_UNDEFINED;
gTotalAdmissions = 0;

View File

@@ -51,7 +51,6 @@ extern money64 gCurrentProfit;
extern money64 gHistoricalProfit;
extern money64 gCashHistory[FINANCE_GRAPH_SIZE];
extern money64 gParkValueHistory[FINANCE_GRAPH_SIZE];
extern money64 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][static_cast<int32_t>(ExpenditureType::Count)];
bool FinanceCheckMoneyRequired(uint32_t flags);

View File

@@ -301,14 +301,14 @@ private:
{ "players", numPlayers },
};
auto& date = GetDate();
const auto& gameState = GetGameState();
const auto& date = GetDate();
json_t mapSize = { { "x", gMapSize.x - 2 }, { "y", gMapSize.y - 2 } };
json_t gameInfo = {
{ "mapSize", mapSize }, { "day", date.GetMonthTicks() }, { "month", date.GetMonthsElapsed() },
{ "guests", gNumGuestsInPark }, { "parkValue", gParkValue },
{ "mapSize", mapSize }, { "day", date.GetMonthTicks() }, { "month", date.GetMonthsElapsed() },
{ "guests", gNumGuestsInPark }, { "parkValue", gameState.ParkValue },
};
auto& gameState = GetGameState();
if (!(gameState.ParkFlags & PARK_FLAGS_NO_MONEY))
{
gameInfo["cash"] = gameState.Cash;

View File

@@ -884,7 +884,7 @@ namespace OpenRCT2
cs.ReadWrite(award.Type);
});
}
cs.ReadWrite(gParkValue);
cs.ReadWrite(gameState.ParkValue);
cs.ReadWrite(gCompanyValue);
cs.ReadWrite(gameState.ParkSize);
cs.ReadWrite(gNumGuestsInPark);
@@ -935,7 +935,7 @@ namespace OpenRCT2
cs.ReadWrite(value);
return true;
});
cs.ReadWriteArray(gParkValueHistory, [&cs](money64& value) {
cs.ReadWriteArray(gameState.ParkValueHistory, [&cs](money64& value) {
cs.ReadWrite(value);
return true;
});

View File

@@ -1404,13 +1404,13 @@ namespace RCT1
gameState.InitialCash = ToMoney64(_s4.Cash);
gCompanyValue = ToMoney64(_s4.CompanyValue);
gParkValue = CorrectRCT1ParkValue(_s4.ParkValue);
gameState.ParkValue = CorrectRCT1ParkValue(_s4.ParkValue);
gCurrentProfit = ToMoney64(_s4.Profit);
for (size_t i = 0; i < Limits::FinanceGraphSize; i++)
{
gCashHistory[i] = ToMoney64(_s4.CashHistory[i]);
gParkValueHistory[i] = CorrectRCT1ParkValue(_s4.ParkValueHistory[i]);
gameState.ParkValueHistory[i] = CorrectRCT1ParkValue(_s4.ParkValueHistory[i]);
gameState.WeeklyProfitHistory[i] = ToMoney64(_s4.WeeklyProfitHistory[i]);
}

View File

@@ -360,13 +360,13 @@ namespace RCT2
gameState.WeeklyProfitAverageDivisor = _s6.WeeklyProfitAverageDivisor;
// Pad0135833A
gParkValue = ToMoney64(_s6.ParkValue);
gameState.ParkValue = ToMoney64(_s6.ParkValue);
for (size_t i = 0; i < Limits::FinanceGraphSize; i++)
{
gCashHistory[i] = ToMoney64(_s6.BalanceHistory[i]);
gameState.WeeklyProfitHistory[i] = ToMoney64(_s6.WeeklyProfitHistory[i]);
gParkValueHistory[i] = ToMoney64(_s6.ParkValueHistory[i]);
gameState.ParkValueHistory[i] = ToMoney64(_s6.ParkValueHistory[i]);
}
gameState.ScenarioCompletedCompanyValue = RCT12CompletedCompanyValueToOpenRCT2(_s6.CompletedCompanyValue);

View File

@@ -105,7 +105,7 @@ void ScenarioReset(GameState_t& gameState)
auto& park = GetContext()->GetGameState()->GetPark();
gameState.ParkRating = park.CalculateParkRating();
gParkValue = park.CalculateParkValue();
gameState.ParkValue = park.CalculateParkValue();
gCompanyValue = park.CalculateCompanyValue();
gHistoricalProfit = gameState.InitialCash - gBankLoan;
gameState.Cash = gameState.InitialCash;
@@ -635,7 +635,7 @@ ObjectiveStatus Objective::CheckParkValueBy() const
{
int32_t currentMonthYear = GetDate().GetMonthsElapsed();
money64 objectiveParkValue = Currency;
money64 parkValue = gParkValue;
money64 parkValue = GetGameState().ParkValue;
if (currentMonthYear == MONTH_COUNT * Year || AllowEarlyCompletion())
{
@@ -819,7 +819,8 @@ ObjectiveStatus Objective::CheckFinish5RollerCoasters() const
ObjectiveStatus Objective::CheckRepayLoanAndParkValue() const
{
money64 parkValue = gParkValue;
const auto& gameState = GetGameState();
money64 parkValue = gameState.ParkValue;
money64 currentLoan = gBankLoan;
if (currentLoan <= 0 && parkValue >= Currency)

View File

@@ -169,15 +169,16 @@ namespace OpenRCT2::Scripting
money64 ScPark::value_get() const
{
return gParkValue;
return GetGameState().ParkValue;
}
void ScPark::value_set(money64 value)
{
ThrowIfGameStateNotMutable();
if (gParkValue != value)
auto& gameState = GetGameState();
if (gameState.ParkValue != value)
{
gParkValue = value;
gameState.ParkValue = value;
auto intent = Intent(INTENT_ACTION_UPDATE_CASH);
ContextBroadcastIntent(&intent);
}

View File

@@ -43,6 +43,7 @@
#include <algorithm>
#include <limits>
#include <type_traits>
using namespace OpenRCT2;
@@ -52,7 +53,6 @@ money64 gConstructionRightsPrice;
uint64_t gTotalAdmissions;
money64 gTotalIncomeFromAdmissions;
money64 gParkValue;
money64 gCompanyValue;
int16_t gParkRatingCasualtyPenalty;
@@ -241,7 +241,7 @@ uint16_t Park::GetParkRating() const
money64 Park::GetParkValue() const
{
return gParkValue;
return GetGameState().ParkValue;
}
money64 Park::GetCompanyValue() const
@@ -321,7 +321,7 @@ void Park::Update(const Date& date)
if (currentTicks % 512 == 0)
{
gameState.ParkRating = CalculateParkRating();
gParkValue = CalculateParkValue();
gameState.ParkValue = CalculateParkValue();
gCompanyValue = CalculateCompanyValue();
gTotalRideValueForMoney = CalculateTotalRideValueForMoney();
_suggestedGuestMaximum = CalculateSuggestedMaxGuests();
@@ -512,7 +512,7 @@ money64 Park::CalculateRideValue(const Ride& ride) const
money64 Park::CalculateCompanyValue() const
{
auto result = gParkValue - gBankLoan;
auto result = GetGameState().ParkValue - gBankLoan;
// Clamp addition to prevent overflow
result = AddClamp_money64(result, FinanceGetCurrentCash());
@@ -773,12 +773,14 @@ void Park::UpdateHistories()
{
currentWeeklyProfit /= gameState.WeeklyProfitAverageDivisor;
}
HistoryPushRecord<money64, FINANCE_GRAPH_SIZE>(gameState.WeeklyProfitHistory, currentWeeklyProfit);
constexpr auto profitHistorySize = std::extent_v<decltype(GameState_t::WeeklyProfitHistory)>;
HistoryPushRecord<money64, profitHistorySize>(gameState.WeeklyProfitHistory, currentWeeklyProfit);
gameState.WeeklyProfitAverageDividend = 0;
gameState.WeeklyProfitAverageDivisor = 0;
// Update park value history
HistoryPushRecord<money64, std::size(gParkValueHistory)>(gParkValueHistory, gParkValue);
constexpr auto parkValueHistorySize = std::extent_v<decltype(GameState_t::WeeklyProfitHistory)>;
HistoryPushRecord<money64, parkValueHistorySize>(gameState.ParkValueHistory, gameState.ParkValue);
// Invalidate relevant windows
auto intent = Intent(INTENT_ACTION_UPDATE_GUEST_COUNT);

View File

@@ -98,7 +98,6 @@ extern money64 gConstructionRightsPrice;
extern uint64_t gTotalAdmissions;
extern money64 gTotalIncomeFromAdmissions;
extern money64 gParkValue;
extern money64 gCompanyValue;
extern int16_t gParkRatingCasualtyPenalty;