Browse Source

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.
Arseniy Shestakov 9 years ago
parent
commit
85f49bc968
3 changed files with 6 additions and 6 deletions
  1. 4 4
      lib/mapObjects/CGHeroInstance.cpp
  2. 1 1
      lib/mapObjects/CGHeroInstance.h
  3. 1 1
      server/CGameHandler.cpp

+ 4 - 4
lib/mapObjects/CGHeroInstance.cpp

@@ -302,7 +302,7 @@ void CGHeroInstance::initHero()
 	setFormation(false);
 	if (!stacksCount()) //standard army//initial army
 	{
-		initArmy();
+		initArmy(cb->gameState()->getRandomGenerator());
 	}
 	assert(validTypes());
 
@@ -326,13 +326,13 @@ void CGHeroInstance::initHero()
 		mana = manaLimit();
 }
 
-void CGHeroInstance::initArmy(IArmyDescriptor *dst /*= nullptr*/)
+void CGHeroInstance::initArmy(CRandomGenerator & rand, IArmyDescriptor *dst /*= nullptr*/)
 {
 	if(!dst)
 		dst = this;
 
 	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;
 
 	if(pom < 9)
@@ -348,7 +348,7 @@ void CGHeroInstance::initArmy(IArmyDescriptor *dst /*= nullptr*/)
 	{
 		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 &&
 		   stack.creature <= CreatureID::ARROW_TOWERS) //war machine

+ 1 - 1
lib/mapObjects/CGHeroInstance.h

@@ -205,7 +205,7 @@ public:
 	void putArtifact(ArtifactPosition pos, CArtifactInstance *art);
 	void putInBackpack(CArtifactInstance *art);
 	void initExp();
-	void initArmy(IArmyDescriptor *dst = nullptr);
+	void initArmy(CRandomGenerator & rand, IArmyDescriptor *dst = nullptr);
 	//void giveArtifact (ui32 aid);
 	void pushPrimSkill(PrimarySkill::PrimarySkill which, int val);
 	ui8 maxlevelsToMagicSchool() const;

+ 1 - 1
server/CGameHandler.cpp

@@ -1518,7 +1518,7 @@ void CGameHandler::newTurn()
 				if(CGHeroInstance *h = gs->hpool.pickHeroFor(j == 0, elem.first, getNativeTown(elem.first), pool, getRandomGenerator(), banned))
 				{
 					sah.hid[j] = h->subID;
-					h->initArmy(&sah.army[j]);
+					h->initArmy(getRandomGenerator(), &sah.army[j]);
 					banned = h->type->heroClass;
 				}
 				else