Merge pull request #20900 from ZehMatt/fix-20748

Calculate guests heading towards park after importing the save file
This commit is contained in:
Matt 2023-10-24 14:57:44 +03:00 committed by GitHub
commit a19879ac1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 20 deletions

View File

@ -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<Guest>())
{
for (auto guest : EntityList<Guest>())
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<Guest>())
{
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<Peep*> 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();

View File

@ -2911,15 +2911,6 @@ namespace RCT1
}
dst->SetItemFlags(src->GetItemFlags());
if (dst->OutsideOfPark && dst->State != PeepState::LeavingPark)
{
IncrementGuestsHeadingForPark();
}
else
{
IncrementGuestsInPark();
}
}
template<> void S4Importer::ImportEntity<Staff>(const RCT12EntityBase& srcBase)