mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #20900 from ZehMatt/fix-20748
Calculate guests heading towards park after importing the save file
This commit is contained in:
commit
a19879ac1f
|
@ -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.
|
static void FixGuestsHeadingToParkCount()
|
||||||
// For example recalculate guest count by looking at all the guests instead of trusting the value in the file.
|
|
||||||
void GameFixSaveVars()
|
|
||||||
{
|
{
|
||||||
// Recalculates peep count after loading a save to fix corrupted files
|
uint32_t guestsHeadingToPark = 0;
|
||||||
uint32_t guestCount = 0;
|
|
||||||
|
for (auto* peep : EntityList<Guest>())
|
||||||
{
|
{
|
||||||
for (auto guest : EntityList<Guest>())
|
if (peep->OutsideOfPark && peep->State != PeepState::LeavingPark)
|
||||||
{
|
{
|
||||||
if (!guest->OutsideOfPark)
|
guestsHeadingToPark++;
|
||||||
{
|
|
||||||
guestCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// Peeps to remove have to be cached here, as removing them from within the loop breaks iteration
|
||||||
std::vector<Peep*> peepsToRemove;
|
std::vector<Peep*> peepsToRemove;
|
||||||
|
|
||||||
|
@ -412,9 +437,13 @@ void GameFixSaveVars()
|
||||||
{
|
{
|
||||||
ptr->Remove();
|
ptr->Remove();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FixInvalidSurfaces()
|
||||||
|
{
|
||||||
// Fixes broken saves where a surface element could be null
|
// Fixes broken saves where a surface element could be null
|
||||||
// and broken saves with incorrect invisible map border tiles
|
// and broken saves with incorrect invisible map border tiles
|
||||||
|
|
||||||
for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
|
for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
|
||||||
{
|
{
|
||||||
for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
|
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();
|
ResearchFix();
|
||||||
|
|
||||||
|
|
|
@ -2911,15 +2911,6 @@ namespace RCT1
|
||||||
}
|
}
|
||||||
|
|
||||||
dst->SetItemFlags(src->GetItemFlags());
|
dst->SetItemFlags(src->GetItemFlags());
|
||||||
|
|
||||||
if (dst->OutsideOfPark && dst->State != PeepState::LeavingPark)
|
|
||||||
{
|
|
||||||
IncrementGuestsHeadingForPark();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IncrementGuestsInPark();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> void S4Importer::ImportEntity<Staff>(const RCT12EntityBase& srcBase)
|
template<> void S4Importer::ImportEntity<Staff>(const RCT12EntityBase& srcBase)
|
||||||
|
|
Loading…
Reference in New Issue