From fe6c0cf89bfb975b44d616fc42270a17c54d1a87 Mon Sep 17 00:00:00 2001 From: Arseniy Shestakov Date: Fri, 9 Sep 2016 22:11:13 +0300 Subject: [PATCH] Use RandomGeneratorUtil::randomShuffle for reproducible gameplay --- lib/spells/BattleSpellMechanics.cpp | 2 +- server/CGameHandler.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/spells/BattleSpellMechanics.cpp b/lib/spells/BattleSpellMechanics.cpp index 1958d3654..83c65bf07 100644 --- a/lib/spells/BattleSpellMechanics.cpp +++ b/lib/spells/BattleSpellMechanics.cpp @@ -428,7 +428,7 @@ void ObstacleMechanics::applyBattleEffects(const SpellCastEnvironment * env, con if(hex.getX() > 2 && hex.getX() < 14 && !(parameters.cb->battleGetStackByPos(hex, false)) && !(parameters.cb->battleGetObstacleOnPos(hex, false))) availableTiles.push_back(hex); } - boost::range::random_shuffle(availableTiles); + RandomGeneratorUtil::randomShuffle(availableTiles, env->getRandomGenerator()); const int patchesForSkill[] = {4, 4, 6, 8}; const int patchesToPut = std::min(patchesForSkill[parameters.spellLvl], availableTiles.size()); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 97b1b005e..ec8643a8e 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -5740,7 +5740,7 @@ void CGameHandler::runBattle() if(!curOwner || curOwner->getSecSkillLevel(SecondarySkill::FIRST_AID) == 0) //no hero or hero has no first aid { - range::random_shuffle(possibleStacks); + RandomGeneratorUtil::randomShuffle(possibleStacks, getRandomGenerator()); const CStack * toBeHealed = possibleStacks.front(); BattleAction heal; @@ -5943,7 +5943,8 @@ void CGameHandler::spawnWanderingMonsters(CreatureID creatureID) std::vector tiles; getFreeTiles(tiles); ui32 amount = tiles.size() / 200; //Chance is 0.5% for each tile - std::random_shuffle(tiles.begin(), tiles.end()); + + RandomGeneratorUtil::randomShuffle(tiles, getRandomGenerator()); logGlobal->trace("Spawning wandering monsters. Found %d free tiles. Creature type: %d", tiles.size(), creatureID.num); const CCreature *cre = VLC->creh->creatures.at(creatureID); for (int i = 0; i < amount; ++i)