mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-21 21:17:49 +02:00
Allow zones to inherit properties recursively, in any order.
This commit is contained in:
parent
23a5a32756
commit
f52c465322
@ -672,28 +672,64 @@ void CRmgTemplate::serializeJson(JsonSerializeFormat & handler)
|
|||||||
afterLoad();
|
afterLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<TerrainId> CRmgTemplate::inheritTerrainType(std::shared_ptr<ZoneOptions> zone, uint32_t iteration /* = 0 */)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
iteration++;
|
||||||
|
const auto otherZone = zones.at(zone->getTreasureLikeZone());
|
||||||
|
zone->setTreasureInfo(inheritTreasureInfo(otherZone, iteration));
|
||||||
|
}
|
||||||
|
return zone->getTreasureInfo();
|
||||||
|
}
|
||||||
|
|
||||||
void CRmgTemplate::afterLoad()
|
void CRmgTemplate::afterLoad()
|
||||||
{
|
{
|
||||||
for(auto & idAndZone : zones)
|
for(auto & idAndZone : zones)
|
||||||
{
|
{
|
||||||
auto zone = idAndZone.second;
|
auto zone = idAndZone.second;
|
||||||
if(zone->getMinesLikeZone() != ZoneOptions::NO_ZONE)
|
|
||||||
{
|
|
||||||
const auto otherZone = zones.at(zone->getMinesLikeZone());
|
|
||||||
zone->setMinesInfo(otherZone->getMinesInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(zone->getTerrainTypeLikeZone() != ZoneOptions::NO_ZONE)
|
//Inherit properties recursively.
|
||||||
{
|
inheritTerrainType(zone);
|
||||||
const auto otherZone = zones.at(zone->getTerrainTypeLikeZone());
|
inheritMineTypes(zone);
|
||||||
zone->setTerrainTypes(otherZone->getTerrainTypes());
|
inheritTreasureInfo(zone);
|
||||||
}
|
|
||||||
|
|
||||||
if(zone->getTreasureLikeZone() != ZoneOptions::NO_ZONE)
|
|
||||||
{
|
|
||||||
const auto otherZone = zones.at(zone->getTreasureLikeZone());
|
|
||||||
zone->setTreasureInfo(otherZone->getTreasureInfo());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const auto & connection : connections)
|
for(const auto & connection : connections)
|
||||||
|
@ -238,6 +238,9 @@ private:
|
|||||||
std::set<EWaterContent::EWaterContent> allowedWaterContent;
|
std::set<EWaterContent::EWaterContent> allowedWaterContent;
|
||||||
|
|
||||||
void afterLoad();
|
void afterLoad();
|
||||||
|
std::set<TerrainId> inheritTerrainType(std::shared_ptr<rmg::ZoneOptions> zone, size_t iteration = 0);
|
||||||
|
std::map<TResource, ui16> inheritMineTypes(std::shared_ptr<rmg::ZoneOptions> zone, size_t iteration = 0);
|
||||||
|
std::vector<CTreasureInfo> inheritTreasureInfo(std::shared_ptr<rmg::ZoneOptions> zone, size_t iteration = 0);
|
||||||
void serializeSize(JsonSerializeFormat & handler, int3 & value, const std::string & fieldName);
|
void serializeSize(JsonSerializeFormat & handler, int3 & value, const std::string & fieldName);
|
||||||
void serializePlayers(JsonSerializeFormat & handler, CPlayerCountRange & value, const std::string & fieldName);
|
void serializePlayers(JsonSerializeFormat & handler, CPlayerCountRange & value, const std::string & fieldName);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user