From ca819b3cda2468b6d2f83d002b19d8f52dc79e2d Mon Sep 17 00:00:00 2001 From: Arseniy Shestakov Date: Tue, 23 Aug 2016 19:12:10 +0300 Subject: [PATCH] CGHeroInstance::nextPrimarySkill: don't use GS RNG directly Code used from both GS and CGameHandler. --- lib/mapObjects/CGHeroInstance.cpp | 6 +++--- lib/mapObjects/CGHeroInstance.h | 2 +- server/CGameHandler.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index d2cd01313..de64490c8 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -1337,10 +1337,10 @@ std::vector CGHeroInstance::getLevelUpProposedSecondarySkills() return skills; } -PrimarySkill::PrimarySkill CGHeroInstance::nextPrimarySkill() const +PrimarySkill::PrimarySkill CGHeroInstance::nextPrimarySkill(CRandomGenerator & rand) const { assert(gainsLevel()); - int randomValue = cb->gameState()->getRandomGenerator().nextInt(99), pom = 0, primarySkill = 0; + int randomValue = rand.nextInt(99), pom = 0, primarySkill = 0; const auto & skillChances = (level > 9) ? type->heroClass->primarySkillLowLevel : type->heroClass->primarySkillHighLevel; for(; primarySkill < GameConstants::PRIMARY_SKILLS; ++primarySkill) @@ -1456,7 +1456,7 @@ void CGHeroInstance::levelUpAutomatically() { while(gainsLevel()) { - const auto primarySkill = nextPrimarySkill(); + const auto primarySkill = nextPrimarySkill(cb->gameState()->getRandomGenerator()); setPrimarySkill(primarySkill, 1, false); auto proposedSecondarySkills = getLevelUpProposedSecondarySkills(); diff --git a/lib/mapObjects/CGHeroInstance.h b/lib/mapObjects/CGHeroInstance.h index 105f54f89..780407a7c 100644 --- a/lib/mapObjects/CGHeroInstance.h +++ b/lib/mapObjects/CGHeroInstance.h @@ -163,7 +163,7 @@ public: bool gainsLevel() const; /// Returns the next primary skill on level up. Can only be called if hero can gain a level up. - PrimarySkill::PrimarySkill nextPrimarySkill() const; + PrimarySkill::PrimarySkill nextPrimarySkill(CRandomGenerator & rand) const; /// Returns the next secondary skill randomly on level up. Can only be called if hero can gain a level up. boost::optional nextSecondarySkill() const; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 5793eceb0..aab40fd39 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -204,7 +204,7 @@ void CGameHandler::levelUpHero(const CGHeroInstance * hero) // give primary skill logGlobal->trace("%s got level %d", hero->name, hero->level); - auto primarySkill = hero->nextPrimarySkill(); + auto primarySkill = hero->nextPrimarySkill(getRandomGenerator()); SetPrimSkill sps; sps.id = hero->id;