mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Moved object type randomization to object class
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "../gameState/CGameState.h"
|
||||
#include "../mapping/CMap.h"
|
||||
#include "../CPlayerState.h"
|
||||
#include "../StartInfo.h"
|
||||
#include "../TerrainHandler.h"
|
||||
#include "../mapObjectConstructors/AObjectTypeHandler.h"
|
||||
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
||||
@@ -459,6 +460,34 @@ void CGTownInstance::deleteTownBonus(BuildingID bid)
|
||||
delete freeIt;
|
||||
}
|
||||
|
||||
FactionID CGTownInstance::randomizeFaction(CRandomGenerator & rand)
|
||||
{
|
||||
if(getOwner().isValidPlayer())
|
||||
return cb->gameState()->scenarioOps->getIthPlayersSettings(getOwner()).castle;
|
||||
|
||||
if(alignmentToPlayer.isValidPlayer())
|
||||
return cb->gameState()->scenarioOps->getIthPlayersSettings(alignmentToPlayer).castle;
|
||||
|
||||
std::vector<FactionID> potentialPicks;
|
||||
|
||||
for (FactionID faction(0); faction < VLC->townh->size(); ++faction)
|
||||
if (VLC->factions()->getById(faction)->hasTown())
|
||||
potentialPicks.push_back(faction);
|
||||
|
||||
assert(!potentialPicks.empty());
|
||||
return *RandomGeneratorUtil::nextItem(potentialPicks, rand);
|
||||
}
|
||||
|
||||
void CGTownInstance::pickRandomObject(CRandomGenerator & rand)
|
||||
{
|
||||
assert(ID == MapObjectID::TOWN || ID == MapObjectID::RANDOM_TOWN);
|
||||
if (ID == MapObjectID::RANDOM_TOWN)
|
||||
{
|
||||
ID = MapObjectID::TOWN;
|
||||
subID = randomizeFaction(rand);
|
||||
}
|
||||
}
|
||||
|
||||
void CGTownInstance::initObj(CRandomGenerator & rand) ///initialize town structures
|
||||
{
|
||||
blockVisit = true;
|
||||
|
||||
Reference in New Issue
Block a user