Browse Source

Add save compatibility

Ivan Savenko 1 year ago
parent
commit
e5f1d60298

+ 15 - 4
lib/CPlayerState.h

@@ -115,10 +115,21 @@ public:
 		h & resources;
 		h & status;
 		h & turnTimer;
-		h & ownedObjects;
-		//h & heroes;
-		//h & towns;
-		//h & dwellings;
+
+		if (h.version >= Handler::Version::PLAYER_STATE_OWNED_OBJECTS)
+		{
+			h & ownedObjects;
+		}
+		else
+		{
+			std::vector<const CGObjectInstance* > heroes;
+			std::vector<const CGObjectInstance* > towns;
+			std::vector<const CGObjectInstance* > dwellings;
+
+			h & heroes;
+			h & towns;
+			h & dwellings;
+		}
 		h & quests;
 		h & visitedObjects;
 		h & visitedObjectsGlobal;

+ 9 - 0
lib/gameState/CGameState.cpp

@@ -344,6 +344,15 @@ void CGameState::initCampaign()
 	map = campaign->getCurrentMap().release();
 }
 
+void CGameState::generateOwnedObjectsAfterDeserialize()
+{
+	for (auto & object : map->objects)
+	{
+		if (object->asOwnable() && object->getOwner().isValidPlayer())
+			players.at(object->getOwner()).addOwnedObject(object.get());
+	}
+}
+
 void CGameState::initGlobalBonuses()
 {
 	const JsonNode & baseBonuses = VLC->settings()->getValue(EGameSettings::BONUSES_GLOBAL);

+ 4 - 0
lib/gameState/CGameState.h

@@ -156,6 +156,8 @@ public:
 		h & day;
 		h & map;
 		h & players;
+		if (h.version < Handler::Version::PLAYER_STATE_OWNED_OBJECTS)
+			generateOwnedObjectsAfterDeserialize();
 		h & teams;
 		h & heroesPool;
 		h & globalEffects;
@@ -195,6 +197,8 @@ private:
 	void initVisitingAndGarrisonedHeroes();
 	void initCampaign();
 
+	void generateOwnedObjectsAfterDeserialize();
+
 	// ----- bonus system handling -----
 
 	void buildBonusSystemTree();

+ 2 - 1
lib/serializer/ESerializationVersion.h

@@ -66,6 +66,7 @@ enum class ESerializationVersion : int32_t
 	NEW_TOWN_BUILDINGS, // 855 - old bonusing buildings have been removed
 	STATISTICS_SCREEN, // 856 - extent statistic functions
 	NEW_MARKETS, // 857 - reworked market classes
+	PLAYER_STATE_OWNED_OBJECTS, // 858 - player state stores all owned objects in a single list
 
-	CURRENT = NEW_MARKETS
+	CURRENT = PLAYER_STATE_OWNED_OBJECTS
 };

+ 1 - 1
server/CGameHandler.cpp

@@ -666,7 +666,7 @@ void CGameHandler::onNewTurn()
 			{
 				if (getPlayerStatus(player.first) == EPlayerStatus::INGAME &&
 					getPlayerRelations(player.first, t->tempOwner) == PlayerRelations::ENEMIES)
-					changeFogOfWar(t->getSightCenter(), t->getFirstBonus(Selector::type()(BonusType::DARKNESS))->val, player.first, ETileVisibility::HIDDEN);
+					changeFogOfWar(t->getSightCenter(), t->valOfBonuses(BonusType::DARKNESS), player.first, ETileVisibility::HIDDEN);
 			}
 		}
 	}