1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-20 03:29:32 +02:00

Replaced most of usages of CRandomGenerator with vstd::RNG in library

This commit is contained in:
Ivan Savenko 2024-06-01 15:28:17 +00:00
parent 60a51e98de
commit 63bcf7d83c
125 changed files with 620 additions and 409 deletions

View File

@ -21,9 +21,19 @@
class HypotheticBattle; class HypotheticBattle;
///Fake random generator, used by AI to evaluate random server behavior ///Fake random generator, used by AI to evaluate random server behavior
class RNGStub : public vstd::RNG class RNGStub final : public vstd::RNG
{ {
public: public:
virtual int nextInt() override
{
return 0;
}
int nextBinomialInt(int coinsCount, double coinChance) override
{
return coinsCount * coinChance;
}
int nextInt(int lower, int upper) override int nextInt(int lower, int upper) override
{ {
return (lower + upper) / 2; return (lower + upper) / 2;
@ -36,6 +46,19 @@ public:
{ {
return (lower + upper) / 2; return (lower + upper) / 2;
} }
int nextInt(int upper) override
{
return upper / 2;
}
int64_t nextInt64(int64_t upper) override
{
return upper / 2;
}
double nextDouble(double upper) override
{
return upper / 2;
}
}; };
class StackWithBonuses : public battle::CUnitState, public virtual IBonusBearer class StackWithBonuses : public battle::CUnitState, public virtual IBonusBearer

View File

@ -70,6 +70,7 @@
#include "../lib/CGeneralTextHandler.h" #include "../lib/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h" #include "../lib/CHeroHandler.h"
#include "../lib/CPlayerState.h" #include "../lib/CPlayerState.h"
#include "../lib/CRandomGenerator.h"
#include "../lib/CStack.h" #include "../lib/CStack.h"
#include "../lib/CStopWatch.h" #include "../lib/CStopWatch.h"
#include "../lib/CThreadHelper.h" #include "../lib/CThreadHelper.h"
@ -413,8 +414,9 @@ void CPlayerInterface::heroVisit(const CGHeroInstance * visitor, const CGObjectI
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
if(start && visitedObj) if(start && visitedObj)
{ {
if(visitedObj->getVisitSound()) auto visitSound = visitedObj->getVisitSound(CRandomGenerator::getDefault());
CCS->soundh->playSound(visitedObj->getVisitSound().value()); if (visitSound)
CCS->soundh->playSound(visitSound.value());
} }
} }
@ -1410,10 +1412,14 @@ void CPlayerInterface::centerView (int3 pos, int focusTime)
void CPlayerInterface::objectRemoved(const CGObjectInstance * obj, const PlayerColor & initiator) void CPlayerInterface::objectRemoved(const CGObjectInstance * obj, const PlayerColor & initiator)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
if(playerID == initiator && obj->getRemovalSound()) if(playerID == initiator)
{
auto removalSound = obj->getRemovalSound(CRandomGenerator::getDefault());
if (removalSound)
{ {
waitWhileDialog(); waitWhileDialog();
CCS->soundh->playSound(obj->getRemovalSound().value()); CCS->soundh->playSound(removalSound.value());
}
} }
CGI->mh->waitForOngoingAnimations(); CGI->mh->waitForOngoingAnimations();

View File

@ -24,6 +24,7 @@
#include "ConditionalWait.h" #include "ConditionalWait.h"
#include "../lib/CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "../lib/CRandomGenerator.h"
#include "../lib/pathfinder/CGPathNode.h" #include "../lib/pathfinder/CGPathNode.h"
#include "../lib/mapObjects/CGHeroInstance.h" #include "../lib/mapObjects/CGHeroInstance.h"
#include "../lib/networkPacks/PacksForClient.h" #include "../lib/networkPacks/PacksForClient.h"
@ -153,8 +154,12 @@ void HeroMovementController::onTryMoveHero(const CGHeroInstance * hero, const Tr
if(details.result == TryMoveHero::EMBARK || details.result == TryMoveHero::DISEMBARK) if(details.result == TryMoveHero::EMBARK || details.result == TryMoveHero::DISEMBARK)
{ {
if(hero->getRemovalSound() && hero->tempOwner == LOCPLINT->playerID) if (hero->tempOwner == LOCPLINT->playerID)
CCS->soundh->playSound(hero->getRemovalSound().value()); {
auto removalSound = hero->getRemovalSound(CRandomGenerator::getDefault());
if (removalSound)
CCS->soundh->playSound(removalSound.value());
}
} }
bool directlyAttackingCreature = bool directlyAttackingCreature =

View File

@ -17,6 +17,7 @@
#include "../media/IMusicPlayer.h" #include "../media/IMusicPlayer.h"
#include "../media/ISoundPlayer.h" #include "../media/ISoundPlayer.h"
#include "../../lib/CRandomGenerator.h"
#include "../../lib/TerrainHandler.h" #include "../../lib/TerrainHandler.h"
#include "../../lib/mapObjects/CArmedInstance.h" #include "../../lib/mapObjects/CArmedInstance.h"
#include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/mapObjects/CGHeroInstance.h"
@ -136,8 +137,12 @@ std::vector<AudioPath> MapAudioPlayer::getAmbientSounds(const int3 & tile)
if (!object) if (!object)
logGlobal->warn("Already removed object %d found on tile! (%d %d %d)", objectID.getNum(), tile.x, tile.y, tile.z); logGlobal->warn("Already removed object %d found on tile! (%d %d %d)", objectID.getNum(), tile.x, tile.y, tile.z);
if(object && object->getAmbientSound()) if(object)
result.push_back(object->getAmbientSound().value()); {
auto ambientSound = object->getAmbientSound(CRandomGenerator::getDefault());
if (ambientSound)
result.push_back(ambientSound.value());
}
} }
if(CGI->mh->getMap()->isCoastalTile(tile)) if(CGI->mh->getMap()->isCoastalTile(tile))

View File

@ -54,6 +54,7 @@
#include "../lib/CHeroHandler.h" #include "../lib/CHeroHandler.h"
#include "../lib/GameSettings.h" #include "../lib/GameSettings.h"
#include "ConditionalWait.h" #include "ConditionalWait.h"
#include "../lib/CRandomGenerator.h"
#include "../lib/CSkillHandler.h" #include "../lib/CSkillHandler.h"
#include "../lib/CSoundBase.h" #include "../lib/CSoundBase.h"

View File

@ -20,9 +20,31 @@ class DLL_LINKAGE RNG
public: public:
virtual ~RNG() = default; virtual ~RNG() = default;
/// Returns random number in range [lower, upper]
virtual int nextInt(int lower, int upper) = 0; virtual int nextInt(int lower, int upper) = 0;
/// Returns random number in range [lower, upper]
virtual int64_t nextInt64(int64_t lower, int64_t upper) = 0; virtual int64_t nextInt64(int64_t lower, int64_t upper) = 0;
/// Returns random number in range [lower, upper]
virtual double nextDouble(double lower, double upper) = 0; virtual double nextDouble(double lower, double upper) = 0;
/// Returns random number in range [0, upper]
virtual int nextInt(int upper) = 0;
/// Returns random number in range [0, upper]
virtual int64_t nextInt64(int64_t upper) = 0;
/// Returns random number in range [0, upper]
virtual double nextDouble(double upper) = 0;
/// Generates an integer between 0 and the maximum value it can hold.
/// Should be only used for seeding other generators
virtual int nextInt() = 0;
/// Returns integer using binomial distribution
/// returned value is number of successfull coin flips with chance 'coinChance' out of 'coinsCount' attempts
virtual int nextBinomialInt(int coinsCount, double coinChance) = 0;
}; };
} }

View File

@ -25,7 +25,6 @@ class CArtHandler;
class CGHeroInstance; class CGHeroInstance;
class CArtifactSet; class CArtifactSet;
class CArtifactInstance; class CArtifactInstance;
class CRandomGenerator;
class CMap; class CMap;
class JsonSerializeFormat; class JsonSerializeFormat;

View File

