mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-19 21:10:12 +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();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
for(auto & idAndZone : zones)
|
||||
{
|
||||
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)
|
||||
{
|
||||
const auto otherZone = zones.at(zone->getTerrainTypeLikeZone());
|
||||
zone->setTerrainTypes(otherZone->getTerrainTypes());
|
||||
}
|
||||
|
||||
if(zone->getTreasureLikeZone() != ZoneOptions::NO_ZONE)
|
||||
{
|
||||
const auto otherZone = zones.at(zone->getTreasureLikeZone());
|
||||
zone->setTreasureInfo(otherZone->getTreasureInfo());
|
||||
}
|
||||
//Inherit properties recursively.
|
||||
inheritTerrainType(zone);
|
||||
inheritMineTypes(zone);
|
||||
inheritTreasureInfo(zone);
|
||||
}
|
||||
|
||||
for(const auto & connection : connections)
|
||||
|
@ -238,6 +238,9 @@ private:
|
||||
std::set<EWaterContent::EWaterContent> allowedWaterContent;
|
||||
|
||||
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 serializePlayers(JsonSerializeFormat & handler, CPlayerCountRange & value, const std::string & fieldName);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user