CMapGenerator.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. #include "StdInc.h"
  2. #include "CMapGenerator.h"
  3. #include "../mapping/CMap.h"
  4. #include "../VCMI_Lib.h"
  5. #include "../CGeneralTextHandler.h"
  6. #include "../mapping/CMapEditManager.h"
  7. #include "../CTownHandler.h"
  8. #include "../StringConstants.h"
  9. #include "../filesystem/Filesystem.h"
  10. #include "CRmgTemplate.h"
  11. #include "CRmgTemplateZone.h"
  12. #include "CZonePlacer.h"
  13. #include "../mapObjects/CObjectClassesHandler.h"
  14. static const int3 dirs4[] = {int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0)};
  15. void CMapGenerator::foreach_neighbour(const int3 &pos, std::function<void(int3& pos)> foo)
  16. {
  17. for(const int3 &dir : dirs)
  18. {
  19. int3 n = pos + dir;
  20. if(map->isInTheMap(n))
  21. foo(n);
  22. }
  23. }
  24. void CMapGenerator::foreachDirectNeighbour(const int3& pos, std::function<void(int3& pos)> foo)
  25. {
  26. for(const int3 &dir : dirs4)
  27. {
  28. int3 n = pos + dir;
  29. if(map->isInTheMap(n))
  30. foo(n);
  31. }
  32. }
  33. CMapGenerator::CMapGenerator() :
  34. zonesTotal(0), monolithIndex(0)
  35. {
  36. }
  37. void CMapGenerator::initTiles()
  38. {
  39. map->initTerrain();
  40. int width = map->width;
  41. int height = map->height;
  42. int level = map->twoLevel ? 2 : 1;
  43. tiles = new CTileInfo**[width];
  44. for (int i = 0; i < width; ++i)
  45. {
  46. tiles[i] = new CTileInfo*[height];
  47. for (int j = 0; j < height; ++j)
  48. {
  49. tiles[i][j] = new CTileInfo[level];
  50. }
  51. }
  52. }
  53. CMapGenerator::~CMapGenerator()
  54. {
  55. if (tiles)
  56. {
  57. int width = mapGenOptions->getWidth();
  58. int height = mapGenOptions->getHeight();
  59. for (int i=0; i < width; i++)
  60. {
  61. for(int j=0; j < height; j++)
  62. {
  63. delete [] tiles[i][j];
  64. }
  65. delete [] tiles[i];
  66. }
  67. delete [] tiles;
  68. }
  69. }
  70. void CMapGenerator::initPrisonsRemaining()
  71. {
  72. prisonsRemaining = 0;
  73. for (auto isAllowed : map->allowedHeroes)
  74. {
  75. if (isAllowed)
  76. prisonsRemaining++;
  77. }
  78. prisonsRemaining = std::max<int> (0, prisonsRemaining - 16 * mapGenOptions->getPlayerCount()); //so at least 16 heroes will be available for every player
  79. }
  80. void CMapGenerator::initQuestArtsRemaining()
  81. {
  82. for (auto art : VLC->arth->artifacts)
  83. {
  84. if (art->aClass == CArtifact::ART_TREASURE && art->constituentOf.empty()) //don't use parts of combined artifacts
  85. questArtifacts.push_back(art->id);
  86. }
  87. }
  88. std::unique_ptr<CMap> CMapGenerator::generate(CMapGenOptions * mapGenOptions, int randomSeed /*= std::time(nullptr)*/)
  89. {
  90. this->mapGenOptions = mapGenOptions;
  91. this->randomSeed = randomSeed;
  92. assert(mapGenOptions);
  93. rand.setSeed(this->randomSeed);
  94. mapGenOptions->finalize(rand);
  95. map = make_unique<CMap>();
  96. editManager = map->getEditManager();
  97. try
  98. {
  99. editManager->getUndoManager().setUndoRedoLimit(0);
  100. //FIXME: somehow mapGenOption is nullptr at this point :?
  101. addHeaderInfo();
  102. initTiles();
  103. initPrisonsRemaining();
  104. initQuestArtsRemaining();
  105. genZones();
  106. map->calculateGuardingGreaturePositions(); //clear map so that all tiles are unguarded
  107. fillZones();
  108. //updated guarded tiles will be calculated in CGameState::initMapObjects()
  109. }
  110. catch (rmgException &e)
  111. {
  112. logGlobal->errorStream() << "Random map generation received exception: " << e.what();
  113. }
  114. return std::move(map);
  115. }
  116. std::string CMapGenerator::getMapDescription() const
  117. {
  118. assert(mapGenOptions);
  119. assert(map);
  120. const std::string waterContentStr[3] = { "none", "normal", "islands" };
  121. const std::string monsterStrengthStr[3] = { "weak", "normal", "strong" };
  122. int monsterStrengthIndex = mapGenOptions->getMonsterStrength() - EMonsterStrength::GLOBAL_WEAK; //does not start from 0
  123. std::stringstream ss;
  124. ss << boost::str(boost::format(std::string("Map created by the Random Map Generator.\nTemplate was %s, Random seed was %d, size %dx%d") +
  125. ", levels %s, humans %d, computers %d, water %s, monster %s, VCMI map") % mapGenOptions->getMapTemplate()->getName() %
  126. randomSeed % map->width % map->height % (map->twoLevel ? "2" : "1") % static_cast<int>(mapGenOptions->getPlayerCount()) %
  127. static_cast<int>(mapGenOptions->getCompOnlyPlayerCount()) % waterContentStr[mapGenOptions->getWaterContent()] %
  128. monsterStrengthStr[monsterStrengthIndex]);
  129. for(const auto & pair : mapGenOptions->getPlayersSettings())
  130. {
  131. const auto & pSettings = pair.second;
  132. if(pSettings.getPlayerType() == EPlayerType::HUMAN)
  133. {
  134. ss << ", " << GameConstants::PLAYER_COLOR_NAMES[pSettings.getColor().getNum()] << " is human";
  135. }
  136. if(pSettings.getStartingTown() != CMapGenOptions::CPlayerSettings::RANDOM_TOWN)
  137. {
  138. ss << ", " << GameConstants::PLAYER_COLOR_NAMES[pSettings.getColor().getNum()]
  139. << " town choice is " << VLC->townh->factions[pSettings.getStartingTown()]->name;
  140. }
  141. }
  142. return ss.str();
  143. }
  144. void CMapGenerator::addPlayerInfo()
  145. {
  146. // Calculate which team numbers exist
  147. std::array<std::list<int>, 2> teamNumbers; // 0= cpu/human, 1= cpu only
  148. int teamOffset = 0;
  149. for(int i = 0; i < 2; ++i)
  150. {
  151. int playerCount = i == 0 ? mapGenOptions->getPlayerCount() : mapGenOptions->getCompOnlyPlayerCount();
  152. int teamCount = i == 0 ? mapGenOptions->getTeamCount() : mapGenOptions->getCompOnlyTeamCount();
  153. if(playerCount == 0)
  154. {
  155. continue;
  156. }
  157. int playersPerTeam = playerCount /
  158. (teamCount == 0 ? playerCount : teamCount);
  159. int teamCountNorm = teamCount;
  160. if(teamCountNorm == 0)
  161. {
  162. teamCountNorm = playerCount;
  163. }
  164. for(int j = 0; j < teamCountNorm; ++j)
  165. {
  166. for(int k = 0; k < playersPerTeam; ++k)
  167. {
  168. teamNumbers[i].push_back(j + teamOffset);
  169. }
  170. }
  171. for(int j = 0; j < playerCount - teamCountNorm * playersPerTeam; ++j)
  172. {
  173. teamNumbers[i].push_back(j + teamOffset);
  174. }
  175. teamOffset += teamCountNorm;
  176. }
  177. // Team numbers are assigned randomly to every player
  178. for(const auto & pair : mapGenOptions->getPlayersSettings())
  179. {
  180. const auto & pSettings = pair.second;
  181. PlayerInfo player;
  182. player.canComputerPlay = true;
  183. int j = pSettings.getPlayerType() == EPlayerType::COMP_ONLY ? 1 : 0;
  184. if(j == 0)
  185. {
  186. player.canHumanPlay = true;
  187. }
  188. auto itTeam = RandomGeneratorUtil::nextItem(teamNumbers[j], rand);
  189. player.team = TeamID(*itTeam);
  190. teamNumbers[j].erase(itTeam);
  191. map->players[pSettings.getColor().getNum()] = player;
  192. }
  193. map->howManyTeams = (mapGenOptions->getTeamCount() == 0 ? mapGenOptions->getPlayerCount() : mapGenOptions->getTeamCount())
  194. + (mapGenOptions->getCompOnlyTeamCount() == 0 ? mapGenOptions->getCompOnlyPlayerCount() : mapGenOptions->getCompOnlyTeamCount());
  195. }
  196. void CMapGenerator::genZones()
  197. {
  198. editManager->clearTerrain(&rand);
  199. editManager->getTerrainSelection().selectRange(MapRect(int3(0, 0, 0), mapGenOptions->getWidth(), mapGenOptions->getHeight()));
  200. editManager->drawTerrain(ETerrainType::GRASS, &rand);
  201. auto tmpl = mapGenOptions->getMapTemplate();
  202. zones = tmpl->getZones(); //copy from template (refactor?)
  203. CZonePlacer placer(this);
  204. placer.placeZones(mapGenOptions, &rand);
  205. placer.assignZones(mapGenOptions);
  206. logGlobal->infoStream() << "Zones generated successfully";
  207. }
  208. void CMapGenerator::fillZones()
  209. {
  210. //init native town count with 0
  211. for (auto faction : VLC->townh->getAllowedFactions())
  212. zonesPerFaction[faction] = 0;
  213. logGlobal->infoStream() << "Started filling zones";
  214. //initialize possible tiles before any object is actually placed
  215. for (auto it : zones)
  216. {
  217. it.second->initFreeTiles(this);
  218. }
  219. findZonesForQuestArts();
  220. createConnections();
  221. //make sure all connections are passable before creating borders
  222. for (auto it : zones)
  223. {
  224. it.second->createBorder(this);
  225. //we need info about all town types to evaluate dwellings and pandoras with creatures properly
  226. it.second->initTownType(this);
  227. }
  228. std::vector<CRmgTemplateZone*> treasureZones;
  229. for (auto it : zones)
  230. {
  231. it.second->fill(this);
  232. if (it.second->getType() == ETemplateZoneType::TREASURE)
  233. treasureZones.push_back(it.second);
  234. }
  235. //set apriopriate free/occupied tiles, including blocked underground rock
  236. createObstaclesCommon1();
  237. //set back original terrain for underground zones
  238. for (auto it : zones)
  239. it.second->createObstacles1(this);
  240. createObstaclesCommon2();
  241. //place actual obstacles matching zone terrain
  242. for (auto it : zones)
  243. {
  244. it.second->createObstacles2(this);
  245. }
  246. #define PRINT_MAP_BEFORE_ROADS true
  247. if (PRINT_MAP_BEFORE_ROADS) //enable to debug
  248. {
  249. std::ofstream out("road debug");
  250. int levels = map->twoLevel ? 2 : 1;
  251. int width = map->width;
  252. int height = map->height;
  253. for (int k = 0; k < levels; k++)
  254. {
  255. for (int j = 0; j<height; j++)
  256. {
  257. for (int i = 0; i<width; i++)
  258. {
  259. char t = '?';
  260. switch (getTile(int3(i, j, k)).getTileType())
  261. {
  262. case ETileType::FREE:
  263. t = ' '; break;
  264. case ETileType::BLOCKED:
  265. t = '#'; break;
  266. case ETileType::POSSIBLE:
  267. t = '-'; break;
  268. case ETileType::USED:
  269. t = 'O'; break;
  270. }
  271. out << t;
  272. }
  273. out << std::endl;
  274. }
  275. out << std::endl;
  276. }
  277. out << std::endl;
  278. }
  279. for (auto it : zones)
  280. {
  281. it.second->connectRoads(this); //draw roads after everything else has been placed
  282. }
  283. //find place for Grail
  284. if (treasureZones.empty())
  285. {
  286. for (auto it : zones)
  287. treasureZones.push_back(it.second);
  288. }
  289. auto grailZone = *RandomGeneratorUtil::nextItem(treasureZones, rand);
  290. map->grailPos = *RandomGeneratorUtil::nextItem(*grailZone->getFreePaths(), rand);
  291. logGlobal->infoStream() << "Zones filled successfully";
  292. }
  293. void CMapGenerator::createObstaclesCommon1()
  294. {
  295. if (map->twoLevel) //underground
  296. {
  297. //negative approach - create rock tiles first, then make sure all accessible tiles have no rock
  298. std::vector<int3> rockTiles;
  299. for (int x = 0; x < map->width; x++)
  300. {
  301. for (int y = 0; y < map->height; y++)
  302. {
  303. int3 tile(x, y, 1);
  304. if (shouldBeBlocked(tile))
  305. {
  306. rockTiles.push_back(tile);
  307. }
  308. }
  309. }
  310. editManager->getTerrainSelection().setSelection(rockTiles);
  311. editManager->drawTerrain(ETerrainType::ROCK, &rand);
  312. }
  313. }
  314. void CMapGenerator::createObstaclesCommon2()
  315. {
  316. if (map->twoLevel)
  317. {
  318. //finally mark rock tiles as occupied, spawn no obstacles there
  319. for (int x = 0; x < map->width; x++)
  320. {
  321. for (int y = 0; y < map->height; y++)
  322. {
  323. int3 tile(x, y, 1);
  324. if (map->getTile(tile).terType == ETerrainType::ROCK)
  325. {
  326. setOccupied(tile, ETileType::USED);
  327. }
  328. }
  329. }
  330. }
  331. //tighten obstacles to improve visuals
  332. for (int i = 0; i < 3; ++i)
  333. {
  334. int blockedTiles = 0;
  335. int freeTiles = 0;
  336. for (int z = 0; z < (map->twoLevel ? 2 : 1); z++)
  337. {
  338. for (int x = 0; x < map->width; x++)
  339. {
  340. for (int y = 0; y < map->height; y++)
  341. {
  342. int3 tile(x, y, z);
  343. if (!isPossible(tile)) //only possible tiles can change
  344. continue;
  345. int blockedNeighbours = 0;
  346. int freeNeighbours = 0;
  347. foreach_neighbour(tile, [this, &blockedNeighbours, &freeNeighbours](int3 &pos)
  348. {
  349. if (this->isBlocked(pos))
  350. blockedNeighbours++;
  351. if (this->isFree(pos))
  352. freeNeighbours++;
  353. });
  354. if (blockedNeighbours > 4)
  355. {
  356. setOccupied(tile, ETileType::BLOCKED);
  357. blockedTiles++;
  358. }
  359. else if (freeNeighbours > 4)
  360. {
  361. setOccupied(tile, ETileType::FREE);
  362. freeTiles++;
  363. }
  364. }
  365. }
  366. }
  367. logGlobal->traceStream() << boost::format("Set %d tiles to BLOCKED and %d tiles to FREE") % blockedTiles % freeTiles;
  368. }
  369. }
  370. void CMapGenerator::findZonesForQuestArts()
  371. {
  372. //we want to place arties in zones that were not yet filled (higher index)
  373. for (auto connection : mapGenOptions->getMapTemplate()->getConnections())
  374. {
  375. auto zoneA = connection.getZoneA();
  376. auto zoneB = connection.getZoneB();
  377. if (zoneA->getId() > zoneB->getId())
  378. {
  379. zoneB->setQuestArtZone(zoneA);
  380. }
  381. else if (zoneA->getId() < zoneB->getId())
  382. {
  383. zoneA->setQuestArtZone(zoneB);
  384. }
  385. }
  386. }
  387. void CMapGenerator::createConnections()
  388. {
  389. for (auto connection : mapGenOptions->getMapTemplate()->getConnections())
  390. {
  391. auto zoneA = connection.getZoneA();
  392. auto zoneB = connection.getZoneB();
  393. //rearrange tiles in random order
  394. auto tilesCopy = zoneA->getTileInfo();
  395. std::vector<int3> tiles(tilesCopy.begin(), tilesCopy.end());
  396. RandomGeneratorUtil::randomShuffle(tiles, rand);
  397. int3 guardPos(-1,-1,-1);
  398. auto otherZoneTiles = zoneB->getTileInfo();
  399. int3 posA = zoneA->getPos();
  400. int3 posB = zoneB->getPos();
  401. if (posA.z == posB.z)
  402. {
  403. for (auto tile : tiles)
  404. {
  405. if (isBlocked(tile)) //tiles may be occupied by subterranean gates already placed
  406. continue;
  407. foreach_neighbour (tile, [&guardPos, tile, &otherZoneTiles, this](int3 &pos)
  408. {
  409. //if (vstd::contains(otherZoneTiles, pos) && !this->isBlocked(pos))
  410. if (vstd::contains(otherZoneTiles, pos))
  411. guardPos = tile;
  412. });
  413. if (guardPos.valid())
  414. {
  415. setOccupied (guardPos, ETileType::FREE); //just in case monster is too weak to spawn
  416. zoneA->addMonster (this, guardPos, connection.getGuardStrength(), false, true);
  417. //zones can make paths only in their own area
  418. zoneA->crunchPath(this, guardPos, posA, zoneA->getFreePaths()); //make connection towards our zone center
  419. zoneB->crunchPath(this, guardPos, posB, zoneB->getFreePaths()); //make connection towards other zone center
  420. zoneA->addRoadNode(guardPos);
  421. zoneB->addRoadNode(guardPos);
  422. break; //we're done with this connection
  423. }
  424. }
  425. }
  426. else //create subterranean gates between two zones
  427. {
  428. //find point on the path between zones
  429. float3 offset (posB.x - posA.x, posB.y - posA.y, 0);
  430. float distance = posB.dist2d(posA);
  431. vstd::amax (distance, 0.5f);
  432. offset /= distance; //get unit vector
  433. float3 vec (0, 0, 0);
  434. //use reduced size of underground zone - make sure gate does not stand on rock
  435. int3 tile = posA;
  436. int3 otherTile = tile;
  437. bool stop = false;
  438. while (!stop)
  439. {
  440. vec += offset; //this vector may extend beyond line between zone centers, in case they are directly over each other
  441. tile = posA + int3(vec.x, vec.y, 0);
  442. float distanceFromA = posA.dist2d(tile);
  443. float distanceFromB = posB.dist2d(tile);
  444. if (distanceFromA + distanceFromB > std::max<int>(zoneA->getSize() + zoneB->getSize(), distance))
  445. break; //we are too far away to ever connect
  446. //if zone is underground, gate must fit within its (reduced) radius
  447. if (distanceFromA > 5 && (!posA.z || distanceFromA < zoneA->getSize() - 3) &&
  448. distanceFromB > 5 && (!posB.z || distanceFromB < zoneB->getSize() - 3))
  449. {
  450. otherTile = tile;
  451. otherTile.z = posB.z;
  452. if (vstd::contains(tiles, tile) && vstd::contains(otherZoneTiles, otherTile))
  453. {
  454. bool withinZone = true;
  455. foreach_neighbour (tile, [&withinZone, &tiles](int3 &pos)
  456. {
  457. if (!vstd::contains(tiles, pos))
  458. withinZone = false;
  459. });
  460. foreach_neighbour (otherTile, [&withinZone, &otherZoneTiles](int3 &pos)
  461. {
  462. if (!vstd::contains(otherZoneTiles, pos))
  463. withinZone = false;
  464. });
  465. if (withinZone)
  466. {
  467. auto gate1 = new CGSubterraneanGate;
  468. gate1->ID = Obj::SUBTERRANEAN_GATE;
  469. gate1->subID = 0;
  470. zoneA->placeAndGuardObject(this, gate1, tile, connection.getGuardStrength());
  471. auto gate2 = new CGSubterraneanGate(*gate1);
  472. zoneB->placeAndGuardObject(this, gate2, otherTile, connection.getGuardStrength());
  473. stop = true; //we are done, go to next connection
  474. }
  475. }
  476. }
  477. }
  478. if (stop)
  479. continue;
  480. }
  481. if (!guardPos.valid())
  482. {
  483. auto teleport1 = new CGMonolith;
  484. teleport1->ID = Obj::MONOLITH_TWO_WAY;
  485. teleport1->subID = getNextMonlithIndex();
  486. auto teleport2 = new CGMonolith(*teleport1);
  487. zoneA->addRequiredObject (teleport1, connection.getGuardStrength());
  488. zoneB->addRequiredObject (teleport2, connection.getGuardStrength());
  489. }
  490. }
  491. }
  492. void CMapGenerator::addHeaderInfo()
  493. {
  494. map->version = EMapFormat::SOD;
  495. map->width = mapGenOptions->getWidth();
  496. map->height = mapGenOptions->getHeight();
  497. map->twoLevel = mapGenOptions->getHasTwoLevels();
  498. map->name = VLC->generaltexth->allTexts[740];
  499. map->description = getMapDescription();
  500. map->difficulty = 1;
  501. addPlayerInfo();
  502. }
  503. void CMapGenerator::checkIsOnMap(const int3& tile) const
  504. {
  505. if (!map->isInTheMap(tile))
  506. throw rmgException(boost::to_string(boost::format("Tile %s is outside the map") % tile));
  507. }
  508. std::map<TRmgTemplateZoneId, CRmgTemplateZone*> CMapGenerator::getZones() const
  509. {
  510. return zones;
  511. }
  512. bool CMapGenerator::isBlocked(const int3 &tile) const
  513. {
  514. checkIsOnMap(tile);
  515. return tiles[tile.x][tile.y][tile.z].isBlocked();
  516. }
  517. bool CMapGenerator::shouldBeBlocked(const int3 &tile) const
  518. {
  519. checkIsOnMap(tile);
  520. return tiles[tile.x][tile.y][tile.z].shouldBeBlocked();
  521. }
  522. bool CMapGenerator::isPossible(const int3 &tile) const
  523. {
  524. checkIsOnMap(tile);
  525. return tiles[tile.x][tile.y][tile.z].isPossible();
  526. }
  527. bool CMapGenerator::isFree(const int3 &tile) const
  528. {
  529. checkIsOnMap(tile);
  530. return tiles[tile.x][tile.y][tile.z].isFree();
  531. }
  532. bool CMapGenerator::isUsed(const int3 &tile) const
  533. {
  534. checkIsOnMap(tile);
  535. return tiles[tile.x][tile.y][tile.z].isUsed();
  536. }
  537. bool CMapGenerator::isRoad(const int3& tile) const
  538. {
  539. checkIsOnMap(tile);
  540. return tiles[tile.x][tile.y][tile.z].isRoad();
  541. }
  542. void CMapGenerator::setOccupied(const int3 &tile, ETileType::ETileType state)
  543. {
  544. checkIsOnMap(tile);
  545. tiles[tile.x][tile.y][tile.z].setOccupied(state);
  546. }
  547. void CMapGenerator::setRoad(const int3& tile, ERoadType::ERoadType roadType)
  548. {
  549. checkIsOnMap(tile);
  550. tiles[tile.x][tile.y][tile.z].setRoadType(roadType);
  551. }
  552. CTileInfo CMapGenerator::getTile(const int3& tile) const
  553. {
  554. checkIsOnMap(tile);
  555. return tiles[tile.x][tile.y][tile.z];
  556. }
  557. void CMapGenerator::setNearestObjectDistance(int3 &tile, float value)
  558. {
  559. checkIsOnMap(tile);
  560. tiles[tile.x][tile.y][tile.z].setNearestObjectDistance(value);
  561. }
  562. float CMapGenerator::getNearestObjectDistance(const int3 &tile) const
  563. {
  564. checkIsOnMap(tile);
  565. return tiles[tile.x][tile.y][tile.z].getNearestObjectDistance();
  566. }
  567. int CMapGenerator::getNextMonlithIndex()
  568. {
  569. if (monolithIndex >= VLC->objtypeh->knownSubObjects(Obj::MONOLITH_TWO_WAY).size())
  570. {
  571. //logGlobal->errorStream() << boost::to_string(boost::format("RMG Error! There is no Monolith Two Way with index %d available!") % monolithIndex);
  572. //monolithIndex++;
  573. //return VLC->objtypeh->knownSubObjects(Obj::MONOLITH_TWO_WAY).size() - 1;
  574. //TODO: interrupt map generation and report error
  575. throw rmgException(boost::to_string(boost::format("There is no Monolith Two Way with index %d available!") % monolithIndex));
  576. }
  577. else
  578. return monolithIndex++;
  579. }
  580. int CMapGenerator::getPrisonsRemaning() const
  581. {
  582. return prisonsRemaining;
  583. }
  584. void CMapGenerator::decreasePrisonsRemaining()
  585. {
  586. prisonsRemaining = std::max (0, prisonsRemaining - 1);
  587. }
  588. std::vector<ArtifactID> CMapGenerator::getQuestArtsRemaning() const
  589. {
  590. return questArtifacts;
  591. }
  592. void CMapGenerator::banQuestArt(ArtifactID id)
  593. {
  594. map->allowedArtifact[id] = false;
  595. vstd::erase_if_present (questArtifacts, id);
  596. }
  597. void CMapGenerator::registerZone (TFaction faction)
  598. {
  599. zonesPerFaction[faction]++;
  600. zonesTotal++;
  601. }
  602. ui32 CMapGenerator::getZoneCount(TFaction faction)
  603. {
  604. return zonesPerFaction[faction];
  605. }
  606. ui32 CMapGenerator::getTotalZoneCount() const
  607. {
  608. return zonesTotal;
  609. }