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

Use the object templates with least terrains allowed.

This commit is contained in:
Tomasz Zieliński 2023-10-31 09:07:53 +01:00
parent 29a78c14a2
commit 6625831cf6

View File

@ -130,6 +130,16 @@ void Object::Instance::setTemplate(TerrainId terrain, CRandomGenerator & rng)
auto terrainName = VLC->terrainTypeHandler->getById(terrain)->getNameTranslated();
throw rmgException(boost::str(boost::format("Did not find graphics for object (%d,%d) at %s") % dObject.ID % dObject.subID % terrainName));
}
//Get terrain-specific template if possible
int leastTerrains = (*boost::min_element(templates, [](const std::shared_ptr<const ObjectTemplate> & tmp1, const std::shared_ptr<const ObjectTemplate> & tmp2)
{
return tmp1->getAllowedTerrains().size() < tmp2->getAllowedTerrains().size();
}))->getAllowedTerrains().size();
vstd::erase_if(templates, [leastTerrains](const std::shared_ptr<const ObjectTemplate> & tmp)
{
return tmp->getAllowedTerrains().size() > leastTerrains;
});
dObject.appearance = *RandomGeneratorUtil::nextItem(templates, rng);
dAccessibleAreaCache.clear();