1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 19:13:07 +01:00

Move gNumGuestsInPark to GameState_t (#21295)

* Move gNumGuestsInPark to GameState_t

* Replace GetGameState() with gameState
This commit is contained in:
Harry Hopkinson
2024-01-28 22:17:43 +00:00
committed by GitHub
parent 396af1f34c
commit 11ae8247bd
14 changed files with 58 additions and 48 deletions

View File

@@ -125,14 +125,14 @@ private:
Widget widget = window_game_bottom_toolbar_widgets[WIDX_GUESTS];
auto screenCoords = ScreenCoordsXY{ windowPos.x + widget.midX(), windowPos.y + widget.midY() - 6 };
StringId stringId = gNumGuestsInPark == 1 ? _guestCountFormatsSingular[gGuestChangeModifier]
: _guestCountFormats[gGuestChangeModifier];
StringId stringId = gameState.NumGuestsInPark == 1 ? _guestCountFormatsSingular[gGuestChangeModifier]
: _guestCountFormats[gGuestChangeModifier];
colour_t colour
= (gHoverWidget.window_classification == WindowClass::BottomToolbar && gHoverWidget.widget_index == WIDX_GUESTS
? COLOUR_WHITE
: NOT_TRANSLUCENT(colours[0]));
auto ft = Formatter();
ft.Add<uint32_t>(gNumGuestsInPark);
ft.Add<uint32_t>(gameState.NumGuestsInPark);
DrawTextBasic(dpi, screenCoords, stringId, ft, { colour, TextAlignment::CENTRE });
}

View File

@@ -772,7 +772,7 @@ private:
// Current value
auto ft = Formatter();
ft.Add<uint32_t>(gNumGuestsInPark);
ft.Add<uint32_t>(OpenRCT2::GetGameState().NumGuestsInPark);
DrawTextBasic(dpi, screenPos + ScreenCoordsXY{ widget->left + 3, widget->top + 2 }, STR_GUESTS_IN_PARK_LABEL, ft);
// Graph border
@@ -997,7 +997,7 @@ private:
// Draw number of guests in park
ft = Formatter();
ft.Add<uint32_t>(gNumGuestsInPark);
ft.Add<uint32_t>(OpenRCT2::GetGameState().NumGuestsInPark);
DrawTextBasic(dpi, screenCoords, STR_GUESTS_IN_PARK_LABEL, ft);
screenCoords.y += LIST_ROW_HEIGHT;

View File

@@ -319,7 +319,7 @@ namespace Editor
ResetAllEntities();
UpdateConsolidatedPatrolAreas();
gNumGuestsInPark = 0;
gameState.NumGuestsInPark = 0;
gameState.NumGuestsHeadingForPark = 0;
gNumGuestsInParkLastWeek = 0;
gGuestChangeModifier = 0;

View File

@@ -383,12 +383,13 @@ static void FixGuestCount()
}
}
if (gNumGuestsInPark != guestCount)
auto& gameState = GetGameState();
if (gameState.NumGuestsInPark != guestCount)
{
LOG_WARNING("Corrected bad amount of guests in park: %u -> %u", gNumGuestsInPark, guestCount);
LOG_WARNING("Corrected bad amount of guests in park: %u -> %u", gameState.NumGuestsInPark, guestCount);
}
gNumGuestsInPark = guestCount;
gameState.NumGuestsInPark = guestCount;
}
static void FixPeepsWithInvalidRideReference()

View File

@@ -47,6 +47,7 @@ namespace OpenRCT2
uint8_t GuestInitialHunger;
uint8_t GuestInitialThirst;
uint32_t NextGuestNumber;
uint32_t NumGuestsInPark;
uint32_t NumGuestsHeadingForPark;
money64 WeeklyProfitAverageDividend;
uint16_t WeeklyProfitAverageDivisor;

View File

@@ -461,7 +461,6 @@ enum
};
extern uint8_t gGuestChangeModifier;
extern uint32_t gNumGuestsInPark;
extern uint32_t gNumGuestsInParkLastWeek;
void PeepThoughtSetFormatArgs(const PeepThought* thought, Formatter& ft);

View File

