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

Do not exceed rolled treasure value - matches OH3.

This commit is contained in:
Tomasz Zieliński 2023-06-08 19:23:23 +02:00
parent 6ed1dab3fb
commit d92ac6bcbe
2 changed files with 4 additions and 4 deletions

View File

@ -562,7 +562,7 @@ std::vector<ObjectInfo*> TreasurePlacer::prepareTreasurePile(const CTreasureInfo
bool hasLargeObject = false;
while(currentValue <= static_cast<int>(desiredValue) - 100) //no objects with value below 100 are available
{
auto * oi = getRandomObject(desiredValue, currentValue, maxValue, !hasLargeObject);
auto * oi = getRandomObject(desiredValue, currentValue, !hasLargeObject);
if(!oi) //fail
break;
@ -659,13 +659,13 @@ rmg::Object TreasurePlacer::constructTreasurePile(const std::vector<ObjectInfo*>
return rmgObject;
}
ObjectInfo * TreasurePlacer::getRandomObject(ui32 desiredValue, ui32 currentValue, ui32 maxValue, bool allowLargeObjects)
ObjectInfo * TreasurePlacer::getRandomObject(ui32 desiredValue, ui32 currentValue, bool allowLargeObjects)
{
std::vector<std::pair<ui32, ObjectInfo*>> thresholds; //handle complex object via pointer
ui32 total = 0;
//calculate actual treasure value range based on remaining value
ui32 maxVal = maxValue - currentValue;
ui32 maxVal = desiredValue - currentValue;
ui32 minValue = static_cast<ui32>(0.25f * (desiredValue - currentValue));
for(ObjectInfo & oi : possibleObjects) //copy constructor turned out to be costly

View File

@ -54,7 +54,7 @@ public:
protected:
bool isGuardNeededForTreasure(int value);
ObjectInfo * getRandomObject(ui32 desiredValue, ui32 currentValue, ui32 maxValue, bool allowLargeObjects);
ObjectInfo * getRandomObject(ui32 desiredValue, ui32 currentValue, bool allowLargeObjects);
std::vector<ObjectInfo*> prepareTreasurePile(const CTreasureInfo & treasureInfo);
rmg::Object constructTreasurePile(const std::vector<ObjectInfo*> & treasureInfos, bool densePlacement = false);