mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Merge pull request #3127 from vcmi/fix_random_object_templates
Use the object templates with least terrains allowed
This commit is contained in:
commit
6fe8ed7a03
@ -128,6 +128,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.getObjTypeIndex() % 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();
|
||||
|
Loading…
Reference in New Issue
Block a user