1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-17 00:07:41 +02:00

Multiple changes to RNG usage to both client and server

Server should never use RNG from CGameState directly.
Instead server get's own RNG that's state is secret for client.
This commit is contained in:
Arseniy Shestakov
2016-09-08 00:54:26 +03:00
parent 960d93ff5f
commit 2ba3b20928
9 changed files with 61 additions and 49 deletions

View File

@ -434,7 +434,7 @@ void CGCreature::fight( const CGHeroInstance *h ) const
const auto & upgrades = getStack(slotID).type->upgrades;
if(!upgrades.empty())
{
auto it = RandomGeneratorUtil::nextItem(upgrades, cb->gameState()->getRandomGenerator());
auto it = RandomGeneratorUtil::nextItem(upgrades, cb->getRandomGenerator());
cb->changeStackType(StackLocation(this, slotID), VLC->creh->creatures[*it]);
}
}
@ -987,7 +987,7 @@ ObjectInstanceID CGTeleport::getRandomExit(const CGHeroInstance * h) const
{
auto passableExits = getPassableExits(cb->gameState(), h, getAllExits(true));
if(passableExits.size())
return *RandomGeneratorUtil::nextItem(passableExits, cb->gameState()->getRandomGenerator());
return *RandomGeneratorUtil::nextItem(passableExits, cb->getRandomGenerator());
return ObjectInstanceID();
}
@ -1283,7 +1283,7 @@ void CGWhirlpool::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer
{
auto obj = cb->getObj(getRandomExit(hero));
std::set<int3> tiles = obj->getBlockedPos();
dPos = CGHeroInstance::convertPosition(*RandomGeneratorUtil::nextItem(tiles, cb->gameState()->getRandomGenerator()), true);
dPos = CGHeroInstance::convertPosition(*RandomGeneratorUtil::nextItem(tiles, cb->getRandomGenerator()), true);
}
cb->moveHero(hero->id, dPos, true);
@ -1714,7 +1714,7 @@ void CGScholar::onHeroVisit( const CGHeroInstance * h ) const
))) //hero doesn't have a spellbook or already knows the spell or doesn't have Wisdom
{
type = PRIM_SKILL;
bid = cb->gameState()->getRandomGenerator().nextInt(GameConstants::PRIMARY_SKILLS - 1);
bid = cb->getRandomGenerator().nextInt(GameConstants::PRIMARY_SKILLS - 1);
}
InfoWindow iw;