1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-29 21:56:54 +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

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

@ -54,7 +54,7 @@ public:
protected: protected:
bool isGuardNeededForTreasure(int value); 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); std::vector<ObjectInfo*> prepareTreasurePile(const CTreasureInfo & treasureInfo);
rmg::Object constructTreasurePile(const std::vector<ObjectInfo*> & treasureInfos, bool densePlacement = false); rmg::Object constructTreasurePile(const std::vector<ObjectInfo*> & treasureInfos, bool densePlacement = false);