|
|
@@ -157,7 +157,7 @@ std::optional<int> ZoneOptions::getOwner() const
|
|
|
return owner;
|
|
|
}
|
|
|
|
|
|
-const std::set<TerrainId> ZoneOptions::getTerrainTypes() const
|
|
|
+std::set<TerrainId> ZoneOptions::getTerrainTypes() const
|
|
|
{
|
|
|
if (terrainTypes.empty())
|
|
|
{
|
|
|
@@ -192,7 +192,7 @@ std::set<FactionID> ZoneOptions::getDefaultTownTypes() const
|
|
|
return VLC->townh->getDefaultAllowed();
|
|
|
}
|
|
|
|
|
|
-const std::set<FactionID> ZoneOptions::getTownTypes() const
|
|
|
+std::set<FactionID> ZoneOptions::getTownTypes() const
|
|
|
{
|
|
|
if (townTypes.empty())
|
|
|
{
|
|
|
@@ -215,7 +215,7 @@ void ZoneOptions::setMonsterTypes(const std::set<FactionID> & value)
|
|
|
monsterTypes = value;
|
|
|
}
|
|
|
|
|
|
-const std::set<FactionID> ZoneOptions::getMonsterTypes() const
|
|
|
+std::set<FactionID> ZoneOptions::getMonsterTypes() const
|
|
|
{
|
|
|
return vstd::difference(monsterTypes, bannedMonsters);
|
|
|
}
|
|
|
@@ -251,7 +251,7 @@ void ZoneOptions::addTreasureInfo(const CTreasureInfo & value)
|
|
|
vstd::amax(maxTreasureValue, value.max);
|
|
|
}
|
|
|
|
|
|
-const std::vector<CTreasureInfo> & ZoneOptions::getTreasureInfo() const
|
|
|
+std::vector<CTreasureInfo> ZoneOptions::getTreasureInfo() const
|
|
|
{
|
|
|
return treasureInfo;
|
|
|
}
|
|
|
@@ -273,7 +273,22 @@ TRmgTemplateZoneId ZoneOptions::getTerrainTypeLikeZone() const
|
|
|
|
|
|
TRmgTemplateZoneId ZoneOptions::getTreasureLikeZone() const
|
|
|
{
|
|
|
- return treasureLikeZone;
|
|
|
+ return treasureLikeZone;
|
|
|
+}
|
|
|
+
|
|
|
+ObjectConfig ZoneOptions::getCustomObjects() const
|
|
|
+{
|
|
|
+ return objectConfig;
|
|
|
+}
|
|
|
+
|
|
|
+void ZoneOptions::setCustomObjects(const ObjectConfig & value)
|
|
|
+{
|
|
|
+ objectConfig = value;
|
|
|
+}
|
|
|
+
|
|
|
+TRmgTemplateZoneId ZoneOptions::getCustomObjectsLikeZone() const
|
|
|
+{
|
|
|
+ return customObjectsLikeZone;
|
|
|
}
|
|
|
|
|
|
void ZoneOptions::addConnection(const ZoneConnection & connection)
|
|
|
@@ -335,7 +350,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
|
|
|
SERIALIZE_ZONE_LINK(minesLikeZone);
|
|
|
SERIALIZE_ZONE_LINK(terrainTypeLikeZone);
|
|
|
SERIALIZE_ZONE_LINK(treasureLikeZone);
|
|
|
-
|
|
|
+ SERIALIZE_ZONE_LINK(customObjectsLikeZone);
|
|
|
#undef SERIALIZE_ZONE_LINK
|
|
|
|
|
|
if(terrainTypeLikeZone == NO_ZONE)
|
|
|
@@ -751,53 +766,29 @@ void CRmgTemplate::serializeJson(JsonSerializeFormat & handler)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-std::set<TerrainId> CRmgTemplate::inheritTerrainType(std::shared_ptr<ZoneOptions> zone, uint32_t iteration /* = 0 */)
|
|
|
+template<typename T>
|
|
|
+T CRmgTemplate::inheritZoneProperty(std::shared_ptr<rmg::ZoneOptions> zone,
|
|
|
+ T (rmg::ZoneOptions::*getter)() const,
|
|
|
+ void (rmg::ZoneOptions::*setter)(const T&),
|
|
|
+ TRmgTemplateZoneId (rmg::ZoneOptions::*inheritFrom)() const,
|
|
|
+ const std::string& propertyString,
|
|
|
+ uint32_t iteration)
|
|
|
{
|
|
|
if (iteration >= 50)
|
|
|
{
|
|
|
- logGlobal->error("Infinite recursion for terrain types detected in template %s", name);
|
|
|
- return std::set<TerrainId>();
|
|
|
- }
|
|
|
- if (zone->getTerrainTypeLikeZone() != ZoneOptions::NO_ZONE)
|
|
|
- {
|
|
|
- iteration++;
|
|
|
- const auto otherZone = zones.at(zone->getTerrainTypeLikeZone());
|
|
|
- zone->setTerrainTypes(inheritTerrainType(otherZone, iteration));
|
|
|
+ logGlobal->error("Infinite recursion for %s detected in template %s", propertyString, name);
|
|
|
+ return T();
|
|
|
}
|
|
|
- //This implicitly excludes banned terrains
|
|
|
- return zone->getTerrainTypes();
|
|
|
-}
|
|
|
-
|
|
|
-std::map<TResource, ui16> CRmgTemplate::inheritMineTypes(std::shared_ptr<ZoneOptions> zone, uint32_t iteration /* = 0 */)
|
|
|
-{
|
|
|
- if (iteration >= 50)
|
|
|
- {
|
|
|
- logGlobal->error("Infinite recursion for mine types detected in template %s", name);
|
|
|
- return std::map<TResource, ui16>();
|
|
|
- }
|
|
|
- if (zone->getMinesLikeZone() != ZoneOptions::NO_ZONE)
|
|
|
- {
|
|
|
- iteration++;
|
|
|
- const auto otherZone = zones.at(zone->getMinesLikeZone());
|
|
|
- zone->setMinesInfo(inheritMineTypes(otherZone, iteration));
|
|
|
- }
|
|
|
- return zone->getMinesInfo();
|
|
|
-}
|
|
|
-
|
|
|
-std::vector<CTreasureInfo> CRmgTemplate::inheritTreasureInfo(std::shared_ptr<ZoneOptions> zone, uint32_t iteration /* = 0 */)
|
|
|
-{
|
|
|
- if (iteration >= 50)
|
|
|
- {
|
|
|
- logGlobal->error("Infinite recursion for treasures detected in template %s", name);
|
|
|
- return std::vector<CTreasureInfo>();
|
|
|
- }
|
|
|
- if (zone->getTreasureLikeZone() != ZoneOptions::NO_ZONE)
|
|
|
+
|
|
|
+ if (((*zone).*inheritFrom)() != rmg::ZoneOptions::NO_ZONE)
|
|
|
{
|
|
|
iteration++;
|
|
|
- const auto otherZone = zones.at(zone->getTreasureLikeZone());
|
|
|
- zone->setTreasureInfo(inheritTreasureInfo(otherZone, iteration));
|
|
|
+ const auto otherZone = zones.at(((*zone).*inheritFrom)());
|
|
|
+ T inheritedValue = inheritZoneProperty(otherZone, getter, setter, inheritFrom, propertyString, iteration);
|
|
|
+ ((*zone).*setter)(inheritedValue);
|
|
|
}
|
|
|
- return zone->getTreasureInfo();
|
|
|
+
|
|
|
+ return ((*zone).*getter)();
|
|
|
}
|
|
|
|
|
|
void CRmgTemplate::afterLoad()
|
|
|
@@ -806,12 +797,32 @@ void CRmgTemplate::afterLoad()
|
|
|
{
|
|
|
auto zone = idAndZone.second;
|
|
|
|
|
|
- //Inherit properties recursively.
|
|
|
- inheritTerrainType(zone);
|
|
|
- inheritMineTypes(zone);
|
|
|
- inheritTreasureInfo(zone);
|
|
|
-
|
|
|
- //TODO: Inherit monster types as well
|
|
|
+ // Inherit properties recursively
|
|
|
+ inheritZoneProperty(zone,
|
|
|
+ &rmg::ZoneOptions::getTerrainTypes,
|
|
|
+ &rmg::ZoneOptions::setTerrainTypes,
|
|
|
+ &rmg::ZoneOptions::getTerrainTypeLikeZone,
|
|
|
+ "terrain types");
|
|
|
+
|
|
|
+ inheritZoneProperty(zone,
|
|
|
+ &rmg::ZoneOptions::getMinesInfo,
|
|
|
+ &rmg::ZoneOptions::setMinesInfo,
|
|
|
+ &rmg::ZoneOptions::getMinesLikeZone,
|
|
|
+ "mine types");
|
|
|
+
|
|
|
+ inheritZoneProperty(zone,
|
|
|
+ &rmg::ZoneOptions::getTreasureInfo,
|
|
|
+ &rmg::ZoneOptions::setTreasureInfo,
|
|
|
+ &rmg::ZoneOptions::getTreasureLikeZone,
|
|
|
+ "treasure info");
|
|
|
+
|
|
|
+ inheritZoneProperty(zone,
|
|
|
+ &rmg::ZoneOptions::getCustomObjects,
|
|
|
+ &rmg::ZoneOptions::setCustomObjects,
|
|
|
+ &rmg::ZoneOptions::getCustomObjectsLikeZone,
|
|
|
+ "custom objects");
|
|
|
+
|
|
|
+ //TODO: Inherit monster types as well
|
|
|
auto monsterTypes = zone->getMonsterTypes();
|
|
|
if (monsterTypes.empty())
|
|
|
{
|
|
|
@@ -919,9 +930,9 @@ const std::vector<ObjectConfig::EObjectCategory> & ZoneOptions::getBannedObjectC
|
|
|
return objectConfig.getBannedObjectCategories();
|
|
|
}
|
|
|
|
|
|
-const std::vector<ObjectInfo> & ZoneOptions::getCustomObjects() const
|
|
|
+const std::vector<ObjectInfo> & ZoneOptions::getConfiguredObjects() const
|
|
|
{
|
|
|
- return objectConfig.getCustomObjects();
|
|
|
+ return objectConfig.getConfiguredObjects();
|
|
|
}
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|