1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Add "bannedTerrains", "bannedMonsters" options for templates.

This commit is contained in:
Tomasz Zieliński 2023-07-06 17:30:23 +02:00
parent 06449ce7b0
commit a592f5604b
2 changed files with 33 additions and 6 deletions

View File

@ -65,6 +65,7 @@ void CTreasureInfo::serializeJson(JsonSerializeFormat & handler)
namespace rmg
{
//FIXME: This is never used, instead TerrainID is used
class TerrainEncoder
{
public:
@ -184,9 +185,16 @@ std::optional<int> ZoneOptions::getOwner() const
return owner;
}
const std::set<TerrainId> & ZoneOptions::getTerrainTypes() const
const std::set<TerrainId> ZoneOptions::getTerrainTypes() const
{
return terrainTypes;
if (terrainTypes.empty())
{
return vstd::difference(getDefaultTerrainTypes(), bannedTerrains);
}
else
{
return terrainTypes;
}
}
void ZoneOptions::setTerrainTypes(const std::set<TerrainId> & value)
@ -194,6 +202,19 @@ void ZoneOptions::setTerrainTypes(const std::set<TerrainId> & value)
terrainTypes = value;
}
std::set<TerrainId> ZoneOptions::getDefaultTerrainTypes() const
{
std::set<TerrainId> terrains;
for (auto terrain : VLC->terrainTypeHandler->objects)
{
if (terrain->isLand() && terrain->isPassable())
{
terrains.insert(terrain->getId());
}
}
return terrains;
}
std::set<FactionID> ZoneOptions::getDefaultTownTypes() const
{
std::set<FactionID> defaultTowns;
@ -228,9 +249,9 @@ void ZoneOptions::setMonsterTypes(const std::set<FactionID> & value)
monsterTypes = value;
}
const std::set<FactionID> & ZoneOptions::getMonsterTypes() const
const std::set<FactionID> ZoneOptions::getMonsterTypes() const
{
return monsterTypes;
return vstd::difference(monsterTypes, bannedMonsters);
}
void ZoneOptions::setMinesInfo(const std::map<TResource, ui16> & value)
@ -354,10 +375,12 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
if(terrainTypeLikeZone == NO_ZONE)
{
handler.serializeIdArray<TerrainId, TerrainID>("terrainTypes", terrainTypes, std::set<TerrainId>());
handler.serializeIdArray<TerrainId, TerrainID>("bannedTerrains", bannedTerrains, std::set<TerrainId>());
}
handler.serializeBool("townsAreSameType", townsAreSameType, false);
handler.serializeIdArray<FactionID>("allowedMonsters", monsterTypes, std::set<FactionID>());
handler.serializeIdArray<FactionID>("bannedMonsters", bannedMonsters, std::set<FactionID>());
handler.serializeIdArray<FactionID>("allowedTowns", townTypes, std::set<FactionID>());
handler.serializeIdArray<FactionID>("bannedTowns", bannedTownTypes, std::set<FactionID>());
@ -727,6 +750,7 @@ std::set<TerrainId> CRmgTemplate::inheritTerrainType(std::shared_ptr<ZoneOptions
const auto otherZone = zones.at(zone->getTerrainTypeLikeZone());
zone->setTerrainTypes(inheritTerrainType(otherZone, iteration));
}
//This implicitely excludes banned terrains
return zone->getTerrainTypes();
}

View File

@ -139,14 +139,15 @@ public:
void setSize(int value);
std::optional<int> getOwner() const;
const std::set<TerrainId> & getTerrainTypes() const;
const std::set<TerrainId> getTerrainTypes() const;
void setTerrainTypes(const std::set<TerrainId> & value);
std::set<TerrainId> getDefaultTerrainTypes() const;
const CTownInfo & getPlayerTowns() const;
const CTownInfo & getNeutralTowns() const;
std::set<FactionID> getDefaultTownTypes() const;
const std::set<FactionID> getTownTypes() const;
const std::set<FactionID> & getMonsterTypes() const;
const std::set<FactionID> getMonsterTypes() const;
void setTownTypes(const std::set<FactionID> & value);
void setMonsterTypes(const std::set<FactionID> & value);
@ -185,11 +186,13 @@ protected:
CTownInfo neutralTowns;
bool matchTerrainToTown;
std::set<TerrainId> terrainTypes;
std::set<TerrainId> bannedTerrains;
bool townsAreSameType;
std::set<FactionID> townTypes;
std::set<FactionID> bannedTownTypes;
std::set<FactionID> monsterTypes;
std::set<FactionID> bannedMonsters;
std::map<TResource, ui16> mines; //obligatory mines to spawn in this zone