From 8a6de886be7a92984f1461068660ed408e0682d0 Mon Sep 17 00:00:00 2001 From: Harry Hopkinson <63599884+Harry-Hopkinson@users.noreply.github.com> Date: Thu, 14 Mar 2024 21:16:33 +0000 Subject: [PATCH] Move awards to GameState_t (#21601) --- src/openrct2-ui/windows/Park.cpp | 6 ++++-- src/openrct2/GameState.h | 3 +++ src/openrct2/management/Award.cpp | 24 +++++++++--------------- src/openrct2/management/Award.h | 2 -- src/openrct2/park/ParkFile.cpp | 7 ++++--- src/openrct2/rct1/S4Importer.cpp | 4 ++-- src/openrct2/rct2/S6Importer.cpp | 4 ++-- src/openrct2/world/Park.cpp | 2 +- 8 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index d69c631a25..28392fbac8 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -1183,7 +1183,9 @@ static constexpr WindowParkAward _parkAwards[] = { auto screenCoords = windowPos + ScreenCoordsXY{ widgets[WIDX_PAGE_BACKGROUND].left + 4, widgets[WIDX_PAGE_BACKGROUND].top + 4 }; - for (const auto& award : GetAwards()) + auto& currentAwards = OpenRCT2::GetGameState().CurrentAwards; + + for (const auto& award : currentAwards) { GfxDrawSprite(dpi, ImageId(_parkAwards[EnumValue(award.Type)].sprite), screenCoords); DrawTextWrapped(dpi, screenCoords + ScreenCoordsXY{ 34, 6 }, 180, _parkAwards[EnumValue(award.Type)].text); @@ -1191,7 +1193,7 @@ static constexpr WindowParkAward _parkAwards[] = { screenCoords.y += 32; } - if (GetAwards().empty()) + if (currentAwards.empty()) DrawTextBasic(dpi, screenCoords + ScreenCoordsXY{ 6, 6 }, STR_NO_RECENT_AWARDS); } #pragma endregion diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index f69913c9a3..ee9a81fb7c 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -14,6 +14,7 @@ #include "Editor.h" #include "Limits.h" #include "interface/ZoomLevel.h" +#include "management/Award.h" #include "management/Finance.h" #include "management/NewsItem.h" #include "ride/Ride.h" @@ -130,6 +131,8 @@ namespace OpenRCT2 ObjectEntryIndex LastEntranceStyle; + std::vector CurrentAwards; + /** * Probability out of 65535, of gaining a new guest per game tick. * new guests per second = 40 * (probability / 65535) diff --git a/src/openrct2/management/Award.cpp b/src/openrct2/management/Award.cpp index 47053fd241..146fe49403 100644 --- a/src/openrct2/management/Award.cpp +++ b/src/openrct2/management/Award.cpp @@ -69,13 +69,6 @@ static constexpr StringId AwardNewsStrings[] = { STR_NEWS_ITEM_BEST_GENTLE_RIDES, }; -static std::vector _currentAwards; - -std::vector& GetAwards() -{ - return _currentAwards; -} - bool AwardIsPositive(AwardType type) { return AwardPositiveMap[EnumValue(type)]; @@ -602,7 +595,7 @@ static bool AwardIsDeserved(AwardType awardType, int32_t activeAwardTypes) void AwardReset() { - _currentAwards.clear(); + GetGameState().CurrentAwards.clear(); } /** @@ -613,17 +606,18 @@ void AwardUpdateAll() { PROFILED_FUNCTION(); + auto& currentAwards = GetGameState().CurrentAwards; // Decrease award times - for (auto& award : _currentAwards) + for (auto& award : currentAwards) { --award.Time; } // Remove any 0 time awards auto res = std::remove_if( - std::begin(_currentAwards), std::end(_currentAwards), [](const Award& award) { return award.Time == 0; }); - if (res != std::end(_currentAwards)) + std::begin(currentAwards), std::end(currentAwards), [](const Award& award) { return award.Time == 0; }); + if (res != std::end(currentAwards)) { - _currentAwards.erase(res, std::end(_currentAwards)); + currentAwards.erase(res, std::end(currentAwards)); WindowInvalidateByClass(WindowClass::ParkInformation); } @@ -632,13 +626,13 @@ void AwardUpdateAll() { // Set active award types as flags int32_t activeAwardTypes = 0; - for (auto& award : _currentAwards) + for (auto& award : currentAwards) { activeAwardTypes |= (1 << EnumValue(award.Type)); } // Check if there was a free award entry - if (_currentAwards.size() < OpenRCT2::Limits::MaxAwards) + if (currentAwards.size() < OpenRCT2::Limits::MaxAwards) { // Get a random award type not already active AwardType awardType; @@ -651,7 +645,7 @@ void AwardUpdateAll() if (AwardIsDeserved(awardType, activeAwardTypes)) { // Add award - _currentAwards.push_back(Award{ 5u, awardType }); + currentAwards.push_back(Award{ 5u, awardType }); if (gConfigNotifications.ParkAward) { News::AddItemToQueue(News::ItemType::Award, AwardNewsStrings[EnumValue(awardType)], 0, {}); diff --git a/src/openrct2/management/Award.h b/src/openrct2/management/Award.h index 0700cb8804..e73e3de6d9 100644 --- a/src/openrct2/management/Award.h +++ b/src/openrct2/management/Award.h @@ -42,8 +42,6 @@ struct Award AwardType Type; }; -std::vector& GetAwards(); - bool AwardIsPositive(AwardType type); void AwardReset(); void AwardUpdateAll(); diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 27e09b9a13..89e7e0c500 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -862,15 +862,16 @@ namespace OpenRCT2 }); // Awards + auto& currentAwards = gameState.CurrentAwards; if (version <= 6) { Award awards[RCT2::Limits::MaxAwards]{}; - cs.ReadWriteArray(awards, [&cs](Award& award) { + cs.ReadWriteArray(awards, [&cs, ¤tAwards](Award& award) { if (award.Time != 0) { cs.ReadWrite(award.Time); cs.ReadWrite(award.Type); - GetAwards().push_back(award); + currentAwards.push_back(award); return true; } @@ -879,7 +880,7 @@ namespace OpenRCT2 } else { - cs.ReadWriteVector(GetAwards(), [&cs](Award& award) { + cs.ReadWriteVector(currentAwards, [&cs](Award& award) { cs.ReadWrite(award.Time); cs.ReadWrite(award.Type); }); diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index ac2758f4f5..be2f25b2f5 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2162,12 +2162,12 @@ namespace RCT1 } // Awards - auto& awards = GetAwards(); + auto& currentAwards = gameState.CurrentAwards; for (auto& src : _s4.Awards) { if (src.Time != 0) { - awards.push_back(Award{ src.Time, static_cast(src.Type) }); + currentAwards.push_back(Award{ src.Time, static_cast(src.Type) }); } } diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 10631bb15a..72a5ce98f1 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -378,12 +378,12 @@ namespace RCT2 std::memcpy(gameState.PeepWarningThrottle, _s6.PeepWarningThrottle, sizeof(_s6.PeepWarningThrottle)); // Awards - auto& awards = GetAwards(); + auto& currentAwards = gameState.CurrentAwards; for (auto& src : _s6.Awards) { if (src.Time != 0) { - awards.push_back(Award{ src.Time, static_cast(src.Type) }); + currentAwards.push_back(Award{ src.Time, static_cast(src.Type) }); } } diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 5ed5f11495..540b8b7705 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -617,7 +617,7 @@ uint32_t Park::CalculateGuestGenerationProbability() const } // Reward or penalties for park awards - for (const auto& award : GetAwards()) + for (const auto& award : GetGameState().CurrentAwards) { // +/- 0.25% of the probability if (AwardIsPositive(award.Type))