Browse Source

Allow "notLikeZone" to be vector

Tomasz Zieliński 7 months ago
parent
commit
38a46d4b3f

+ 9 - 1
config/schemas/template.json

@@ -25,7 +25,15 @@
 						"type": "object",
 						"properties": {
 							"likeZone": { "type": "number" },
-							"notLikeZone": { "type": "number" },
+							"notLikeZone": { 
+								"oneOf": [
+									{ "type": "number" },
+									{ 
+										"type": "array",
+										"items": { "type": "number" }
+									}
+								]
+							},
 							"relatedToZoneTerrain": { "type": "number" }
 						}
 					}

+ 17 - 2
lib/rmg/CRmgTemplate.cpp

@@ -109,7 +109,6 @@ void ZoneOptions::CTownInfo::serializeJson(JsonSerializeFormat & handler)
 
 ZoneOptions::CTownHints::CTownHints()
 	: likeZone(NO_ZONE),
-	notLikeZone(NO_ZONE),
 	relatedToZoneTerrain(NO_ZONE)
 {
 
@@ -118,7 +117,23 @@ ZoneOptions::CTownHints::CTownHints()
 void ZoneOptions::CTownHints::serializeJson(JsonSerializeFormat & handler)
 {
 	handler.serializeInt("likeZone", likeZone, NO_ZONE);
-	handler.serializeInt("notLikeZone", notLikeZone, NO_ZONE);
+	auto node = handler.getCurrent();
+	if (node["notLikeZone"].isVector())
+	{
+		// TODO: Utility to serialize vector of ints?
+		auto notLikeZoneData = handler.enterArray("notLikeZone");
+		notLikeZone.resize(notLikeZoneData.size());
+		for (size_t i = 0; i < notLikeZoneData.size(); ++i)
+		{
+			notLikeZoneData.serializeInt(i, notLikeZone[i]);
+		}
+	}
+	else
+	{
+		int temp;
+		handler.serializeInt("notLikeZone", temp, NO_ZONE);
+		notLikeZone.push_back(temp);
+	}
 	handler.serializeInt("relatedToZoneTerrain", relatedToZoneTerrain, NO_ZONE);
 }
 

+ 1 - 1
lib/rmg/CRmgTemplate.h

@@ -154,7 +154,7 @@ public:
 		CTownHints();
 		// TODO: Make private
 		TRmgTemplateZoneId likeZone = NO_ZONE;
-		TRmgTemplateZoneId notLikeZone = NO_ZONE;
+		std::vector<TRmgTemplateZoneId> notLikeZone;
 		TRmgTemplateZoneId relatedToZoneTerrain = NO_ZONE;
 
 		void serializeJson(JsonSerializeFormat & handler);

+ 11 - 5
lib/rmg/modificators/TownPlacer.cpp

@@ -54,10 +54,13 @@ void TownPlacer::init()
 			logGlobal->info("Dependency on town type of zone %d", townHint.likeZone);
 			dependency(map.getZones().at(townHint.likeZone)->getModificator<TownPlacer>());
 		}
-		else if(townHint.notLikeZone != rmg::ZoneOptions::NO_ZONE)
+		else if(!townHint.notLikeZone.empty())
 		{
-			logGlobal->info("Dependency on town unlike type of zone %d", townHint.notLikeZone);
-			dependency(map.getZones().at(townHint.notLikeZone)->getModificator<TownPlacer>());
+			for(auto zoneId : townHint.notLikeZone)
+			{
+				logGlobal->info("Dependency on town unlike type of zone %d", zoneId);
+				dependency(map.getZones().at(zoneId)->getModificator<TownPlacer>());
+			}
 		}
 		else if(townHint.relatedToZoneTerrain != rmg::ZoneOptions::NO_ZONE)
 		{
@@ -218,11 +221,14 @@ FactionID TownPlacer::getTownTypeFromHint(size_t hintIndex)
 		// Copy directly from other zone
 		subType = map.getZones().at(townHints.likeZone)->getTownType();
 	}
-	else if(townHints.notLikeZone != rmg::ZoneOptions::NO_ZONE)
+	else if(!townHints.notLikeZone.empty())
 	{
 		// Exclude type rolled for other zone
 		auto townTypes = zone.getTownTypes();
-		townTypes.erase(map.getZones().at(townHints.notLikeZone)->getTownType());
+		for(auto zoneId : townHints.notLikeZone)
+		{
+			townTypes.erase(map.getZones().at(zoneId)->getTownType());
+		}
 		zone.setTownTypes(townTypes);
 		
 		if(!townTypes.empty())