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:
@ -105,7 +105,12 @@ public:
|
|||||||
inline bool canBePlacedAtAnyTerrain() const
|
inline bool canBePlacedAtAnyTerrain() const
|
||||||
{
|
{
|
||||||
return anyTerrain;
|
return anyTerrain;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const std::set<TerrainId>& getAllowedTerrains() const
|
||||||
|
{
|
||||||
|
return allowedTerrains;
|
||||||
|
}
|
||||||
|
|
||||||
// Checks if object can be placed on specific terrain
|
// Checks if object can be placed on specific terrain
|
||||||
bool canBePlacedAt(TerrainId terrain) const;
|
bool canBePlacedAt(TerrainId terrain) const;
|
||||||
|
@ -79,7 +79,15 @@ void ObjectDistributor::distributeLimitedObjects()
|
|||||||
|
|
||||||
for (auto& zone : matchingZones)
|
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 *
|
oi.generateObject = [temp]() -> CGObjectInstance *
|
||||||
{
|
{
|
||||||
return VLC->objtypeh->getHandlerFor(temp->id, temp->subid)->create(temp);
|
return VLC->objtypeh->getHandlerFor(temp->id, temp->subid)->create(temp);
|
||||||
|
@ -71,23 +71,25 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const auto & temp : handler->getTemplates())
|
auto templates = handler->getTemplates(zone.getTerrainType());
|
||||||
{
|
if (templates.empty())
|
||||||
if(temp->canBePlacedAt(zone.getTerrainType()))
|
continue;
|
||||||
{
|
|
||||||
oi.generateObject = [temp]() -> CGObjectInstance *
|
|
||||||
{
|
|
||||||
return VLC->objtypeh->getHandlerFor(temp->id, temp->subid)->create(temp);
|
|
||||||
};
|
|
||||||
oi.value = rmgInfo.value;
|
|
||||||
oi.probability = rmgInfo.rarity;
|
|
||||||
oi.templ = temp;
|
|
||||||
oi.maxPerZone = rmgInfo.zoneLimit;
|
|
||||||
addObjectToRandomPool(oi);
|
|
||||||
|
|
||||||
break;
|
//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);
|
||||||
|
};
|
||||||
|
oi.value = rmgInfo.value;
|
||||||
|
oi.probability = rmgInfo.rarity;
|
||||||
|
oi.templ = temp;
|
||||||
|
oi.maxPerZone = rmgInfo.zoneLimit;
|
||||||
|
addObjectToRandomPool(oi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user