CMap.cpp 17 KB

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