CMap.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*
  2. * CMap.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CMap.h"
  12. #include "../CArtHandler.h"
  13. #include "../VCMI_Lib.h"
  14. #include "../CCreatureHandler.h"
  15. #include "../CTownHandler.h"
  16. #include "../CHeroHandler.h"
  17. #include "../RiverHandler.h"
  18. #include "../RoadHandler.h"
  19. #include "../TerrainHandler.h"
  20. #include "../mapObjects/CGHeroInstance.h"
  21. #include "../mapObjects/ObjectTemplate.h"
  22. #include "../CGeneralTextHandler.h"
  23. #include "../spells/CSpellHandler.h"
  24. #include "../CSkillHandler.h"
  25. #include "CMapEditManager.h"
  26. #include "CMapOperation.h"
  27. #include "../serializer/JsonSerializeFormat.h"
  28. VCMI_LIB_NAMESPACE_BEGIN
  29. void Rumor::serializeJson(JsonSerializeFormat & handler)
  30. {
  31. handler.serializeString("name", name);
  32. handler.serializeStruct("text", text);
  33. }
  34. DisposedHero::DisposedHero() : heroId(0), portrait(255)
  35. {
  36. }
  37. CMapEvent::CMapEvent() : players(0), humanAffected(0), computerAffected(0),
  38. firstOccurence(0), nextOccurence(0)
  39. {
  40. }
  41. bool CMapEvent::earlierThan(const CMapEvent & other) const
  42. {
  43. return firstOccurence < other.firstOccurence;
  44. }
  45. bool CMapEvent::earlierThanOrEqual(const CMapEvent & other) const
  46. {
  47. return firstOccurence <= other.firstOccurence;
  48. }
  49. void CMapEvent::serializeJson(JsonSerializeFormat & handler)
  50. {
  51. handler.serializeString("name", name);
  52. handler.serializeString("message", message);
  53. handler.serializeInt("players", players);
  54. handler.serializeInt("humanAffected", humanAffected);
  55. handler.serializeInt("computerAffected", computerAffected);
  56. handler.serializeInt("firstOccurence", firstOccurence);
  57. handler.serializeInt("nextOccurence", nextOccurence);
  58. resources.serializeJson(handler, "resources");
  59. }
  60. void CCastleEvent::serializeJson(JsonSerializeFormat & handler)
  61. {
  62. CMapEvent::serializeJson(handler);
  63. {
  64. std::vector<BuildingID> temp(buildings.begin(), buildings.end());
  65. auto a = handler.enterArray("buildings");
  66. a.syncSize(temp);
  67. for(int i = 0; i < temp.size(); ++i)
  68. {
  69. a.serializeInt(i, temp[i]);
  70. buildings.insert(temp[i]);
  71. }
  72. }
  73. {
  74. auto a = handler.enterArray("creatures");
  75. a.syncSize(creatures);
  76. for(int i = 0; i < creatures.size(); ++i)
  77. a.serializeInt(i, creatures[i]);
  78. }
  79. }
  80. TerrainTile::TerrainTile():
  81. terType(nullptr),
  82. terView(0),
  83. riverType(VLC->riverTypeHandler->getById(River::NO_RIVER)),
  84. riverDir(0),
  85. roadType(VLC->roadTypeHandler->getById(Road::NO_ROAD)),
  86. roadDir(0),
  87. extTileFlags(0),
  88. visitable(false),
  89. blocked(false)
  90. {
  91. }
  92. bool TerrainTile::entrableTerrain(const TerrainTile * from) const
  93. {
  94. return entrableTerrain(from ? from->terType->isLand() : true, from ? from->terType->isWater() : true);
  95. }
  96. bool TerrainTile::entrableTerrain(bool allowLand, bool allowSea) const
  97. {
  98. return terType->isPassable()
  99. && ((allowSea && terType->isWater()) || (allowLand && terType->isLand()));
  100. }
  101. bool TerrainTile::isClear(const TerrainTile * from) const
  102. {
  103. return entrableTerrain(from) && !blocked;
  104. }
  105. Obj TerrainTile::topVisitableId(bool excludeTop) const
  106. {
  107. return topVisitableObj(excludeTop) ? topVisitableObj(excludeTop)->ID : Obj(Obj::NO_OBJ);
  108. }
  109. CGObjectInstance * TerrainTile::topVisitableObj(bool excludeTop) const
  110. {
  111. if(visitableObjects.empty() || (excludeTop && visitableObjects.size() == 1))
  112. return nullptr;
  113. if(excludeTop)
  114. return visitableObjects[visitableObjects.size()-2];
  115. return visitableObjects.back();
  116. }
  117. EDiggingStatus TerrainTile::getDiggingStatus(const bool excludeTop) const
  118. {
  119. if(terType->isWater() || !terType->isPassable())
  120. return EDiggingStatus::WRONG_TERRAIN;
  121. int allowedBlocked = excludeTop ? 1 : 0;
  122. if(blockingObjects.size() > allowedBlocked || topVisitableObj(excludeTop))
  123. return EDiggingStatus::TILE_OCCUPIED;
  124. else
  125. return EDiggingStatus::CAN_DIG;
  126. }
  127. bool TerrainTile::hasFavorableWinds() const
  128. {
  129. return extTileFlags & 128;
  130. }
  131. bool TerrainTile::isWater() const
  132. {
  133. return terType->isWater();
  134. }
  135. CMap::CMap()
  136. : checksum(0)
  137. , grailPos(-1, -1, -1)
  138. , grailRadius(0)
  139. , uidCounter(0)
  140. {
  141. allHeroes.resize(allowedHeroes.size());
  142. allowedAbilities = VLC->skillh->getDefaultAllowed();
  143. allowedArtifact = VLC->arth->getDefaultAllowed();
  144. allowedSpells = VLC->spellh->getDefaultAllowed();
  145. }
  146. CMap::~CMap()
  147. {
  148. getEditManager()->getUndoManager().clearAll();
  149. for(auto obj : objects)
  150. obj.dellNull();
  151. for(auto quest : quests)
  152. quest.dellNull();
  153. resetStaticData();
  154. }
  155. void CMap::removeBlockVisTiles(CGObjectInstance * obj, bool total)
  156. {
  157. const int zVal = obj->pos.z;
  158. for(int fx = 0; fx < obj->getWidth(); ++fx)
  159. {
  160. int xVal = obj->pos.x - fx;
  161. for(int fy = 0; fy < obj->getHeight(); ++fy)
  162. {
  163. int yVal = obj->pos.y - fy;
  164. if(xVal>=0 && xVal < width && yVal>=0 && yVal < height)
  165. {
  166. TerrainTile & curt = terrain[zVal][xVal][yVal];
  167. if(total || obj->visitableAt(xVal, yVal))
  168. {
  169. curt.visitableObjects -= obj;
  170. curt.visitable = curt.visitableObjects.size();
  171. }
  172. if(total || obj->blockingAt(xVal, yVal))
  173. {
  174. curt.blockingObjects -= obj;
  175. curt.blocked = curt.blockingObjects.size();
  176. }
  177. }
  178. }
  179. }
  180. }
  181. void CMap::addBlockVisTiles(CGObjectInstance * obj)
  182. {
  183. const int zVal = obj->pos.z;
  184. for(int fx = 0; fx < obj->getWidth(); ++fx)
  185. {
  186. int xVal = obj->pos.x - fx;
  187. for(int fy = 0; fy < obj->getHeight(); ++fy)
  188. {
  189. int yVal = obj->pos.y - fy;
  190. if(xVal>=0 && xVal < width && yVal >= 0 && yVal < height)
  191. {
  192. TerrainTile & curt = terrain[zVal][xVal][yVal];
  193. if(obj->visitableAt(xVal, yVal))
  194. {
  195. curt.visitableObjects.push_back(obj);
  196. curt.visitable = true;
  197. }
  198. if(obj->blockingAt(xVal, yVal))
  199. {
  200. curt.blockingObjects.push_back(obj);
  201. curt.blocked = true;
  202. }
  203. }
  204. }
  205. }
  206. }
  207. void CMap::calculateGuardingGreaturePositions()
  208. {
  209. int levels = twoLevel ? 2 : 1;
  210. for(int z = 0; z < levels; z++)
  211. {
  212. for(int x = 0; x < width; x++)
  213. {
  214. for(int y = 0; y < height; y++)
  215. {
  216. guardingCreaturePositions[z][x][y] = guardingCreaturePosition(int3(x, y, z));
  217. }
  218. }
  219. }
  220. }
  221. CGHeroInstance * CMap::getHero(int heroID)
  222. {
  223. for(auto & elem : heroesOnMap)
  224. if(elem->subID == heroID)
  225. return elem;
  226. return nullptr;
  227. }
  228. bool CMap::isCoastalTile(const int3 & pos) const
  229. {
  230. //todo: refactoring: extract neighbor tile iterator and use it in GameState
  231. static const int3 dirs[] = { int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0),
  232. int3(1,1,0),int3(-1,1,0),int3(1,-1,0),int3(-1,-1,0) };
  233. if(!isInTheMap(pos))
  234. {
  235. logGlobal->error("Coastal check outside of map: %s", pos.toString());
  236. return false;
  237. }
  238. if(isWaterTile(pos))
  239. return false;
  240. for(const auto & dir : dirs)
  241. {
  242. const int3 hlp = pos + dir;
  243. if(!isInTheMap(hlp))
  244. continue;
  245. const TerrainTile &hlpt = getTile(hlp);
  246. if(hlpt.isWater())
  247. return true;
  248. }
  249. return false;
  250. }
  251. bool CMap::isInTheMap(const int3 & pos) const
  252. {
  253. return pos.x >= 0 && pos.y >= 0 && pos.z >= 0 && pos.x < width && pos.y < height && pos.z <= (twoLevel ? 1 : 0);
  254. }
  255. TerrainTile & CMap::getTile(const int3 & tile)
  256. {
  257. assert(isInTheMap(tile));
  258. return terrain[tile.z][tile.x][tile.y];
  259. }
  260. const TerrainTile & CMap::getTile(const int3 & tile) const
  261. {
  262. assert(isInTheMap(tile));
  263. return terrain[tile.z][tile.x][tile.y];
  264. }
  265. bool CMap::isWaterTile(const int3 &pos) const
  266. {
  267. return isInTheMap(pos) && getTile(pos).isWater();
  268. }
  269. bool CMap::canMoveBetween(const int3 &src, const int3 &dst) const
  270. {
  271. const TerrainTile * dstTile = &getTile(dst);
  272. const TerrainTile * srcTile = &getTile(src);
  273. return checkForVisitableDir(src, dstTile, dst) && checkForVisitableDir(dst, srcTile, src);
  274. }
  275. bool CMap::checkForVisitableDir(const int3 & src, const TerrainTile * pom, const int3 & dst) const
  276. {
  277. if (!pom->entrableTerrain()) //rock is never accessible
  278. return false;
  279. for(auto * obj : pom->visitableObjects) //checking destination tile
  280. {
  281. if(!vstd::contains(pom->blockingObjects, obj)) //this visitable object is not blocking, ignore
  282. continue;
  283. if (!obj->appearance->isVisitableFrom(src.x - dst.x, src.y - dst.y))
  284. return false;
  285. }
  286. return true;
  287. }
  288. int3 CMap::guardingCreaturePosition (int3 pos) const
  289. {
  290. const int3 originalPos = pos;
  291. // Give monster at position priority.
  292. if (!isInTheMap(pos))
  293. return int3(-1, -1, -1);
  294. const TerrainTile &posTile = getTile(pos);
  295. if (posTile.visitable)
  296. {
  297. for (CGObjectInstance* obj : posTile.visitableObjects)
  298. {
  299. if(obj->isBlockedVisitable())
  300. {
  301. if (obj->ID == Obj::MONSTER) // Monster
  302. return pos;
  303. else
  304. return int3(-1, -1, -1); //blockvis objects are not guarded by neighbouring creatures
  305. }
  306. }
  307. }
  308. // See if there are any monsters adjacent.
  309. bool water = posTile.isWater();
  310. pos -= int3(1, 1, 0); // Start with top left.
  311. for (int dx = 0; dx < 3; dx++)
  312. {
  313. for (int dy = 0; dy < 3; dy++)
  314. {
  315. if (isInTheMap(pos))
  316. {
  317. const auto & tile = getTile(pos);
  318. if (tile.visitable && (tile.isWater() == water))
  319. {
  320. for (CGObjectInstance* obj : tile.visitableObjects)
  321. {
  322. if (obj->ID == Obj::MONSTER && checkForVisitableDir(pos, &posTile, originalPos)) // Monster being able to attack investigated tile
  323. {
  324. return pos;
  325. }
  326. }
  327. }
  328. }
  329. pos.y++;
  330. }
  331. pos.y -= 3;
  332. pos.x++;
  333. }
  334. return int3(-1, -1, -1);
  335. }
  336. const CGObjectInstance * CMap::getObjectiveObjectFrom(const int3 & pos, Obj type)
  337. {
  338. for (CGObjectInstance * object : getTile(pos).visitableObjects)
  339. {
  340. if (object->ID == type)
  341. return object;
  342. }
  343. // There is weird bug because of which sometimes heroes will not be found properly despite having correct position
  344. // Try to workaround that and find closest object that we can use
  345. logGlobal->error("Failed to find object of type %d at %s", static_cast<int>(type), pos.toString());
  346. logGlobal->error("Will try to find closest matching object");
  347. CGObjectInstance * bestMatch = nullptr;
  348. for (CGObjectInstance * object : objects)
  349. {
  350. if (object && object->ID == type)
  351. {
  352. if (bestMatch == nullptr)
  353. bestMatch = object;
  354. else
  355. {
  356. if (object->pos.dist2dSQ(pos) < bestMatch->pos.dist2dSQ(pos))
  357. bestMatch = object;// closer than one we already found
  358. }
  359. }
  360. }
  361. assert(bestMatch != nullptr); // if this happens - victory conditions or map itself is very, very broken
  362. logGlobal->error("Will use %s from %s", bestMatch->getObjectName(), bestMatch->pos.toString());
  363. return bestMatch;
  364. }
  365. void CMap::checkForObjectives()
  366. {
  367. // NOTE: probably should be moved to MapFormatH3M.cpp
  368. for (TriggeredEvent & event : triggeredEvents)
  369. {
  370. auto patcher = [&](EventCondition cond) -> EventExpression::Variant
  371. {
  372. switch (cond.condition)
  373. {
  374. case EventCondition::HAVE_ARTIFACT:
  375. event.onFulfill.replaceTextID(VLC->artifacts()->getByIndex(cond.objectType)->getNameTextID());
  376. break;
  377. case EventCondition::HAVE_CREATURES:
  378. event.onFulfill.replaceTextID(VLC->creatures()->getByIndex(cond.objectType)->getNameSingularTextID());
  379. event.onFulfill.replaceNumber(cond.value);
  380. break;
  381. case EventCondition::HAVE_RESOURCES:
  382. event.onFulfill.replaceLocalString(EMetaText::RES_NAMES, cond.objectType);
  383. event.onFulfill.replaceNumber(cond.value);
  384. break;
  385. case EventCondition::HAVE_BUILDING:
  386. if (isInTheMap(cond.position))
  387. cond.object = getObjectiveObjectFrom(cond.position, Obj::TOWN);
  388. break;
  389. case EventCondition::CONTROL:
  390. if (isInTheMap(cond.position))
  391. cond.object = getObjectiveObjectFrom(cond.position, static_cast<Obj>(cond.objectType));
  392. if (cond.object)
  393. {
  394. const auto * town = dynamic_cast<const CGTownInstance *>(cond.object);
  395. if (town)
  396. event.onFulfill.replaceRawString(town->getNameTranslated());
  397. const auto * hero = dynamic_cast<const CGHeroInstance *>(cond.object);
  398. if (hero)
  399. event.onFulfill.replaceRawString(hero->getNameTranslated());
  400. }
  401. break;
  402. case EventCondition::DESTROY:
  403. if (isInTheMap(cond.position))
  404. cond.object = getObjectiveObjectFrom(cond.position, static_cast<Obj>(cond.objectType));
  405. if (cond.object)
  406. {
  407. const auto * hero = dynamic_cast<const CGHeroInstance *>(cond.object);
  408. if (hero)
  409. event.onFulfill.replaceRawString(hero->getNameTranslated());
  410. }
  411. break;
  412. case EventCondition::TRANSPORT:
  413. cond.object = getObjectiveObjectFrom(cond.position, Obj::TOWN);
  414. break;
  415. //break; case EventCondition::DAYS_PASSED:
  416. //break; case EventCondition::IS_HUMAN:
  417. //break; case EventCondition::DAYS_WITHOUT_TOWN:
  418. //break; case EventCondition::STANDARD_WIN:
  419. //TODO: support new condition format
  420. case EventCondition::HAVE_0:
  421. break;
  422. case EventCondition::DESTROY_0:
  423. break;
  424. case EventCondition::HAVE_BUILDING_0:
  425. break;
  426. }
  427. return cond;
  428. };
  429. event.trigger = event.trigger.morph(patcher);
  430. }
  431. }
  432. void CMap::addNewArtifactInstance(ConstTransitivePtr<CArtifactInstance> art)
  433. {
  434. art->setId(static_cast<ArtifactInstanceID>(artInstances.size()));
  435. artInstances.emplace_back(art);
  436. }
  437. void CMap::eraseArtifactInstance(CArtifactInstance * art)
  438. {
  439. //TODO: handle for artifacts removed in map editor
  440. assert(artInstances[art->getId().getNum()] == art);
  441. artInstances[art->getId().getNum()].dellNull();
  442. }
  443. void CMap::addNewQuestInstance(CQuest* quest)
  444. {
  445. quest->qid = static_cast<si32>(quests.size());
  446. quests.emplace_back(quest);
  447. }
  448. void CMap::removeQuestInstance(CQuest * quest)
  449. {
  450. //TODO: should be called only by map editor.
  451. //During game, completed quests or quests from removed objects stay forever
  452. //Shift indexes
  453. auto iter = std::next(quests.begin(), quest->qid);
  454. iter = quests.erase(iter);
  455. for (int i = quest->qid; iter != quests.end(); ++i, ++iter)
  456. {
  457. (*iter)->qid = i;
  458. }
  459. }
  460. void CMap::setUniqueInstanceName(CGObjectInstance * obj)
  461. {
  462. //this gives object unique name even if objects are removed later
  463. auto uid = uidCounter++;
  464. boost::format fmt("%s_%d");
  465. fmt % obj->typeName % uid;
  466. obj->instanceName = fmt.str();
  467. }
  468. void CMap::addNewObject(CGObjectInstance * obj)
  469. {
  470. if(obj->id != ObjectInstanceID(static_cast<si32>(objects.size())))
  471. throw std::runtime_error("Invalid object instance id");
  472. if(obj->instanceName.empty())
  473. throw std::runtime_error("Object instance name missing");
  474. if (vstd::contains(instanceNames, obj->instanceName))
  475. throw std::runtime_error("Object instance name duplicated: "+obj->instanceName);
  476. objects.emplace_back(obj);
  477. instanceNames[obj->instanceName] = obj;
  478. addBlockVisTiles(obj);
  479. //TODO: how about defeated heroes recruited again?
  480. obj->afterAddToMap(this);
  481. }
  482. void CMap::moveObject(CGObjectInstance * obj, const int3 & pos)
  483. {
  484. removeBlockVisTiles(obj);
  485. obj->pos = pos;
  486. addBlockVisTiles(obj);
  487. }
  488. void CMap::removeObject(CGObjectInstance * obj)
  489. {
  490. removeBlockVisTiles(obj);
  491. instanceNames.erase(obj->instanceName);
  492. //update indeces
  493. auto iter = std::next(objects.begin(), obj->id.getNum());
  494. iter = objects.erase(iter);
  495. for(int i = obj->id.getNum(); iter != objects.end(); ++i, ++iter)
  496. {
  497. (*iter)->id = ObjectInstanceID(i);
  498. }
  499. obj->afterRemoveFromMap(this);
  500. //TOOD: Clean artifact instances (mostly worn by hero?) and quests related to this object
  501. }
  502. bool CMap::isWaterMap() const
  503. {
  504. return waterMap;
  505. }
  506. bool CMap::calculateWaterContent()
  507. {
  508. size_t totalTiles = height * width * levels();
  509. size_t waterTiles = 0;
  510. for(auto tile = terrain.origin(); tile < (terrain.origin() + terrain.num_elements()); ++tile)
  511. {
  512. if (tile->isWater())
  513. {
  514. waterTiles++;
  515. }
  516. }
  517. if (waterTiles >= totalTiles / 100) //At least 1% of area is water
  518. {
  519. waterMap = true;
  520. }
  521. return waterMap;
  522. }
  523. void CMap::banWaterContent()
  524. {
  525. banWaterHeroes();
  526. banWaterArtifacts();
  527. banWaterSpells();
  528. banWaterSkills();
  529. }
  530. void CMap::banWaterSpells()
  531. {
  532. for (int j = 0; j < allowedSpells.size(); j++)
  533. {
  534. if (allowedSpells[j])
  535. {
  536. auto* spell = dynamic_cast<const CSpell*>(VLC->spells()->getByIndex(j));
  537. if (spell->onlyOnWaterMap && !isWaterMap())
  538. {
  539. allowedSpells[j] = false;
  540. }
  541. }
  542. }
  543. }
  544. void CMap::banWaterArtifacts()
  545. {
  546. for (int j = 0; j < allowedArtifact.size(); j++)
  547. {
  548. if (allowedArtifact[j])
  549. {
  550. auto* art = dynamic_cast<const CArtifact*>(VLC->artifacts()->getByIndex(j));
  551. if (art->onlyOnWaterMap && !isWaterMap())
  552. {
  553. allowedArtifact[j] = false;
  554. }
  555. }
  556. }
  557. }
  558. void CMap::banWaterSkills()
  559. {
  560. for (int j = 0; j < allowedAbilities.size(); j++)
  561. {
  562. if (allowedAbilities[j])
  563. {
  564. auto* skill = dynamic_cast<const CSkill*>(VLC->skills()->getByIndex(j));
  565. if (skill->onlyOnWaterMap && !isWaterMap())
  566. {
  567. allowedAbilities[j] = false;
  568. }
  569. }
  570. }
  571. }
  572. void CMap::banWaterHeroes()
  573. {
  574. for (int j = 0; j < allowedHeroes.size(); j++)
  575. {
  576. if (allowedHeroes[j])
  577. {
  578. auto* h = dynamic_cast<const CHero*>(VLC->heroTypes()->getByIndex(j));
  579. if ((h->onlyOnWaterMap && !isWaterMap()) || (h->onlyOnMapWithoutWater && isWaterMap()))
  580. {
  581. banHero(HeroTypeID(j));
  582. }
  583. }
  584. }
  585. }
  586. void CMap::banHero(const HeroTypeID & id)
  587. {
  588. allowedHeroes.at(id) = false;
  589. }
  590. void CMap::initTerrain()
  591. {
  592. terrain.resize(boost::extents[levels()][width][height]);
  593. guardingCreaturePositions.resize(boost::extents[levels()][width][height]);
  594. }
  595. CMapEditManager * CMap::getEditManager()
  596. {
  597. if(!editManager) editManager = std::make_unique<CMapEditManager>(this);
  598. return editManager.get();
  599. }
  600. void CMap::resetStaticData()
  601. {
  602. CGKeys::reset();
  603. CGMagi::reset();
  604. CGObelisk::reset();
  605. CGTownInstance::reset();
  606. }
  607. VCMI_LIB_NAMESPACE_END