mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
Remove empty obstacle sets, just in case.
This commit is contained in:
parent
f95f6de46d
commit
e28fd869aa
@ -34,6 +34,19 @@ void ObstacleSet::addObstacle(std::shared_ptr<const ObjectTemplate> obstacle)
|
|||||||
obstacles.push_back(obstacle);
|
obstacles.push_back(obstacle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObstacleSet::removeEmptyTemplates()
|
||||||
|
{
|
||||||
|
vstd::erase_if(obstacles, [](const std::shared_ptr<const ObjectTemplate> &tmpl)
|
||||||
|
{
|
||||||
|
if (tmpl->getBlockedOffsets().empty())
|
||||||
|
{
|
||||||
|
logMod->warn("Obstacle template %s blocks no tiles, removing it", tmpl->stringID);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ObstacleSetFilter::ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes, TerrainId terrain = TerrainId::ANY_TERRAIN, FactionID faction = FactionID::ANY, EAlignment alignment = EAlignment::ANY):
|
ObstacleSetFilter::ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes, TerrainId terrain = TerrainId::ANY_TERRAIN, FactionID faction = FactionID::ANY, EAlignment alignment = EAlignment::ANY):
|
||||||
allowedTypes(allowedTypes),
|
allowedTypes(allowedTypes),
|
||||||
terrain(terrain),
|
terrain(terrain),
|
||||||
@ -272,17 +285,8 @@ void ObstacleSetHandler::loadObject(std::string scope, std::string name, const J
|
|||||||
|
|
||||||
void ObstacleSetHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
void ObstacleSetHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
||||||
{
|
{
|
||||||
auto os = loadFromJson(scope, data, name, index);
|
//Unused
|
||||||
if(os)
|
loadObject(scope, name, data);
|
||||||
{
|
|
||||||
addObstacleSet(os);
|
|
||||||
VLC->identifiersHandler->registerObject(scope, "biome", name, biomes.at(index)->id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logMod->error("Failed to load obstacle set: %s", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<ObstacleSet> ObstacleSetHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index)
|
std::shared_ptr<ObstacleSet> ObstacleSetHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index)
|
||||||
@ -415,10 +419,32 @@ void ObstacleSetHandler::addTemplate(const std::string & scope, const std::strin
|
|||||||
|
|
||||||
void ObstacleSetHandler::addObstacleSet(std::shared_ptr<ObstacleSet> os)
|
void ObstacleSetHandler::addObstacleSet(std::shared_ptr<ObstacleSet> os)
|
||||||
{
|
{
|
||||||
obstacleSets[os->getType()].push_back(os);
|
|
||||||
biomes.push_back(os);
|
biomes.push_back(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObstacleSetHandler::afterLoadFinalization()
|
||||||
|
{
|
||||||
|
for (auto &os :biomes)
|
||||||
|
{
|
||||||
|
os->removeEmptyTemplates();
|
||||||
|
}
|
||||||
|
vstd::erase_if(biomes, [](const std::shared_ptr<ObstacleSet> &os)
|
||||||
|
{
|
||||||
|
if (os->getObstacles().empty())
|
||||||
|
{
|
||||||
|
logMod->warn("Obstacle set %d is empty, removing it", os->id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Populate map
|
||||||
|
for (auto &os : biomes)
|
||||||
|
{
|
||||||
|
obstacleSets[os->getType()].push_back(os);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TObstacleTypes ObstacleSetHandler::getObstacles( const ObstacleSetFilter &filter) const
|
TObstacleTypes ObstacleSetHandler::getObstacles( const ObstacleSetFilter &filter) const
|
||||||
{
|
{
|
||||||
TObstacleTypes result;
|
TObstacleTypes result;
|
||||||
|
@ -41,6 +41,7 @@ public:
|
|||||||
explicit ObstacleSet(EObstacleType type, TerrainId terrain);
|
explicit ObstacleSet(EObstacleType type, TerrainId terrain);
|
||||||
|
|
||||||
void addObstacle(std::shared_ptr<const ObjectTemplate> obstacle);
|
void addObstacle(std::shared_ptr<const ObjectTemplate> obstacle);
|
||||||
|
void removeEmptyTemplates();
|
||||||
std::vector<std::shared_ptr<const ObjectTemplate>> getObstacles() const;
|
std::vector<std::shared_ptr<const ObjectTemplate>> getObstacles() const;
|
||||||
|
|
||||||
EObstacleType getType() const;
|
EObstacleType getType() const;
|
||||||
@ -113,6 +114,8 @@ public:
|
|||||||
void addTemplate(const std::string & scope, const std::string &name, std::shared_ptr<const ObjectTemplate> tmpl);
|
void addTemplate(const std::string & scope, const std::string &name, std::shared_ptr<const ObjectTemplate> tmpl);
|
||||||
|
|
||||||
void addObstacleSet(std::shared_ptr<ObstacleSet> set);
|
void addObstacleSet(std::shared_ptr<ObstacleSet> set);
|
||||||
|
|
||||||
|
void afterLoadFinalization() override;
|
||||||
|
|
||||||
TObstacleTypes getObstacles(const ObstacleSetFilter &filter) const;
|
TObstacleTypes getObstacles(const ObstacleSetFilter &filter) const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user