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

Some preparation towards mantis #1743:

- refactored CRandomGenerator (added util methods, improved method names)
- usages of std::minstd_ran are replaced by CRandomGenerator (not in entire code base, C rand() usages are still not replaced)
- refactored getArtSync method of CArtHandler -> now named pickRandomArtifact
- fixed some compiler warnings
- updated source code URL in VCMI spec
This commit is contained in:
beegee1
2014-03-17 19:51:07 +00:00
parent 1aff899f5b
commit fe1b16a7ec
22 changed files with 6774 additions and 6695 deletions

View File

@@ -1,3 +1,13 @@
/*
* CArtHandler.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "CArtHandler.h"
@@ -9,20 +19,10 @@
#include "CObjectHandler.h"
#include "NetPacksBase.h"
#include "GameConstants.h"
#include "CRandomGenerator.h"
using namespace boost::assign;
/*
* CArtHandler.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
extern std::minstd_rand ran;
// Note: list must match entries in ArtTraits.txt
#define ART_POS_LIST \
ART_POS(SPELLBOOK) \
@@ -422,11 +422,7 @@ CreatureID CArtHandler::machineIDToCreature(ArtifactID id)
return CreatureID::NONE; //this artifact is not a creature
}
ArtifactID CArtHandler::getRandomArt(int flags)
{
return getArtSync(ran(), flags, true);
}
ArtifactID CArtHandler::getArtSync (ui32 rand, int flags, bool erasePicked)
ArtifactID CArtHandler::pickRandomArtifact(CRandomGenerator & rand, int flags)
{
auto getAllowedArts = [&](std::vector<ConstTransitivePtr<CArtifact> > &out, std::vector<CArtifact*> *arts, CArtifact::EartClass flag)
{
@@ -466,9 +462,8 @@ ArtifactID CArtHandler::getArtSync (ui32 rand, int flags, bool erasePicked)
std::vector<ConstTransitivePtr<CArtifact> > out;
getAllowed(out);
ArtifactID artID = out[rand % out.size()]->id;
if(erasePicked)
erasePickedArt (artID);
ArtifactID artID = (*RandomGeneratorUtil::nextItem(out, rand))->id;
erasePickedArt(artID);
return artID;
}