mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-17 00:07:41 +02:00
CGHeroInstance::initArmy: don't use GS RNG. Get RNG through a ref
This function used by both server-side and gamestate so it's must use appropriate random source.
This commit is contained in:
@ -302,7 +302,7 @@ void CGHeroInstance::initHero()
|
|||||||
setFormation(false);
|
setFormation(false);
|
||||||
if (!stacksCount()) //standard army//initial army
|
if (!stacksCount()) //standard army//initial army
|
||||||
{
|
{
|
||||||
initArmy();
|
initArmy(cb->gameState()->getRandomGenerator());
|
||||||
}
|
}
|
||||||
assert(validTypes());
|
assert(validTypes());
|
||||||
|
|
||||||
@ -326,13 +326,13 @@ void CGHeroInstance::initHero()
|
|||||||
mana = manaLimit();
|
mana = manaLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGHeroInstance::initArmy(IArmyDescriptor *dst /*= nullptr*/)
|
void CGHeroInstance::initArmy(CRandomGenerator & rand, IArmyDescriptor *dst /*= nullptr*/)
|
||||||
{
|
{
|
||||||
if(!dst)
|
if(!dst)
|
||||||
dst = this;
|
dst = this;
|
||||||
|
|
||||||
int howManyStacks = 0; //how many stacks will hero receives <1 - 3>
|
int howManyStacks = 0; //how many stacks will hero receives <1 - 3>
|
||||||
int pom = cb->getRandomGenerator().nextInt(99);
|
int pom = rand.nextInt(99);
|
||||||
int warMachinesGiven = 0;
|
int warMachinesGiven = 0;
|
||||||
|
|
||||||
if(pom < 9)
|
if(pom < 9)
|
||||||
@ -348,7 +348,7 @@ void CGHeroInstance::initArmy(IArmyDescriptor *dst /*= nullptr*/)
|
|||||||
{
|
{
|
||||||
auto & stack = type->initialArmy[stackNo];
|
auto & stack = type->initialArmy[stackNo];
|
||||||
|
|
||||||
int count = cb->getRandomGenerator().nextInt(stack.minAmount, stack.maxAmount);
|
int count = rand.nextInt(stack.minAmount, stack.maxAmount);
|
||||||
|
|
||||||
if(stack.creature >= CreatureID::CATAPULT &&
|
if(stack.creature >= CreatureID::CATAPULT &&
|
||||||
stack.creature <= CreatureID::ARROW_TOWERS) //war machine
|
stack.creature <= CreatureID::ARROW_TOWERS) //war machine
|
||||||
|
@ -205,7 +205,7 @@ public:
|
|||||||
void putArtifact(ArtifactPosition pos, CArtifactInstance *art);
|
void putArtifact(ArtifactPosition pos, CArtifactInstance *art);
|
||||||
void putInBackpack(CArtifactInstance *art);
|
void putInBackpack(CArtifactInstance *art);
|
||||||
void initExp();
|
void initExp();
|
||||||
void initArmy(IArmyDescriptor *dst = nullptr);
|
void initArmy(CRandomGenerator & rand, IArmyDescriptor *dst = nullptr);
|
||||||
//void giveArtifact (ui32 aid);
|
//void giveArtifact (ui32 aid);
|
||||||
void pushPrimSkill(PrimarySkill::PrimarySkill which, int val);
|
void pushPrimSkill(PrimarySkill::PrimarySkill which, int val);
|
||||||
ui8 maxlevelsToMagicSchool() const;
|
ui8 maxlevelsToMagicSchool() const;
|
||||||
|
@ -1518,7 +1518,7 @@ void CGameHandler::newTurn()
|
|||||||
if(CGHeroInstance *h = gs->hpool.pickHeroFor(j == 0, elem.first, getNativeTown(elem.first), pool, getRandomGenerator(), banned))
|
if(CGHeroInstance *h = gs->hpool.pickHeroFor(j == 0, elem.first, getNativeTown(elem.first), pool, getRandomGenerator(), banned))
|
||||||
{
|
{
|
||||||
sah.hid[j] = h->subID;
|
sah.hid[j] = h->subID;
|
||||||
h->initArmy(&sah.army[j]);
|
h->initArmy(getRandomGenerator(), &sah.army[j]);
|
||||||
banned = h->type->heroClass;
|
banned = h->type->heroClass;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user