1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00

Use the most suitable template for object

This commit is contained in:
Tomasz Zieliński
2023-03-28 17:53:08 +02:00
parent 49c029ea6c
commit b184e80b72
3 changed files with 33 additions and 18 deletions

View File

@ -79,7 +79,15 @@ void ObjectDistributor::distributeLimitedObjects()
for (auto& zone : matchingZones)
{
auto temp = handler->getTemplates(zone->getTerrainType()).front();
//We already know there are some templates
auto templates = handler->getTemplates(zone->getTerrainType());
//Assume the template with fewest terrains is the most suitable
auto temp = *boost::min_element(templates, [](std::shared_ptr<const ObjectTemplate> lhs, std::shared_ptr<const ObjectTemplate> rhs) -> bool
{
return lhs->getAllowedTerrains().size() < rhs->getAllowedTerrains().size();
});
oi.generateObject = [temp]() -> CGObjectInstance *
{
return VLC->objtypeh->getHandlerFor(temp->id, temp->subid)->create(temp);