From e5a10c15149fc772aae53f62424bd5e1de02856c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:34:00 +0200 Subject: [PATCH] Fix #21274: Collision of PeepId when importing SV4 --- src/openrct2/rct1/S4Importer.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 8740cb3fba..6ec4b734b9 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -177,7 +177,7 @@ namespace RCT1 ImportRides(); ImportRideMeasurements(); - ImportSprites(); + ImportEntities(); ImportTileElements(); ImportPeepSpawns(); ImportFinance(gameState); @@ -190,6 +190,7 @@ namespace RCT1 ImportSavedView(); FixLandOwnership(); FixUrbanPark(); + FixNextGuestNumber(gameState); CountBlockSections(); SetDefaultNames(); DetermineRideEntranceAndExitLocations(); @@ -1199,7 +1200,7 @@ namespace RCT1 void ImportEntity(const RCT12EntityBase& src); template void ImportEntity(const RCT12EntityBase& src); - void ImportSprites() + void ImportEntities() { for (int i = 0; i < Limits::MaxEntities; i++) { @@ -2601,6 +2602,22 @@ namespace RCT1 } } + void FixNextGuestNumber(GameState_t& gameState) + { + // In RCT1, the next guest number is not saved, so we have to calculate it. + // This is done by finding the highest guest number in the park, and adding 1. + uint32_t nextGuestNumber = 0; + + // TODO: Entities are currently read from the global state, change this once entities are stored + // in the passed gameState. + for (auto peep : EntityList()) + { + nextGuestNumber = std::max(nextGuestNumber, peep->PeepId); + } + + gameState.NextGuestNumber = nextGuestNumber + 1; + } + /** * Counts the block sections. The reason this iterates over the map is to avoid getting into infinite loops, * which can happen with hacked parks.