1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Refactoring: only use RNGs explicitly to avoid bug prone code in future

Now server-side code should always use CRandomGenerator::getDefault which is serialized in GH.
CGameState::getRandomGenerator should be only used from GS code and CPackForClient-based applyGs.
This commit is contained in:
Arseniy Shestakov
2016-09-09 20:30:36 +03:00
parent 70abae9b51
commit c8faca8f39
28 changed files with 225 additions and 219 deletions

View File

@@ -282,18 +282,18 @@ std::vector<int> CGBlackMarket::availableItemsIds(EMarketMode::EMarketMode mode)
}
}
void CGBlackMarket::newTurn() const
void CGBlackMarket::newTurn(CRandomGenerator & rand) const
{
if(cb->getDate(Date::DAY_OF_MONTH) != 1) //new month
return;
SetAvailableArtifacts saa;
saa.id = id.getNum();
cb->pickAllowedArtsSet(saa.arts, cb->getRandomGenerator());
cb->pickAllowedArtsSet(saa.arts, rand);
cb->sendAndApply(&saa);
}
void CGUniversity::initObj()
void CGUniversity::initObj(CRandomGenerator & rand)
{
std::vector<int> toChoose;
for(int i = 0; i < GameConstants::SKILL_QUANTITY; ++i)
@@ -313,7 +313,7 @@ void CGUniversity::initObj()
for(int i = 0; i < 4; ++i)
{
// move randomly one skill to selected and remove from list
auto it = RandomGeneratorUtil::nextItem(toChoose, cb->gameState()->getRandomGenerator());
auto it = RandomGeneratorUtil::nextItem(toChoose, rand);
skills.push_back(*it);
toChoose.erase(it);
}