mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Allow "notLikeZone" to be vector
This commit is contained in:
@@ -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" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user