mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-15 00:05:02 +02:00
Replaced most of usages of CRandomGenerator with vstd::RNG in library
This commit is contained in:
@ -32,6 +32,8 @@
|
||||
#include "../networkPacks/PacksForClientBattle.h"
|
||||
#include "../networkPacks/StackLocation.h"
|
||||
|
||||
#include <vstd/RNG.h>
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
///helpers
|
||||
@ -93,7 +95,7 @@ void CGMine::onHeroVisit( const CGHeroInstance * h ) const
|
||||
|
||||
}
|
||||
|
||||
void CGMine::newTurn(CRandomGenerator & rand) const
|
||||
void CGMine::newTurn(vstd::RNG & rand) const
|
||||
{
|
||||
if(cb->getDate() == 1)
|
||||
return;
|
||||
@ -104,7 +106,7 @@ void CGMine::newTurn(CRandomGenerator & rand) const
|
||||
cb->giveResource(tempOwner, producedResource, producedQuantity);
|
||||
}
|
||||
|
||||
void CGMine::initObj(CRandomGenerator & rand)
|
||||
void CGMine::initObj(vstd::RNG & rand)
|
||||
{
|
||||
if(isAbandoned())
|
||||
{
|
||||
@ -254,7 +256,7 @@ std::string CGResource::getHoverText(PlayerColor player) const
|
||||
return VLC->generaltexth->restypes[resourceID().getNum()];
|
||||
}
|
||||
|
||||
void CGResource::pickRandomObject(CRandomGenerator & rand)
|
||||
void CGResource::pickRandomObject(vstd::RNG & rand)
|
||||
{
|
||||
assert(ID == Obj::RESOURCE || ID == Obj::RANDOM_RESOURCE);
|
||||
|
||||
@ -269,7 +271,7 @@ void CGResource::pickRandomObject(CRandomGenerator & rand)
|
||||
}
|
||||
}
|
||||
|
||||
void CGResource::initObj(CRandomGenerator & rand)
|
||||
void CGResource::initObj(vstd::RNG & rand)
|
||||
{
|
||||
blockVisit = true;
|
||||
|
||||
@ -327,7 +329,7 @@ void CGResource::collectRes(const PlayerColor & player) const
|
||||
sii.text.replaceName(resourceID());
|
||||
}
|
||||
sii.components.emplace_back(ComponentType::RESOURCE, resourceID(), amount);
|
||||
sii.soundID = soundBase::pickup01 + CRandomGenerator::getDefault().nextInt(6);
|
||||
sii.soundID = soundBase::pickup01 + cb->gameState()->getRandomGenerator().nextInt(6);
|
||||
cb->showInfoDialog(&sii);
|
||||
cb->removeObject(this, player);
|
||||
}
|
||||
@ -395,7 +397,7 @@ ObjectInstanceID CGTeleport::getRandomExit(const CGHeroInstance * h) const
|
||||
{
|
||||
auto passableExits = getPassableExits(cb->gameState(), h, getAllExits(true));
|
||||
if(!passableExits.empty())
|
||||
return *RandomGeneratorUtil::nextItem(passableExits, CRandomGenerator::getDefault());
|
||||
return *RandomGeneratorUtil::nextItem(passableExits, cb->gameState()->getRandomGenerator());
|
||||
|
||||
return ObjectInstanceID();
|
||||
}
|
||||
@ -530,7 +532,7 @@ void CGMonolith::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer,
|
||||
cb->moveHero(hero->id, hero->convertFromVisitablePos(dPos), EMovementMode::MONOLITH);
|
||||
}
|
||||
|
||||
void CGMonolith::initObj(CRandomGenerator & rand)
|
||||
void CGMonolith::initObj(vstd::RNG & rand)
|
||||
{
|
||||
std::vector<Obj> IDs;
|
||||
IDs.push_back(ID);
|
||||
@ -575,7 +577,7 @@ void CGSubterraneanGate::onHeroVisit( const CGHeroInstance * h ) const
|
||||
cb->showTeleportDialog(&td);
|
||||
}
|
||||
|
||||
void CGSubterraneanGate::initObj(CRandomGenerator & rand)
|
||||
void CGSubterraneanGate::initObj(vstd::RNG & rand)
|
||||
{
|
||||
type = BOTH;
|
||||
}
|
||||
@ -703,7 +705,7 @@ void CGWhirlpool::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer
|
||||
|
||||
const auto * obj = cb->getObj(exit);
|
||||
std::set<int3> tiles = obj->getBlockedPos();
|
||||
dPos = *RandomGeneratorUtil::nextItem(tiles, CRandomGenerator::getDefault());
|
||||
dPos = *RandomGeneratorUtil::nextItem(tiles, cb->gameState()->getRandomGenerator()));
|
||||
}
|
||||
|
||||
cb->moveHero(hero->id, hero->convertFromVisitablePos(dPos), EMovementMode::MONOLITH);
|
||||
@ -724,7 +726,7 @@ ArtifactID CGArtifact::getArtifact() const
|
||||
return getObjTypeIndex().getNum();
|
||||
}
|
||||
|
||||
void CGArtifact::pickRandomObject(CRandomGenerator & rand)
|
||||
void CGArtifact::pickRandomObject(vstd::RNG & rand)
|
||||
{
|
||||
switch(ID.toEnum())
|
||||
{
|
||||
@ -754,7 +756,7 @@ void CGArtifact::pickRandomObject(CRandomGenerator & rand)
|
||||
ID = MapObjectID::ARTIFACT;
|
||||
}
|
||||
|
||||
void CGArtifact::initObj(CRandomGenerator & rand)
|
||||
void CGArtifact::initObj(vstd::RNG & rand)
|
||||
{
|
||||
blockVisit = true;
|
||||
if(ID == Obj::ARTIFACT)
|
||||
@ -936,7 +938,7 @@ void CGArtifact::serializeJsonOptions(JsonSerializeFormat& handler)
|
||||
}
|
||||
}
|
||||
|
||||
void CGSignBottle::initObj(CRandomGenerator & rand)
|
||||
void CGSignBottle::initObj(vstd::RNG & rand)
|
||||
{
|
||||
//if no text is set than we pick random from the predefined ones
|
||||
if(message.empty())
|
||||
@ -1011,7 +1013,7 @@ void CGGarrison::serializeJsonOptions(JsonSerializeFormat& handler)
|
||||
CArmedInstance::serializeJsonOptions(handler);
|
||||
}
|
||||
|
||||
void CGGarrison::initObj(CRandomGenerator &rand)
|
||||
void CGGarrison::initObj(vstd::RNG &rand)
|
||||
{
|
||||
if(this->subID == MapObjectSubID::decode(this->ID, "antiMagic"))
|
||||
addAntimagicGarrisonBonus();
|
||||
@ -1028,7 +1030,7 @@ void CGGarrison::addAntimagicGarrisonBonus()
|
||||
this->addNewBonus(bonus);
|
||||
}
|
||||
|
||||
void CGMagi::initObj(CRandomGenerator & rand)
|
||||
void CGMagi::initObj(vstd::RNG & rand)
|
||||
{
|
||||
if (ID == Obj::EYE_OF_MAGI)
|
||||
blockVisit = true;
|
||||
@ -1091,7 +1093,7 @@ bool CGBoat::isCoastVisitable() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void CGSirens::initObj(CRandomGenerator & rand)
|
||||
void CGSirens::initObj(vstd::RNG & rand)
|
||||
{
|
||||
blockVisit = true;
|
||||
}
|
||||
@ -1238,7 +1240,7 @@ void CGObelisk::onHeroVisit( const CGHeroInstance * h ) const
|
||||
|
||||
}
|
||||
|
||||
void CGObelisk::initObj(CRandomGenerator & rand)
|
||||
void CGObelisk::initObj(vstd::RNG & rand)
|
||||
{
|
||||
cb->gameState()->map->obeliskCount++;
|
||||
}
|
||||
@ -1291,7 +1293,7 @@ void CGLighthouse::onHeroVisit( const CGHeroInstance * h ) const
|
||||
}
|
||||
}
|
||||
|
||||
void CGLighthouse::initObj(CRandomGenerator & rand)
|
||||
void CGLighthouse::initObj(vstd::RNG & rand)
|
||||
{
|
||||
if(tempOwner.isValidPlayer())
|
||||
{
|
||||
|
Reference in New Issue
Block a user