@ -14,7 +14,6 @@
#include "ResourceSet.h" #include "ResourceSet.h"
#include "filesystem/Filesystem.h" #include "filesystem/Filesystem.h"
#include "VCMI_Lib.h" #include "VCMI_Lib.h"
#include "CRandomGenerator.h"
#include "CTownHandler.h" #include "CTownHandler.h"
#include "GameSettings.h" #include "GameSettings.h"
#include "constants/StringConstants.h" #include "constants/StringConstants.h"
@ -28,6 +27,8 @@
#include "modding/CModHandler.h" #include "modding/CModHandler.h"
#include "ExceptionsCommon.h" #include "ExceptionsCommon.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
const std::map<CCreature::CreatureQuantityId, std::string> CCreature::creatureQuantityRanges = const std::map<CCreature::CreatureQuantityId, std::string> CCreature::creatureQuantityRanges =
@ -1362,7 +1363,7 @@ CCreatureHandler::~CCreatureHandler()
p.first = nullptr; p.first = nullptr;
} }
CreatureID CCreatureHandler::pickRandomMonster(CRandomGenerator & rand, int tier) const CreatureID CCreatureHandler::pickRandomMonster(vstd::RNG & rand, int tier) const
{ {
std::vector<CreatureID> allowed; std::vector<CreatureID> allowed;
for(const auto & creature : objects) for(const auto & creature : objects)

View File

@ -23,11 +23,15 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
class CLegacyConfigParser; class CLegacyConfigParser;
class CCreatureHandler; class CCreatureHandler;
class CCreature; class CCreature;
class JsonSerializeFormat; class JsonSerializeFormat;
class CRandomGenerator;
class DLL_LINKAGE CCreature : public Creature, public CBonusSystemNode class DLL_LINKAGE CCreature : public Creature, public CBonusSystemNode
{ {
@ -225,7 +229,7 @@ public:
std::vector< std::vector <ui8> > skillLevels; //how much of a bonus will be given to commander with every level. SPELL_POWER also gives CASTS and RESISTANCE std::vector< std::vector <ui8> > skillLevels; //how much of a bonus will be given to commander with every level. SPELL_POWER also gives CASTS and RESISTANCE
std::vector <std::pair <std::shared_ptr<Bonus>, std::pair <ui8, ui8> > > skillRequirements; // first - Bonus, second - which two skills are needed to use it std::vector <std::pair <std::shared_ptr<Bonus>, std::pair <ui8, ui8> > > skillRequirements; // first - Bonus, second - which two skills are needed to use it
CreatureID pickRandomMonster(CRandomGenerator & rand, int tier = -1) const; //tier <1 - CREATURES_PER_TOWN> or -1 for any CreatureID pickRandomMonster(vstd::RNG & rand, int tier = -1) const; //tier <1 - CREATURES_PER_TOWN> or -1 for any
CCreatureHandler(); CCreatureHandler();
~CCreatureHandler(); ~CCreatureHandler();

View File

@ -17,7 +17,6 @@
#include "battle/BattleHex.h" #include "battle/BattleHex.h"
#include "CCreatureHandler.h" #include "CCreatureHandler.h"
#include "GameSettings.h" #include "GameSettings.h"
#include "CRandomGenerator.h"
#include "CTownHandler.h" #include "CTownHandler.h"
#include "CSkillHandler.h" #include "CSkillHandler.h"
#include "BattleFieldHandler.h" #include "BattleFieldHandler.h"
@ -29,6 +28,8 @@
#include "mapObjectConstructors/CObjectClassesHandler.h" #include "mapObjectConstructors/CObjectClassesHandler.h"
#include "modding/IdentifierStorage.h" #include "modding/IdentifierStorage.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
CHero::CHero() = default; CHero::CHero() = default;
@ -123,7 +124,7 @@ void CHero::serializeJson(JsonSerializeFormat & handler)
} }
SecondarySkill CHeroClass::chooseSecSkill(const std::set<SecondarySkill> & possibles, CRandomGenerator & rand) const //picks secondary skill out from given possibilities SecondarySkill CHeroClass::chooseSecSkill(const std::set<SecondarySkill> & possibles, vstd::RNG & rand) const //picks secondary skill out from given possibilities
{ {
assert(!possibles.empty()); assert(!possibles.empty());

View File

@ -23,11 +23,15 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
class CHeroClass; class CHeroClass;
class CGHeroInstance; class CGHeroInstance;
struct BattleHex; struct BattleHex;
class JsonNode; class JsonNode;
class CRandomGenerator;
class JsonSerializeFormat; class JsonSerializeFormat;
class BattleField; class BattleField;
@ -148,7 +152,7 @@ public:
std::string getNameTextID() const override; std::string getNameTextID() const override;
bool isMagicHero() const; bool isMagicHero() const;
SecondarySkill chooseSecSkill(const std::set<SecondarySkill> & possibles, CRandomGenerator & rand) const; //picks secondary skill out from given possibilities SecondarySkill chooseSecSkill(const std::set<SecondarySkill> & possibles, vstd::RNG & rand) const; //picks secondary skill out from given possibilities
void updateFrom(const JsonNode & data); void updateFrom(const JsonNode & data);
void serializeJson(JsonSerializeFormat & handler); void serializeJson(JsonSerializeFormat & handler);

View File

@ -40,6 +40,11 @@ int CRandomGenerator::nextInt(int upper)
return nextInt(0, upper); return nextInt(0, upper);
} }
int64_t CRandomGenerator::nextInt64(int64_t upper)
{
return nextInt64(0, upper);
}
int CRandomGenerator::nextInt(int lower, int upper) int CRandomGenerator::nextInt(int lower, int upper)
{ {
if (lower > upper) if (lower > upper)
@ -53,6 +58,12 @@ int CRandomGenerator::nextInt()
return TIntDist()(rand); return TIntDist()(rand);
} }
int CRandomGenerator::nextBinomialInt(int coinsCount, double coinChance)
{
std::binomial_distribution<> distribution(coinsCount, coinChance);
return distribution(rand);
}
int64_t CRandomGenerator::nextInt64(int64_t lower, int64_t upper) int64_t CRandomGenerator::nextInt64(int64_t lower, int64_t upper)
{ {
if (lower > upper) if (lower > upper)
@ -74,20 +85,11 @@ double CRandomGenerator::nextDouble(double lower, double upper)
return TRealDist(lower, upper)(rand); return TRealDist(lower, upper)(rand);
} }
//double CRandomGenerator::nextDouble()
//{
// return TRealDist()(rand);
//}
CRandomGenerator & CRandomGenerator::getDefault() CRandomGenerator & CRandomGenerator::getDefault()
{ {
static thread_local CRandomGenerator defaultRand; static thread_local CRandomGenerator defaultRand;
return defaultRand; return defaultRand;
} }
TGenerator & CRandomGenerator::getStdGenerator()
{
return rand;
}
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -46,18 +46,23 @@ public:
/// Generates an integer between 0 and upper. /// Generates an integer between 0 and upper.
/// requires: 0 <= upper /// requires: 0 <= upper
int nextInt(int upper); int nextInt(int upper) override;
int64_t nextInt64(int64_t upper) override;
/// requires: lower <= upper /// requires: lower <= upper
int nextInt(int lower, int upper) override; int nextInt(int lower, int upper) override;
int64_t nextInt64(int64_t lower, int64_t upper) override; int64_t nextInt64(int64_t lower, int64_t upper) override;
/// Generates an integer between 0 and the maximum value it can hold. /// Generates an integer between 0 and the maximum value it can hold.
int nextInt(); int nextInt() override;
///
int nextBinomialInt(int coinsCount, double coinChance) override;
/// Generates a double between 0 and upper. /// Generates a double between 0 and upper.
/// requires: 0 <= upper /// requires: 0 <= upper
double nextDouble(double upper); double nextDouble(double upper) override;
/// requires: lower <= upper /// requires: lower <= upper
double nextDouble(double lower, double upper) override; double nextDouble(double lower, double upper) override;
@ -66,9 +71,6 @@ public:
/// seed a combination of the thread ID and current time in milliseconds will be used. /// seed a combination of the thread ID and current time in milliseconds will be used.
static CRandomGenerator & getDefault(); static CRandomGenerator & getDefault();
/// Provide method so that this RNG can be used with legacy std:: API
TGenerator & getStdGenerator();
private: private:
TGenerator rand; TGenerator rand;

View File

@ -14,6 +14,7 @@
#include "spells/CSpellHandler.h"// for CSpell #include "spells/CSpellHandler.h"// for CSpell
#include "CSkillHandler.h"// for CSkill #include "CSkillHandler.h"// for CSkill
#include "CBonusTypeHandler.h" #include "CBonusTypeHandler.h"
#include "CRandomGenerator.h"
#include "BattleFieldHandler.h" #include "BattleFieldHandler.h"
#include "ObstacleHandler.h" #include "ObstacleHandler.h"
#include "bonuses/Limiters.h" #include "bonuses/Limiters.h"
@ -51,6 +52,8 @@
#include "RiverHandler.h" #include "RiverHandler.h"
#include "TerrainHandler.h" #include "TerrainHandler.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
void CPrivilegedInfoCallback::getFreeTiles(std::vector<int3> & tiles) const void CPrivilegedInfoCallback::getFreeTiles(std::vector<int3> & tiles) const
@ -146,7 +149,7 @@ void CPrivilegedInfoCallback::getAllTiles(std::unordered_set<int3> & tiles, std:
} }
} }
void CPrivilegedInfoCallback::pickAllowedArtsSet(std::vector<const CArtifact *> & out, CRandomGenerator & rand) void CPrivilegedInfoCallback::pickAllowedArtsSet(std::vector<const CArtifact *> & out, vstd::RNG & rand)
{ {
for (int j = 0; j < 3 ; j++) for (int j = 0; j < 3 ; j++)
out.push_back(gameState()->pickRandomArtifact(rand, CArtifact::ART_TREASURE).toArtifact()); out.push_back(gameState()->pickRandomArtifact(rand, CArtifact::ART_TREASURE).toArtifact());

View File

@ -16,13 +16,17 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
struct SetMovePoints; struct SetMovePoints;
struct GiveBonus; struct GiveBonus;
struct BlockingDialog; struct BlockingDialog;
struct TeleportDialog; struct TeleportDialog;
struct StackLocation; struct StackLocation;
struct ArtifactLocation; struct ArtifactLocation;
class CRandomGenerator;
class CCreatureSet; class CCreatureSet;
class CStackBasicDescriptor; class CStackBasicDescriptor;
class CGCreature; class CGCreature;
@ -61,7 +65,7 @@ public:
void getAllTiles(std::unordered_set<int3> &tiles, std::optional<PlayerColor> player, int level, std::function<bool(const TerrainTile *)> filter) const; void getAllTiles(std::unordered_set<int3> &tiles, std::optional<PlayerColor> player, int level, std::function<bool(const TerrainTile *)> filter) const;
//gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
void pickAllowedArtsSet(std::vector<const CArtifact *> & out, CRandomGenerator & rand); void pickAllowedArtsSet(std::vector<const CArtifact *> & out, vstd::RNG & rand);
void getAllowedSpells(std::vector<SpellID> &out, std::optional<ui16> level = std::nullopt); void getAllowedSpells(std::vector<SpellID> &out, std::optional<ui16> level = std::nullopt);
template<typename Saver> template<typename Saver>

View File

@ -12,7 +12,6 @@
#include "CObstacleInstance.h" #include "CObstacleInstance.h"
#include "bonuses/Limiters.h" #include "bonuses/Limiters.h"
#include "bonuses/Updaters.h" #include "bonuses/Updaters.h"
#include "../CRandomGenerator.h"
#include "../CStack.h" #include "../CStack.h"
#include "../CHeroHandler.h" #include "../CHeroHandler.h"
#include "../filesystem/Filesystem.h" #include "../filesystem/Filesystem.h"
@ -21,6 +20,7 @@
#include "../BattleFieldHandler.h" #include "../BattleFieldHandler.h"
#include "../ObstacleHandler.h" #include "../ObstacleHandler.h"
#include <vstd/RNG.h>
//TODO: remove //TODO: remove
#include "../IGameCallback.h" #include "../IGameCallback.h"

View File

@ -11,6 +11,7 @@
#include "CBattleInfoCallback.h" #include "CBattleInfoCallback.h"
#include <vcmi/scripting/Service.h> #include <vcmi/scripting/Service.h>
#include <vstd/RNG.h>
#include "../CStack.h" #include "../CStack.h"
#include "BattleInfo.h" #include "BattleInfo.h"
@ -25,7 +26,6 @@
#include "../networkPacks/PacksForClientBattle.h" #include "../networkPacks/PacksForClientBattle.h"
#include "../BattleFieldHandler.h" #include "../BattleFieldHandler.h"
#include "../Rect.h" #include "../Rect.h"
#include "../CRandomGenerator.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
@ -1602,7 +1602,7 @@ std::set<const battle::Unit *> CBattleInfoCallback::battleAdjacentUnits(const ba
return ret; return ret;
} }
SpellID CBattleInfoCallback::getRandomBeneficialSpell(CRandomGenerator & rand, const battle::Unit * caster, const battle::Unit * subject) const SpellID CBattleInfoCallback::getRandomBeneficialSpell(vstd::RNG & rand, const battle::Unit * caster, const battle::Unit * subject) const
{ {
RETURN_IF_NOT_BATTLE(SpellID::NONE); RETURN_IF_NOT_BATTLE(SpellID::NONE);
//This is complete list. No spells from mods. //This is complete list. No spells from mods.
@ -1748,7 +1748,7 @@ SpellID CBattleInfoCallback::getRandomBeneficialSpell(CRandomGenerator & rand, c
} }
} }
SpellID CBattleInfoCallback::getRandomCastedSpell(CRandomGenerator & rand,const CStack * caster) const SpellID CBattleInfoCallback::getRandomCastedSpell(vstd::RNG & rand,const CStack * caster) const
{ {
RETURN_IF_NOT_BATTLE(SpellID::NONE); RETURN_IF_NOT_BATTLE(SpellID::NONE);

View File

@ -23,9 +23,13 @@ class SpellCastEnvironment;
class CSpell; class CSpell;
struct CObstacleInstance; struct CObstacleInstance;
class IBonusBearer; class IBonusBearer;
class CRandomGenerator;
class PossiblePlayerBattleAction; class PossiblePlayerBattleAction;
namespace vstd
{
class RNG;
}
namespace spells namespace spells
{ {
class Caster; class Caster;
@ -116,8 +120,8 @@ public:
int32_t battleGetSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const; //returns cost of given spell int32_t battleGetSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const; //returns cost of given spell
ESpellCastProblem battleCanCastSpell(const spells::Caster * caster, spells::Mode mode) const; //returns true if there are no general issues preventing from casting a spell ESpellCastProblem battleCanCastSpell(const spells::Caster * caster, spells::Mode mode) const; //returns true if there are no general issues preventing from casting a spell
SpellID getRandomBeneficialSpell(CRandomGenerator & rand, const battle::Unit * caster, const battle::Unit * target) const; SpellID getRandomBeneficialSpell(vstd::RNG & rand, const battle::Unit * caster, const battle::Unit * target) const;
SpellID getRandomCastedSpell(CRandomGenerator & rand, const CStack * caster) const; //called at the beginning of turn for Faerie Dragon SpellID getRandomCastedSpell(vstd::RNG & rand, const CStack * caster) const; //called at the beginning of turn for Faerie Dragon
std::vector<PossiblePlayerBattleAction> getClientActionsForStack(const CStack * stack, const BattleClientInterfaceData & data); std::vector<PossiblePlayerBattleAction> getClientActionsForStack(const CStack * stack, const BattleClientInterfaceData & data);
PossiblePlayerBattleAction getCasterAction(const CSpell * spell, const spells::Caster * caster, spells::Mode mode) const; PossiblePlayerBattleAction getCasterAction(const CSpell * spell, const spells::Caster * caster, spells::Mode mode) const;

View File

@ -21,6 +21,7 @@
#include "../CGeneralTextHandler.h" #include "../CGeneralTextHandler.h"
#include "../CHeroHandler.h" #include "../CHeroHandler.h"
#include "../CPlayerState.h" #include "../CPlayerState.h"
#include "../CRandomGenerator.h"
#include "../CStopWatch.h" #include "../CStopWatch.h"
#include "../GameSettings.h" #include "../GameSettings.h"
#include "../StartInfo.h" #include "../StartInfo.h"
@ -53,6 +54,8 @@
#include "../serializer/CTypeList.h" #include "../serializer/CTypeList.h"
#include "../spells/CSpellHandler.h" #include "../spells/CSpellHandler.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
boost::shared_mutex CGameState::mutex; boost::shared_mutex CGameState::mutex;
@ -183,7 +186,7 @@ void CGameState::init(const IMapService * mapService, StartInfo * si, Load::Prog
assert(services); assert(services);
assert(callback); assert(callback);
logGlobal->info("\tUsing random seed: %d", si->seedToBeUsed); logGlobal->info("\tUsing random seed: %d", si->seedToBeUsed);
getRandomGenerator().setSeed(si->seedToBeUsed); rand = std::make_unique<CRandomGenerator>(si->seedToBeUsed);
scenarioOps = CMemorySerializer::deepCopy(*si).release(); scenarioOps = CMemorySerializer::deepCopy(*si).release();
initialOpts = CMemorySerializer::deepCopy(*si).release(); initialOpts = CMemorySerializer::deepCopy(*si).release();
si = nullptr; si = nullptr;
@ -1072,7 +1075,7 @@ BattleInfo * CGameState::getBattle(const BattleID & battle)
return nullptr; return nullptr;
} }
BattleField CGameState::battleGetBattlefieldType(int3 tile, CRandomGenerator & rand) BattleField CGameState::battleGetBattlefieldType(int3 tile, vstd::RNG & rand)
{ {
assert(tile.valid()); assert(tile.valid());
@ -1961,12 +1964,12 @@ TeamState::TeamState()
setNodeType(TEAM); setNodeType(TEAM);
} }
CRandomGenerator & CGameState::getRandomGenerator() vstd::RNG & CGameState::getRandomGenerator()
{ {
return rand; return *rand;
} }
ArtifactID CGameState::pickRandomArtifact(CRandomGenerator & rand, int flags, std::function<bool(ArtifactID)> accepts) ArtifactID CGameState::pickRandomArtifact(vstd::RNG & rand, int flags, std::function<bool(ArtifactID)> accepts)
{ {
std::set<ArtifactID> potentialPicks; std::set<ArtifactID> potentialPicks;
@ -2001,7 +2004,7 @@ ArtifactID CGameState::pickRandomArtifact(CRandomGenerator & rand, int flags, st
return pickRandomArtifact(rand, potentialPicks); return pickRandomArtifact(rand, potentialPicks);
} }
ArtifactID CGameState::pickRandomArtifact(CRandomGenerator & rand, std::set<ArtifactID> potentialPicks) ArtifactID CGameState::pickRandomArtifact(vstd::RNG & rand, std::set<ArtifactID> potentialPicks)
{ {
// No allowed artifacts at all - give Grail - this can't be banned (hopefully) // No allowed artifacts at all - give Grail - this can't be banned (hopefully)
// FIXME: investigate how such cases are handled by H3 - some heavily customized user-made maps likely rely on H3 behavior // FIXME: investigate how such cases are handled by H3 - some heavily customized user-made maps likely rely on H3 behavior
@ -2030,12 +2033,12 @@ ArtifactID CGameState::pickRandomArtifact(CRandomGenerator & rand, std::set<Arti
return artID; return artID;
} }
ArtifactID CGameState::pickRandomArtifact(CRandomGenerator & rand, std::function<bool(ArtifactID)> accepts) ArtifactID CGameState::pickRandomArtifact(vstd::RNG & rand, std::function<bool(ArtifactID)> accepts)
{ {
return pickRandomArtifact(rand, 0xff, std::move(accepts)); return pickRandomArtifact(rand, 0xff, std::move(accepts));
} }
ArtifactID CGameState::pickRandomArtifact(CRandomGenerator & rand, int flags) ArtifactID CGameState::pickRandomArtifact(vstd::RNG & rand, int flags)
{ {
return pickRandomArtifact(rand, flags, [](const ArtifactID &) { return true; }); return pickRandomArtifact(rand, flags, [](const ArtifactID &) { return true; });
} }

View File

@ -13,7 +13,6 @@
#include "IGameCallback.h" #include "IGameCallback.h"
#include "LoadProgress.h" #include "LoadProgress.h"
#include "ConstTransitivePtr.h" #include "ConstTransitivePtr.h"
#include "../CRandomGenerator.h"
namespace boost namespace boost
{ {
@ -34,6 +33,7 @@ class CStackInstance;
class CGameStateCampaign; class CGameStateCampaign;
class TavernHeroesPool; class TavernHeroesPool;
struct SThievesGuildInfo; struct SThievesGuildInfo;
class CRandomGenerator;
template<typename T> class CApplier; template<typename T> class CApplier;
class CBaseForGSApply; class CBaseForGSApply;
@ -126,7 +126,7 @@ public:
HeroTypeID pickNextHeroType(const PlayerColor & owner); HeroTypeID pickNextHeroType(const PlayerColor & owner);
void apply(CPack *pack); void apply(CPack *pack);
BattleField battleGetBattlefieldType(int3 tile, CRandomGenerator & rand); BattleField battleGetBattlefieldType(int3 tile, vstd::RNG & rand);
void fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out) const override; void fillUpgradeInfo(const CArmedInstance *obj, SlotID stackPos, UpgradeInfo &out) const override;
PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const override; PlayerRelations getPlayerRelations(PlayerColor color1, PlayerColor color2) const override;
@ -138,10 +138,10 @@ public:
void updateRumor(); void updateRumor();
/// Gets a artifact ID randomly and removes the selected artifact from this handler. /// Gets a artifact ID randomly and removes the selected artifact from this handler.
ArtifactID pickRandomArtifact(CRandomGenerator & rand, int flags); ArtifactID pickRandomArtifact(vstd::RNG & rand, int flags);
ArtifactID pickRandomArtifact(CRandomGenerator & rand, std::function<bool(ArtifactID)> accepts); ArtifactID pickRandomArtifact(vstd::RNG & rand, std::function<bool(ArtifactID)> accepts);
ArtifactID pickRandomArtifact(CRandomGenerator & rand, int flags, std::function<bool(ArtifactID)> accepts); ArtifactID pickRandomArtifact(vstd::RNG & rand, int flags, std::function<bool(ArtifactID)> accepts);
ArtifactID pickRandomArtifact(CRandomGenerator & rand, std::set<ArtifactID> filtered); ArtifactID pickRandomArtifact(vstd::RNG & rand, std::set<ArtifactID> filtered);
/// Returns battle in which selected player is engaged, or nullptr if none. /// Returns battle in which selected player is engaged, or nullptr if none.
/// Can NOT be used with neutral player, use battle by ID instead /// Can NOT be used with neutral player, use battle by ID instead
@ -169,11 +169,11 @@ public:
/// This RNG should only be used inside GS or CPackForClient-derived applyGs /// This RNG should only be used inside GS or CPackForClient-derived applyGs
/// If this doesn't work for your code that mean you need a new netpack /// If this doesn't work for your code that mean you need a new netpack
/// ///
/// Client-side must use CRandomGenerator::getDefault which is not serialized /// Client-side must use vstd::RNG::getDefault which is not serialized
/// ///
/// CGameHandler have it's own getter for CRandomGenerator::getDefault /// CGameHandler have it's own getter for vstd::RNG::getDefault
/// Any server-side code outside of GH must use CRandomGenerator::getDefault /// Any server-side code outside of GH must use vstd::RNG::getDefault
CRandomGenerator & getRandomGenerator(); vstd::RNG & getRandomGenerator();
template <typename Handler> void serialize(Handler &h) template <typename Handler> void serialize(Handler &h)
{ {
@ -234,7 +234,7 @@ private:
// ---- data ----- // ---- data -----
std::shared_ptr<CApplier<CBaseForGSApply>> applier; std::shared_ptr<CApplier<CBaseForGSApply>> applier;
CRandomGenerator rand; std::unique_ptr<CRandomGenerator> rand;
Services * services; Services * services;
/// Pointer to campaign state manager. Nullptr for single scenarios /// Pointer to campaign state manager. Nullptr for single scenarios

View File

@ -28,6 +28,8 @@
#include "../CPlayerState.h" #include "../CPlayerState.h"
#include "../serializer/CMemorySerializer.h" #include "../serializer/CMemorySerializer.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
CampaignHeroReplacement::CampaignHeroReplacement(CGHeroInstance * hero, const ObjectInstanceID & heroPlaceholderId): CampaignHeroReplacement::CampaignHeroReplacement(CGHeroInstance * hero, const ObjectInstanceID & heroPlaceholderId):

View File

@ -18,7 +18,6 @@ VCMI_LIB_NAMESPACE_BEGIN
class CGHeroInstance; class CGHeroInstance;
class CTown; class CTown;
class CRandomGenerator;
class CHeroClass; class CHeroClass;
class CGameState; class CGameState;
class CSimpleArmy; class CSimpleArmy;

View File

@ -12,10 +12,10 @@
#include "JsonRandom.h" #include "JsonRandom.h"
#include <vstd/StringUtils.h> #include <vstd/StringUtils.h>
#include <vstd/RNG.h>
#include "JsonBonus.h" #include "JsonBonus.h"
#include "../CRandomGenerator.h"
#include "../constants/StringConstants.h" #include "../constants/StringConstants.h"
#include "../VCMI_Lib.h" #include "../VCMI_Lib.h"
#include "../CArtHandler.h" #include "../CArtHandler.h"
@ -50,7 +50,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return variables.at(variableID); return variables.at(variableID);
} }
si32 JsonRandom::loadValue(const JsonNode & value, CRandomGenerator & rng, const Variables & variables, si32 defaultValue) si32 JsonRandom::loadValue(const JsonNode & value, vstd::RNG & rng, const Variables & variables, si32 defaultValue)
{ {
if(value.isNull()) if(value.isNull())
return defaultValue; return defaultValue;
@ -256,7 +256,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return valuesSet; return valuesSet;
} }
TResources JsonRandom::loadResources(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) TResources JsonRandom::loadResources(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
TResources ret; TResources ret;
@ -274,7 +274,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return ret; return ret;
} }
TResources JsonRandom::loadResource(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) TResources JsonRandom::loadResource(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
std::set<GameResID> defaultResources{ std::set<GameResID> defaultResources{
GameResID::WOOD, GameResID::WOOD,
@ -295,7 +295,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return ret; return ret;
} }
PrimarySkill JsonRandom::loadPrimary(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) PrimarySkill JsonRandom::loadPrimary(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
std::set<PrimarySkill> defaultSkills{ std::set<PrimarySkill> defaultSkills{
PrimarySkill::ATTACK, PrimarySkill::ATTACK,
@ -307,7 +307,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return *RandomGeneratorUtil::nextItem(potentialPicks, rng); return *RandomGeneratorUtil::nextItem(potentialPicks, rng);
} }
std::vector<si32> JsonRandom::loadPrimaries(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) std::vector<si32> JsonRandom::loadPrimaries(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
std::vector<si32> ret(GameConstants::PRIMARY_SKILLS, 0); std::vector<si32> ret(GameConstants::PRIMARY_SKILLS, 0);
std::set<PrimarySkill> defaultSkills{ std::set<PrimarySkill> defaultSkills{
@ -339,7 +339,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return ret; return ret;
} }
SecondarySkill JsonRandom::loadSecondary(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) SecondarySkill JsonRandom::loadSecondary(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
std::set<SecondarySkill> defaultSkills; std::set<SecondarySkill> defaultSkills;
for(const auto & skill : VLC->skillh->objects) for(const auto & skill : VLC->skillh->objects)
@ -350,7 +350,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return *RandomGeneratorUtil::nextItem(potentialPicks, rng); return *RandomGeneratorUtil::nextItem(potentialPicks, rng);
} }
std::map<SecondarySkill, si32> JsonRandom::loadSecondaries(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) std::map<SecondarySkill, si32> JsonRandom::loadSecondaries(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
std::map<SecondarySkill, si32> ret; std::map<SecondarySkill, si32> ret;
if(value.isStruct()) if(value.isStruct())
@ -380,7 +380,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return ret; return ret;
} }
ArtifactID JsonRandom::loadArtifact(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) ArtifactID JsonRandom::loadArtifact(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
std::set<ArtifactID> allowedArts; std::set<ArtifactID> allowedArts;
for(const auto & artifact : VLC->arth->objects) for(const auto & artifact : VLC->arth->objects)
@ -392,7 +392,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return cb->gameState()->pickRandomArtifact(rng, potentialPicks); return cb->gameState()->pickRandomArtifact(rng, potentialPicks);
} }
std::vector<ArtifactID> JsonRandom::loadArtifacts(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) std::vector<ArtifactID> JsonRandom::loadArtifacts(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
std::vector<ArtifactID> ret; std::vector<ArtifactID> ret;
for (const JsonNode & entry : value.Vector()) for (const JsonNode & entry : value.Vector())
@ -402,7 +402,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return ret; return ret;
} }
SpellID JsonRandom::loadSpell(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) SpellID JsonRandom::loadSpell(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
std::set<SpellID> defaultSpells; std::set<SpellID> defaultSpells;
for(const auto & spell : VLC->spellh->objects) for(const auto & spell : VLC->spellh->objects)
@ -419,7 +419,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return *RandomGeneratorUtil::nextItem(potentialPicks, rng); return *RandomGeneratorUtil::nextItem(potentialPicks, rng);
} }
std::vector<SpellID> JsonRandom::loadSpells(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) std::vector<SpellID> JsonRandom::loadSpells(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
std::vector<SpellID> ret; std::vector<SpellID> ret;
for (const JsonNode & entry : value.Vector()) for (const JsonNode & entry : value.Vector())
@ -429,7 +429,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return ret; return ret;
} }
std::vector<PlayerColor> JsonRandom::loadColors(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) std::vector<PlayerColor> JsonRandom::loadColors(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
std::vector<PlayerColor> ret; std::vector<PlayerColor> ret;
std::set<PlayerColor> defaultPlayers; std::set<PlayerColor> defaultPlayers;
@ -445,7 +445,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return ret; return ret;
} }
std::vector<HeroTypeID> JsonRandom::loadHeroes(const JsonNode & value, CRandomGenerator & rng) std::vector<HeroTypeID> JsonRandom::loadHeroes(const JsonNode & value, vstd::RNG & rng)
{ {
std::vector<HeroTypeID> ret; std::vector<HeroTypeID> ret;
for(auto & entry : value.Vector()) for(auto & entry : value.Vector())
@ -455,7 +455,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return ret; return ret;
} }
std::vector<HeroClassID> JsonRandom::loadHeroClasses(const JsonNode & value, CRandomGenerator & rng) std::vector<HeroClassID> JsonRandom::loadHeroClasses(const JsonNode & value, vstd::RNG & rng)
{ {
std::vector<HeroClassID> ret; std::vector<HeroClassID> ret;
for(auto & entry : value.Vector()) for(auto & entry : value.Vector())
@ -465,7 +465,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return ret; return ret;
} }
CStackBasicDescriptor JsonRandom::loadCreature(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) CStackBasicDescriptor JsonRandom::loadCreature(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
CStackBasicDescriptor stack; CStackBasicDescriptor stack;
@ -494,7 +494,7 @@ VCMI_LIB_NAMESPACE_BEGIN
return stack; return stack;
} }
std::vector<CStackBasicDescriptor> JsonRandom::loadCreatures(const JsonNode & value, CRandomGenerator & rng, const Variables & variables) std::vector<CStackBasicDescriptor> JsonRandom::loadCreatures(const JsonNode & value, vstd::RNG & rng, const Variables & variables)
{ {
std::vector<CStackBasicDescriptor> ret; std::vector<CStackBasicDescriptor> ret;
for (const JsonNode & node : value.Vector()) for (const JsonNode & node : value.Vector())

View File

@ -15,9 +15,13 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
class JsonNode; class JsonNode;
using JsonVector = std::vector<JsonNode>; using JsonVector = std::vector<JsonNode>;
class CRandomGenerator;
struct Bonus; struct Bonus;
struct Component; struct Component;
@ -53,28 +57,28 @@ public:
si32 maxAmount; si32 maxAmount;
}; };
si32 loadValue(const JsonNode & value, CRandomGenerator & rng, const Variables & variables, si32 defaultValue = 0); si32 loadValue(const JsonNode & value, vstd::RNG & rng, const Variables & variables, si32 defaultValue = 0);
TResources loadResources(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); TResources loadResources(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
TResources loadResource(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); TResources loadResource(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
PrimarySkill loadPrimary(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); PrimarySkill loadPrimary(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
std::vector<si32> loadPrimaries(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); std::vector<si32> loadPrimaries(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
SecondarySkill loadSecondary(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); SecondarySkill loadSecondary(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
std::map<SecondarySkill, si32> loadSecondaries(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); std::map<SecondarySkill, si32> loadSecondaries(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
ArtifactID loadArtifact(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); ArtifactID loadArtifact(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
std::vector<ArtifactID> loadArtifacts(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); std::vector<ArtifactID> loadArtifacts(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
SpellID loadSpell(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); SpellID loadSpell(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
std::vector<SpellID> loadSpells(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); std::vector<SpellID> loadSpells(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
CStackBasicDescriptor loadCreature(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); CStackBasicDescriptor loadCreature(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
std::vector<CStackBasicDescriptor> loadCreatures(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); std::vector<CStackBasicDescriptor> loadCreatures(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
std::vector<RandomStackInfo> evaluateCreatures(const JsonNode & value, const Variables & variables); std::vector<RandomStackInfo> evaluateCreatures(const JsonNode & value, const Variables & variables);
std::vector<PlayerColor> loadColors(const JsonNode & value, CRandomGenerator & rng, const Variables & variables); std::vector<PlayerColor> loadColors(const JsonNode & value, vstd::RNG & rng, const Variables & variables);
std::vector<HeroTypeID> loadHeroes(const JsonNode & value, CRandomGenerator & rng); std::vector<HeroTypeID> loadHeroes(const JsonNode & value, vstd::RNG & rng);
std::vector<HeroClassID> loadHeroClasses(const JsonNode & value, CRandomGenerator & rng); std::vector<HeroClassID> loadHeroClasses(const JsonNode & value, vstd::RNG & rng);
static std::vector<Bonus> loadBonuses(const JsonNode & value); static std::vector<Bonus> loadBonuses(const JsonNode & value);
}; };

View File

@ -15,9 +15,13 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
class ObjectTemplate; class ObjectTemplate;
class CGObjectInstance; class CGObjectInstance;
class CRandomGenerator;
class IObjectInfo; class IObjectInfo;
class IGameCallback; class IGameCallback;
@ -114,7 +118,7 @@ public:
/// Configures object properties. Should be re-entrable, resetting state of the object if necessarily /// Configures object properties. Should be re-entrable, resetting state of the object if necessarily
/// This should set remaining properties, including randomized or depending on map /// This should set remaining properties, including randomized or depending on map
virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const = 0; virtual void configureObject(CGObjectInstance * object, vstd::RNG & rng) const = 0;
/// Returns object configuration, if available. Otherwise returns NULL /// Returns object configuration, if available. Otherwise returns NULL
virtual std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const; virtual std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const;

View File

@ -13,7 +13,8 @@
#include "../json/JsonRandom.h" #include "../json/JsonRandom.h"
#include "../CGeneralTextHandler.h" #include "../CGeneralTextHandler.h"
#include "../IGameCallback.h" #include "../IGameCallback.h"
#include "../CRandomGenerator.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
@ -36,7 +37,7 @@ void CBankInstanceConstructor::initTypeData(const JsonNode & input)
regularUnitPlacement = input["regularUnitPlacement"].Bool(); regularUnitPlacement = input["regularUnitPlacement"].Bool();
} }
BankConfig CBankInstanceConstructor::generateConfig(IGameCallback * cb, const JsonNode & level, CRandomGenerator & rng) const BankConfig CBankInstanceConstructor::generateConfig(IGameCallback * cb, const JsonNode & level, vstd::RNG & rng) const
{ {
BankConfig bc; BankConfig bc;
JsonRandom randomizer(cb); JsonRandom randomizer(cb);
@ -53,7 +54,7 @@ BankConfig CBankInstanceConstructor::generateConfig(IGameCallback * cb, const Js
return bc; return bc;
} }
void CBankInstanceConstructor::randomizeObject(CBank * bank, CRandomGenerator & rng) const void CBankInstanceConstructor::randomizeObject(CBank * bank, vstd::RNG & rng) const
{ {
bank->resetDuration = bankResetDuration; bank->resetDuration = bankResetDuration;
bank->blockVisit = blockVisit; bank->blockVisit = blockVisit;

View File

@ -69,7 +69,7 @@ public:
class CBankInstanceConstructor : public CDefaultObjectTypeHandler<CBank> class CBankInstanceConstructor : public CDefaultObjectTypeHandler<CBank>
{ {
BankConfig generateConfig(IGameCallback * cb, const JsonNode & conf, CRandomGenerator & rng) const; BankConfig generateConfig(IGameCallback * cb, const JsonNode & conf, vstd::RNG & rng) const;
JsonVector levels; JsonVector levels;
@ -87,7 +87,7 @@ protected:
public: public:
void randomizeObject(CBank * object, CRandomGenerator & rng) const override; void randomizeObject(CBank * object, vstd::RNG & rng) const override;
bool hasNameTextID() const override; bool hasNameTextID() const override;

View File

@ -17,7 +17,7 @@ VCMI_LIB_NAMESPACE_BEGIN
template<class ObjectType> template<class ObjectType>
class CDefaultObjectTypeHandler : public AObjectTypeHandler class CDefaultObjectTypeHandler : public AObjectTypeHandler
{ {
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const final void configureObject(CGObjectInstance * object, vstd::RNG & rng) const final
{ {
ObjectType * castedObject = dynamic_cast<ObjectType*>(object); ObjectType * castedObject = dynamic_cast<ObjectType*>(object);
@ -43,7 +43,7 @@ class CDefaultObjectTypeHandler : public AObjectTypeHandler
protected: protected:
virtual void initializeObject(ObjectType * object) const {} virtual void initializeObject(ObjectType * object) const {}
virtual void randomizeObject(ObjectType * object, CRandomGenerator & rng) const {} virtual void randomizeObject(ObjectType * object, vstd::RNG & rng) const {}
virtual ObjectType * createObject(IGameCallback * cb) const virtual ObjectType * createObject(IGameCallback * cb) const
{ {
return new ObjectType(cb); return new ObjectType(cb);

View File

@ -15,7 +15,6 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class CRandomGenerator;
class AObjectTypeHandler; class AObjectTypeHandler;
class ObjectTemplate; class ObjectTemplate;
struct SObjectSounds; struct SObjectSounds;

View File

@ -40,7 +40,7 @@ CGObjectInstance * CRewardableConstructor::create(IGameCallback * cb, std::share
return ret; return ret;
} }
void CRewardableConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const void CRewardableConstructor::configureObject(CGObjectInstance * object, vstd::RNG & rng) const
{ {
if(auto * rewardableObject = dynamic_cast<CRewardableObject*>(object)) if(auto * rewardableObject = dynamic_cast<CRewardableObject*>(object))
{ {

View File

@ -27,7 +27,7 @@ public:
CGObjectInstance * create(IGameCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override; CGObjectInstance * create(IGameCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override; void configureObject(CGObjectInstance * object, vstd::RNG & rng) const override;
std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const override; std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const override;
}; };

View File

@ -100,7 +100,7 @@ void CTownInstanceConstructor::initializeObject(CGTownInstance * obj) const
obj->tempOwner = PlayerColor::NEUTRAL; obj->tempOwner = PlayerColor::NEUTRAL;
} }
void CTownInstanceConstructor::randomizeObject(CGTownInstance * object, CRandomGenerator & rng) const void CTownInstanceConstructor::randomizeObject(CGTownInstance * object, vstd::RNG & rng) const
{ {
auto templ = getOverride(object->cb->getTile(object->pos)->terType->getId(), object); auto templ = getOverride(object->cb->getTile(object->pos)->terType->getId(), object);
if(templ) if(templ)
@ -159,7 +159,7 @@ void CHeroInstanceConstructor::initializeObject(CGHeroInstance * obj) const
obj->type = nullptr; //FIXME: set to valid value. somehow. obj->type = nullptr; //FIXME: set to valid value. somehow.
} }
void CHeroInstanceConstructor::randomizeObject(CGHeroInstance * object, CRandomGenerator & rng) const void CHeroInstanceConstructor::randomizeObject(CGHeroInstance * object, vstd::RNG & rng) const
{ {
} }
@ -259,7 +259,7 @@ void MarketInstanceConstructor::initializeObject(CGMarket * market) const
market->speech = VLC->generaltexth->translate(speech); market->speech = VLC->generaltexth->translate(speech);
} }
void MarketInstanceConstructor::randomizeObject(CGMarket * object, CRandomGenerator & rng) const void MarketInstanceConstructor::randomizeObject(CGMarket * object, vstd::RNG & rng) const
{ {
JsonRandom randomizer(object->cb); JsonRandom randomizer(object->cb);
JsonRandom::Variables emptyVariables; JsonRandom::Variables emptyVariables;

View File

@ -63,7 +63,7 @@ public:
std::map<std::string, LogicalExpression<BuildingID>> filters; std::map<std::string, LogicalExpression<BuildingID>> filters;
void initializeObject(CGTownInstance * object) const override; void initializeObject(CGTownInstance * object) const override;
void randomizeObject(CGTownInstance * object, CRandomGenerator & rng) const override; void randomizeObject(CGTownInstance * object, vstd::RNG & rng) const override;
void afterLoadFinalization() override; void afterLoadFinalization() override;
bool hasNameTextID() const override; bool hasNameTextID() const override;
@ -82,7 +82,7 @@ public:
std::map<std::string, LogicalExpression<HeroTypeID>> filters; std::map<std::string, LogicalExpression<HeroTypeID>> filters;
void initializeObject(CGHeroInstance * object) const override; void initializeObject(CGHeroInstance * object) const override;
void randomizeObject(CGHeroInstance * object, CRandomGenerator & rng) const override; void randomizeObject(CGHeroInstance * object, vstd::RNG & rng) const override;
void afterLoadFinalization() override; void afterLoadFinalization() override;
bool hasNameTextID() const override; bool hasNameTextID() const override;
@ -125,7 +125,7 @@ protected:
public: public:
CGMarket * createObject(IGameCallback * cb) const override; CGMarket * createObject(IGameCallback * cb) const override;
void initializeObject(CGMarket * object) const override; void initializeObject(CGMarket * object) const override;
void randomizeObject(CGMarket * object, CRandomGenerator & rng) const override; void randomizeObject(CGMarket * object, vstd::RNG & rng) const override;
}; };

View File

@ -74,7 +74,7 @@ void DwellingInstanceConstructor::initializeObject(CGDwelling * obj) const
} }
} }
void DwellingInstanceConstructor::randomizeObject(CGDwelling * dwelling, CRandomGenerator &rng) const void DwellingInstanceConstructor::randomizeObject(CGDwelling * dwelling, vstd::RNG &rng) const
{ {
JsonRandom randomizer(dwelling->cb); JsonRandom randomizer(dwelling->cb);

View File

@ -33,7 +33,7 @@ public:
bool hasNameTextID() const override; bool hasNameTextID() const override;
void initializeObject(CGDwelling * object) const override; void initializeObject(CGDwelling * object) const override;
void randomizeObject(CGDwelling * object, CRandomGenerator & rng) const override; void randomizeObject(CGDwelling * object, vstd::RNG & rng) const override;
bool isBannedForRandomDwelling() const; bool isBannedForRandomDwelling() const;
bool producesCreature(const CCreature * crea) const; bool producesCreature(const CCreature * crea) const;

View File

@ -44,7 +44,7 @@ CBank::CBank(IGameCallback *cb)
//must be instantiated in .cpp file for access to complete types of all member fields //must be instantiated in .cpp file for access to complete types of all member fields
CBank::~CBank() = default; CBank::~CBank() = default;
void CBank::initObj(CRandomGenerator & rand) void CBank::initObj(vstd::RNG & rand)
{ {
daycounter = 0; daycounter = 0;
resetDuration = 0; resetDuration = 0;
@ -117,7 +117,7 @@ void CBank::setPropertyDer (ObjProperty what, ObjPropertyID identifier)
} }
} }
void CBank::newTurn(CRandomGenerator & rand) const void CBank::newTurn(vstd::RNG & rand) const
{ {
if (bankConfig == nullptr) if (bankConfig == nullptr)
{ {

View File

@ -33,9 +33,9 @@ public:
void setConfig(const BankConfig & bc); void setConfig(const BankConfig & bc);
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
std::string getHoverText(PlayerColor player) const override; std::string getHoverText(PlayerColor player) const override;
void newTurn(CRandomGenerator & rand) const override; void newTurn(vstd::RNG & rand) const override;
bool wasVisited (PlayerColor player) const override; bool wasVisited (PlayerColor player) const override;
bool isCoastVisitable() const override; bool isCoastVisitable() const override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;

View File

@ -16,12 +16,14 @@
#include "../CConfigHandler.h" #include "../CConfigHandler.h"
#include "../GameSettings.h" #include "../GameSettings.h"
#include "../IGameCallback.h" #include "../IGameCallback.h"
#include "../gameState/CGameState.h"
#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../mapObjectConstructors/CObjectClassesHandler.h"
#include "../networkPacks/PacksForClient.h" #include "../networkPacks/PacksForClient.h"
#include "../networkPacks/PacksForClientBattle.h" #include "../networkPacks/PacksForClientBattle.h"
#include "../networkPacks/StackLocation.h" #include "../networkPacks/StackLocation.h"
#include "../serializer/JsonSerializeFormat.h" #include "../serializer/JsonSerializeFormat.h"
#include "../CRandomGenerator.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
@ -189,7 +191,7 @@ CreatureID CGCreature::getCreature() const
return CreatureID(getObjTypeIndex().getNum()); return CreatureID(getObjTypeIndex().getNum());
} }
void CGCreature::pickRandomObject(CRandomGenerator & rand) void CGCreature::pickRandomObject(vstd::RNG & rand)
{ {
switch(ID.toEnum()) switch(ID.toEnum())
{ {
@ -234,7 +236,7 @@ void CGCreature::pickRandomObject(CRandomGenerator & rand)
setType(ID, subID); setType(ID, subID);
} }
void CGCreature::initObj(CRandomGenerator & rand) void CGCreature::initObj(vstd::RNG & rand)
{ {
blockVisit = true; blockVisit = true;
switch(character) switch(character)
@ -274,7 +276,7 @@ void CGCreature::initObj(CRandomGenerator & rand)
refusedJoining = false; refusedJoining = false;
} }
void CGCreature::newTurn(CRandomGenerator & rand) const void CGCreature::newTurn(vstd::RNG & rand) const
{//Works only for stacks of single type of size up to 2 millions {//Works only for stacks of single type of size up to 2 millions
if (!notGrowingTeam) if (!notGrowingTeam)
{ {
@ -457,7 +459,7 @@ void CGCreature::fight( const CGHeroInstance *h ) const
const auto & upgrades = getStack(slotID).type->upgrades; const auto & upgrades = getStack(slotID).type->upgrades;
if(!upgrades.empty()) if(!upgrades.empty())
{ {
auto it = RandomGeneratorUtil::nextItem(upgrades, CRandomGenerator::getDefault()); auto it = RandomGeneratorUtil::nextItem(upgrades, cb->gameState()->getRandomGenerator());
cb->changeStackType(StackLocation(this, slotID), it->toCreature()); cb->changeStackType(StackLocation(this, slotID), it->toCreature());
} }
} }

View File

@ -45,9 +45,9 @@ public:
std::string getPopupText(PlayerColor player) const override; std::string getPopupText(PlayerColor player) const override;
std::string getPopupText(const CGHeroInstance * hero) const override; std::string getPopupText(const CGHeroInstance * hero) const override;
std::vector<Component> getPopupComponents(PlayerColor player) const override; std::vector<Component> getPopupComponents(PlayerColor player) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
void pickRandomObject(CRandomGenerator & rand) override; void pickRandomObject(vstd::RNG & rand) override;
void newTurn(CRandomGenerator & rand) const override; void newTurn(vstd::RNG & rand) const override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
CreatureID getCreature() const; CreatureID getCreature() const;

View File

@ -27,6 +27,8 @@
#include "../GameSettings.h" #include "../GameSettings.h"
#include "../CConfigHandler.h" #include "../CConfigHandler.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
void CGDwellingRandomizationInfo::serializeJson(JsonSerializeFormat & handler) void CGDwellingRandomizationInfo::serializeJson(JsonSerializeFormat & handler)
@ -50,7 +52,7 @@ CGDwelling::CGDwelling(IGameCallback *cb):
CGDwelling::~CGDwelling() = default; CGDwelling::~CGDwelling() = default;
FactionID CGDwelling::randomizeFaction(CRandomGenerator & rand) FactionID CGDwelling::randomizeFaction(vstd::RNG & rand)
{ {
if (ID == Obj::RANDOM_DWELLING_FACTION) if (ID == Obj::RANDOM_DWELLING_FACTION)
return FactionID(subID.getNum()); return FactionID(subID.getNum());
@ -108,7 +110,7 @@ FactionID CGDwelling::randomizeFaction(CRandomGenerator & rand)
return *RandomGeneratorUtil::nextItem(potentialPicks, rand); return *RandomGeneratorUtil::nextItem(potentialPicks, rand);
} }
int CGDwelling::randomizeLevel(CRandomGenerator & rand) int CGDwelling::randomizeLevel(vstd::RNG & rand)
{ {
if (ID == Obj::RANDOM_DWELLING_LVL) if (ID == Obj::RANDOM_DWELLING_LVL)
return subID.getNum(); return subID.getNum();
@ -125,7 +127,7 @@ int CGDwelling::randomizeLevel(CRandomGenerator & rand)
return rand.nextInt(randomizationInfo->minLevel, randomizationInfo->maxLevel) - 1; return rand.nextInt(randomizationInfo->minLevel, randomizationInfo->maxLevel) - 1;
} }
void CGDwelling::pickRandomObject(CRandomGenerator & rand) void CGDwelling::pickRandomObject(vstd::RNG & rand)
{ {
if (ID == Obj::RANDOM_DWELLING || ID == Obj::RANDOM_DWELLING_LVL || ID == Obj::RANDOM_DWELLING_FACTION) if (ID == Obj::RANDOM_DWELLING || ID == Obj::RANDOM_DWELLING_LVL || ID == Obj::RANDOM_DWELLING_FACTION)
{ {
@ -172,7 +174,7 @@ void CGDwelling::pickRandomObject(CRandomGenerator & rand)
} }
} }
void CGDwelling::initObj(CRandomGenerator & rand) void CGDwelling::initObj(vstd::RNG & rand)
{ {
switch(ID.toEnum()) switch(ID.toEnum())
{ {
@ -298,7 +300,7 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
cb->showBlockingDialog(&bd); cb->showBlockingDialog(&bd);
} }
void CGDwelling::newTurn(CRandomGenerator & rand) const void CGDwelling::newTurn(vstd::RNG & rand) const
{ {
if(cb->getDate(Date::DAY_OF_WEEK) != 1) //not first day of week if(cb->getDate(Date::DAY_OF_WEEK) != 1) //not first day of week
return; return;

View File

@ -45,13 +45,13 @@ protected:
void serializeJsonOptions(JsonSerializeFormat & handler) override; void serializeJsonOptions(JsonSerializeFormat & handler) override;
private: private:
FactionID randomizeFaction(CRandomGenerator & rand); FactionID randomizeFaction(vstd::RNG & rand);
int randomizeLevel(CRandomGenerator & rand); int randomizeLevel(vstd::RNG & rand);
void pickRandomObject(CRandomGenerator & rand) override; void pickRandomObject(vstd::RNG & rand) override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void newTurn(CRandomGenerator & rand) const override; void newTurn(vstd::RNG & rand) const override;
void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override; void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;

View File

@ -313,13 +313,13 @@ void CGHeroInstance::setHeroType(HeroTypeID heroType)
subID = heroType; subID = heroType;
} }
void CGHeroInstance::initHero(CRandomGenerator & rand, const HeroTypeID & SUBID) void CGHeroInstance::initHero(vstd::RNG & rand, const HeroTypeID & SUBID)
{ {
subID = SUBID.getNum(); subID = SUBID.getNum();
initHero(rand); initHero(rand);
} }
void CGHeroInstance::initHero(CRandomGenerator & rand) void CGHeroInstance::initHero(vstd::RNG & rand)
{ {
assert(validTypes(true)); assert(validTypes(true));
if(!type) if(!type)
@ -422,7 +422,7 @@ void CGHeroInstance::initHero(CRandomGenerator & rand)
mana = manaLimit(); //after all bonuses are taken into account, make sure this line is the last one mana = manaLimit(); //after all bonuses are taken into account, make sure this line is the last one
} }
void CGHeroInstance::initArmy(CRandomGenerator & rand, IArmyDescriptor * dst) void CGHeroInstance::initArmy(vstd::RNG & rand, IArmyDescriptor * dst)
{ {
if(!dst) if(!dst)
dst = this; dst = this;
@ -589,7 +589,7 @@ void CGHeroInstance::SecondarySkillsInfo::resetWisdomCounter()
wisdomCounter = 0; wisdomCounter = 0;
} }
void CGHeroInstance::pickRandomObject(CRandomGenerator & rand) void CGHeroInstance::pickRandomObject(vstd::RNG & rand)
{ {
assert(ID == Obj::HERO || ID == Obj::PRISON || ID == Obj::RANDOM_HERO); assert(ID == Obj::HERO || ID == Obj::PRISON || ID == Obj::RANDOM_HERO);
@ -614,7 +614,7 @@ void CGHeroInstance::pickRandomObject(CRandomGenerator & rand)
this->subID = oldSubID; this->subID = oldSubID;
} }
void CGHeroInstance::initObj(CRandomGenerator & rand) void CGHeroInstance::initObj(vstd::RNG & rand)
{ {
} }
@ -959,7 +959,7 @@ CStackBasicDescriptor CGHeroInstance::calculateNecromancy (const BattleResult &b
* @param raisedStack Pair where the first element represents ID of the raised creature * @param raisedStack Pair where the first element represents ID of the raised creature
* and the second element the amount. * and the second element the amount.
*/ */
void CGHeroInstance::showNecromancyDialog(const CStackBasicDescriptor &raisedStack, CRandomGenerator & rand) const void CGHeroInstance::showNecromancyDialog(const CStackBasicDescriptor &raisedStack, vstd::RNG & rand) const
{ {
InfoWindow iw; InfoWindow iw;
iw.type = EInfoWindowMode::AUTO; iw.type = EInfoWindowMode::AUTO;
@ -1068,7 +1068,7 @@ EAlignment CGHeroInstance::getAlignment() const
return type->heroClass->getAlignment(); return type->heroClass->getAlignment();
} }
void CGHeroInstance::initExp(CRandomGenerator & rand) void CGHeroInstance::initExp(vstd::RNG & rand)
{ {
exp = rand.nextInt(40, 89); exp = rand.nextInt(40, 89);
} }
@ -1286,7 +1286,7 @@ ArtBearer::ArtBearer CGHeroInstance::bearerType() const
return ArtBearer::HERO; return ArtBearer::HERO;
} }
std::vector<SecondarySkill> CGHeroInstance::getLevelUpProposedSecondarySkills(CRandomGenerator & rand) const std::vector<SecondarySkill> CGHeroInstance::getLevelUpProposedSecondarySkills(vstd::RNG & rand) const
{ {
auto getObligatorySkills = [](CSkill::Obligatory obl){ auto getObligatorySkills = [](CSkill::Obligatory obl){
std::set<SecondarySkill> obligatory; std::set<SecondarySkill> obligatory;
@ -1365,7 +1365,7 @@ std::vector<SecondarySkill> CGHeroInstance::getLevelUpProposedSecondarySkills(CR
return skills; return skills;
} }
PrimarySkill CGHeroInstance::nextPrimarySkill(CRandomGenerator & rand) const PrimarySkill CGHeroInstance::nextPrimarySkill(vstd::RNG & rand) const
{ {
assert(gainsLevel()); assert(gainsLevel());
const auto isLowLevelHero = level < GameConstants::HERO_HIGH_LEVEL; const auto isLowLevelHero = level < GameConstants::HERO_HIGH_LEVEL;
@ -1381,7 +1381,7 @@ PrimarySkill CGHeroInstance::nextPrimarySkill(CRandomGenerator & rand) const
return static_cast<PrimarySkill>(RandomGeneratorUtil::nextItemWeighted(skillChances, rand)); return static_cast<PrimarySkill>(RandomGeneratorUtil::nextItemWeighted(skillChances, rand));
} }
std::optional<SecondarySkill> CGHeroInstance::nextSecondarySkill(CRandomGenerator & rand) const std::optional<SecondarySkill> CGHeroInstance::nextSecondarySkill(vstd::RNG & rand) const
{ {
assert(gainsLevel()); assert(gainsLevel());
@ -1469,7 +1469,7 @@ void CGHeroInstance::levelUp(const std::vector<SecondarySkill> & skills)
treeHasChanged(); treeHasChanged();
} }
void CGHeroInstance::levelUpAutomatically(CRandomGenerator & rand) void CGHeroInstance::levelUpAutomatically(vstd::RNG & rand)
{ {
while(gainsLevel()) while(gainsLevel())
{ {

View File

@ -187,13 +187,13 @@ public:
bool gainsLevel() const; bool gainsLevel() const;
/// Returns the next primary skill on level up. Can only be called if hero can gain a level up. /// Returns the next primary skill on level up. Can only be called if hero can gain a level up.
PrimarySkill nextPrimarySkill(CRandomGenerator & rand) const; PrimarySkill nextPrimarySkill(vstd::RNG & rand) const;
/// Returns the next secondary skill randomly on level up. Can only be called if hero can gain a level up. /// Returns the next secondary skill randomly on level up. Can only be called if hero can gain a level up.
std::optional<SecondarySkill> nextSecondarySkill(CRandomGenerator & rand) const; std::optional<SecondarySkill> nextSecondarySkill(vstd::RNG & rand) const;
/// Gets 0, 1 or 2 secondary skills which are proposed on hero level up. /// Gets 0, 1 or 2 secondary skills which are proposed on hero level up.
std::vector<SecondarySkill> getLevelUpProposedSecondarySkills(CRandomGenerator & rand) const; std::vector<SecondarySkill> getLevelUpProposedSecondarySkills(vstd::RNG & rand) const;
ui8 getSecSkillLevel(const SecondarySkill & skill) const; //0 - no skill ui8 getSecSkillLevel(const SecondarySkill & skill) const; //0 - no skill
@ -225,7 +225,7 @@ public:
TExpType calculateXp(TExpType exp) const; //apply learning skill TExpType calculateXp(TExpType exp) const; //apply learning skill
CStackBasicDescriptor calculateNecromancy (const BattleResult &battleResult) const; CStackBasicDescriptor calculateNecromancy (const BattleResult &battleResult) const;
void showNecromancyDialog(const CStackBasicDescriptor &raisedStack, CRandomGenerator & rand) const; void showNecromancyDialog(const CStackBasicDescriptor &raisedStack, vstd::RNG & rand) const;
EDiggingStatus diggingStatus() const; EDiggingStatus diggingStatus() const;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -233,13 +233,13 @@ public:
HeroTypeID getHeroType() const; HeroTypeID getHeroType() const;
void setHeroType(HeroTypeID type); void setHeroType(HeroTypeID type);
void initHero(CRandomGenerator & rand); void initHero(vstd::RNG & rand);
void initHero(CRandomGenerator & rand, const HeroTypeID & SUBID); void initHero(vstd::RNG & rand, const HeroTypeID & SUBID);
ArtPlacementMap putArtifact(ArtifactPosition pos, CArtifactInstance * art) override; ArtPlacementMap putArtifact(ArtifactPosition pos, CArtifactInstance * art) override;
void removeArtifact(ArtifactPosition pos) override; void removeArtifact(ArtifactPosition pos) override;
void initExp(CRandomGenerator & rand); void initExp(vstd::RNG & rand);
void initArmy(CRandomGenerator & rand, IArmyDescriptor *dst = nullptr); void initArmy(vstd::RNG & rand, IArmyDescriptor *dst = nullptr);
void pushPrimSkill(PrimarySkill which, int val); void pushPrimSkill(PrimarySkill which, int val);
ui8 maxlevelsToMagicSchool() const; ui8 maxlevelsToMagicSchool() const;
ui8 maxlevelsToWisdom() const; ui8 maxlevelsToWisdom() const;
@ -293,8 +293,8 @@ public:
void boatDeserializationFix(); void boatDeserializationFix();
void deserializationFix(); void deserializationFix();
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
void pickRandomObject(CRandomGenerator & rand) override; void pickRandomObject(vstd::RNG & rand) override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
std::string getObjectName() const override; std::string getObjectName() const override;
@ -318,7 +318,7 @@ protected:
void serializeJsonOptions(JsonSerializeFormat & handler) override; void serializeJsonOptions(JsonSerializeFormat & handler) override;
private: private:
void levelUpAutomatically(CRandomGenerator & rand); void levelUpAutomatically(vstd::RNG & rand);
public: public:
std::string getHeroTypeName() const; std::string getHeroTypeName() const;

View File

@ -23,7 +23,7 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
void CGMarket::initObj(CRandomGenerator & rand) void CGMarket::initObj(vstd::RNG & rand)
{ {
getObjectHandler()->configureObject(this, rand); getObjectHandler()->configureObject(this, rand);
} }
@ -80,7 +80,7 @@ std::vector<TradeItemBuy> CGBlackMarket::availableItemsIds(EMarketMode mode) con
} }
} }
void CGBlackMarket::newTurn(CRandomGenerator & rand) const void CGBlackMarket::newTurn(vstd::RNG & rand) const
{ {
int resetPeriod = VLC->settings()->getInteger(EGameSettings::MARKETS_BLACK_MARKET_RESTOCK_PERIOD); int resetPeriod = VLC->settings()->getInteger(EGameSettings::MARKETS_BLACK_MARKET_RESTOCK_PERIOD);

View File

@ -29,7 +29,7 @@ public:
CGMarket(IGameCallback *cb); CGMarket(IGameCallback *cb);
///IObjectInterface ///IObjectInterface
void onHeroVisit(const CGHeroInstance * h) const override; //open trading window void onHeroVisit(const CGHeroInstance * h) const override; //open trading window
void initObj(CRandomGenerator & rand) override;//set skills for trade void initObj(vstd::RNG & rand) override;//set skills for trade
///IMarket ///IMarket
int getMarketEfficiency() const override; int getMarketEfficiency() const override;
@ -54,7 +54,7 @@ public:
std::vector<const CArtifact *> artifacts; //available artifacts std::vector<const CArtifact *> artifacts; //available artifacts
void newTurn(CRandomGenerator & rand) const override; //reset artifacts for black market every month void newTurn(vstd::RNG & rand) const override; //reset artifacts for black market every month
std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override; std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;
template <typename Handler> void serialize(Handler &h) template <typename Handler> void serialize(Handler &h)

View File

@ -25,6 +25,8 @@
#include "../networkPacks/PacksForClient.h" #include "../networkPacks/PacksForClient.h"
#include "../serializer/JsonSerializeFormat.h" #include "../serializer/JsonSerializeFormat.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
//TODO: remove constructor //TODO: remove constructor
@ -164,12 +166,12 @@ void CGObjectInstance::setType(MapObjectID newID, MapObjectSubID newSubID)
cb->gameState()->map->addBlockVisTiles(this); cb->gameState()->map->addBlockVisTiles(this);
} }
void CGObjectInstance::pickRandomObject(CRandomGenerator & rand) void CGObjectInstance::pickRandomObject(vstd::RNG & rand)
{ {
// no-op // no-op
} }
void CGObjectInstance::initObj(CRandomGenerator & rand) void CGObjectInstance::initObj(vstd::RNG & rand)
{ {
// no-op // no-op
} }
@ -232,7 +234,7 @@ std::string CGObjectInstance::getObjectName() const
return VLC->objtypeh->getObjectName(ID, subID); return VLC->objtypeh->getObjectName(ID, subID);
} }
std::optional<AudioPath> CGObjectInstance::getAmbientSound() const std::optional<AudioPath> CGObjectInstance::getAmbientSound(vstd::RNG & rng) const
{ {
const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).ambient; const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).ambient;
if(!sounds.empty()) if(!sounds.empty())
@ -241,20 +243,20 @@ std::optional<AudioPath> CGObjectInstance::getAmbientSound() const
return std::nullopt; return std::nullopt;
} }
std::optional<AudioPath> CGObjectInstance::getVisitSound() const std::optional<AudioPath> CGObjectInstance::getVisitSound(vstd::RNG & rng) const
{ {
const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).visit; const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).visit;
if(!sounds.empty()) if(!sounds.empty())
return *RandomGeneratorUtil::nextItem(sounds, CRandomGenerator::getDefault()); return *RandomGeneratorUtil::nextItem(sounds, rng);
return std::nullopt; return std::nullopt;
} }
std::optional<AudioPath> CGObjectInstance::getRemovalSound() const std::optional<AudioPath> CGObjectInstance::getRemovalSound(vstd::RNG & rng) const
{ {
const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).removal; const auto & sounds = VLC->objtypeh->getObjectSounds(ID, subID).removal;
if(!sounds.empty()) if(!sounds.empty())
return *RandomGeneratorUtil::nextItem(sounds, CRandomGenerator::getDefault()); return *RandomGeneratorUtil::nextItem(sounds, rng);
return std::nullopt; return std::nullopt;
} }

View File

@ -97,9 +97,9 @@ public:
virtual bool isTile2Terrain() const { return false; } virtual bool isTile2Terrain() const { return false; }
std::optional<AudioPath> getAmbientSound() const; std::optional<AudioPath> getAmbientSound(vstd::RNG & rng) const;
std::optional<AudioPath> getVisitSound() const; std::optional<AudioPath> getVisitSound(vstd::RNG & rng) const;
std::optional<AudioPath> getRemovalSound() const; std::optional<AudioPath> getRemovalSound(vstd::RNG & rng) const;
TObjectTypeHandler getObjectHandler() const; TObjectTypeHandler getObjectHandler() const;
@ -128,8 +128,8 @@ public:
/** OVERRIDES OF IObjectInterface **/ /** OVERRIDES OF IObjectInterface **/
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
void pickRandomObject(CRandomGenerator & rand) override; void pickRandomObject(vstd::RNG & rand) override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
/// method for synchronous update. Note: For new properties classes should override setPropertyDer instead /// method for synchronous update. Note: For new properties classes should override setPropertyDer instead
void setProperty(ObjProperty what, ObjPropertyID identifier) final; void setProperty(ObjProperty what, ObjPropertyID identifier) final;

View File

@ -41,7 +41,7 @@ void CGPandoraBox::init()
} }
} }
void CGPandoraBox::initObj(CRandomGenerator & rand) void CGPandoraBox::initObj(vstd::RNG & rand)
{ {
init(); init();

View File

@ -23,7 +23,7 @@ public:
MetaString message; MetaString message;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;

View File

@ -17,6 +17,8 @@
#include "../mapObjects/CGHeroInstance.h" #include "../mapObjects/CGHeroInstance.h"
#include "../networkPacks/PacksForClient.h" #include "../networkPacks/PacksForClient.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
CGTownBuilding::CGTownBuilding(IGameCallback * cb) CGTownBuilding::CGTownBuilding(IGameCallback * cb)
@ -314,7 +316,7 @@ CTownRewardableBuilding::CTownRewardableBuilding(IGameCallback *cb)
: CGTownBuilding(cb) : CGTownBuilding(cb)
{} {}
CTownRewardableBuilding::CTownRewardableBuilding(const BuildingID & index, BuildingSubID::EBuildingSubID subId, CGTownInstance * cgTown, CRandomGenerator & rand) CTownRewardableBuilding::CTownRewardableBuilding(const BuildingID & index, BuildingSubID::EBuildingSubID subId, CGTownInstance * cgTown, vstd::RNG & rand)
: CGTownBuilding(cgTown) : CGTownBuilding(cgTown)
{ {
bID = index; bID = index;
@ -323,7 +325,7 @@ CTownRewardableBuilding::CTownRewardableBuilding(const BuildingID & index, Build
initObj(rand); initObj(rand);
} }
void CTownRewardableBuilding::initObj(CRandomGenerator & rand) void CTownRewardableBuilding::initObj(vstd::RNG & rand)
{ {
assert(town && town->town); assert(town && town->town);
@ -340,7 +342,7 @@ void CTownRewardableBuilding::initObj(CRandomGenerator & rand)
} }
} }
void CTownRewardableBuilding::newTurn(CRandomGenerator & rand) const void CTownRewardableBuilding::newTurn(vstd::RNG & rand) const
{ {
if (configuration.resetParameters.period != 0 && cb->getDate(Date::DAY) > 1 && ((cb->getDate(Date::DAY)-1) % configuration.resetParameters.period) == 0) if (configuration.resetParameters.period != 0 && cb->getDate(Date::DAY) > 1 && ((cb->getDate(Date::DAY)-1) % configuration.resetParameters.period) == 0)
{ {

View File

@ -123,17 +123,17 @@ public:
void setProperty(ObjProperty what, ObjPropertyID identifier) override; void setProperty(ObjProperty what, ObjPropertyID identifier) override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void newTurn(CRandomGenerator & rand) const override; void newTurn(vstd::RNG & rand) const override;
/// gives second part of reward after hero level-ups for proper granting of spells/mana /// gives second part of reward after hero level-ups for proper granting of spells/mana
void heroLevelUpDone(const CGHeroInstance *hero) const override; void heroLevelUpDone(const CGHeroInstance *hero) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
/// applies player selection of reward /// applies player selection of reward
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
CTownRewardableBuilding(const BuildingID & index, BuildingSubID::EBuildingSubID subId, CGTownInstance * town, CRandomGenerator & rand); CTownRewardableBuilding(const BuildingID & index, BuildingSubID::EBuildingSubID subId, CGTownInstance * town, vstd::RNG & rand);
CTownRewardableBuilding(IGameCallback *cb); CTownRewardableBuilding(IGameCallback *cb);
template <typename Handler> void serialize(Handler &h) template <typename Handler> void serialize(Handler &h)

View File

@ -31,6 +31,8 @@
#include "../networkPacks/PacksForClientBattle.h" #include "../networkPacks/PacksForClientBattle.h"
#include "../serializer/JsonSerializeFormat.h" #include "../serializer/JsonSerializeFormat.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
int CGTownInstance::getSightRadius() const //returns sight distance int CGTownInstance::getSightRadius() const //returns sight distance
@ -379,7 +381,7 @@ bool CGTownInstance::isBonusingBuildingAdded(BuildingID bid) const
return present != bonusingBuildings.end(); return present != bonusingBuildings.end();
} }
void CGTownInstance::addTownBonuses(CRandomGenerator & rand) void CGTownInstance::addTownBonuses(vstd::RNG & rand)
{ {
for(const auto & kvp : town->buildings) for(const auto & kvp : town->buildings)
{ {
@ -461,7 +463,7 @@ void CGTownInstance::deleteTownBonus(BuildingID bid)
delete freeIt; delete freeIt;
} }
FactionID CGTownInstance::randomizeFaction(CRandomGenerator & rand) FactionID CGTownInstance::randomizeFaction(vstd::RNG & rand)
{ {
if(getOwner().isValidPlayer()) if(getOwner().isValidPlayer())
return cb->gameState()->scenarioOps->getIthPlayersSettings(getOwner()).castle; return cb->gameState()->scenarioOps->getIthPlayersSettings(getOwner()).castle;
@ -479,7 +481,7 @@ FactionID CGTownInstance::randomizeFaction(CRandomGenerator & rand)
return *RandomGeneratorUtil::nextItem(potentialPicks, rand); return *RandomGeneratorUtil::nextItem(potentialPicks, rand);
} }
void CGTownInstance::pickRandomObject(CRandomGenerator & rand) void CGTownInstance::pickRandomObject(vstd::RNG & rand)
{ {
assert(ID == MapObjectID::TOWN || ID == MapObjectID::RANDOM_TOWN); assert(ID == MapObjectID::TOWN || ID == MapObjectID::RANDOM_TOWN);
if (ID == MapObjectID::RANDOM_TOWN) if (ID == MapObjectID::RANDOM_TOWN)
@ -495,7 +497,7 @@ void CGTownInstance::pickRandomObject(CRandomGenerator & rand)
updateAppearance(); updateAppearance();
} }
void CGTownInstance::initObj(CRandomGenerator & rand) ///initialize town structures void CGTownInstance::initObj(vstd::RNG & rand) ///initialize town structures
{ {
blockVisit = true; blockVisit = true;
@ -521,7 +523,7 @@ void CGTownInstance::initObj(CRandomGenerator & rand) ///initialize town structu
updateAppearance(); updateAppearance();
} }
void CGTownInstance::newTurn(CRandomGenerator & rand) const void CGTownInstance::newTurn(vstd::RNG & rand) const
{ {
if (cb->getDate(Date::DAY_OF_WEEK) == 1) //reset on new week if (cb->getDate(Date::DAY_OF_WEEK) == 1) //reset on new week
{ {

View File

@ -201,11 +201,11 @@ public:
virtual ~CGTownInstance(); virtual ~CGTownInstance();
///IObjectInterface overrides ///IObjectInterface overrides
void newTurn(CRandomGenerator & rand) const override; void newTurn(vstd::RNG & rand) const override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void onHeroLeave(const CGHeroInstance * h) const override; void onHeroLeave(const CGHeroInstance * h) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
void pickRandomObject(CRandomGenerator & rand) override; void pickRandomObject(vstd::RNG & rand) override;
void battleFinished(const CGHeroInstance * hero, const BattleResult & result) const override; void battleFinished(const CGHeroInstance * hero, const BattleResult & result) const override;
std::string getObjectName() const override; std::string getObjectName() const override;
@ -224,14 +224,14 @@ protected:
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
private: private:
FactionID randomizeFaction(CRandomGenerator & rand); FactionID randomizeFaction(vstd::RNG & rand);
void setOwner(const PlayerColor & owner) const; void setOwner(const PlayerColor & owner) const;
void onTownCaptured(const PlayerColor & winner) const; void onTownCaptured(const PlayerColor & winner) const;
int getDwellingBonus(const std::vector<CreatureID>& creatureIds, const std::vector<ConstTransitivePtr<CGDwelling> >& dwellings) const; int getDwellingBonus(const std::vector<CreatureID>& creatureIds, const std::vector<ConstTransitivePtr<CGDwelling> >& dwellings) const;
bool townEnvisagesBuilding(BuildingSubID::EBuildingSubID bid) const; bool townEnvisagesBuilding(BuildingSubID::EBuildingSubID bid) const;
bool isBonusingBuildingAdded(BuildingID bid) const; bool isBonusingBuildingAdded(BuildingID bid) const;
void initOverriddenBids(); void initOverriddenBids();
void addTownBonuses(CRandomGenerator & rand); void addTownBonuses(vstd::RNG & rand);
}; };
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -31,7 +31,8 @@
#include "../modding/ModUtility.h" #include "../modding/ModUtility.h"
#include "../networkPacks/PacksForClient.h" #include "../networkPacks/PacksForClient.h"
#include "../spells/CSpellHandler.h" #include "../spells/CSpellHandler.h"
#include "../CRandomGenerator.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
@ -441,7 +442,7 @@ void CGSeerHut::setObjToKill()
} }
} }
void CGSeerHut::init(CRandomGenerator & rand) void CGSeerHut::init(vstd::RNG & rand)
{ {
auto names = VLC->generaltexth->findStringsWithPrefix("core.seerhut.names"); auto names = VLC->generaltexth->findStringsWithPrefix("core.seerhut.names");
@ -455,7 +456,7 @@ void CGSeerHut::init(CRandomGenerator & rand)
configuration.selectMode = Rewardable::ESelectMode::SELECT_PLAYER; configuration.selectMode = Rewardable::ESelectMode::SELECT_PLAYER;
} }
void CGSeerHut::initObj(CRandomGenerator & rand) void CGSeerHut::initObj(vstd::RNG & rand)
{ {
init(rand); init(rand);
@ -562,7 +563,7 @@ void CGSeerHut::setPropertyDer(ObjProperty what, ObjPropertyID identifier)
} }
} }
void CGSeerHut::newTurn(CRandomGenerator & rand) const void CGSeerHut::newTurn(vstd::RNG & rand) const
{ {
CRewardableObject::newTurn(rand); CRewardableObject::newTurn(rand);
if(quest->lastDay >= 0 && quest->lastDay <= cb->getDate() - 1) //time is up if(quest->lastDay >= 0 && quest->lastDay <= cb->getDate() - 1) //time is up
@ -750,7 +751,7 @@ void CGSeerHut::serializeJsonOptions(JsonSerializeFormat & handler)
} }
} }
void CGQuestGuard::init(CRandomGenerator & rand) void CGQuestGuard::init(vstd::RNG & rand)
{ {
blockVisit = true; blockVisit = true;
quest->textOption = rand.nextInt(3, 5); quest->textOption = rand.nextInt(3, 5);
@ -818,7 +819,7 @@ void CGKeymasterTent::onHeroVisit( const CGHeroInstance * h ) const
h->showInfoDialog(txt_id); h->showInfoDialog(txt_id);
} }
void CGBorderGuard::initObj(CRandomGenerator & rand) void CGBorderGuard::initObj(vstd::RNG & rand)
{ {
blockVisit = true; blockVisit = true;
} }

View File

@ -141,19 +141,19 @@ public:
std::string seerName; std::string seerName;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
std::string getHoverText(PlayerColor player) const override; std::string getHoverText(PlayerColor player) const override;
std::string getHoverText(const CGHeroInstance * hero) const override; std::string getHoverText(const CGHeroInstance * hero) const override;
std::string getPopupText(PlayerColor player) const override; std::string getPopupText(PlayerColor player) const override;
std::string getPopupText(const CGHeroInstance * hero) const override; std::string getPopupText(const CGHeroInstance * hero) const override;
std::vector<Component> getPopupComponents(PlayerColor player) const override; std::vector<Component> getPopupComponents(PlayerColor player) const override;
std::vector<Component> getPopupComponents(const CGHeroInstance * hero) const override; std::vector<Component> getPopupComponents(const CGHeroInstance * hero) const override;
void newTurn(CRandomGenerator & rand) const override; void newTurn(vstd::RNG & rand) const override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
void getVisitText (MetaString &text, std::vector<Component> &components, bool FirstVisit, const CGHeroInstance * h = nullptr) const override; void getVisitText (MetaString &text, std::vector<Component> &components, bool FirstVisit, const CGHeroInstance * h = nullptr) const override;
virtual void init(CRandomGenerator & rand); virtual void init(vstd::RNG & rand);
int checkDirection() const; //calculates the region of map where monster is placed int checkDirection() const; //calculates the region of map where monster is placed
void setObjToKill(); //remember creatures / heroes to kill after they are initialized void setObjToKill(); //remember creatures / heroes to kill after they are initialized
const CGHeroInstance *getHeroToKill(bool allowNull) const; const CGHeroInstance *getHeroToKill(bool allowNull) const;
@ -179,7 +179,7 @@ class DLL_LINKAGE CGQuestGuard : public CGSeerHut
public: public:
using CGSeerHut::CGSeerHut; using CGSeerHut::CGSeerHut;
void init(CRandomGenerator & rand) override; void init(vstd::RNG & rand) override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
bool passableFor(PlayerColor color) const override; bool passableFor(PlayerColor color) const override;
@ -227,7 +227,7 @@ class DLL_LINKAGE CGBorderGuard : public CGKeys, public IQuestObject
public: public:
using CGKeys::CGKeys; using CGKeys::CGKeys;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;

View File

@ -20,6 +20,8 @@
#include "../networkPacks/PacksForClient.h" #include "../networkPacks/PacksForClient.h"
#include "../serializer/JsonSerializeFormat.h" #include "../serializer/JsonSerializeFormat.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
void CRewardableObject::grantRewardWithMessage(const CGHeroInstance * contextHero, int index, bool markAsVisit) const void CRewardableObject::grantRewardWithMessage(const CGHeroInstance * contextHero, int index, bool markAsVisit) const
@ -387,7 +389,7 @@ void CRewardableObject::setPropertyDer(ObjProperty what, ObjPropertyID identifie
} }
} }
void CRewardableObject::newTurn(CRandomGenerator & rand) const void CRewardableObject::newTurn(vstd::RNG & rand) const
{ {
if (configuration.resetParameters.period != 0 && cb->getDate(Date::DAY) > 1 && ((cb->getDate(Date::DAY)-1) % configuration.resetParameters.period) == 0) if (configuration.resetParameters.period != 0 && cb->getDate(Date::DAY) > 1 && ((cb->getDate(Date::DAY)-1) % configuration.resetParameters.period) == 0)
{ {
@ -404,7 +406,7 @@ void CRewardableObject::newTurn(CRandomGenerator & rand) const
} }
} }
void CRewardableObject::initObj(CRandomGenerator & rand) void CRewardableObject::initObj(vstd::RNG & rand)
{ {
getObjectHandler()->configureObject(this, rand); getObjectHandler()->configureObject(this, rand);
} }

View File

@ -57,7 +57,7 @@ public:
void onHeroVisit(const CGHeroInstance *h) const override; void onHeroVisit(const CGHeroInstance *h) const override;
///possibly resets object state ///possibly resets object state
void newTurn(CRandomGenerator & rand) const override; void newTurn(vstd::RNG & rand) const override;
/// gives second part of reward after hero level-ups for proper granting of spells/mana /// gives second part of reward after hero level-ups for proper granting of spells/mana
void heroLevelUpDone(const CGHeroInstance *hero) const override; void heroLevelUpDone(const CGHeroInstance *hero) const override;
@ -65,7 +65,7 @@ public:
/// applies player selection of reward /// applies player selection of reward
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override; void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;

View File

@ -38,13 +38,13 @@ void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const
void IObjectInterface::onHeroLeave(const CGHeroInstance * h) const void IObjectInterface::onHeroLeave(const CGHeroInstance * h) const
{} {}
void IObjectInterface::newTurn(CRandomGenerator & rand) const void IObjectInterface::newTurn(vstd::RNG & rand) const
{} {}
void IObjectInterface::initObj(CRandomGenerator & rand) void IObjectInterface::initObj(vstd::RNG & rand)
{} {}
void IObjectInterface::pickRandomObject(CRandomGenerator & rand) void IObjectInterface::pickRandomObject(vstd::RNG & rand)
{} {}
void IObjectInterface::setProperty(ObjProperty what, ObjPropertyID identifier) void IObjectInterface::setProperty(ObjProperty what, ObjPropertyID identifier)

View File

@ -17,11 +17,15 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
struct BattleResult; struct BattleResult;
struct UpgradeInfo; struct UpgradeInfo;
class BoatId; class BoatId;
class CGObjectInstance; class CGObjectInstance;
class CRandomGenerator;
class CStackInstance; class CStackInstance;
class CGHeroInstance; class CGHeroInstance;
class IGameCallback; class IGameCallback;
@ -46,9 +50,9 @@ public:
virtual void onHeroVisit(const CGHeroInstance * h) const; virtual void onHeroVisit(const CGHeroInstance * h) const;
virtual void onHeroLeave(const CGHeroInstance * h) const; virtual void onHeroLeave(const CGHeroInstance * h) const;
virtual void newTurn(CRandomGenerator & rand) const; virtual void newTurn(vstd::RNG & rand) const;
virtual void initObj(CRandomGenerator & rand); //synchr virtual void initObj(vstd::RNG & rand); //synchr
virtual void pickRandomObject(CRandomGenerator & rand); virtual void pickRandomObject(vstd::RNG & rand);
virtual void setProperty(ObjProperty what, ObjPropertyID identifier);//synchr virtual void setProperty(ObjProperty what, ObjPropertyID identifier);//synchr
//Called when queries created DURING HERO VISIT are resolved //Called when queries created DURING HERO VISIT are resolved

View File

@ -32,6 +32,8 @@
#include "../networkPacks/PacksForClientBattle.h" #include "../networkPacks/PacksForClientBattle.h"
#include "../networkPacks/StackLocation.h" #include "../networkPacks/StackLocation.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
///helpers ///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) if(cb->getDate() == 1)
return; return;
@ -104,7 +106,7 @@ void CGMine::newTurn(CRandomGenerator & rand) const
cb->giveResource(tempOwner, producedResource, producedQuantity); cb->giveResource(tempOwner, producedResource, producedQuantity);
} }
void CGMine::initObj(CRandomGenerator & rand) void CGMine::initObj(vstd::RNG & rand)
{ {
if(isAbandoned()) if(isAbandoned())
{ {
@ -254,7 +256,7 @@ std::string CGResource::getHoverText(PlayerColor player) const
return VLC->generaltexth->restypes[resourceID().getNum()]; 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); 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; blockVisit = true;
@ -327,7 +329,7 @@ void CGResource::collectRes(const PlayerColor & player) const
sii.text.replaceName(resourceID()); sii.text.replaceName(resourceID());
} }
sii.components.emplace_back(ComponentType::RESOURCE, resourceID(), amount); 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->showInfoDialog(&sii);
cb->removeObject(this, player); cb->removeObject(this, player);
} }
@ -395,7 +397,7 @@ ObjectInstanceID CGTeleport::getRandomExit(const CGHeroInstance * h) const
{ {
auto passableExits = getPassableExits(cb->gameState(), h, getAllExits(true)); auto passableExits = getPassableExits(cb->gameState(), h, getAllExits(true));
if(!passableExits.empty()) if(!passableExits.empty())
return *RandomGeneratorUtil::nextItem(passableExits, CRandomGenerator::getDefault()); return *RandomGeneratorUtil::nextItem(passableExits, cb->gameState()->getRandomGenerator());
return ObjectInstanceID(); return ObjectInstanceID();
} }
@ -530,7 +532,7 @@ void CGMonolith::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer,
cb->moveHero(hero->id, hero->convertFromVisitablePos(dPos), EMovementMode::MONOLITH); cb->moveHero(hero->id, hero->convertFromVisitablePos(dPos), EMovementMode::MONOLITH);
} }
void CGMonolith::initObj(CRandomGenerator & rand) void CGMonolith::initObj(vstd::RNG & rand)
{ {
std::vector<Obj> IDs; std::vector<Obj> IDs;
IDs.push_back(ID); IDs.push_back(ID);
@ -575,7 +577,7 @@ void CGSubterraneanGate::onHeroVisit( const CGHeroInstance * h ) const
cb->showTeleportDialog(&td); cb->showTeleportDialog(&td);
} }
void CGSubterraneanGate::initObj(CRandomGenerator & rand) void CGSubterraneanGate::initObj(vstd::RNG & rand)
{ {
type = BOTH; type = BOTH;
} }
@ -703,7 +705,7 @@ void CGWhirlpool::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer
const auto * obj = cb->getObj(exit); const auto * obj = cb->getObj(exit);
std::set<int3> tiles = obj->getBlockedPos(); 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); cb->moveHero(hero->id, hero->convertFromVisitablePos(dPos), EMovementMode::MONOLITH);
@ -724,7 +726,7 @@ ArtifactID CGArtifact::getArtifact() const
return getObjTypeIndex().getNum(); return getObjTypeIndex().getNum();
} }
void CGArtifact::pickRandomObject(CRandomGenerator & rand) void CGArtifact::pickRandomObject(vstd::RNG & rand)
{ {
switch(ID.toEnum()) switch(ID.toEnum())
{ {
@ -754,7 +756,7 @@ void CGArtifact::pickRandomObject(CRandomGenerator & rand)
ID = MapObjectID::ARTIFACT; ID = MapObjectID::ARTIFACT;
} }
void CGArtifact::initObj(CRandomGenerator & rand) void CGArtifact::initObj(vstd::RNG & rand)
{ {
blockVisit = true; blockVisit = true;
if(ID == Obj::ARTIFACT) 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 no text is set than we pick random from the predefined ones
if(message.empty()) if(message.empty())
@ -1011,7 +1013,7 @@ void CGGarrison::serializeJsonOptions(JsonSerializeFormat& handler)
CArmedInstance::serializeJsonOptions(handler); CArmedInstance::serializeJsonOptions(handler);
} }
void CGGarrison::initObj(CRandomGenerator &rand) void CGGarrison::initObj(vstd::RNG &rand)
{ {
if(this->subID == MapObjectSubID::decode(this->ID, "antiMagic")) if(this->subID == MapObjectSubID::decode(this->ID, "antiMagic"))
addAntimagicGarrisonBonus(); addAntimagicGarrisonBonus();
@ -1028,7 +1030,7 @@ void CGGarrison::addAntimagicGarrisonBonus()
this->addNewBonus(bonus); this->addNewBonus(bonus);
} }
void CGMagi::initObj(CRandomGenerator & rand) void CGMagi::initObj(vstd::RNG & rand)
{ {
if (ID == Obj::EYE_OF_MAGI) if (ID == Obj::EYE_OF_MAGI)
blockVisit = true; blockVisit = true;
@ -1091,7 +1093,7 @@ bool CGBoat::isCoastVisitable() const
return true; return true;
} }
void CGSirens::initObj(CRandomGenerator & rand) void CGSirens::initObj(vstd::RNG & rand)
{ {
blockVisit = true; 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++; 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()) if(tempOwner.isValidPlayer())
{ {

View File

@ -48,7 +48,7 @@ public:
MetaString message; MetaString message;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
template <typename Handler> void serialize(Handler &h) template <typename Handler> void serialize(Handler &h)
{ {
@ -66,7 +66,7 @@ public:
bool removableUnits; bool removableUnits;
void initObj(CRandomGenerator &rand) override; void initObj(vstd::RNG &rand) override;
bool passableFor(PlayerColor color) const override; bool passableFor(PlayerColor color) const override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
@ -99,8 +99,8 @@ public:
std::vector<Component> getPopupComponents(PlayerColor player) const override; std::vector<Component> getPopupComponents(PlayerColor player) const override;
void pick( const CGHeroInstance * h ) const; void pick( const CGHeroInstance * h ) const;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
void pickRandomObject(CRandomGenerator & rand) override; void pickRandomObject(vstd::RNG & rand) override;
void afterAddToMap(CMap * map) override; void afterAddToMap(CMap * map) override;
BattleField getBattlefield() const override; BattleField getBattlefield() const override;
@ -129,8 +129,8 @@ public:
MetaString message; MetaString message;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
void pickRandomObject(CRandomGenerator & rand) override; void pickRandomObject(vstd::RNG & rand) override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
std::string getHoverText(PlayerColor player) const override; std::string getHoverText(PlayerColor player) const override;
@ -166,8 +166,8 @@ private:
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
void flagMine(const PlayerColor & player) const; void flagMine(const PlayerColor & player) const;
void newTurn(CRandomGenerator & rand) const override; void newTurn(vstd::RNG & rand) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
std::string getObjectName() const override; std::string getObjectName() const override;
std::string getHoverText(PlayerColor player) const override; std::string getHoverText(PlayerColor player) const override;
@ -248,7 +248,7 @@ class DLL_LINKAGE CGMonolith : public CGTeleport
protected: protected:
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, TTeleportExitsList exits) const override; void teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, TTeleportExitsList exits) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
public: public:
using CGTeleport::CGTeleport; using CGTeleport::CGTeleport;
@ -262,7 +262,7 @@ public:
class DLL_LINKAGE CGSubterraneanGate : public CGMonolith class DLL_LINKAGE CGSubterraneanGate : public CGMonolith
{ {
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
public: public:
using CGMonolith::CGMonolith; using CGMonolith::CGMonolith;
@ -297,7 +297,7 @@ public:
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
std::string getHoverText(const CGHeroInstance * hero) const override; std::string getHoverText(const CGHeroInstance * hero) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
template <typename Handler> void serialize(Handler &h) template <typename Handler> void serialize(Handler &h)
{ {
@ -369,7 +369,7 @@ class DLL_LINKAGE CGMagi : public CGObjectInstance
public: public:
using CGObjectInstance::CGObjectInstance; using CGObjectInstance::CGObjectInstance;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
template <typename Handler> void serialize(Handler &h) template <typename Handler> void serialize(Handler &h)
@ -391,7 +391,7 @@ public:
using CTeamVisited::CTeamVisited; using CTeamVisited::CTeamVisited;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
std::string getHoverText(PlayerColor player) const override; std::string getHoverText(PlayerColor player) const override;
template <typename Handler> void serialize(Handler &h) template <typename Handler> void serialize(Handler &h)
@ -408,7 +408,7 @@ public:
using CGObjectInstance::CGObjectInstance; using CGObjectInstance::CGObjectInstance;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void initObj(CRandomGenerator & rand) override; void initObj(vstd::RNG & rand) override;
template <typename Handler> void serialize(Handler &h) template <typename Handler> void serialize(Handler &h)
{ {

View File

@ -12,11 +12,12 @@
#include "CDrawRoadsOperation.h" #include "CDrawRoadsOperation.h"
#include "CMap.h" #include "CMap.h"
#include "../CRandomGenerator.h"
#include "../RoadHandler.h" #include "../RoadHandler.h"
#include "../RiverHandler.h" #include "../RiverHandler.h"
#include "../VCMI_Lib.h" #include "../VCMI_Lib.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
const std::vector<CDrawLinesOperation::LinePattern> CDrawLinesOperation::patterns = const std::vector<CDrawLinesOperation::LinePattern> CDrawLinesOperation::patterns =
@ -155,7 +156,7 @@ static bool ruleIsAny(const std::string & rule)
#endif #endif
///CDrawLinesOperation ///CDrawLinesOperation
CDrawLinesOperation::CDrawLinesOperation(CMap * map, CTerrainSelection terrainSel, CRandomGenerator * gen): CDrawLinesOperation::CDrawLinesOperation(CMap * map, CTerrainSelection terrainSel, vstd::RNG * gen):
CMapOperation(map), CMapOperation(map),
terrainSel(std::move(terrainSel)), terrainSel(std::move(terrainSel)),
gen(gen) gen(gen)
@ -163,14 +164,14 @@ CDrawLinesOperation::CDrawLinesOperation(CMap * map, CTerrainSelection terrainSe
} }
///CDrawRoadsOperation ///CDrawRoadsOperation
CDrawRoadsOperation::CDrawRoadsOperation(CMap * map, const CTerrainSelection & terrainSel, RoadId roadType, CRandomGenerator * gen): CDrawRoadsOperation::CDrawRoadsOperation(CMap * map, const CTerrainSelection & terrainSel, RoadId roadType, vstd::RNG * gen):
CDrawLinesOperation(map, terrainSel,gen), CDrawLinesOperation(map, terrainSel,gen),
roadType(roadType) roadType(roadType)
{ {
} }
///CDrawRiversOperation ///CDrawRiversOperation
CDrawRiversOperation::CDrawRiversOperation(CMap * map, const CTerrainSelection & terrainSel, RiverId riverType, CRandomGenerator * gen): CDrawRiversOperation::CDrawRiversOperation(CMap * map, const CTerrainSelection & terrainSel, RiverId riverType, vstd::RNG * gen):
CDrawLinesOperation(map, terrainSel, gen), CDrawLinesOperation(map, terrainSel, gen),
riverType(riverType) riverType(riverType)
{ {

View File

@ -41,7 +41,7 @@ protected:
int flip; int flip;
}; };
CDrawLinesOperation(CMap * map, CTerrainSelection terrainSel, CRandomGenerator * gen); CDrawLinesOperation(CMap * map, CTerrainSelection terrainSel, vstd::RNG * gen);
virtual void executeTile(TerrainTile & tile) = 0; virtual void executeTile(TerrainTile & tile) = 0;
virtual bool canApplyPattern(const CDrawLinesOperation::LinePattern & pattern) const = 0; virtual bool canApplyPattern(const CDrawLinesOperation::LinePattern & pattern) const = 0;
@ -58,13 +58,13 @@ protected:
ValidationResult validateTile(const LinePattern & pattern, const int3 & pos); ValidationResult validateTile(const LinePattern & pattern, const int3 & pos);
CTerrainSelection terrainSel; CTerrainSelection terrainSel;
CRandomGenerator * gen; vstd::RNG * gen;
}; };
class CDrawRoadsOperation : public CDrawLinesOperation class CDrawRoadsOperation : public CDrawLinesOperation
{ {
public: public:
CDrawRoadsOperation(CMap * map, const CTerrainSelection & terrainSel, RoadId roadType, CRandomGenerator * gen); CDrawRoadsOperation(CMap * map, const CTerrainSelection & terrainSel, RoadId roadType, vstd::RNG * gen);
std::string getLabel() const override; std::string getLabel() const override;
protected: protected:
@ -81,7 +81,7 @@ private:
class CDrawRiversOperation : public CDrawLinesOperation class CDrawRiversOperation : public CDrawLinesOperation
{ {
public: public:
CDrawRiversOperation(CMap * map, const CTerrainSelection & terrainSel, RiverId roadType, CRandomGenerator * gen); CDrawRiversOperation(CMap * map, const CTerrainSelection & terrainSel, RiverId roadType, vstd::RNG * gen);
std::string getLabel() const override; std::string getLabel() const override;
protected: protected:

View File

@ -29,6 +29,8 @@
#include "CMapOperation.h" #include "CMapOperation.h"
#include "../serializer/JsonSerializeFormat.h" #include "../serializer/JsonSerializeFormat.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
void Rumor::serializeJson(JsonSerializeFormat & handler) void Rumor::serializeJson(JsonSerializeFormat & handler)

View File

@ -15,6 +15,8 @@
#include "CDrawRoadsOperation.h" #include "CDrawRoadsOperation.h"
#include "CMapOperation.h" #include "CMapOperation.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
CMapUndoManager::CMapUndoManager() : CMapUndoManager::CMapUndoManager() :
@ -121,26 +123,26 @@ CMap * CMapEditManager::getMap()
return map; return map;
} }
void CMapEditManager::clearTerrain(CRandomGenerator * gen) void CMapEditManager::clearTerrain(vstd::RNG * gen)
{ {
execute(std::make_unique<CClearTerrainOperation>(map, gen ? gen : &(this->gen))); execute(std::make_unique<CClearTerrainOperation>(map, gen ? gen : this->gen.get()));
} }
void CMapEditManager::drawTerrain(TerrainId terType, int decorationsPercentage, CRandomGenerator * gen) void CMapEditManager::drawTerrain(TerrainId terType, int decorationsPercentage, vstd::RNG * gen)
{ {
execute(std::make_unique<CDrawTerrainOperation>(map, terrainSel, terType, decorationsPercentage, gen ? gen : &(this->gen))); execute(std::make_unique<CDrawTerrainOperation>(map, terrainSel, terType, decorationsPercentage, gen ? gen : this->gen.get()));
terrainSel.clearSelection(); terrainSel.clearSelection();
} }
void CMapEditManager::drawRoad(RoadId roadType, CRandomGenerator* gen) void CMapEditManager::drawRoad(RoadId roadType, vstd::RNG* gen)
{ {
execute(std::make_unique<CDrawRoadsOperation>(map, terrainSel, roadType, gen ? gen : &(this->gen))); execute(std::make_unique<CDrawRoadsOperation>(map, terrainSel, roadType, gen ? gen : this->gen.get()));
terrainSel.clearSelection(); terrainSel.clearSelection();
} }
void CMapEditManager::drawRiver(RiverId riverType, CRandomGenerator* gen) void CMapEditManager::drawRiver(RiverId riverType, vstd::RNG* gen)
{ {
execute(std::make_unique<CDrawRiversOperation>(map, terrainSel, riverType, gen ? gen : &(this->gen))); execute(std::make_unique<CDrawRiversOperation>(map, terrainSel, riverType, gen ? gen : this->gen.get()));
terrainSel.clearSelection(); terrainSel.clearSelection();
} }

View File

@ -11,13 +11,17 @@
#pragma once #pragma once
#include "../GameConstants.h" #include "../GameConstants.h"
#include "../CRandomGenerator.h"
#include "MapEditUtils.h" #include "MapEditUtils.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class CMapOperation; class CMapOperation;
namespace vstd
{
class RNG;
}
/// The CMapUndoManager provides the functionality to save operations and undo/redo them. /// The CMapUndoManager provides the functionality to save operations and undo/redo them.
class DLL_LINKAGE CMapUndoManager : boost::noncopyable class DLL_LINKAGE CMapUndoManager : boost::noncopyable
{ {
@ -67,16 +71,16 @@ public:
CMap * getMap(); CMap * getMap();
/// Clears the terrain. The free level is filled with water and the underground level with rock. /// Clears the terrain. The free level is filled with water and the underground level with rock.
void clearTerrain(CRandomGenerator * gen = nullptr); void clearTerrain(vstd::RNG * gen = nullptr);
/// Draws terrain at the current terrain selection. The selection will be cleared automatically. /// Draws terrain at the current terrain selection. The selection will be cleared automatically.
void drawTerrain(TerrainId terType, int decorationsPercentage, CRandomGenerator * gen = nullptr); void drawTerrain(TerrainId terType, int decorationsPercentage, vstd::RNG * gen = nullptr);
/// Draws roads at the current terrain selection. The selection will be cleared automatically. /// Draws roads at the current terrain selection. The selection will be cleared automatically.
void drawRoad(RoadId roadType, CRandomGenerator * gen = nullptr); void drawRoad(RoadId roadType, vstd::RNG * gen = nullptr);
/// Draws rivers at the current terrain selection. The selection will be cleared automatically. /// Draws rivers at the current terrain selection. The selection will be cleared automatically.
void drawRiver(RiverId riverType, CRandomGenerator * gen = nullptr); void drawRiver(RiverId riverType, vstd::RNG * gen = nullptr);
void insertObject(CGObjectInstance * obj); void insertObject(CGObjectInstance * obj);
void insertObjects(std::set<CGObjectInstance *> & objects); void insertObjects(std::set<CGObjectInstance *> & objects);
@ -94,7 +98,7 @@ private:
CMap * map; CMap * map;
CMapUndoManager undoManager; CMapUndoManager undoManager;
CRandomGenerator gen; std::unique_ptr<vstd::RNG> gen;
CTerrainSelection terrainSel; CTerrainSelection terrainSel;
CObjectSelection objectSel; CObjectSelection objectSel;
}; };

View File

@ -12,12 +12,13 @@
#include "CMapOperation.h" #include "CMapOperation.h"
#include "../VCMI_Lib.h" #include "../VCMI_Lib.h"
#include "../CRandomGenerator.h"
#include "../TerrainHandler.h" #include "../TerrainHandler.h"
#include "../mapObjects/CGObjectInstance.h" #include "../mapObjects/CGObjectInstance.h"
#include "CMap.h" #include "CMap.h"
#include "MapEditUtils.h" #include "MapEditUtils.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
CMapOperation::CMapOperation(CMap* map) : map(map) CMapOperation::CMapOperation(CMap* map) : map(map)
@ -87,7 +88,7 @@ void CComposedOperation::addOperation(std::unique_ptr<CMapOperation>&& operation
operations.push_back(std::move(operation)); operations.push_back(std::move(operation));
} }
CDrawTerrainOperation::CDrawTerrainOperation(CMap * map, CTerrainSelection terrainSel, TerrainId terType, int decorationsPercentage, CRandomGenerator * gen): CDrawTerrainOperation::CDrawTerrainOperation(CMap * map, CTerrainSelection terrainSel, TerrainId terType, int decorationsPercentage, vstd::RNG * gen):
CMapOperation(map), CMapOperation(map),
terrainSel(std::move(terrainSel)), terrainSel(std::move(terrainSel)),
terType(terType), terType(terType),
@ -560,7 +561,7 @@ CDrawTerrainOperation::ValidationResult::ValidationResult(bool result, std::stri
} }
CClearTerrainOperation::CClearTerrainOperation(CMap* map, CRandomGenerator* gen) : CComposedOperation(map) CClearTerrainOperation::CClearTerrainOperation(CMap* map, vstd::RNG* gen) : CComposedOperation(map)
{ {
CTerrainSelection terrainSel(map); CTerrainSelection terrainSel(map);
terrainSel.selectRange(MapRect(int3(0, 0, 0), map->width, map->height)); terrainSel.selectRange(MapRect(int3(0, 0, 0), map->width, map->height));

View File

@ -17,7 +17,11 @@ VCMI_LIB_NAMESPACE_BEGIN
class CGObjectInstance; class CGObjectInstance;
class CMap; class CMap;
class CRandomGenerator;
namespace vstd
{
class RNG;
}
/// The abstract base class CMapOperation defines an operation that can be executed, undone and redone. /// The abstract base class CMapOperation defines an operation that can be executed, undone and redone.
class DLL_LINKAGE CMapOperation : public boost::noncopyable class DLL_LINKAGE CMapOperation : public boost::noncopyable
@ -63,7 +67,7 @@ private:
class CDrawTerrainOperation : public CMapOperation class CDrawTerrainOperation : public CMapOperation
{ {
public: public:
CDrawTerrainOperation(CMap * map, CTerrainSelection terrainSel, TerrainId terType, int decorationsPercentage, CRandomGenerator * gen); CDrawTerrainOperation(CMap * map, CTerrainSelection terrainSel, TerrainId terType, int decorationsPercentage, vstd::RNG * gen);
void execute() override; void execute() override;
void undo() override; void undo() override;
@ -103,7 +107,7 @@ private:
CTerrainSelection terrainSel; CTerrainSelection terrainSel;
TerrainId terType; TerrainId terType;
int decorationsPercentage; int decorationsPercentage;
CRandomGenerator* gen; vstd::RNG* gen;
std::set<int3> invalidatedTerViews; std::set<int3> invalidatedTerViews;
}; };
@ -111,7 +115,7 @@ private:
class CClearTerrainOperation : public CComposedOperation class CClearTerrainOperation : public CComposedOperation
{ {
public: public:
CClearTerrainOperation(CMap * map, CRandomGenerator * gen); CClearTerrainOperation(CMap * map, vstd::RNG * gen);
std::string getLabel() const override; std::string getLabel() const override;
}; };

View File

@ -18,6 +18,8 @@
#include "../mapObjects/ObstacleSetHandler.h" #include "../mapObjects/ObstacleSetHandler.h"
#include "../VCMI_Lib.h" #include "../VCMI_Lib.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
void ObstacleProxy::collectPossibleObstacles(TerrainId terrain) void ObstacleProxy::collectPossibleObstacles(TerrainId terrain)
@ -53,7 +55,7 @@ void ObstacleProxy::sortObstacles()
}); });
} }
bool ObstacleProxy::prepareBiome(const ObstacleSetFilter & filter, CRandomGenerator & rand) bool ObstacleProxy::prepareBiome(const ObstacleSetFilter & filter, vstd::RNG & rand)
{ {
possibleObstacles.clear(); possibleObstacles.clear();
@ -228,7 +230,7 @@ bool ObstacleProxy::isProhibited(const rmg::Area& objArea) const
return false; return false;
}; };
int ObstacleProxy::getWeightedObjects(const int3 & tile, CRandomGenerator & rand, IGameCallback * cb, std::list<rmg::Object> & allObjects, std::vector<std::pair<rmg::Object*, int3>> & weightedObjects) int ObstacleProxy::getWeightedObjects(const int3 & tile, vstd::RNG & rand, IGameCallback * cb, std::list<rmg::Object> & allObjects, std::vector<std::pair<rmg::Object*, int3>> & weightedObjects)
{ {
int maxWeight = std::numeric_limits<int>::min(); int maxWeight = std::numeric_limits<int>::min();
for(auto & possibleObstacle : possibleObstacles) for(auto & possibleObstacle : possibleObstacles)
@ -309,7 +311,7 @@ int ObstacleProxy::getWeightedObjects(const int3 & tile, CRandomGenerator & rand
return maxWeight; return maxWeight;
} }
std::set<CGObjectInstance*> ObstacleProxy::createObstacles(CRandomGenerator & rand, IGameCallback * cb) std::set<CGObjectInstance*> ObstacleProxy::createObstacles(vstd::RNG & rand, IGameCallback * cb)
{ {
//reverse order, since obstacles begin in bottom-right corner, while the map coordinates begin in top-left //reverse order, since obstacles begin in bottom-right corner, while the map coordinates begin in top-left
auto blockedTiles = blockedArea.getTilesVector(); auto blockedTiles = blockedArea.getTilesVector();
@ -382,7 +384,7 @@ bool EditorObstaclePlacer::isInTheMap(const int3& tile)
return map->isInTheMap(tile); return map->isInTheMap(tile);
} }
std::set<CGObjectInstance*> EditorObstaclePlacer::placeObstacles(CRandomGenerator & rand) std::set<CGObjectInstance*> EditorObstaclePlacer::placeObstacles(vstd::RNG & rand)
{ {
auto obstacles = createObstacles(rand, map->cb); auto obstacles = createObstacles(rand, map->cb);
finalInsertion(map->getEditManager(), obstacles); finalInsertion(map->getEditManager(), obstacles);

View File

@ -18,7 +18,6 @@ VCMI_LIB_NAMESPACE_BEGIN
class CMapEditManager; class CMapEditManager;
class CGObjectInstance; class CGObjectInstance;
class ObjectTemplate; class ObjectTemplate;
class CRandomGenerator;
class IGameCallback; class IGameCallback;
class ObstacleSetFilter; class ObstacleSetFilter;
@ -30,7 +29,7 @@ public:
virtual ~ObstacleProxy() = default; virtual ~ObstacleProxy() = default;
void collectPossibleObstacles(TerrainId terrain); void collectPossibleObstacles(TerrainId terrain);
bool prepareBiome(const ObstacleSetFilter & filter, CRandomGenerator & rand); bool prepareBiome(const ObstacleSetFilter & filter, vstd::RNG & rand);
void addBlockedTile(const int3 & tile); void addBlockedTile(const int3 & tile);
@ -44,7 +43,7 @@ public:
virtual void placeObject(rmg::Object & object, std::set<CGObjectInstance*> & instances); virtual void placeObject(rmg::Object & object, std::set<CGObjectInstance*> & instances);
virtual std::set<CGObjectInstance*> createObstacles(CRandomGenerator & rand, IGameCallback * cb); virtual std::set<CGObjectInstance*> createObstacles(vstd::RNG & rand, IGameCallback * cb);
virtual bool isInTheMap(const int3& tile) = 0; virtual bool isInTheMap(const int3& tile) = 0;
@ -53,7 +52,7 @@ public:
virtual void postProcess(const rmg::Object& object) {}; virtual void postProcess(const rmg::Object& object) {};
protected: protected:
int getWeightedObjects(const int3& tile, CRandomGenerator& rand, IGameCallback * cb, std::list<rmg::Object>& allObjects, std::vector<std::pair<rmg::Object*, int3>>& weightedObjects); int getWeightedObjects(const int3& tile, vstd::RNG& rand, IGameCallback * cb, std::list<rmg::Object>& allObjects, std::vector<std::pair<rmg::Object*, int3>>& weightedObjects);
void sortObstacles(); void sortObstacles();
rmg::Area blockedArea; rmg::Area blockedArea;
@ -71,7 +70,7 @@ public:
bool isInTheMap(const int3& tile) override; bool isInTheMap(const int3& tile) override;
std::set<CGObjectInstance*> placeObstacles(CRandomGenerator& rand); std::set<CGObjectInstance*> placeObstacles(vstd::RNG& rand);
private: private:
CMap* map; CMap* map;

View File

@ -17,6 +17,7 @@
#include "../gameState/TavernHeroesPool.h" #include "../gameState/TavernHeroesPool.h"
#include "../gameState/CGameStateCampaign.h" #include "../gameState/CGameStateCampaign.h"
#include "../mapping/CMap.h" #include "../mapping/CMap.h"
#include "../CRandomGenerator.h"
#include "../TerrainHandler.h" #include "../TerrainHandler.h"
#include "../RiverHandler.h" #include "../RiverHandler.h"
#include "../RoadHandler.h" #include "../RoadHandler.h"

View File

@ -20,7 +20,8 @@
#include "../json/JsonRandom.h" #include "../json/JsonRandom.h"
#include "../mapObjects/IObjectInterface.h" #include "../mapObjects/IObjectInterface.h"
#include "../modding/IdentifierStorage.h" #include "../modding/IdentifierStorage.h"
#include "../CRandomGenerator.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
@ -106,7 +107,7 @@ void Rewardable::Info::init(const JsonNode & objectConfig, const std::string & o
loadString(parameters["onEmptyMessage"], TextIdentifier(objectName, "onEmpty")); loadString(parameters["onEmptyMessage"], TextIdentifier(objectName, "onEmpty"));
} }
Rewardable::LimitersList Rewardable::Info::configureSublimiters(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, const JsonNode & source) const Rewardable::LimitersList Rewardable::Info::configureSublimiters(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb, const JsonNode & source) const
{ {
Rewardable::LimitersList result; Rewardable::LimitersList result;
for (const auto & input : source.Vector()) for (const auto & input : source.Vector())
@ -121,7 +122,7 @@ Rewardable::LimitersList Rewardable::Info::configureSublimiters(Rewardable::Conf
return result; return result;
} }
void Rewardable::Info::configureLimiter(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, Rewardable::Limiter & limiter, const JsonNode & source) const void Rewardable::Info::configureLimiter(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb, Rewardable::Limiter & limiter, const JsonNode & source) const
{ {
auto const & variables = object.variables.values; auto const & variables = object.variables.values;
JsonRandom randomizer(cb); JsonRandom randomizer(cb);
@ -153,7 +154,7 @@ void Rewardable::Info::configureLimiter(Rewardable::Configuration & object, CRan
limiter.noneOf = configureSublimiters(object, rng, cb, source["noneOf"] ); limiter.noneOf = configureSublimiters(object, rng, cb, source["noneOf"] );
} }
void Rewardable::Info::configureReward(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, Rewardable::Reward & reward, const JsonNode & source) const void Rewardable::Info::configureReward(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb, Rewardable::Reward & reward, const JsonNode & source) const
{ {
auto const & variables = object.variables.values; auto const & variables = object.variables.values;
JsonRandom randomizer(cb); JsonRandom randomizer(cb);
@ -210,14 +211,14 @@ void Rewardable::Info::configureReward(Rewardable::Configuration & object, CRand
} }
} }
void Rewardable::Info::configureResetInfo(Rewardable::Configuration & object, CRandomGenerator & rng, Rewardable::ResetInfo & resetParameters, const JsonNode & source) const void Rewardable::Info::configureResetInfo(Rewardable::Configuration & object, vstd::RNG & rng, Rewardable::ResetInfo & resetParameters, const JsonNode & source) const
{ {
resetParameters.period = static_cast<ui32>(source["period"].Float()); resetParameters.period = static_cast<ui32>(source["period"].Float());
resetParameters.visitors = source["visitors"].Bool(); resetParameters.visitors = source["visitors"].Bool();
resetParameters.rewards = source["rewards"].Bool(); resetParameters.rewards = source["rewards"].Bool();
} }
void Rewardable::Info::configureVariables(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, const JsonNode & source) const void Rewardable::Info::configureVariables(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb, const JsonNode & source) const
{ {
JsonRandom randomizer(cb); JsonRandom randomizer(cb);
@ -277,7 +278,7 @@ void Rewardable::Info::replaceTextPlaceholders(MetaString & target, const Variab
void Rewardable::Info::configureRewards( void Rewardable::Info::configureRewards(
Rewardable::Configuration & object, Rewardable::Configuration & object,
CRandomGenerator & rng, vstd::RNG & rng,
IGameCallback * cb, IGameCallback * cb,
const JsonNode & source, const JsonNode & source,
Rewardable::EEventType event, Rewardable::EEventType event,
@ -335,7 +336,7 @@ void Rewardable::Info::configureRewards(
} }
} }
void Rewardable::Info::configureObject(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb) const void Rewardable::Info::configureObject(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb) const
{ {
object.info.clear(); object.info.clear();

View File

@ -15,13 +15,16 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class CRandomGenerator; namespace vstd
{
class RNG;
}
class MetaString; class MetaString;
class IGameCallback; class IGameCallback;
namespace Rewardable namespace Rewardable
{ {
struct Limiter; struct Limiter;
using LimitersList = std::vector<std::shared_ptr<Rewardable::Limiter>>; using LimitersList = std::vector<std::shared_ptr<Rewardable::Limiter>>;
struct Reward; struct Reward;
@ -39,14 +42,14 @@ class DLL_LINKAGE Info : public IObjectInfo
void replaceTextPlaceholders(MetaString & target, const Variables & variables) const; void replaceTextPlaceholders(MetaString & target, const Variables & variables) const;
void replaceTextPlaceholders(MetaString & target, const Variables & variables, const VisitInfo & info) const; void replaceTextPlaceholders(MetaString & target, const Variables & variables, const VisitInfo & info) const;
void configureVariables(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, const JsonNode & source) const; void configureVariables(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb, const JsonNode & source) const;
void configureRewards(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, const JsonNode & source, Rewardable::EEventType mode, const std::string & textPrefix) const; void configureRewards(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb, const JsonNode & source, Rewardable::EEventType mode, const std::string & textPrefix) const;
void configureLimiter(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, Rewardable::Limiter & limiter, const JsonNode & source) const; void configureLimiter(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb, Rewardable::Limiter & limiter, const JsonNode & source) const;
Rewardable::LimitersList configureSublimiters(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, const JsonNode & source) const; Rewardable::LimitersList configureSublimiters(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb, const JsonNode & source) const;
void configureReward(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb, Rewardable::Reward & info, const JsonNode & source) const; void configureReward(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb, Rewardable::Reward & info, const JsonNode & source) const;
void configureResetInfo(Rewardable::Configuration & object, CRandomGenerator & rng, Rewardable::ResetInfo & info, const JsonNode & source) const; void configureResetInfo(Rewardable::Configuration & object, vstd::RNG & rng, Rewardable::ResetInfo & info, const JsonNode & source) const;
public: public:
const JsonNode & getParameters() const; const JsonNode & getParameters() const;
@ -65,7 +68,7 @@ public:
bool givesBonuses() const override; bool givesBonuses() const override;
void configureObject(Rewardable::Configuration & object, CRandomGenerator & rng, IGameCallback * cb) const; void configureObject(Rewardable::Configuration & object, vstd::RNG & rng, IGameCallback * cb) const;
void init(const JsonNode & objectConfig, const std::string & objectTextID); void init(const JsonNode & objectConfig, const std::string & objectTextID);

View File

@ -14,11 +14,12 @@
#include "../mapping/CMapHeader.h" #include "../mapping/CMapHeader.h"
#include "CRmgTemplateStorage.h" #include "CRmgTemplateStorage.h"
#include "CRmgTemplate.h" #include "CRmgTemplate.h"
#include "CRandomGenerator.h"
#include "../VCMI_Lib.h" #include "../VCMI_Lib.h"
#include "../CTownHandler.h" #include "../CTownHandler.h"
#include "serializer/JsonSerializeFormat.h" #include "serializer/JsonSerializeFormat.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
CMapGenOptions::CMapGenOptions() CMapGenOptions::CMapGenOptions()
@ -487,7 +488,7 @@ void CMapGenOptions::setPlayerTeam(const PlayerColor & color, const TeamID & tea
customizedPlayers = true; customizedPlayers = true;
} }
void CMapGenOptions::finalize(CRandomGenerator & rand) void CMapGenOptions::finalize(vstd::RNG & rand)
{ {
logGlobal->info("RMG map: %dx%d, %s underground", getWidth(), getHeight(), getHasTwoLevels() ? "WITH" : "NO"); logGlobal->info("RMG map: %dx%d, %s underground", getWidth(), getHeight(), getHasTwoLevels() ? "WITH" : "NO");
logGlobal->info("RMG settings: players %d, teams %d, computer players %d, computer teams %d, water %d, monsters %d", logGlobal->info("RMG settings: players %d, teams %d, computer players %d, computer teams %d, water %d, monsters %d",
@ -690,8 +691,7 @@ bool CMapGenOptions::checkOptions() const
} }
else else
{ {
CRandomGenerator gen; return !getPossibleTemplates().empty();
return getPossibleTemplate(gen) != nullptr;
} }
} }
@ -750,7 +750,7 @@ std::vector<const CRmgTemplate *> CMapGenOptions::getPossibleTemplates() const
return templates; return templates;
} }
const CRmgTemplate * CMapGenOptions::getPossibleTemplate(CRandomGenerator & rand) const const CRmgTemplate * CMapGenOptions::getPossibleTemplate(vstd::RNG & rand) const
{ {
auto templates = getPossibleTemplates(); auto templates = getPossibleTemplates();

View File

@ -16,7 +16,10 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class CRandomGenerator; namespace vstd
{
class RNG;
}
enum class EPlayerType enum class EPlayerType
{ {
@ -148,7 +151,7 @@ public:
/// Finalizes the options. All random sizes for various properties will be overwritten by numbers from /// Finalizes the options. All random sizes for various properties will be overwritten by numbers from
/// a random number generator by keeping the options in a valid state. Check options should return true, otherwise /// a random number generator by keeping the options in a valid state. Check options should return true, otherwise
/// this function fails. /// this function fails.
void finalize(CRandomGenerator & rand); void finalize(vstd::RNG & rand);
/// Returns false if there is no template available which fits to the currently selected options. /// Returns false if there is no template available which fits to the currently selected options.
bool checkOptions() const; bool checkOptions() const;
@ -166,7 +169,7 @@ private:
PlayerColor getNextPlayerColor() const; PlayerColor getNextPlayerColor() const;
void updateCompOnlyPlayers(); void updateCompOnlyPlayers();
void updatePlayers(); void updatePlayers();
const CRmgTemplate * getPossibleTemplate(CRandomGenerator & rand) const; const CRmgTemplate * getPossibleTemplate(vstd::RNG & rand) const;
si32 width; si32 width;
si32 height; si32 height;

View File

@ -14,6 +14,7 @@
#include "../mapping/MapFormat.h" #include "../mapping/MapFormat.h"
#include "../VCMI_Lib.h" #include "../VCMI_Lib.h"
#include "../CGeneralTextHandler.h" #include "../CGeneralTextHandler.h"
#include "../CRandomGenerator.h"
#include "../mapObjectConstructors/AObjectTypeHandler.h" #include "../mapObjectConstructors/AObjectTypeHandler.h"
#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../mapObjectConstructors/CObjectClassesHandler.h"
#include "../mapping/CMapEditManager.h" #include "../mapping/CMapEditManager.h"
@ -32,15 +33,17 @@
#include "modificators/TreasurePlacer.h" #include "modificators/TreasurePlacer.h"
#include "modificators/RoadPlacer.h" #include "modificators/RoadPlacer.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
CMapGenerator::CMapGenerator(CMapGenOptions& mapGenOptions, IGameCallback * cb, int RandomSeed) : CMapGenerator::CMapGenerator(CMapGenOptions& mapGenOptions, IGameCallback * cb, int RandomSeed) :
mapGenOptions(mapGenOptions), randomSeed(RandomSeed), mapGenOptions(mapGenOptions), randomSeed(RandomSeed),
monolithIndex(0) monolithIndex(0),
rand(std::make_unique<CRandomGenerator>(RandomSeed))
{ {
loadConfig(); loadConfig();
rand.setSeed(this->randomSeed); mapGenOptions.finalize(*rand);
mapGenOptions.finalize(rand);
map = std::make_unique<RmgMap>(mapGenOptions, cb); map = std::make_unique<RmgMap>(mapGenOptions, cb);
placer = std::make_shared<CZonePlacer>(*map); placer = std::make_shared<CZonePlacer>(*map);
} }
@ -116,7 +119,7 @@ std::unique_ptr<CMap> CMapGenerator::generate()
try try
{ {
addHeaderInfo(); addHeaderInfo();
map->initTiles(*this, rand); map->initTiles(*this, *rand);
Load::Progress::step(); Load::Progress::step();
initQuestArtsRemaining(); initQuestArtsRemaining();
genZones(); genZones();
@ -286,7 +289,7 @@ void CMapGenerator::addPlayerInfo()
logGlobal->error("Not enough places in team for %s player", ((j == CPUONLY) ? "CPU" : "CPU or human")); logGlobal->error("Not enough places in team for %s player", ((j == CPUONLY) ? "CPU" : "CPU or human"));
assert (teamNumbers[j].size()); assert (teamNumbers[j].size());
} }
auto itTeam = RandomGeneratorUtil::nextItem(teamNumbers[j], rand); auto itTeam = RandomGeneratorUtil::nextItem(teamNumbers[j], *rand);
player.team = TeamID(*itTeam); player.team = TeamID(*itTeam);
teamNumbers[j].erase(itTeam); teamNumbers[j].erase(itTeam);
} }
@ -306,8 +309,8 @@ void CMapGenerator::addPlayerInfo()
void CMapGenerator::genZones() void CMapGenerator::genZones()
{ {
placer->placeZones(&rand); placer->placeZones(rand.get());
placer->assignZones(&rand); placer->assignZones(rand.get());
logGlobal->info("Zones generated successfully"); logGlobal->info("Zones generated successfully");
} }
@ -428,9 +431,9 @@ void CMapGenerator::fillZones()
if (it.second->getType() != ETemplateZoneType::WATER) if (it.second->getType() != ETemplateZoneType::WATER)
treasureZones.push_back(it.second); treasureZones.push_back(it.second);
} }
auto grailZone = *RandomGeneratorUtil::nextItem(treasureZones, rand); auto grailZone = *RandomGeneratorUtil::nextItem(treasureZones, *rand);
map->getMap(this).grailPos = *RandomGeneratorUtil::nextItem(grailZone->freePaths()->getTiles(), rand); map->getMap(this).grailPos = *RandomGeneratorUtil::nextItem(grailZone->freePaths()->getTiles(), *rand);
map->getMap(this).reindexObjects(); map->getMap(this).reindexObjects();
logGlobal->info("Zones filled successfully"); logGlobal->info("Zones filled successfully");

View File

@ -11,7 +11,6 @@
#pragma once #pragma once
#include "../GameConstants.h" #include "../GameConstants.h"
#include "../CRandomGenerator.h"
#include "CMapGenOptions.h" #include "CMapGenOptions.h"
#include "../int3.h" #include "../int3.h"
#include "CRmgTemplate.h" #include "CRmgTemplate.h"
@ -79,7 +78,7 @@ public:
int getRandomSeed() const; int getRandomSeed() const;
private: private:
CRandomGenerator rand; std::unique_ptr<vstd::RNG> rand;
int randomSeed; int randomSeed;
CMapGenOptions& mapGenOptions; CMapGenOptions& mapGenOptions;
Config config; Config config;

View File

@ -11,7 +11,6 @@
#include "StdInc.h" #include "StdInc.h"
#include "CZonePlacer.h" #include "CZonePlacer.h"
#include "../CRandomGenerator.h"
#include "../CTownHandler.h" #include "../CTownHandler.h"
#include "../TerrainHandler.h" #include "../TerrainHandler.h"
#include "../mapping/CMap.h" #include "../mapping/CMap.h"
@ -23,12 +22,12 @@
#include "Functions.h" #include "Functions.h"
#include "PenroseTiling.h" #include "PenroseTiling.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
//#define ZONE_PLACEMENT_LOG true //#define ZONE_PLACEMENT_LOG true
class CRandomGenerator;
CZonePlacer::CZonePlacer(RmgMap & map) CZonePlacer::CZonePlacer(RmgMap & map)
: width(0), height(0), mapSize(0), : width(0), height(0), mapSize(0),
gravityConstant(1e-3f), gravityConstant(1e-3f),
@ -97,7 +96,7 @@ void CZonePlacer::findPathsBetweenZones()
} }
} }
void CZonePlacer::placeOnGrid(CRandomGenerator* rand) void CZonePlacer::placeOnGrid(vstd::RNG* rand)
{ {
auto zones = map.getZones(); auto zones = map.getZones();
assert(zones.size()); assert(zones.size());
@ -118,7 +117,7 @@ void CZonePlacer::placeOnGrid(CRandomGenerator* rand)
auto getRandomEdge = [rand, gridSize](size_t& x, size_t& y) auto getRandomEdge = [rand, gridSize](size_t& x, size_t& y)
{ {
switch (rand->nextInt() % 4) switch (rand->nextInt(0, 3) % 4)
{ {
case 0: case 0:
x = 0; x = 0;
@ -150,7 +149,7 @@ void CZonePlacer::placeOnGrid(CRandomGenerator* rand)
else else
{ {
//Random corner //Random corner
if (rand->nextInt() % 2) if (rand->nextInt(0, 1) == 1)
{ {
x = 0; x = 0;
} }
@ -158,7 +157,7 @@ void CZonePlacer::placeOnGrid(CRandomGenerator* rand)
{ {
x = gridSize - 1; x = gridSize - 1;
} }
if (rand->nextInt() % 2) if (rand->nextInt(0, 1) == 1)
{ {
y = 0; y = 0;
} }
@ -176,8 +175,8 @@ void CZonePlacer::placeOnGrid(CRandomGenerator* rand)
else else
{ {
//One of 4 squares in the middle //One of 4 squares in the middle
x = (gridSize / 2) - 1 + rand->nextInt() % 2; x = (gridSize / 2) - 1 + rand->nextInt(0, 1);
y = (gridSize / 2) - 1 + rand->nextInt() % 2; y = (gridSize / 2) - 1 + rand->nextInt(0, 1);
} }
break; break;
case ETemplateZoneType::JUNCTION: case ETemplateZoneType::JUNCTION:
@ -308,7 +307,7 @@ float CZonePlacer::scaleForceBetweenZones(const std::shared_ptr<Zone> zoneA, con
} }
} }
void CZonePlacer::placeZones(CRandomGenerator * rand) void CZonePlacer::placeZones(vstd::RNG * rand)
{ {
logGlobal->info("Starting zone placement"); logGlobal->info("Starting zone placement");
@ -432,7 +431,7 @@ void CZonePlacer::placeZones(CRandomGenerator * rand)
} }
} }
void CZonePlacer::prepareZones(TZoneMap &zones, TZoneVector &zonesVector, const bool underground, CRandomGenerator * rand) void CZonePlacer::prepareZones(TZoneMap &zones, TZoneVector &zonesVector, const bool underground, vstd::RNG * rand)
{ {
std::vector<float> totalSize = { 0, 0 }; //make sure that sum of zone sizes on surface and uderground match size of the map std::vector<float> totalSize = { 0, 0 }; //make sure that sum of zone sizes on surface and uderground match size of the map
@ -824,7 +823,7 @@ float CZonePlacer::metric (const int3 &A, const int3 &B) const
} }
void CZonePlacer::assignZones(CRandomGenerator * rand) void CZonePlacer::assignZones(vstd::RNG * rand)
{ {
logGlobal->info("Starting zone colouring"); logGlobal->info("Starting zone colouring");

View File

@ -16,9 +16,13 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
class CZoneGraph; class CZoneGraph;
class CMap; class CMap;
class CRandomGenerator;
class RmgMap; class RmgMap;
class Zone; class Zone;
@ -37,16 +41,16 @@ public:
float getDistance(float distance) const; //additional scaling without 0 division float getDistance(float distance) const; //additional scaling without 0 division
~CZonePlacer() = default; ~CZonePlacer() = default;
void placeZones(CRandomGenerator * rand); void placeZones(vstd::RNG * rand);
void findPathsBetweenZones(); void findPathsBetweenZones();
void placeOnGrid(CRandomGenerator* rand); void placeOnGrid(vstd::RNG* rand);
float scaleForceBetweenZones(const std::shared_ptr<Zone> zoneA, const std::shared_ptr<Zone> zoneB) const; float scaleForceBetweenZones(const std::shared_ptr<Zone> zoneA, const std::shared_ptr<Zone> zoneB) const;
void assignZones(CRandomGenerator * rand); void assignZones(vstd::RNG * rand);
const TDistanceMap & getDistanceMap(); const TDistanceMap & getDistanceMap();
private: private:
void prepareZones(TZoneMap &zones, TZoneVector &zonesVector, const bool underground, CRandomGenerator * rand); void prepareZones(TZoneMap &zones, TZoneVector &zonesVector, const bool underground, vstd::RNG * rand);
void attractConnectedZones(TZoneMap & zones, TForceVector & forces, TDistanceVector & distances) const; void attractConnectedZones(TZoneMap & zones, TForceVector & forces, TDistanceVector & distances) const;
void separateOverlappingZones(TZoneMap &zones, TForceVector &forces, TDistanceVector &overlaps); void separateOverlappingZones(TZoneMap &zones, TForceVector &forces, TDistanceVector &overlaps);
void moveOneZone(TZoneMap & zones, TForceVector & totalForces, TDistanceVector & distances, TDistanceVector & overlaps); void moveOneZone(TZoneMap & zones, TForceVector & totalForces, TDistanceVector & distances, TDistanceVector & overlaps);

View File

@ -21,6 +21,8 @@
#include "../mapObjectConstructors/CObjectClassesHandler.h" #include "../mapObjectConstructors/CObjectClassesHandler.h"
#include "../VCMI_Lib.h" #include "../VCMI_Lib.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
rmg::Tileset collectDistantTiles(const Zone& zone, int distance) rmg::Tileset collectDistantTiles(const Zone& zone, int distance)
@ -34,7 +36,7 @@ rmg::Tileset collectDistantTiles(const Zone& zone, int distance)
return subarea.getTiles(); return subarea.getTiles();
} }
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TerrainId terrain) int chooseRandomAppearance(vstd::RNG & generator, si32 ObjID, TerrainId terrain)
{ {
auto factories = VLC->objtypeh->knownSubObjects(ObjID); auto factories = VLC->objtypeh->knownSubObjects(ObjID);
vstd::erase_if(factories, [ObjID, &terrain](si32 f) vstd::erase_if(factories, [ObjID, &terrain](si32 f)

View File

@ -19,7 +19,6 @@ class RmgMap;
class ObjectManager; class ObjectManager;
class ObjectTemplate; class ObjectTemplate;
class CMapGenerator; class CMapGenerator;
class CRandomGenerator;
class rmgException : public std::exception class rmgException : public std::exception
{ {
@ -37,7 +36,7 @@ public:
rmg::Tileset collectDistantTiles(const Zone & zone, int distance); rmg::Tileset collectDistantTiles(const Zone & zone, int distance);
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TerrainId terrain); int chooseRandomAppearance(vstd::RNG & generator, si32 ObjID, TerrainId terrain);
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -13,6 +13,8 @@
#include "StdInc.h" #include "StdInc.h"
#include "PenroseTiling.h" #include "PenroseTiling.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
@ -143,7 +145,7 @@ void PenroseTiling::split(Triangle& p, std::vector<Point2D>& points,
return; return;
} }
std::set<Point2D> PenroseTiling::generatePenroseTiling(size_t numZones, CRandomGenerator * rand) std::set<Point2D> PenroseTiling::generatePenroseTiling(size_t numZones, vstd::RNG * rand)
{ {
float scale = 173.2f / (numZones * 1.5f + 20); float scale = 173.2f / (numZones * 1.5f + 20);
float polyAngle = (2 * PI_CONSTANT) / POLY; float polyAngle = (2 * PI_CONSTANT) / POLY;

View File

@ -11,12 +11,16 @@
#pragma once #pragma once
#include "../GameConstants.h" #include "../GameConstants.h"
#include "../CRandomGenerator.h"
#include <boost/geometry.hpp> #include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/point_xy.hpp>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
using namespace boost::geometry; using namespace boost::geometry;
typedef std::array<uint32_t, 3> TIndices; typedef std::array<uint32_t, 3> TIndices;
@ -66,7 +70,7 @@ public:
const bool P2 = false; // Tiling type const bool P2 = false; // Tiling type
std::set<Point2D> generatePenroseTiling(size_t numZones, CRandomGenerator * rand); std::set<Point2D> generatePenroseTiling(size_t numZones, vstd::RNG * rand);
private: private:
void split(Triangle& p, std::vector<Point2D>& points, std::array<std::vector<uint32_t>, 5>& indices, uint32_t depth); void split(Triangle& p, std::vector<Point2D>& points, std::array<std::vector<uint32_t>, 5>& indices, uint32_t depth);

View File

@ -84,7 +84,7 @@ void RmgMap::foreachDiagonalNeighbour(const int3 & pos, const std::function<void
} }
} }
void RmgMap::initTiles(CMapGenerator & generator, CRandomGenerator & rand) void RmgMap::initTiles(CMapGenerator & generator, vstd::RNG & rand)
{ {
mapInstance->initTerrain(); mapInstance->initTerrain();

View File

@ -17,7 +17,6 @@ VCMI_LIB_NAMESPACE_BEGIN
class CMap; class CMap;
class CMapEditManager; class CMapEditManager;
class CRandomGenerator;
class TileInfo; class TileInfo;
class CMapGenOptions; class CMapGenOptions;
class Zone; class Zone;
@ -25,6 +24,11 @@ class CMapGenerator;
class MapProxy; class MapProxy;
class playerInfo; class playerInfo;
namespace vstd
{
class RNG;
}
class RmgMap class RmgMap
{ {
public: public:
@ -79,7 +83,7 @@ public:
void registerZone(FactionID faction); void registerZone(FactionID faction);
ui32 getZoneCount(FactionID faction); ui32 getZoneCount(FactionID faction);
ui32 getTotalZoneCount() const; ui32 getTotalZoneCount() const;
void initTiles(CMapGenerator & generator, CRandomGenerator & rand); void initTiles(CMapGenerator & generator, vstd::RNG & rand);
void addModificators(); void addModificators();
bool isAllowedSpell(const SpellID & sid) const; bool isAllowedSpell(const SpellID & sid) const;

View File

@ -21,6 +21,8 @@
#include "Functions.h" #include "Functions.h"
#include "../TerrainHandler.h" #include "../TerrainHandler.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
using namespace rmg; using namespace rmg;
@ -111,7 +113,7 @@ void Object::Instance::setPositionRaw(const int3 & position)
dObject.pos = dPosition + dParent.getPosition(); dObject.pos = dPosition + dParent.getPosition();
} }
void Object::Instance::setAnyTemplate(CRandomGenerator & rng) void Object::Instance::setAnyTemplate(vstd::RNG & rng)
{ {
auto templates = dObject.getObjectHandler()->getTemplates(); auto templates = dObject.getObjectHandler()->getTemplates();
if(templates.empty()) if(templates.empty())
@ -122,7 +124,7 @@ void Object::Instance::setAnyTemplate(CRandomGenerator & rng)
setPosition(getPosition(false)); setPosition(getPosition(false));
} }
void Object::Instance::setTemplate(TerrainId terrain, CRandomGenerator & rng) void Object::Instance::setTemplate(TerrainId terrain, vstd::RNG & rng)
{ {
auto templates = dObject.getObjectHandler()->getMostSpecificTemplates(terrain); auto templates = dObject.getObjectHandler()->getMostSpecificTemplates(terrain);
@ -366,7 +368,7 @@ void Object::setPosition(const int3 & position)
i.setPositionRaw(i.getPosition()); i.setPositionRaw(i.getPosition());
} }
void Object::setTemplate(const TerrainId & terrain, CRandomGenerator & rng) void Object::setTemplate(const TerrainId & terrain, vstd::RNG & rng)
{ {
for(auto& i : dInstances) for(auto& i : dInstances)
i.setTemplate(terrain, rng); i.setTemplate(terrain, rng);
@ -474,7 +476,7 @@ rmg::Area Object::Instance::getBorderAbove() const
return borderAbove; return borderAbove;
} }
void Object::Instance::finalize(RmgMap & map, CRandomGenerator & rng) void Object::Instance::finalize(RmgMap & map, vstd::RNG & rng)
{ {
if(!map.isOnMap(getPosition(true))) if(!map.isOnMap(getPosition(true)))
throw rmgException(boost::str(boost::format("Position of object %d at %s is outside the map") % dObject.id % getPosition(true).toString())); throw rmgException(boost::str(boost::format("Position of object %d at %s is outside the map") % dObject.id % getPosition(true).toString()));
@ -511,7 +513,7 @@ void Object::Instance::finalize(RmgMap & map, CRandomGenerator & rng)
map.getMapProxy()->insertObject(&dObject); map.getMapProxy()->insertObject(&dObject);
} }
void Object::finalize(RmgMap & map, CRandomGenerator & rng) void Object::finalize(RmgMap & map, vstd::RNG & rng)
{ {
if(dInstances.empty()) if(dInstances.empty())
throw rmgException("Cannot finalize object without instances"); throw rmgException("Cannot finalize object without instances");

View File

@ -16,8 +16,12 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
namespace vstd
{
class RNG;
}
class CGObjectInstance; class CGObjectInstance;
class CRandomGenerator;
class RmgMap; class RmgMap;
namespace rmg { namespace rmg {
@ -39,8 +43,8 @@ public:
bool isRemovable() const; bool isRemovable() const;
const Area & getAccessibleArea() const; const Area & getAccessibleArea() const;
Area getBorderAbove() const; Area getBorderAbove() const;
void setTemplate(TerrainId terrain, CRandomGenerator &); //cache invalidation void setTemplate(TerrainId terrain, vstd::RNG &); //cache invalidation
void setAnyTemplate(CRandomGenerator &); //cache invalidation void setAnyTemplate(vstd::RNG &); //cache invalidation
int3 getTopTile() const; int3 getTopTile() const;
int3 getPosition(bool isAbsolute = false) const; int3 getPosition(bool isAbsolute = false) const;
@ -49,7 +53,7 @@ public:
const CGObjectInstance & object() const; const CGObjectInstance & object() const;
CGObjectInstance & object(); CGObjectInstance & object();
void finalize(RmgMap & map, CRandomGenerator &); //cache invalidation void finalize(RmgMap & map, vstd::RNG &); //cache invalidation
void clear(); void clear();
std::function<void(CGObjectInstance *)> onCleared; std::function<void(CGObjectInstance *)> onCleared;
@ -83,7 +87,7 @@ public:
const int3 & getPosition() const; const int3 & getPosition() const;
void setPosition(const int3 & position); void setPosition(const int3 & position);
void setTemplate(const TerrainId & terrain, CRandomGenerator &); void setTemplate(const TerrainId & terrain, vstd::RNG &);
const Area & getArea() const; //lazy cache invalidation const Area & getArea() const; //lazy cache invalidation
const int3 getVisibleTop() const; const int3 getVisibleTop() const;
@ -94,7 +98,7 @@ public:
void setValue(uint32_t value); void setValue(uint32_t value);
uint32_t getValue() const; uint32_t getValue() const;
void finalize(RmgMap & map, CRandomGenerator &); void finalize(RmgMap & map, vstd::RNG &);
void clearCachedArea() const; void clearCachedArea() const;
void clear(); void clear();

View File

@ -17,6 +17,10 @@
#include "RmgPath.h" #include "RmgPath.h"
#include "modificators/ObjectManager.h" #include "modificators/ObjectManager.h"
#include "../CRandomGenerator.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
const std::function<bool(const int3 &)> AREA_NO_FILTER = [](const int3 & t) const std::function<bool(const int3 &)> AREA_NO_FILTER = [](const int3 & t)
@ -24,16 +28,18 @@ const std::function<bool(const int3 &)> AREA_NO_FILTER = [](const int3 & t)
return true; return true;
}; };
Zone::Zone(RmgMap & map, CMapGenerator & generator, CRandomGenerator & r) Zone::Zone(RmgMap & map, CMapGenerator & generator, vstd::RNG & r)
: finished(false) : finished(false)
, townType(ETownType::NEUTRAL) , townType(ETownType::NEUTRAL)
, terrainType(ETerrainId::GRASS) , terrainType(ETerrainId::GRASS)
, map(map) , map(map)
, rand(std::make_unique<CRandomGenerator>(r.nextInt()))
, generator(generator) , generator(generator)
{ {
rand.setSeed(r.nextInt());
} }
Zone::~Zone() = default;
bool Zone::isUnderground() const bool Zone::isUnderground() const
{ {
return getPos().z; return getPos().z;
@ -401,9 +407,9 @@ void Zone::initModificators()
} }
} }
CRandomGenerator& Zone::getRand() vstd::RNG& Zone::getRand()
{ {
return rand; return *rand;
} }
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -13,7 +13,6 @@
#include "../GameConstants.h" #include "../GameConstants.h"
#include "float3.h" #include "float3.h"
#include "../int3.h" #include "../int3.h"
#include "../CRandomGenerator.h"
#include "CRmgTemplate.h" #include "CRmgTemplate.h"
#include "RmgArea.h" #include "RmgArea.h"
#include "RmgPath.h" #include "RmgPath.h"
@ -28,7 +27,6 @@ VCMI_LIB_NAMESPACE_BEGIN
class RmgMap; class RmgMap;
class CMapGenerator; class CMapGenerator;
class Modificator; class Modificator;
class CRandomGenerator;
extern const std::function<bool(const int3 &)> AREA_NO_FILTER; extern const std::function<bool(const int3 &)> AREA_NO_FILTER;
@ -74,8 +72,9 @@ private:
class Zone : public rmg::ZoneOptions class Zone : public rmg::ZoneOptions
{ {
public: public:
Zone(RmgMap & map, CMapGenerator & generator, CRandomGenerator & rand); Zone(RmgMap & map, CMapGenerator & generator, vstd::RNG & rand);
Zone(const Zone &) = delete; Zone(const Zone &) = delete;
~Zone();
void setOptions(const rmg::ZoneOptions & options); void setOptions(const rmg::ZoneOptions & options);
bool isUnderground() const; bool isUnderground() const;
@ -127,14 +126,14 @@ public:
void initModificators(); void initModificators();
CRandomGenerator & getRand(); vstd::RNG & getRand();
public: public:
mutable boost::recursive_mutex areaMutex; mutable boost::recursive_mutex areaMutex;
using Lock = boost::unique_lock<boost::recursive_mutex>; using Lock = boost::unique_lock<boost::recursive_mutex>;
protected: protected:
CMapGenerator & generator; CMapGenerator & generator;
CRandomGenerator rand; std::unique_ptr<vstd::RNG> rand;
RmgMap & map; RmgMap & map;
TModificators modificators; TModificators modificators;
bool finished; bool finished;

View File

@ -26,6 +26,8 @@
#include "WaterProxy.h" #include "WaterProxy.h"
#include "TownPlacer.h" #include "TownPlacer.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
std::pair<Zone::Lock, Zone::Lock> ConnectionsPlacer::lockZones(std::shared_ptr<Zone> otherZone) std::pair<Zone::Lock, Zone::Lock> ConnectionsPlacer::lockZones(std::shared_ptr<Zone> otherZone)

View File

@ -22,6 +22,8 @@
#include "WaterAdopter.h" #include "WaterAdopter.h"
#include "../TileInfo.h" #include "../TileInfo.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
void MinePlacer::process() void MinePlacer::process()

View File

@ -25,6 +25,8 @@
#include "../Functions.h" #include "../Functions.h"
#include "../RmgObject.h" #include "../RmgObject.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
void ObjectDistributor::process() void ObjectDistributor::process()

View File

@ -29,6 +29,8 @@
#include "../Functions.h" #include "../Functions.h"
#include "../RmgObject.h" #include "../RmgObject.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
void ObjectManager::process() void ObjectManager::process()

View File

@ -19,7 +19,6 @@
#include "RiverPlacer.h" #include "RiverPlacer.h"
#include "../RmgMap.h" #include "../RmgMap.h"
#include "../CMapGenerator.h" #include "../CMapGenerator.h"
#include "../../CRandomGenerator.h"
#include "../Functions.h" #include "../Functions.h"
#include "../../mapping/CMapEditManager.h" #include "../../mapping/CMapEditManager.h"
#include "../../mapping/CMap.h" #include "../../mapping/CMap.h"

View File

@ -19,6 +19,8 @@
#include "../../mapObjectConstructors/CObjectClassesHandler.h" #include "../../mapObjectConstructors/CObjectClassesHandler.h"
#include "../../mapObjects/MapObjects.h" #include "../../mapObjects/MapObjects.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
void PrisonHeroPlacer::process() void PrisonHeroPlacer::process()

View File

@ -15,8 +15,6 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class CRandomGenerator;
class PrisonHeroPlacer : public Modificator class PrisonHeroPlacer : public Modificator
{ {
public: public:

View File

@ -19,6 +19,8 @@
#include "../../mapObjectConstructors/CObjectClassesHandler.h" #include "../../mapObjectConstructors/CObjectClassesHandler.h"
#include "../../mapObjects/MapObjects.h" #include "../../mapObjects/MapObjects.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
void QuestArtifactPlacer::process() void QuestArtifactPlacer::process()
@ -95,7 +97,7 @@ void QuestArtifactPlacer::findZonesForQuestArts()
logGlobal->trace("Number of nearby zones suitable for quest artifacts: %d", questArtZones.size()); logGlobal->trace("Number of nearby zones suitable for quest artifacts: %d", questArtZones.size());
} }
void QuestArtifactPlacer::placeQuestArtifacts(CRandomGenerator & rand) void QuestArtifactPlacer::placeQuestArtifacts(vstd::RNG & rand)
{ {
for (const auto & artifactToPlace : questArtifactsToPlace) for (const auto & artifactToPlace : questArtifactsToPlace)
{ {

View File

@ -15,8 +15,6 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class CRandomGenerator;
class QuestArtifactPlacer : public Modificator class QuestArtifactPlacer : public Modificator
{ {
public: public:
@ -33,7 +31,7 @@ public:
void rememberPotentialArtifactToReplace(CGObjectInstance* obj); void rememberPotentialArtifactToReplace(CGObjectInstance* obj);
CGObjectInstance * drawObjectToReplace(); CGObjectInstance * drawObjectToReplace();
std::vector<CGObjectInstance*> getPossibleArtifactsToReplace() const; std::vector<CGObjectInstance*> getPossibleArtifactsToReplace() const;
void placeQuestArtifacts(CRandomGenerator & rand); void placeQuestArtifacts(vstd::RNG & rand);
void dropReplacedArtifact(CGObjectInstance* obj); void dropReplacedArtifact(CGObjectInstance* obj);
size_t getMaxQuestArtifactCount() const; size_t getMaxQuestArtifactCount() const;

View File

@ -27,6 +27,8 @@
#include "WaterProxy.h" #include "WaterProxy.h"
#include "RoadPlacer.h" #include "RoadPlacer.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
const int RIVER_DELTA_ID = 143; const int RIVER_DELTA_ID = 143;

View File

@ -19,7 +19,6 @@
#include "../CMapGenerator.h" #include "../CMapGenerator.h"
#include "../Functions.h" #include "../Functions.h"
#include "../../TerrainHandler.h" #include "../../TerrainHandler.h"
#include "../../CRandomGenerator.h"
#include "../lib/mapping/CMapEditManager.h" #include "../lib/mapping/CMapEditManager.h"
#include "../TileInfo.h" #include "../TileInfo.h"
#include "../threadpool/MapProxy.h" #include "../threadpool/MapProxy.h"

Some files were not shown because too many files have changed in this diff Show More