@@ -67,7 +67,6 @@ using namespace OpenRCT2;
using namespace OpenRCT2::Audio;
uint8_t gGuestChangeModifier;
uint32_t gNumGuestsInPark;
uint32_t gNumGuestsInParkLastWeek;
uint8_t gPeepWarningThrottle[16];
@@ -1122,10 +1121,12 @@ void PeepProblemWarningsUpdate()
break;
}
}
auto& gameState = GetGameState();
// could maybe be packed into a loop, would lose a lot of clarity though
if (warningThrottle[0])
--warningThrottle[0];
else if (hungerCounter >= PEEP_HUNGER_WARNING_THRESHOLD && hungerCounter >= gNumGuestsInPark / 16)
else if (hungerCounter >= PEEP_HUNGER_WARNING_THRESHOLD && hungerCounter >= gameState.NumGuestsInPark / 16)
{
warningThrottle[0] = 4;
if (gConfigNotifications.GuestWarnings)
@@ -1137,7 +1138,7 @@ void PeepProblemWarningsUpdate()
if (warningThrottle[1])
--warningThrottle[1];
else if (thirstCounter >= PEEP_THIRST_WARNING_THRESHOLD && thirstCounter >= gNumGuestsInPark / 16)
else if (thirstCounter >= PEEP_THIRST_WARNING_THRESHOLD && thirstCounter >= gameState.NumGuestsInPark / 16)
{
warningThrottle[1] = 4;
if (gConfigNotifications.GuestWarnings)
@@ -1149,7 +1150,7 @@ void PeepProblemWarningsUpdate()
if (warningThrottle[2])
--warningThrottle[2];
else if (toiletCounter >= PEEP_TOILET_WARNING_THRESHOLD && toiletCounter >= gNumGuestsInPark / 16)
else if (toiletCounter >= PEEP_TOILET_WARNING_THRESHOLD && toiletCounter >= gameState.NumGuestsInPark / 16)
{
warningThrottle[2] = 4;
if (gConfigNotifications.GuestWarnings)
@@ -1161,7 +1162,7 @@ void PeepProblemWarningsUpdate()
if (warningThrottle[3])
--warningThrottle[3];
else if (litterCounter >= PEEP_LITTER_WARNING_THRESHOLD && litterCounter >= gNumGuestsInPark / 32)
else if (litterCounter >= PEEP_LITTER_WARNING_THRESHOLD && litterCounter >= gameState.NumGuestsInPark / 32)
{
warningThrottle[3] = 4;
if (gConfigNotifications.GuestWarnings)
@@ -1173,7 +1174,7 @@ void PeepProblemWarningsUpdate()
if (warningThrottle[4])
--warningThrottle[4];
else if (disgustCounter >= PEEP_DISGUST_WARNING_THRESHOLD && disgustCounter >= gNumGuestsInPark / 32)
else if (disgustCounter >= PEEP_DISGUST_WARNING_THRESHOLD && disgustCounter >= gameState.NumGuestsInPark / 32)
{
warningThrottle[4] = 4;
if (gConfigNotifications.GuestWarnings)
@@ -1185,7 +1186,7 @@ void PeepProblemWarningsUpdate()
if (warningThrottle[5])
--warningThrottle[5];
else if (vandalismCounter >= PEEP_VANDALISM_WARNING_THRESHOLD && vandalismCounter >= gNumGuestsInPark / 32)
else if (vandalismCounter >= PEEP_VANDALISM_WARNING_THRESHOLD && vandalismCounter >= gameState.NumGuestsInPark / 32)
{
warningThrottle[5] = 4;
if (gConfigNotifications.GuestWarnings)
@@ -2633,9 +2634,10 @@ void PeepUpdateNames(bool realNames)
void IncrementGuestsInPark()
{
if (gNumGuestsInPark < UINT32_MAX)
auto& gameState = GetGameState();
if (gameState.NumGuestsInPark < UINT32_MAX)
{
gNumGuestsInPark++;
gameState.NumGuestsInPark++;
}
else
{
@@ -2646,7 +2648,6 @@ void IncrementGuestsInPark()
void IncrementGuestsHeadingForPark()
{
auto& gameState = GetGameState();
if (gameState.NumGuestsHeadingForPark < UINT32_MAX)
{
gameState.NumGuestsHeadingForPark++;
@@ -2659,9 +2660,10 @@ void IncrementGuestsHeadingForPark()
void DecrementGuestsInPark()
{
if (gNumGuestsInPark > 0)
auto& gameState = GetGameState();
if (gameState.NumGuestsInPark > 0)
{
gNumGuestsInPark--;
gameState.NumGuestsInPark--;
}
else
{

View File

@@ -110,7 +110,7 @@ static bool AwardIsDeservedMostUntidy(int32_t activeAwardTypes)
}
}
return (negativeCount > gNumGuestsInPark / 16);
return (negativeCount > GetGameState().NumGuestsInPark / 16);
}
/** More than 1/64 of the total guests must be thinking tidy thoughts and less than 6 guests thinking untidy thoughts. */
@@ -142,7 +142,7 @@ static bool AwardIsDeservedMostTidy(int32_t activeAwardTypes)
}
}
return (negativeCount <= 5 && positiveCount > gNumGuestsInPark / 64);
return (negativeCount <= 5 && positiveCount > GetGameState().NumGuestsInPark / 64);
}
/** At least 6 open roller coasters. */
@@ -223,7 +223,7 @@ static bool AwardIsDeservedMostBeautiful(int32_t activeAwardTypes)
}
}
return (negativeCount <= 15 && positiveCount > gNumGuestsInPark / 128);
return (negativeCount <= 15 && positiveCount > GetGameState().NumGuestsInPark / 128);
}
/** Entrance fee is more than total ride value. */
@@ -311,7 +311,7 @@ static bool AwardIsDeservedBestFood(int32_t activeAwardTypes)
}
}
if (shops < 7 || uniqueShops < 4 || shops < gNumGuestsInPark / 128)
if (shops < 7 || uniqueShops < 4 || shops < GetGameState().NumGuestsInPark / 128)
return false;
// Count hungry peeps
@@ -356,7 +356,7 @@ static bool AwardIsDeservedWorstFood(int32_t activeAwardTypes)
}
}
if (uniqueShops > 2 || shops > gNumGuestsInPark / 256)
if (uniqueShops > 2 || shops > GetGameState().NumGuestsInPark / 256)
return false;
// Count hungry peeps
@@ -388,7 +388,7 @@ static bool AwardIsDeservedBestToilets([[maybe_unused]] int32_t activeAwardTypes
return false;
// At least one open toilet for every 128 guests
if (numToilets < gNumGuestsInPark / 128u)
if (numToilets < GetGameState().NumGuestsInPark / 128u)
return false;
// Count number of guests who are thinking they need the toilet

View File

@@ -305,8 +305,11 @@ private:
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", gameState.ParkValue },
{ "mapSize", mapSize },
{ "day", date.GetMonthTicks() },
{ "month", date.GetMonthsElapsed() },
{ "guests", gameState.NumGuestsInPark },
{ "parkValue", gameState.ParkValue },
};
if (!(gameState.ParkFlags & PARK_FLAGS_NO_MONEY))

