1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fix for randomly banning or exceeding limits of zone objects

This commit is contained in:
Tomasz Zieliński 2023-12-07 17:41:09 +01:00
parent 960697873a
commit 7fa01a3497

View File

@ -836,13 +836,18 @@ void TreasurePlacer::createTreasures(ObjectManager& manager)
int value = std::accumulate(treasurePileInfos.begin(), treasurePileInfos.end(), 0, [](int v, const ObjectInfo* oi) {return v + oi->value; });
for (ui32 attempt = 0; attempt <= 2; attempt++)
const ui32 maxPileGenerationAttemps = 2;
for (ui32 attempt = 0; attempt <= maxPileGenerationAttemps; attempt++)
{
auto rmgObject = constructTreasurePile(treasurePileInfos, attempt == maxAttempts);
if (rmgObject.instances().empty()) //handle incorrect placement
if (rmgObject.instances().empty())
{
restoreZoneLimits(treasurePileInfos);
// Restore once if all attemps failed
if (attempt == (maxPileGenerationAttemps - 1))
{
restoreZoneLimits(treasurePileInfos);
}
continue;
}