From b817e6509b250e6ba28c36079c4483d6ab232a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zieli=C5=84ski?= Date: Tue, 6 Sep 2022 15:53:32 +0200 Subject: [PATCH] Serialize new field with new save format --- lib/mapping/CMap.cpp | 4 ++-- lib/mapping/CMap.h | 12 ++++++++++-- lib/serializer/CSerializer.h | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index e4c23d054..93c5fab2e 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -234,7 +234,7 @@ CMapHeader::~CMapHeader() CMap::CMap() : checksum(0), grailPos(-1, -1, -1), grailRadius(0), terrain(nullptr), guardingCreaturePositions(nullptr), - uid_counter(0) + uidCounter(0) { allHeroes.resize(allowedHeroes.size()); allowedAbilities = VLC->skillh->getDefaultAllowed(); @@ -608,7 +608,7 @@ void CMap::setUniqueInstanceName(CGObjectInstance* obj) { //this gives object unique name even if objects are removed later - auto uid = uid_counter++; + auto uid = uidCounter++; boost::format fmt("%s_%d"); fmt % obj->typeName % uid; diff --git a/lib/mapping/CMap.h b/lib/mapping/CMap.h index dff87aa20..dd7f8bdfe 100644 --- a/lib/mapping/CMap.h +++ b/lib/mapping/CMap.h @@ -412,7 +412,7 @@ public: private: /// a 3-dimensional array of terrain tiles, access is as follows: x, y, level. where level=1 is underground TerrainTile*** terrain; - si32 uid_counter; //TODO: initialize when loading an old map + si32 uidCounter; //TODO: initialize when loading an old map public: template @@ -490,6 +490,14 @@ public: h & CGTownInstance::universitySkills; h & instanceNames; - h & uid_counter; + + if (!h.saving && formatVersion < 804) + { + uidCounter = objects.size(); + } + else + { + h & uidCounter; + } } }; diff --git a/lib/serializer/CSerializer.h b/lib/serializer/CSerializer.h index e07e48d04..cb1f6af17 100644 --- a/lib/serializer/CSerializer.h +++ b/lib/serializer/CSerializer.h @@ -12,7 +12,7 @@ #include "../ConstTransitivePtr.h" #include "../GameConstants.h" -const ui32 SERIALIZATION_VERSION = 803; +const ui32 SERIALIZATION_VERSION = 804; const ui32 MINIMAL_SERIALIZATION_VERSION = 803; const std::string SAVEGAME_MAGIC = "VCMISVG";