View File

@@ -887,7 +887,7 @@ namespace OpenRCT2
cs.ReadWrite(gameState.ParkValue);
cs.ReadWrite(gCompanyValue);
cs.ReadWrite(gameState.ParkSize);
cs.ReadWrite(gNumGuestsInPark);
cs.ReadWrite(gameState.NumGuestsInPark);
cs.ReadWrite(gameState.NumGuestsHeadingForPark);
cs.ReadWrite(gameState.ParkRating);
cs.ReadWrite(gParkRatingCasualtyPenalty);

View File

@@ -288,7 +288,7 @@ namespace RCT2
// _s6.ResearchedTrackTypesA
// _s6.ResearchedTrackTypesB
gNumGuestsInPark = _s6.GuestsInPark;
gameState.NumGuestsInPark = _s6.GuestsInPark;
gameState.NumGuestsHeadingForPark = _s6.GuestsHeadingForPark;
for (size_t i = 0; i < Limits::ExpenditureTableMonthCount; i++)

View File

@@ -615,7 +615,7 @@ ObjectiveStatus Objective::CheckGuestsBy() const
if (currentMonthYear == MONTH_COUNT * Year || AllowEarlyCompletion())
{
if (parkRating >= 600 && gNumGuestsInPark >= NumGuests)
if (parkRating >= 600 && GetGameState().NumGuestsInPark >= NumGuests)
{
return ObjectiveStatus::Success;
}
@@ -735,7 +735,7 @@ ObjectiveStatus Objective::CheckGuestsAndRating() const
}
if (gameState.ParkRating >= 700)
if (gNumGuestsInPark >= NumGuests)
if (gameState.NumGuestsInPark >= NumGuests)
return ObjectiveStatus::Success;
return ObjectiveStatus::Undecided;

View File

@@ -134,7 +134,7 @@ namespace OpenRCT2::Scripting
uint32_t ScPark::guests_get() const
{
return gNumGuestsInPark;
return GetGameState().NumGuestsInPark;
}
uint32_t ScPark::suggestedGuestMaximum_get() const

View File

