Переглянути джерело

moatHexes: add saves and mods compatability

Arseniy Shestakov 9 роки тому
батько
коміт
8c39ecf538
4 змінених файлів з 26 додано та 5 видалено
  1. 0 1
      config/schemas/faction.json
  2. 13 2
      lib/CTownHandler.cpp
  3. 12 1
      lib/CTownHandler.h
  4. 1 1
      lib/Connection.h

+ 0 - 1
config/schemas/faction.json

@@ -233,7 +233,6 @@
 				"moatHexes": {
 					"type" : "array",
 					"description" : "Numbers of battlefield hexes affected by moat during siege",
-					"minItems" : 1,
 					"items" : { "type" : "number" }
 				},
 				"musicTheme": {

+ 13 - 2
lib/CTownHandler.cpp

@@ -86,6 +86,12 @@ CTown::~CTown()
 		str.dellNull();
 }
 
+std::vector<BattleHex> CTown::defaultMoatHexes()
+{
+	static const BattleHex moatHexes[] = {11, 28, 44, 61, 77, 111, 129, 146, 164, 181};
+	return std::vector<BattleHex>(moatHexes, moatHexes + ARRAY_COUNT(moatHexes));
+}
+
 CTownHandler::CTownHandler()
 {
 	VLC->townh = this;
@@ -543,8 +549,13 @@ void CTownHandler::loadTown(CTown &town, const JsonNode & source)
 
 	town.moatDamage = source["moatDamage"].Float();
 
-	town.moatHexes = source["moatHexes"].convertTo<std::vector<BattleHex> >();
-	
+	// Mods Compatability for pre 0.99
+	if(source["moatHexes"].isNull())
+	{
+		town.moatHexes = CTown::defaultMoatHexes();
+	}
+	else
+		town.moatHexes = source["moatHexes"].convertTo<std::vector<BattleHex> >();
 
 	town.mageLevel = source["mageGuild"].Float();
 	town.names = source["names"].convertTo<std::vector<std::string> >();

+ 12 - 1
lib/CTownHandler.h

@@ -137,6 +137,8 @@ class DLL_LINKAGE CTown
 public:
 	CTown();
 	~CTown();
+	// TODO: remove once save and mod compatability not needed
+	static std::vector<BattleHex> defaultMoatHexes();
 
 	CFaction * faction;
 	
@@ -207,7 +209,16 @@ public:
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
 		h & names & faction & creatures & dwellings & dwellingNames & buildings & hordeLvl & mageLevel
-			& primaryRes & warMachine & clientInfo & moatDamage & moatHexes & defaultTavernChance;
+			& primaryRes & warMachine & clientInfo & moatDamage;
+		if(version >= 758)
+		{
+			h & moatHexes;
+		}
+		else if(!h.saving)
+		{
+			moatHexes = defaultMoatHexes();
+		}
+		h & defaultTavernChance;
 
 		auto findNull = [](const std::pair<BuildingID, ConstTransitivePtr<CBuilding>> &building)
 		{ return building.second == nullptr; };

+ 1 - 1
lib/Connection.h

@@ -27,7 +27,7 @@
 #include "mapping/CCampaignHandler.h" //for CCampaignState
 #include "rmg/CMapGenerator.h" // for CMapGenOptions
 
-const ui32 version = 757;
+const ui32 version = 758;
 const ui32 minSupportedVersion = 753;
 
 class CISer;