1
0
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:
Ivan Savenko 2023-12-10 23:11:20 +02:00 committed by GitHub
commit 6fe8ed7a03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();