2013-01-06 22:30:12 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CMapGenerator.h"
|
|
|
|
|
2013-04-07 13:48:07 +03:00
|
|
|
#include "../mapping/CMap.h"
|
2013-01-06 22:30:12 +03:00
|
|
|
#include "../VCMI_Lib.h"
|
|
|
|
#include "../CGeneralTextHandler.h"
|
2013-04-07 13:48:07 +03:00
|
|
|
#include "../mapping/CMapEditManager.h"
|
2013-01-06 22:30:12 +03:00
|
|
|
#include "../CTownHandler.h"
|
|
|
|
#include "../StringConstants.h"
|
2014-05-22 17:27:13 +03:00
|
|
|
#include "../filesystem/Filesystem.h"
|
2014-05-22 20:25:17 +03:00
|
|
|
#include "CRmgTemplate.h"
|
|
|
|
#include "CRmgTemplateZone.h"
|
2014-05-24 13:42:06 +03:00
|
|
|
#include "CZonePlacer.h"
|
2013-08-19 21:20:11 +03:00
|
|
|
|
2014-05-30 22:23:41 +03:00
|
|
|
void CMapGenerator::foreach_neighbour(const int3 &pos, std::function<void(int3& pos)> foo)
|
2014-05-24 19:39:58 +03:00
|
|
|
{
|
2014-05-30 17:50:06 +03:00
|
|
|
for(const int3 &dir : dirs)
|
|
|
|
{
|
2014-05-30 22:23:41 +03:00
|
|
|
int3 n = pos + dir;
|
2014-05-30 17:50:06 +03:00
|
|
|
if(map->isInTheMap(n))
|
2014-05-31 15:11:20 +03:00
|
|
|
foo(n);
|
2014-05-30 17:50:06 +03:00
|
|
|
}
|
2014-05-24 19:39:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-01 13:07:53 +03:00
|
|
|
CMapGenerator::CMapGenerator(shared_ptr<CMapGenOptions> mapGenOptions, int RandomSeed /*= std::time(nullptr)*/) :
|
|
|
|
mapGenOptions(mapGenOptions), randomSeed(RandomSeed), monolithIndex(0)
|
2014-05-22 17:27:13 +03:00
|
|
|
{
|
2014-05-22 20:25:17 +03:00
|
|
|
rand.setSeed(randomSeed);
|
2013-01-06 22:30:12 +03:00
|
|
|
}
|
|
|
|
|
2014-05-30 17:50:06 +03:00
|
|
|
void CMapGenerator::initTiles()
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
2014-05-30 17:50:06 +03:00
|
|
|
map->initTerrain();
|
|
|
|
|
|
|
|
int width = map->width;
|
|
|
|
int height = map->height;
|
|
|
|
|
|
|
|
int level = map->twoLevel ? 2 : 1;
|
|
|
|
tiles = new CTileInfo**[width];
|
|
|
|
for (int i = 0; i < width; ++i)
|
|
|
|
{
|
|
|
|
tiles[i] = new CTileInfo*[height];
|
|
|
|
for (int j = 0; j < height; ++j)
|
|
|
|
{
|
|
|
|
tiles[i][j] = new CTileInfo[level];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2014-05-30 17:50:06 +03:00
|
|
|
CMapGenerator::~CMapGenerator()
|
|
|
|
{
|
2014-07-01 13:07:53 +03:00
|
|
|
if (tiles)
|
2014-05-30 17:50:06 +03:00
|
|
|
{
|
2014-07-01 13:07:53 +03:00
|
|
|
int width = mapGenOptions->getWidth();
|
|
|
|
int height = mapGenOptions->getHeight();
|
|
|
|
for (int i=0; i < width; i++)
|
2014-05-30 17:50:06 +03:00
|
|
|
{
|
2014-07-01 13:07:53 +03:00
|
|
|
for(int j=0; j < height; j++)
|
2014-05-30 17:50:06 +03:00
|
|
|
{
|
|
|
|
delete [] tiles[i][j];
|
|
|
|
}
|
|
|
|
delete [] tiles[i];
|
|
|
|
}
|
|
|
|
delete [] tiles;
|
|
|
|
}
|
2013-01-06 22:30:12 +03:00
|
|
|
}
|
|
|
|
|
2014-05-23 14:23:03 +03:00
|
|
|
std::unique_ptr<CMap> CMapGenerator::generate()
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
2014-05-24 13:42:06 +03:00
|
|
|
mapGenOptions->finalize(rand);
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2014-05-24 13:42:06 +03:00
|
|
|
map = make_unique<CMap>();
|
|
|
|
editManager = map->getEditManager();
|
2014-05-23 18:12:31 +03:00
|
|
|
try
|
|
|
|
{
|
|
|
|
editManager->getUndoManager().setUndoRedoLimit(0);
|
|
|
|
addHeaderInfo();
|
2014-05-30 17:50:06 +03:00
|
|
|
initTiles();
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2014-05-23 18:12:31 +03:00
|
|
|
genZones();
|
2014-05-23 20:14:20 +03:00
|
|
|
map->calculateGuardingGreaturePositions(); //clear map so that all tiles are unguarded
|
2014-05-23 18:12:31 +03:00
|
|
|
fillZones();
|
2014-07-01 13:07:53 +03:00
|
|
|
//updated fuarded tiles will be calculated in CGameState::initMapObjects()
|
2014-05-23 18:12:31 +03:00
|
|
|
}
|
|
|
|
catch (rmgException &e)
|
|
|
|
{
|
2014-05-23 20:14:20 +03:00
|
|
|
logGlobal->errorStream() << "Random map generation received exception: " << e.what();
|
2014-05-23 18:12:31 +03:00
|
|
|
}
|
2013-01-06 22:30:12 +03:00
|
|
|
return std::move(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CMapGenerator::getMapDescription() const
|
|
|
|
{
|
|
|
|
const std::string waterContentStr[3] = { "none", "normal", "islands" };
|
|
|
|
const std::string monsterStrengthStr[3] = { "weak", "normal", "strong" };
|
|
|
|
|
2013-05-21 22:08:06 +03:00
|
|
|
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") +
|
2014-05-23 12:56:51 +03:00
|
|
|
", 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()]);
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2014-05-23 12:56:51 +03:00
|
|
|
for(const auto & pair : mapGenOptions->getPlayersSettings())
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
2013-04-14 22:24:31 +03:00
|
|
|
const auto & pSettings = pair.second;
|
|
|
|
if(pSettings.getPlayerType() == EPlayerType::HUMAN)
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
2013-03-03 20:06:03 +03:00
|
|
|
ss << ", " << GameConstants::PLAYER_COLOR_NAMES[pSettings.getColor().getNum()] << " is human";
|
2013-01-06 22:30:12 +03:00
|
|
|
}
|
2013-04-14 22:24:31 +03:00
|
|
|
if(pSettings.getStartingTown() != CMapGenOptions::CPlayerSettings::RANDOM_TOWN)
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
2013-03-03 20:06:03 +03:00
|
|
|
ss << ", " << GameConstants::PLAYER_COLOR_NAMES[pSettings.getColor().getNum()]
|
2014-05-22 22:40:34 +03:00
|
|
|
<< " town choice is " << VLC->townh->factions[pSettings.getStartingTown()]->name;
|
2013-01-06 22:30:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenerator::addPlayerInfo()
|
|
|
|
{
|
|
|
|
// Calculate which team numbers exist
|
|
|
|
std::array<std::list<int>, 2> teamNumbers; // 0= cpu/human, 1= cpu only
|
|
|
|
int teamOffset = 0;
|
|
|
|
for(int i = 0; i < 2; ++i)
|
|
|
|
{
|
2014-05-23 12:56:51 +03:00
|
|
|
int playerCount = i == 0 ? mapGenOptions->getPlayerCount() : mapGenOptions->getCompOnlyPlayerCount();
|
|
|
|
int teamCount = i == 0 ? mapGenOptions->getTeamCount() : mapGenOptions->getCompOnlyTeamCount();
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2013-05-21 22:08:06 +03:00
|
|
|
if(playerCount == 0)
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-21 22:08:06 +03:00
|
|
|
int playersPerTeam = playerCount /
|
|
|
|
(teamCount == 0 ? playerCount : teamCount);
|
|
|
|
int teamCountNorm = teamCount;
|
|
|
|
if(teamCountNorm == 0)
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
2013-05-21 22:08:06 +03:00
|
|
|
teamCountNorm = playerCount;
|
2013-01-06 22:30:12 +03:00
|
|
|
}
|
2013-05-21 22:08:06 +03:00
|
|
|
for(int j = 0; j < teamCountNorm; ++j)
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
|
|
|
for(int k = 0; k < playersPerTeam; ++k)
|
|
|
|
{
|
|
|
|
teamNumbers[i].push_back(j + teamOffset);
|
|
|
|
}
|
|
|
|
}
|
2013-05-21 22:08:06 +03:00
|
|
|
for(int j = 0; j < playerCount - teamCountNorm * playersPerTeam; ++j)
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
|
|
|
teamNumbers[i].push_back(j + teamOffset);
|
|
|
|
}
|
2013-05-21 22:08:06 +03:00
|
|
|
teamOffset += teamCountNorm;
|
2013-01-06 22:30:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Team numbers are assigned randomly to every player
|
2014-05-23 12:56:51 +03:00
|
|
|
for(const auto & pair : mapGenOptions->getPlayersSettings())
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
2013-04-14 22:24:31 +03:00
|
|
|
const auto & pSettings = pair.second;
|
2013-01-06 22:30:12 +03:00
|
|
|
PlayerInfo player;
|
|
|
|
player.canComputerPlay = true;
|
2013-04-14 22:24:31 +03:00
|
|
|
int j = pSettings.getPlayerType() == EPlayerType::COMP_ONLY ? 1 : 0;
|
2013-01-06 22:30:12 +03:00
|
|
|
if(j == 0)
|
|
|
|
{
|
|
|
|
player.canHumanPlay = true;
|
|
|
|
}
|
2014-05-29 18:34:46 +03:00
|
|
|
|
|
|
|
auto itTeam = RandomGeneratorUtil::nextItem(teamNumbers[j], rand);
|
2013-03-03 20:06:03 +03:00
|
|
|
player.team = TeamID(*itTeam);
|
2013-01-06 22:30:12 +03:00
|
|
|
teamNumbers[j].erase(itTeam);
|
2013-03-03 20:06:03 +03:00
|
|
|
map->players[pSettings.getColor().getNum()] = player;
|
2013-01-06 22:30:12 +03:00
|
|
|
}
|
|
|
|
|
2014-05-23 12:56:51 +03:00
|
|
|
map->howManyTeams = (mapGenOptions->getTeamCount() == 0 ? mapGenOptions->getPlayerCount() : mapGenOptions->getTeamCount())
|
|
|
|
+ (mapGenOptions->getCompOnlyTeamCount() == 0 ? mapGenOptions->getCompOnlyPlayerCount() : mapGenOptions->getCompOnlyTeamCount());
|
2013-01-06 22:30:12 +03:00
|
|
|
}
|
|
|
|
|
2014-05-22 17:27:13 +03:00
|
|
|
void CMapGenerator::genZones()
|
2013-01-06 22:30:12 +03:00
|
|
|
{
|
2014-05-22 20:25:17 +03:00
|
|
|
editManager->clearTerrain(&rand);
|
2014-05-23 12:56:51 +03:00
|
|
|
editManager->getTerrainSelection().selectRange(MapRect(int3(0, 0, 0), mapGenOptions->getWidth(), mapGenOptions->getHeight()));
|
2014-05-22 20:25:17 +03:00
|
|
|
editManager->drawTerrain(ETerrainType::GRASS, &rand);
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2014-05-23 12:56:51 +03:00
|
|
|
auto pcnt = mapGenOptions->getPlayerCount();
|
|
|
|
auto w = mapGenOptions->getWidth();
|
|
|
|
auto h = mapGenOptions->getHeight();
|
2013-01-06 22:30:12 +03:00
|
|
|
|
2013-04-14 21:52:05 +03:00
|
|
|
|
2014-05-23 12:56:51 +03:00
|
|
|
auto tmpl = mapGenOptions->getMapTemplate();
|
2014-05-24 13:42:06 +03:00
|
|
|
zones = tmpl->getZones(); //copy from template (refactor?)
|
2013-01-20 17:43:58 +03:00
|
|
|
|
2014-05-22 17:27:13 +03:00
|
|
|
int player_per_side = zones.size() > 4 ? 3 : 2;
|
|
|
|
|
|
|
|
logGlobal->infoStream() << boost::format("Map size %d %d, players per side %d") % w % h % player_per_side;
|
|
|
|
|
2014-05-24 13:42:06 +03:00
|
|
|
CZonePlacer placer(this);
|
|
|
|
placer.placeZones(mapGenOptions, &rand);
|
2014-05-24 15:06:08 +03:00
|
|
|
placer.assignZones(mapGenOptions);
|
2014-05-24 13:42:06 +03:00
|
|
|
|
2014-05-22 17:27:13 +03:00
|
|
|
int i = 0;
|
2014-05-24 15:06:08 +03:00
|
|
|
|
2014-05-22 17:27:13 +03:00
|
|
|
for(auto const it : zones)
|
|
|
|
{
|
2014-05-22 20:25:17 +03:00
|
|
|
CRmgTemplateZone * zone = it.second;
|
|
|
|
zone->setType(i < pcnt ? ETemplateZoneType::PLAYER_START : ETemplateZoneType::TREASURE);
|
2014-05-22 17:27:13 +03:00
|
|
|
this->zones[it.first] = zone;
|
|
|
|
++i;
|
2013-01-06 22:30:12 +03:00
|
|
|
}
|
2014-05-22 17:27:13 +03:00
|
|
|
logGlobal->infoStream() << "Zones generated successfully";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenerator::fillZones()
|
|
|
|
{
|
|
|
|
logGlobal->infoStream() << "Started filling zones";
|
2014-05-31 11:56:14 +03:00
|
|
|
|
2014-06-01 17:31:15 +03:00
|
|
|
createConnections();
|
2014-05-31 11:56:14 +03:00
|
|
|
for (auto it : zones)
|
2014-05-22 17:27:13 +03:00
|
|
|
{
|
2014-05-31 11:56:14 +03:00
|
|
|
//make sure all connections are passable before creating borders
|
2014-05-30 22:23:41 +03:00
|
|
|
it.second->createBorder(this);
|
2014-05-22 20:25:17 +03:00
|
|
|
it.second->fill(this);
|
2014-05-22 17:27:13 +03:00
|
|
|
}
|
|
|
|
logGlobal->infoStream() << "Zones filled successfully";
|
2013-01-06 22:30:12 +03:00
|
|
|
}
|
|
|
|
|
2014-06-01 17:31:15 +03:00
|
|
|
void CMapGenerator::createConnections()
|
|
|
|
{
|
|
|
|
for (auto connection : mapGenOptions->getMapTemplate()->getConnections())
|
|
|
|
{
|
|
|
|
auto zoneA = connection.getZoneA();
|
|
|
|
auto zoneB = connection.getZoneB();
|
|
|
|
|
|
|
|
//rearrange tiles in random order
|
|
|
|
auto tilesCopy = zoneA->getTileInfo();
|
|
|
|
std::vector<int3> tiles(tilesCopy.begin(), tilesCopy.end());
|
2014-06-07 15:02:57 +03:00
|
|
|
RandomGeneratorUtil::randomShuffle(tiles, rand);
|
2014-06-01 17:31:15 +03:00
|
|
|
|
|
|
|
int3 guardPos(-1,-1,-1);
|
|
|
|
|
|
|
|
auto otherZoneTiles = zoneB->getTileInfo();
|
|
|
|
|
2014-07-04 10:54:55 +03:00
|
|
|
int3 posA = zoneA->getPos();
|
|
|
|
int3 posB = zoneB->getPos();
|
|
|
|
|
|
|
|
if (posA.z == posB.z)
|
2014-06-01 17:31:15 +03:00
|
|
|
{
|
2014-07-03 18:24:28 +03:00
|
|
|
for (auto tile : tiles)
|
2014-06-01 17:31:15 +03:00
|
|
|
{
|
2014-07-03 18:24:28 +03:00
|
|
|
if (isBlocked(tile)) //tiles may be occupied by subterranean gates already placed
|
|
|
|
continue;
|
|
|
|
foreach_neighbour (tile, [&guardPos, tile, &otherZoneTiles, this](int3 &pos)
|
|
|
|
{
|
2014-07-04 11:45:00 +03:00
|
|
|
//if (vstd::contains(otherZoneTiles, pos) && !this->isBlocked(pos))
|
|
|
|
if (vstd::contains(otherZoneTiles, pos))
|
2014-07-03 18:24:28 +03:00
|
|
|
guardPos = tile;
|
|
|
|
});
|
|
|
|
if (guardPos.valid())
|
|
|
|
{
|
|
|
|
setOccupied (guardPos, ETileType::FREE); //just in case monster is too weak to spawn
|
2014-07-04 10:54:55 +03:00
|
|
|
zoneA->addMonster (this, guardPos, connection.getGuardStrength());
|
2014-07-03 18:24:28 +03:00
|
|
|
//zones can make paths only in their own area
|
2014-07-04 10:54:55 +03:00
|
|
|
zoneA->crunchPath (this, guardPos, posA, zoneA->getId(), zoneA->getFreePaths()); //make connection towards our zone center
|
|
|
|
zoneB->crunchPath (this, guardPos, posB, zoneB->getId(), zoneB->getFreePaths()); //make connection towards other zone center
|
2014-07-03 18:24:28 +03:00
|
|
|
break; //we're done with this connection
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //create subterranean gates between two zones
|
|
|
|
{
|
2014-07-04 00:11:24 +03:00
|
|
|
//find point on the path between zones
|
2014-07-03 18:24:28 +03:00
|
|
|
float3 offset (posB.x - posA.x, posB.y - posA.y, 0);
|
|
|
|
|
2014-07-04 00:11:24 +03:00
|
|
|
float distance = posB.dist2d(posA);
|
|
|
|
offset /= distance; //get unit vector
|
|
|
|
float3 vec (0, 0, 0);
|
2014-07-03 18:24:28 +03:00
|
|
|
//use reduced size of underground zone - make sure gate does not stand on rock
|
2014-07-04 00:11:24 +03:00
|
|
|
int3 tile = posA;
|
2014-07-03 18:24:28 +03:00
|
|
|
int3 otherTile = tile;
|
|
|
|
|
2014-07-04 00:11:24 +03:00
|
|
|
bool stop = false;
|
|
|
|
while (!stop)
|
2014-06-01 17:31:15 +03:00
|
|
|
{
|
2014-07-04 10:54:55 +03:00
|
|
|
vec += offset; //this vector may extend beyond line between zone centers, in case they are directly over each other
|
2014-07-04 00:11:24 +03:00
|
|
|
tile = posA + int3(vec.x, vec.y, 0);
|
|
|
|
float distanceFromA = posA.dist2d(tile);
|
|
|
|
float distanceFromB = posB.dist2d(tile);
|
2014-07-04 10:54:55 +03:00
|
|
|
|
2014-07-04 11:45:00 +03:00
|
|
|
if (distanceFromA + distanceFromB > std::max<int>(zoneA->getSize() + zoneB->getSize(), distance))
|
2014-07-04 10:54:55 +03:00
|
|
|
break; //we are too far away to ever connect
|
2014-07-04 00:11:24 +03:00
|
|
|
|
2014-07-04 11:45:00 +03:00
|
|
|
//if zone is underground, gate must fit within its (reduced) radius
|
|
|
|
if (distanceFromA > 5 && (!posA.z || distanceFromA < zoneA->getSize() - 3) &&
|
|
|
|
distanceFromB > 5 && (!posB.z || distanceFromB < zoneB->getSize() - 3))
|
2014-07-04 00:11:24 +03:00
|
|
|
{
|
|
|
|
otherTile = tile;
|
|
|
|
otherTile.z = posB.z;
|
|
|
|
|
|
|
|
if (vstd::contains(tiles, tile) && vstd::contains(otherZoneTiles, otherTile))
|
|
|
|
{
|
2014-07-04 11:45:00 +03:00
|
|
|
bool withinZone = true;
|
|
|
|
|
|
|
|
foreach_neighbour (tile, [&withinZone, &tiles](int3 &pos)
|
|
|
|
{
|
|
|
|
if (!vstd::contains(tiles, pos))
|
|
|
|
withinZone = false;
|
|
|
|
});
|
|
|
|
foreach_neighbour (otherTile, [&withinZone, &otherZoneTiles](int3 &pos)
|
|
|
|
{
|
|
|
|
if (!vstd::contains(otherZoneTiles, pos))
|
|
|
|
withinZone = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (withinZone)
|
|
|
|
{
|
|
|
|
auto gate1 = new CGTeleport;
|
|
|
|
gate1->ID = Obj::SUBTERRANEAN_GATE;
|
|
|
|
gate1->subID = 0;
|
|
|
|
zoneA->placeAndGuardObject(this, gate1, tile, connection.getGuardStrength());
|
|
|
|
auto gate2 = new CGTeleport(*gate1);
|
|
|
|
zoneB->placeAndGuardObject(this, gate2, otherTile, connection.getGuardStrength());
|
|
|
|
|
|
|
|
stop = true; //we are done, go to next connection
|
|
|
|
}
|
2014-07-04 00:11:24 +03:00
|
|
|
}
|
|
|
|
}
|
2014-06-01 17:31:15 +03:00
|
|
|
}
|
2014-07-04 00:11:24 +03:00
|
|
|
if (stop)
|
|
|
|
continue;
|
2014-06-01 17:31:15 +03:00
|
|
|
}
|
|
|
|
if (!guardPos.valid())
|
|
|
|
{
|
|
|
|
auto teleport1 = new CGTeleport;
|
|
|
|
teleport1->ID = Obj::MONOLITH_TWO_WAY;
|
|
|
|
teleport1->subID = getNextMonlithIndex();
|
|
|
|
|
|
|
|
auto teleport2 = new CGTeleport(*teleport1);
|
|
|
|
|
|
|
|
zoneA->addRequiredObject (teleport1, connection.getGuardStrength());
|
|
|
|
zoneB->addRequiredObject (teleport2, connection.getGuardStrength());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-06 22:30:12 +03:00
|
|
|
void CMapGenerator::addHeaderInfo()
|
|
|
|
{
|
|
|
|
map->version = EMapFormat::SOD;
|
2014-05-23 12:56:51 +03:00
|
|
|
map->width = mapGenOptions->getWidth();
|
|
|
|
map->height = mapGenOptions->getHeight();
|
|
|
|
map->twoLevel = mapGenOptions->getHasTwoLevels();
|
2013-01-06 22:30:12 +03:00
|
|
|
map->name = VLC->generaltexth->allTexts[740];
|
|
|
|
map->description = getMapDescription();
|
|
|
|
map->difficulty = 1;
|
|
|
|
addPlayerInfo();
|
2014-05-24 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::map<TRmgTemplateZoneId, CRmgTemplateZone*> CMapGenerator::getZones() const
|
|
|
|
{
|
|
|
|
return zones;
|
2014-05-29 18:34:46 +03:00
|
|
|
}
|
2014-05-30 17:50:06 +03:00
|
|
|
|
2014-05-30 22:23:41 +03:00
|
|
|
bool CMapGenerator::isBlocked(const int3 &tile) const
|
2014-05-30 17:50:06 +03:00
|
|
|
{
|
|
|
|
if (!map->isInTheMap(tile))
|
|
|
|
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
|
|
|
|
|
|
|
|
return tiles[tile.x][tile.y][tile.z].isBlocked();
|
|
|
|
}
|
2014-05-30 22:23:41 +03:00
|
|
|
bool CMapGenerator::shouldBeBlocked(const int3 &tile) const
|
2014-05-30 17:50:06 +03:00
|
|
|
{
|
|
|
|
if (!map->isInTheMap(tile))
|
|
|
|
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
|
|
|
|
|
|
|
|
return tiles[tile.x][tile.y][tile.z].shouldBeBlocked();
|
|
|
|
}
|
2014-05-30 22:23:41 +03:00
|
|
|
bool CMapGenerator::isPossible(const int3 &tile) const
|
2014-05-30 17:50:06 +03:00
|
|
|
{
|
|
|
|
if (!map->isInTheMap(tile))
|
|
|
|
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
|
|
|
|
|
|
|
|
return tiles[tile.x][tile.y][tile.z].isPossible();
|
|
|
|
}
|
2014-05-30 22:23:41 +03:00
|
|
|
bool CMapGenerator::isFree(const int3 &tile) const
|
2014-05-30 17:50:06 +03:00
|
|
|
{
|
|
|
|
if (!map->isInTheMap(tile))
|
|
|
|
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
|
|
|
|
|
|
|
|
return tiles[tile.x][tile.y][tile.z].isFree();
|
|
|
|
}
|
2014-07-04 00:11:24 +03:00
|
|
|
bool CMapGenerator::isUsed(const int3 &tile) const
|
|
|
|
{
|
|
|
|
if (!map->isInTheMap(tile))
|
|
|
|
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
|
|
|
|
|
|
|
|
return tiles[tile.x][tile.y][tile.z].isUsed();
|
|
|
|
}
|
2014-05-31 15:11:20 +03:00
|
|
|
void CMapGenerator::setOccupied(const int3 &tile, ETileType::ETileType state)
|
2014-05-30 17:50:06 +03:00
|
|
|
{
|
|
|
|
if (!map->isInTheMap(tile))
|
|
|
|
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
|
|
|
|
|
|
|
|
tiles[tile.x][tile.y][tile.z].setOccupied(state);
|
|
|
|
}
|
2014-05-30 22:23:41 +03:00
|
|
|
|
2014-05-31 15:11:20 +03:00
|
|
|
CTileInfo CMapGenerator::getTile(const int3& tile) const
|
2014-05-30 22:23:41 +03:00
|
|
|
{
|
|
|
|
if (!map->isInTheMap(tile))
|
|
|
|
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
|
|
|
|
|
|
|
|
return tiles[tile.x][tile.y][tile.z];
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMapGenerator::setNearestObjectDistance(int3 &tile, int value)
|
|
|
|
{
|
|
|
|
if (!map->isInTheMap(tile))
|
|
|
|
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
|
|
|
|
|
|
|
|
tiles[tile.x][tile.y][tile.z].setNearestObjectDistance(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CMapGenerator::getNearestObjectDistance(const int3 &tile) const
|
|
|
|
{
|
|
|
|
if (!map->isInTheMap(tile))
|
|
|
|
throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
|
|
|
|
|
|
|
|
return tiles[tile.x][tile.y][tile.z].getNearestObjectDistance();
|
2014-06-01 13:02:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int CMapGenerator::getNextMonlithIndex()
|
|
|
|
{
|
|
|
|
return monolithIndex++;
|
2014-06-01 22:53:00 +03:00
|
|
|
}
|