1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Fix initialization of gold pile from random resource with fixed amount

This commit is contained in:
Ivan Savenko 2024-06-17 20:08:07 +00:00
parent f2d870e651
commit c68f2da977
3 changed files with 8 additions and 4 deletions

View File

@ -263,6 +263,9 @@ void CGResource::pickRandomObject(CRandomGenerator & rand)
ID = Obj::RESOURCE;
subID = rand.nextInt(EGameResID::WOOD, EGameResID::GOLD);
setType(ID, subID);
if (subID == EGameResID::GOLD && amount != CGResource::RANDOM_AMOUNT)
amount *= CGResource::GOLD_AMOUNT_MULTIPLIER;
}
}
@ -275,7 +278,7 @@ void CGResource::initObj(CRandomGenerator & rand)
switch(resourceID().toEnum())
{
case EGameResID::GOLD:
amount = rand.nextInt(5, 10) * 100;
amount = rand.nextInt(5, 10) * CGResource::GOLD_AMOUNT_MULTIPLIER;
break;
case EGameResID::WOOD: case EGameResID::ORE:
amount = rand.nextInt(6, 10);

View File

@ -122,8 +122,9 @@ class DLL_LINKAGE CGResource : public CArmedInstance
public:
using CArmedInstance::CArmedInstance;
static constexpr ui32 RANDOM_AMOUNT = 0;
ui32 amount = RANDOM_AMOUNT; //0 if random
static constexpr uint32_t RANDOM_AMOUNT = 0;
static constexpr uint32_t GOLD_AMOUNT_MULTIPLIER = 100;
uint32_t amount = RANDOM_AMOUNT; //0 if random
MetaString message;

View File

@ -1315,7 +1315,7 @@ CGObjectInstance * CMapLoaderH3M::readResource(const int3 & mapPosition, std::sh
if(GameResID(objectTemplate->subid) == GameResID(EGameResID::GOLD))
{
// Gold is multiplied by 100.
object->amount *= 100;
object->amount *= CGResource::GOLD_AMOUNT_MULTIPLIER;
}
reader->skipZero(4);
return object;