CMap.cpp 17 KB

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