@@ -258,7 +258,7 @@ void Park::Initialise()
gameState.StaffHandymanColour = COLOUR_BRIGHT_RED;
gameState.StaffMechanicColour = COLOUR_LIGHT_BLUE;
gameState.StaffSecurityColour = COLOUR_YELLOW;
gNumGuestsInPark = 0;
gameState.NumGuestsInPark = 0;
gNumGuestsInParkLastWeek = 0;
gameState.NumGuestsHeadingForPark = 0;
gGuestChangeModifier = 0;
@@ -375,8 +375,9 @@ int32_t Park::CalculateParkRating() const
return _forcedParkRating;
}
auto& gameState = GetGameState();
int32_t result = 1150;
if (GetGameState().ParkFlags & PARK_FLAGS_DIFFICULT_PARK_RATING)
if (gameState.ParkFlags & PARK_FLAGS_DIFFICULT_PARK_RATING)
{
result = 1050;
}
@@ -384,7 +385,7 @@ int32_t Park::CalculateParkRating() const
// Guests
{
// -150 to +3 based on a range of guests from 0 to 2000
result -= 150 - (std::min<int32_t>(2000, gNumGuestsInPark) / 13);
result -= 150 - (std::min<int32_t>(2000, gameState.NumGuestsInPark) / 13);
// Find the number of happy peeps and the number of peeps who can't find the park exit
uint32_t happyGuestCount = 0;
@@ -406,9 +407,9 @@ int32_t Park::CalculateParkRating() const
// Peep happiness -500 to +0
result -= 500;
if (gNumGuestsInPark > 0)
if (gameState.NumGuestsInPark > 0)
{
result += 2 * std::min(250u, (happyGuestCount * 300) / gNumGuestsInPark);
result += 2 * std::min(250u, (happyGuestCount * 300) / gameState.NumGuestsInPark);
}
// Up to 25 guests can be lost without affecting the park rating.
@@ -494,7 +495,7 @@ money64 Park::CalculateParkValue() const
}
// +7.00 per guest
result += static_cast<money64>(gNumGuestsInPark) * 7.00_GBP;
result += static_cast<money64>(GetGameState().NumGuestsInPark) * 7.00_GBP;
return result;
}
@@ -606,7 +607,7 @@ uint32_t Park::CalculateGuestGenerationProbability() const
uint32_t probability = 50 + std::clamp(gameState.ParkRating - 200, 0, 650);
// The more guests, the lower the chance of a new one
uint32_t numGuests = gNumGuestsInPark + gameState.NumGuestsHeadingForPark;
uint32_t numGuests = gameState.NumGuestsInPark + gameState.NumGuestsHeadingForPark;
if (numGuests > _suggestedGuestMaximum)
{
probability /= 4;
@@ -676,11 +677,13 @@ uint8_t Park::CalculateGuestInitialHappiness(uint8_t percentage)
void Park::GenerateGuests()
{
auto& gameState = GetGameState();
// Generate a new guest for some probability
if (static_cast<int32_t>(ScenarioRand() & 0xFFFF) < _guestGenerationProbability)
{
bool difficultGeneration = (GetGameState().ParkFlags & PARK_FLAGS_DIFFICULT_GUEST_GENERATION) != 0;
if (!difficultGeneration || _suggestedGuestMaximum + 150 >= gNumGuestsInPark)
bool difficultGeneration = (gameState.ParkFlags & PARK_FLAGS_DIFFICULT_GUEST_GENERATION) != 0;
if (!difficultGeneration || _suggestedGuestMaximum + 150 >= gameState.NumGuestsInPark)
{
GenerateGuest();
}
@@ -748,8 +751,10 @@ void Park::ResetHistories()
void Park::UpdateHistories()
{
auto& gameState = GetGameState();
uint8_t guestChangeModifier = 1;
int32_t changeInGuestsInPark = static_cast<int32_t>(gNumGuestsInPark) - static_cast<int32_t>(gNumGuestsInParkLastWeek);
int32_t changeInGuestsInPark = static_cast<int32_t>(gameState.NumGuestsInPark)
- static_cast<int32_t>(gNumGuestsInParkLastWeek);
if (changeInGuestsInPark > -20)
{
guestChangeModifier++;
@@ -759,12 +764,11 @@ void Park::UpdateHistories()
}
}
gGuestChangeModifier = guestChangeModifier;
gNumGuestsInParkLastWeek = gNumGuestsInPark;
gNumGuestsInParkLastWeek = gameState.NumGuestsInPark;
// Update park rating, guests in park and current cash history
auto& gameState = GetGameState();
HistoryPushRecord<uint8_t, 32>(gParkRatingHistory, gameState.ParkRating / 4);
HistoryPushRecord<uint32_t, 32>(gGuestsInParkHistory, gNumGuestsInPark);
HistoryPushRecord<uint32_t, 32>(gGuestsInParkHistory, gameState.NumGuestsInPark);
HistoryPushRecord<money64, std::size(gCashHistory)>(gCashHistory, FinanceGetCurrentCash() - gBankLoan);
// Update weekly profit history