mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Treasure placement uses random templates now
This commit is contained in:
@@ -79,25 +79,14 @@ void ObjectDistributor::distributeLimitedObjects()
|
||||
|
||||
for (auto& zone : matchingZones)
|
||||
{
|
||||
//We already know there are some templates
|
||||
auto templates = handler->getTemplates(zone->getTerrainType());
|
||||
|
||||
//FIXME: Templates empty?! Maybe zone changed terrain type over time?
|
||||
|
||||
//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
|
||||
oi.generateObject = [primaryID, secondaryID]() -> CGObjectInstance *
|
||||
{
|
||||
return lhs->getAllowedTerrains().size() < rhs->getAllowedTerrains().size();
|
||||
});
|
||||
|
||||
oi.generateObject = [temp]() -> CGObjectInstance *
|
||||
{
|
||||
return VLC->objtypeh->getHandlerFor(temp->id, temp->subid)->create(temp);
|
||||
return VLC->objtypeh->getHandlerFor(primaryID, secondaryID)->create();
|
||||
};
|
||||
|
||||
oi.value = rmgInfo.value;
|
||||
oi.probability = rmgInfo.rarity;
|
||||
oi.templ = temp;
|
||||
oi.setTemplates(primaryID, secondaryID, zone->getTerrainType());
|
||||
|
||||
//Rounding up will make sure all possible objects are exhausted
|
||||
uint32_t mapLimit = rmgInfo.mapLimit.value();
|
||||
@@ -109,7 +98,7 @@ void ObjectDistributor::distributeLimitedObjects()
|
||||
|
||||
rmgInfo.setMapLimit(mapLimit - oi.maxPerZone);
|
||||
//Don't add objects with 0 count remaining
|
||||
if (oi.maxPerZone)
|
||||
if(oi.maxPerZone && !oi.templates.empty())
|
||||
{
|
||||
zone->getModificator<TreasurePlacer>()->addObjectToRandomPool(oi);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user