From f0ee6de5fc2e386ad306e81fe8024af907be273c Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 25 Apr 2021 16:23:59 +0100 Subject: [PATCH] Use real values for gGuestsInParkHistory --- src/openrct2-ui/windows/Park.cpp | 15 ++++++++++++++- src/openrct2/ParkFile.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 8 ++++++-- src/openrct2/rct2/S6Importer.cpp | 10 +++++++++- src/openrct2/world/Park.cpp | 11 ++++------- src/openrct2/world/Park.h | 2 +- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index d239568d59..0dd955388c 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -1062,7 +1062,20 @@ static void window_park_guests_paint(rct_window* w, rct_drawpixelinfo* dpi) // Graph screenPos = w->windowPos + ScreenCoordsXY{ widget->left + 47, widget->top + 26 }; - Graph::Draw(dpi, gGuestsInParkHistory, 32, screenPos); + uint8_t cappedHistory[32]; + for (size_t i = 0; i < std::size(cappedHistory); i++) + { + auto value = gGuestsInParkHistory[i]; + if (value != std::numeric_limits::max()) + { + cappedHistory[i] = static_cast(std::min(value, 5000) / 20); + } + else + { + cappedHistory[i] = std::numeric_limits::max(); + } + } + Graph::Draw(dpi, cappedHistory, static_cast(std::size(cappedHistory)), screenPos); } #pragma endregion diff --git a/src/openrct2/ParkFile.cpp b/src/openrct2/ParkFile.cpp index dbd6eb8133..b6200b53b8 100644 --- a/src/openrct2/ParkFile.cpp +++ b/src/openrct2/ParkFile.cpp @@ -647,7 +647,7 @@ namespace OpenRCT2 return true; }); - cs.ReadWriteArray(gGuestsInParkHistory, [&cs](uint8_t& value) { + cs.ReadWriteArray(gGuestsInParkHistory, [&cs](uint32_t& value) { cs.ReadWrite(value); return true; }); diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 575b4eb101..cb4e60e516 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2076,9 +2076,13 @@ private: } // Number of guests history - for (size_t i = 0; i < 32; i++) + std::fill(std::begin(gGuestsInParkHistory), std::end(gGuestsInParkHistory), std::numeric_limits::max()); + for (size_t i = 0; i < std::size(_s4.guests_in_park_history); i++) { - gGuestsInParkHistory[i] = _s4.guests_in_park_history[i]; + if (_s4.guests_in_park_history[i] != std::numeric_limits::max()) + { + gGuestsInParkHistory[i] = _s4.guests_in_park_history[i] * 20; + } } // News items diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index bb832ff9ce..1e858e1210 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -264,7 +264,15 @@ public: gParkRating = _s6.park_rating; std::memcpy(gParkRatingHistory, _s6.park_rating_history, sizeof(_s6.park_rating_history)); - std::memcpy(gGuestsInParkHistory, _s6.guests_in_park_history, sizeof(_s6.guests_in_park_history)); + + std::fill(std::begin(gGuestsInParkHistory), std::end(gGuestsInParkHistory), std::numeric_limits::max()); + for (size_t i = 0; i < std::size(_s6.guests_in_park_history); i++) + { + if (_s6.guests_in_park_history[i] != std::numeric_limits::max()) + { + gGuestsInParkHistory[i] = _s6.guests_in_park_history[i] * 20; + } + } gResearchPriorities = _s6.active_research_types; gResearchProgressStage = _s6.research_progress_stage; diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 1291e9d7bb..cd054402af 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -61,7 +61,7 @@ money64 gCompanyValue; int16_t gParkRatingCasualtyPenalty; uint8_t gParkRatingHistory[32]; -uint8_t gGuestsInParkHistory[32]; +uint32_t gGuestsInParkHistory[32]; // If this value is more than or equal to 0, the park rating is forced to this value. Used for cheat static int32_t _forcedParkRating = -1; @@ -743,11 +743,8 @@ template static void HistoryPushRecord(T history[TSize void Park::ResetHistories() { - for (size_t i = 0; i < 32; i++) - { - gParkRatingHistory[i] = 255; - gGuestsInParkHistory[i] = 255; - } + std::fill(std::begin(gParkRatingHistory), std::end(gParkRatingHistory), std::numeric_limits::max()); + std::fill(std::begin(gGuestsInParkHistory), std::end(gGuestsInParkHistory), std::numeric_limits::max()); } void Park::UpdateHistories() @@ -767,7 +764,7 @@ void Park::UpdateHistories() // Update park rating, guests in park and current cash history HistoryPushRecord(gParkRatingHistory, CalculateParkRating() / 4); - HistoryPushRecord(gGuestsInParkHistory, std::min(gNumGuestsInPark, 5000) / 20); + HistoryPushRecord(gGuestsInParkHistory, gNumGuestsInPark); HistoryPushRecord(gCashHistory, finance_get_current_cash() - gBankLoan); // Update weekly profit history diff --git a/src/openrct2/world/Park.h b/src/openrct2/world/Park.h index b4ec887bbf..1b559009cf 100644 --- a/src/openrct2/world/Park.h +++ b/src/openrct2/world/Park.h @@ -102,7 +102,7 @@ extern money64 gCompanyValue; extern int16_t gParkRatingCasualtyPenalty; extern uint8_t gParkRatingHistory[32]; -extern uint8_t gGuestsInParkHistory[32]; +extern uint32_t gGuestsInParkHistory[32]; extern int32_t _guestGenerationProbability; extern uint32_t _suggestedGuestMaximum;