1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Trying to restore recent type of mapGenOptions.

This commit is contained in:
DjWarmonger 2014-05-23 11:56:51 +02:00
parent eae7e5c51f
commit 5b0b152aa3
4 changed files with 24 additions and 24 deletions

View File

@ -840,7 +840,7 @@ void CGameState::initNewGame()
CStopWatch sw;
// Gen map
CMapGenerator mapGenerator(*scenarioOps->mapGenOptions, scenarioOps->seedToBeUsed);
CMapGenerator mapGenerator(scenarioOps->mapGenOptions, scenarioOps->seedToBeUsed);
map = mapGenerator.generate();
// Update starting options

View File

@ -13,7 +13,7 @@
#include "CRmgTemplate.h"
#include "CRmgTemplateZone.h"
CMapGenerator::CMapGenerator(const CMapGenOptions & mapGenOptions, int randomSeed /*= std::time(nullptr)*/) :
CMapGenerator::CMapGenerator(shared_ptr<CMapGenOptions> mapGenOptions, int randomSeed /*= std::time(nullptr)*/) :
mapGenOptions(mapGenOptions), randomSeed(randomSeed)
{
rand.setSeed(randomSeed);
@ -26,7 +26,7 @@ CMapGenerator::~CMapGenerator()
ConstTransitivePtr<CMap> CMapGenerator::generate()
{
mapGenOptions.finalize(rand);
mapGenOptions->finalize(rand);
//map = make_unique<CMap>();
editManager = map->getEditManager();
@ -46,12 +46,12 @@ std::string CMapGenerator::getMapDescription() const
std::stringstream ss;
ss << boost::str(boost::format(std::string("Map created by the Random Map Generator.\nTemplate was %s, Random seed was %d, size %dx%d") +
", levels %s, humans %d, computers %d, water %s, monster %s, second expansion map") % mapGenOptions.getMapTemplate()->getName() %
randomSeed % map->width % map->height % (map->twoLevel ? "2" : "1") % static_cast<int>(mapGenOptions.getPlayerCount()) %
static_cast<int>(mapGenOptions.getCompOnlyPlayerCount()) % waterContentStr[mapGenOptions.getWaterContent()] %
monsterStrengthStr[mapGenOptions.getMonsterStrength()]);
", levels %s, humans %d, computers %d, water %s, monster %s, second expansion map") % mapGenOptions->getMapTemplate()->getName() %
randomSeed % map->width % map->height % (map->twoLevel ? "2" : "1") % static_cast<int>(mapGenOptions->getPlayerCount()) %
static_cast<int>(mapGenOptions->getCompOnlyPlayerCount()) % waterContentStr[mapGenOptions->getWaterContent()] %
monsterStrengthStr[mapGenOptions->getMonsterStrength()]);
for(const auto & pair : mapGenOptions.getPlayersSettings())
for(const auto & pair : mapGenOptions->getPlayersSettings())
{
const auto & pSettings = pair.second;
if(pSettings.getPlayerType() == EPlayerType::HUMAN)
@ -75,8 +75,8 @@ void CMapGenerator::addPlayerInfo()
int teamOffset = 0;
for(int i = 0; i < 2; ++i)
{
int playerCount = i == 0 ? mapGenOptions.getPlayerCount() : mapGenOptions.getCompOnlyPlayerCount();
int teamCount = i == 0 ? mapGenOptions.getTeamCount() : mapGenOptions.getCompOnlyTeamCount();
int playerCount = i == 0 ? mapGenOptions->getPlayerCount() : mapGenOptions->getCompOnlyPlayerCount();
int teamCount = i == 0 ? mapGenOptions->getTeamCount() : mapGenOptions->getCompOnlyTeamCount();
if(playerCount == 0)
{
@ -104,7 +104,7 @@ void CMapGenerator::addPlayerInfo()
}
// Team numbers are assigned randomly to every player
for(const auto & pair : mapGenOptions.getPlayersSettings())
for(const auto & pair : mapGenOptions->getPlayersSettings())
{
const auto & pSettings = pair.second;
PlayerInfo player;
@ -120,23 +120,23 @@ void CMapGenerator::addPlayerInfo()
map->players[pSettings.getColor().getNum()] = player;
}
map->howManyTeams = (mapGenOptions.getTeamCount() == 0 ? mapGenOptions.getPlayerCount() : mapGenOptions.getTeamCount())
+ (mapGenOptions.getCompOnlyTeamCount() == 0 ? mapGenOptions.getCompOnlyPlayerCount() : mapGenOptions.getCompOnlyTeamCount());
map->howManyTeams = (mapGenOptions->getTeamCount() == 0 ? mapGenOptions->getPlayerCount() : mapGenOptions->getTeamCount())
+ (mapGenOptions->getCompOnlyTeamCount() == 0 ? mapGenOptions->getCompOnlyPlayerCount() : mapGenOptions->getCompOnlyTeamCount());
}
void CMapGenerator::genZones()
{
map->initTerrain();
editManager->clearTerrain(&rand);
editManager->getTerrainSelection().selectRange(MapRect(int3(0, 0, 0), mapGenOptions.getWidth(), mapGenOptions.getHeight()));
editManager->getTerrainSelection().selectRange(MapRect(int3(0, 0, 0), mapGenOptions->getWidth(), mapGenOptions->getHeight()));
editManager->drawTerrain(ETerrainType::GRASS, &rand);
auto pcnt = mapGenOptions.getPlayerCount();
auto w = mapGenOptions.getWidth();
auto h = mapGenOptions.getHeight();
auto pcnt = mapGenOptions->getPlayerCount();
auto w = mapGenOptions->getWidth();
auto h = mapGenOptions->getHeight();
auto tmpl = mapGenOptions.getMapTemplate();
auto tmpl = mapGenOptions->getMapTemplate();
auto zones = tmpl->getZones();
int player_per_side = zones.size() > 4 ? 3 : 2;
@ -178,9 +178,9 @@ void CMapGenerator::fillZones()
void CMapGenerator::addHeaderInfo()
{
map->version = EMapFormat::SOD;
map->width = mapGenOptions.getWidth();
map->height = mapGenOptions.getHeight();
map->twoLevel = mapGenOptions.getHasTwoLevels();
map->width = mapGenOptions->getWidth();
map->height = mapGenOptions->getHeight();
map->twoLevel = mapGenOptions->getHasTwoLevels();
map->name = VLC->generaltexth->allTexts[740];
map->description = getMapDescription();
map->difficulty = 1;

View File

@ -33,12 +33,12 @@ class CMapGenerator;
class DLL_LINKAGE CMapGenerator
{
public:
explicit CMapGenerator(const CMapGenOptions & mapGenOptions, int randomSeed = std::time(nullptr));
explicit CMapGenerator(shared_ptr<CMapGenOptions> mapGenOptions, int randomSeed = std::time(nullptr));
~CMapGenerator(); // required due to unique_ptr
ConstTransitivePtr<CMap> generate();
CMapGenOptions mapGenOptions;
shared_ptr<CMapGenOptions> mapGenOptions;
ConstTransitivePtr<CMap> map;
CRandomGenerator rand;
int randomSeed;

View File

@ -340,7 +340,7 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
PlayerColor player(player_id);
auto town = new CGTownInstance();
town->ID = Obj::TOWN;
int townId = gen->mapGenOptions.getPlayersSettings().find(player)->second.getStartingTown();
int townId = gen->mapGenOptions->getPlayersSettings().find(player)->second.getStartingTown();
if(townId == CMapGenOptions::CPlayerSettings::RANDOM_TOWN)
townId = gen->rand.nextInt (VLC->townh->factions.size()); // all possible towns