From 11ae8247bdff15fca53ef85bd1294d6ccd7864bd Mon Sep 17 00:00:00 2001 From: Harry Hopkinson <63599884+Harry-Hopkinson@users.noreply.github.com> Date: Sun, 28 Jan 2024 22:17:43 +0000 Subject: [PATCH] Move gNumGuestsInPark to GameState_t (#21295) * Move gNumGuestsInPark to GameState_t * Replace GetGameState() with gameState --- src/openrct2-ui/windows/GameBottomToolbar.cpp | 6 ++-- src/openrct2-ui/windows/Park.cpp | 4 +-- src/openrct2/Editor.cpp | 2 +- src/openrct2/Game.cpp | 7 +++-- src/openrct2/GameState.h | 1 + src/openrct2/entity/Guest.h | 1 - src/openrct2/entity/Peep.cpp | 26 ++++++++-------- src/openrct2/management/Award.cpp | 12 ++++---- .../network/NetworkServerAdvertiser.cpp | 7 +++-- src/openrct2/park/ParkFile.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/scenario/Scenario.cpp | 4 +-- .../scripting/bindings/world/ScPark.cpp | 2 +- src/openrct2/world/Park.cpp | 30 +++++++++++-------- 14 files changed, 58 insertions(+), 48 deletions(-) diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index 101853dff3..496f775b7a 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -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(gNumGuestsInPark); + ft.Add(gameState.NumGuestsInPark); DrawTextBasic(dpi, screenCoords, stringId, ft, { colour, TextAlignment::CENTRE }); } diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index e2461ad0a0..1656f1c8bb 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -772,7 +772,7 @@ private: // Current value auto ft = Formatter(); - ft.Add(gNumGuestsInPark); + ft.Add(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(gNumGuestsInPark); + ft.Add(OpenRCT2::GetGameState().NumGuestsInPark); DrawTextBasic(dpi, screenCoords, STR_GUESTS_IN_PARK_LABEL, ft); screenCoords.y += LIST_ROW_HEIGHT; diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 6452bf901c..951e767bab 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -319,7 +319,7 @@ namespace Editor ResetAllEntities(); UpdateConsolidatedPatrolAreas(); - gNumGuestsInPark = 0; + gameState.NumGuestsInPark = 0; gameState.NumGuestsHeadingForPark = 0; gNumGuestsInParkLastWeek = 0; gGuestChangeModifier = 0; diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index f646437b6c..526ff90801 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -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() diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 5a1dc30354..61265f57b6 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -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; diff --git a/src/openrct2/entity/Guest.h b/src/openrct2/entity/Guest.h index 6277fe062c..cca88e4c21 100644 --- a/src/openrct2/entity/Guest.h +++ b/src/openrct2/entity/Guest.h @@ -461,7 +461,6 @@ enum }; extern uint8_t gGuestChangeModifier; -extern uint32_t gNumGuestsInPark; extern uint32_t gNumGuestsInParkLastWeek; void PeepThoughtSetFormatArgs(const PeepThought* thought, Formatter& ft); diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 07d13750b4..7b2c805cc4 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -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 { diff --git a/src/openrct2/management/Award.cpp b/src/openrct2/management/Award.cpp index 5cbd50a2ed..cc228fa5bf 100644 --- a/src/openrct2/management/Award.cpp +++ b/src/openrct2/management/Award.cpp @@ -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 diff --git a/src/openrct2/network/NetworkServerAdvertiser.cpp b/src/openrct2/network/NetworkServerAdvertiser.cpp index 6f9e044da0..b1702206cb 100644 --- a/src/openrct2/network/NetworkServerAdvertiser.cpp +++ b/src/openrct2/network/NetworkServerAdvertiser.cpp @@ -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)) diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 80e8fff852..a01450af5b 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -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); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index ac90fefe5c..5ecefa2b71 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -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++) diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index 3efd5cff75..17320fbce1 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -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; diff --git a/src/openrct2/scripting/bindings/world/ScPark.cpp b/src/openrct2/scripting/bindings/world/ScPark.cpp index 6113c90ce0..22a7b5ac36 100644 --- a/src/openrct2/scripting/bindings/world/ScPark.cpp +++ b/src/openrct2/scripting/bindings/world/ScPark.cpp @@ -134,7 +134,7 @@ namespace OpenRCT2::Scripting uint32_t ScPark::guests_get() const { - return gNumGuestsInPark; + return GetGameState().NumGuestsInPark; } uint32_t ScPark::suggestedGuestMaximum_get() const diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index d1831ee0c9..ae4e0b30e8 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -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(2000, gNumGuestsInPark) / 13); + result -= 150 - (std::min(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(gNumGuestsInPark) * 7.00_GBP; + result += static_cast(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(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(gNumGuestsInPark) - static_cast(gNumGuestsInParkLastWeek); + int32_t changeInGuestsInPark = static_cast(gameState.NumGuestsInPark) + - static_cast(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(gParkRatingHistory, gameState.ParkRating / 4); - HistoryPushRecord(gGuestsInParkHistory, gNumGuestsInPark); + HistoryPushRecord(gGuestsInParkHistory, gameState.NumGuestsInPark); HistoryPushRecord(gCashHistory, FinanceGetCurrentCash() - gBankLoan); // Update weekly profit history