mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +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:
@@ -128,6 +128,16 @@ void Object::Instance::setTemplate(TerrainId terrain, CRandomGenerator & rng)
|
|||||||
auto terrainName = VLC->terrainTypeHandler->getById(terrain)->getNameTranslated();
|
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));
|
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);
|
dObject.appearance = *RandomGeneratorUtil::nextItem(templates, rng);
|
||||||
dAccessibleAreaCache.clear();
|
dAccessibleAreaCache.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user