diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 0defe78448..bed3ce61b7 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -345,24 +345,49 @@ void RCT2StringToUTF8Self(char* buffer, size_t length) } } -// OpenRCT2 workaround to recalculate some values which are saved redundantly in the save to fix corrupted files. -// For example recalculate guest count by looking at all the guests instead of trusting the value in the file. -void GameFixSaveVars() +static void FixGuestsHeadingToParkCount() { - // Recalculates peep count after loading a save to fix corrupted files - uint32_t guestCount = 0; + uint32_t guestsHeadingToPark = 0; + + for (auto* peep : EntityList()) { - for (auto guest : EntityList()) + if (peep->OutsideOfPark && peep->State != PeepState::LeavingPark) { - if (!guest->OutsideOfPark) - { - guestCount++; - } + guestsHeadingToPark++; } } - gNumGuestsInPark = guestCount; + if (gNumGuestsHeadingForPark != guestsHeadingToPark) + { + LOG_WARNING("Corrected bad amount of guests heading to park: %u -> %u", gNumGuestsHeadingForPark, guestsHeadingToPark); + } + gNumGuestsHeadingForPark = guestsHeadingToPark; +} + +static void FixGuestCount() +{ + // Recalculates peep count after loading a save to fix corrupted files + uint32_t guestCount = 0; + + for (auto guest : EntityList()) + { + if (!guest->OutsideOfPark) + { + guestCount++; + } + } + + if (gNumGuestsInPark != guestCount) + { + LOG_WARNING("Corrected bad amount of guests in park: %u -> %u", gNumGuestsInPark, guestCount); + } + + gNumGuestsInPark = guestCount; +} + +static void FixPeepsWithInvalidRideReference() +{ // Peeps to remove have to be cached here, as removing them from within the loop breaks iteration std::vector peepsToRemove; @@ -412,9 +437,13 @@ void GameFixSaveVars() { ptr->Remove(); } +} +static void FixInvalidSurfaces() +{ // Fixes broken saves where a surface element could be null // and broken saves with incorrect invisible map border tiles + for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) { for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) @@ -443,6 +472,19 @@ void GameFixSaveVars() } } } +} + +// OpenRCT2 workaround to recalculate some values which are saved redundantly in the save to fix corrupted files. +// For example recalculate guest count by looking at all the guests instead of trusting the value in the file. +void GameFixSaveVars() +{ + FixGuestsHeadingToParkCount(); + + FixGuestCount(); + + FixPeepsWithInvalidRideReference(); + + FixInvalidSurfaces(); ResearchFix(); diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index d17d7bf052..d8c0ada15d 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2911,15 +2911,6 @@ namespace RCT1 } dst->SetItemFlags(src->GetItemFlags()); - - if (dst->OutsideOfPark && dst->State != PeepState::LeavingPark) - { - IncrementGuestsHeadingForPark(); - } - else - { - IncrementGuestsInPark(); - } } template<> void S4Importer::ImportEntity(const RCT12EntityBase& srcBase)