1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-25 21:38:59 +02:00
This commit is contained in:
Tomasz Zieliński 2024-04-06 15:06:08 +02:00
parent 305e2bdf2f
commit b0cff23c37
3 changed files with 8 additions and 40 deletions

View File

@ -151,9 +151,6 @@ void ObstacleSetHandler::addObstacleSet(const ObstacleSet &os)
TObstacleTypes ObstacleSetHandler::getObstacles( const ObstacleSetFilter &filter) const
{
// TODO: Handle multiple terrains for one obstacle set?
auto terrainType = filter.getTerrain();
TObstacleTypes result;
for (const auto &allowedType : filter.getAllowedTypes())
@ -173,24 +170,5 @@ TObstacleTypes ObstacleSetHandler::getObstacles( const ObstacleSetFilter &filter
return result;
}
/*
ObstacleSet ObstacleSetHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
{
// TODO: Merge by name with existing obstacle sets?
const JsonNode & biome = json["biome"];
auto objectType = ObstacleSet::typeFromString(biome["objectType"].String());
for (const JsonNode & type : data["types"])
{
for (const JsonNode & obstacle : type["templates"])
{
// TODO: Reuse templates (pointers) parsed by CObjectClassesHandler
}
}
}
*/
VCMI_LIB_NAMESPACE_END

View File

@ -37,6 +37,11 @@ void ObstacleProxy::collectPossibleObstacles(TerrainId terrain)
}
}
}
sortObstacles();
}
void ObstacleProxy::sortObstacles()
{
for(const auto & o : obstaclesBySize)
{
possibleObstacles.emplace_back(o);
@ -51,12 +56,8 @@ bool ObstacleProxy::prepareBiome(TerrainId terrain, CRandomGenerator & rand)
{
// FIXME: All the mountains have same ID and mostly same subID, how to differentiate them?
bool isPrepared = false;
possibleObstacles.clear();
// TODO: Where to parse these sets?
std::vector<ObstacleSet> obstacleSets;
size_t selectedSets = 0;
@ -176,8 +177,6 @@ bool ObstacleProxy::prepareBiome(TerrainId terrain, CRandomGenerator & rand)
}
// Copy this set to our possible obstacles
// if (selectedSets >= MINIMUM_SETS)
if (selectedSets >= MINIMUM_SETS ||
(terrain == TerrainId::WATER && selectedSets > 0))
@ -194,24 +193,14 @@ bool ObstacleProxy::prepareBiome(TerrainId terrain, CRandomGenerator & rand)
}
}
for(const auto & o : obstaclesBySize)
{
possibleObstacles.emplace_back(o);
}
boost::sort(possibleObstacles, [](const ObstaclePair &p1, const ObstaclePair &p2) -> bool
{
return p1.first > p2.first; //bigger obstacles first
});
sortObstacles();
return true;
}
else
{
return false; // Proceed with old method
return false; // Proceed with old method
}
return isPrepared;
}
void ObstacleProxy::addBlockedTile(const int3& tile)

View File

@ -53,6 +53,7 @@ public:
protected:
int getWeightedObjects(const int3& tile, CRandomGenerator& rand, IGameCallback * cb, std::list<rmg::Object>& allObjects, std::vector<std::pair<rmg::Object*, int3>>& weightedObjects);
void ObstacleProxy::sortObstacles();
rmg::Area blockedArea;