2
0

Nullkiller.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. * Nullkiller.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 "Nullkiller.h"
  12. #include "../../../lib/CPlayerState.h"
  13. #include "../../lib/StartInfo.h"
  14. #include "../../lib/pathfinder/PathfinderCache.h"
  15. #include "../../lib/pathfinder/PathfinderOptions.h"
  16. #include "../AIGateway.h"
  17. #include "../Behaviors/BuildingBehavior.h"
  18. #include "../Behaviors/BuyArmyBehavior.h"
  19. #include "../Behaviors/CaptureObjectsBehavior.h"
  20. #include "../Behaviors/ClusterBehavior.h"
  21. #include "../Behaviors/DefenceBehavior.h"
  22. #include "../Behaviors/ExplorationBehavior.h"
  23. #include "../Behaviors/GatherArmyBehavior.h"
  24. #include "../Behaviors/RecruitHeroBehavior.h"
  25. #include "../Behaviors/StayAtTownBehavior.h"
  26. #include "../Goals/Invalid.h"
  27. #include "Goals/RecruitHero.h"
  28. #include "ResourceTrader.h"
  29. #include <boost/range/algorithm/sort.hpp>
  30. namespace NK2AI
  31. {
  32. using namespace Goals;
  33. // while we play vcmieagles graph can be shared
  34. std::unique_ptr<ObjectGraph> Nullkiller::baseGraph;
  35. Nullkiller::Nullkiller()
  36. : activeHero(nullptr)
  37. , scanDepth(ScanDepth::MAIN_FULL)
  38. , useHeroChain(true)
  39. , memory(std::make_unique<AIMemory>())
  40. {
  41. }
  42. Nullkiller::~Nullkiller() = default;
  43. bool canUseOpenMap(const std::shared_ptr<CCallback>& cb, const PlayerColor playerID)
  44. {
  45. if(!cb->getStartInfo()->extraOptionsInfo.cheatsAllowed)
  46. {
  47. return false;
  48. }
  49. const TeamState * team = cb->getPlayerTeam(playerID);
  50. const auto hasHumanInTeam = vstd::contains_if(
  51. team->players,
  52. [cb](const PlayerColor teamMateID) -> bool
  53. {
  54. return cb->getPlayerState(teamMateID)->isHuman();
  55. }
  56. );
  57. return !hasHumanInTeam;
  58. }
  59. void Nullkiller::init(const std::shared_ptr<CCallback> & cbInput, AIGateway * aiGwInput)
  60. {
  61. cc = cbInput;
  62. aiGw = aiGwInput;
  63. playerID = aiGwInput->playerID;
  64. settings = std::make_unique<Settings>(cc->getStartInfo()->difficulty);
  65. PathfinderOptions pathfinderOptions(*cc);
  66. pathfinderOptions.useTeleportTwoWay = true;
  67. pathfinderOptions.useTeleportOneWay = settings->isOneWayMonolithUsageAllowed();
  68. pathfinderOptions.useTeleportOneWayRandom = settings->isOneWayMonolithUsageAllowed();
  69. pathfinderCache = std::make_unique<PathfinderCache>(cc.get(), pathfinderOptions);
  70. if(canUseOpenMap(cc, playerID))
  71. {
  72. useObjectGraph = settings->isObjectGraphAllowed();
  73. openMap = settings->isOpenMap() || useObjectGraph;
  74. }
  75. else
  76. {
  77. useObjectGraph = false;
  78. openMap = false;
  79. }
  80. baseGraph.reset();
  81. priorityEvaluator.reset(new PriorityEvaluator(this));
  82. priorityEvaluators.reset(
  83. new SharedPool<PriorityEvaluator>(
  84. [&]()->std::unique_ptr<PriorityEvaluator>
  85. {
  86. return std::make_unique<PriorityEvaluator>(this);
  87. }));
  88. dangerHitMap.reset(new DangerHitMapAnalyzer(this));
  89. buildAnalyzer.reset(new BuildAnalyzer(this));
  90. objectClusterizer.reset(new ObjectClusterizer(this));
  91. dangerEvaluator.reset(new FuzzyHelper(this));
  92. pathfinder.reset(new AIPathfinder(this));
  93. armyManager.reset(new ArmyManager(cc.get(), this));
  94. heroManager.reset(new HeroManager(cc.get(), this));
  95. decomposer.reset(new DeepDecomposer(this));
  96. armyFormation.reset(new ArmyFormation(cc, this));
  97. }
  98. TaskPlanItem::TaskPlanItem(const TSubgoal & task)
  99. : affectedObjects(task->asTask()->getAffectedObjects())
  100. , task(task)
  101. {
  102. }
  103. Goals::TTaskVec TaskPlan::getTasks() const
  104. {
  105. Goals::TTaskVec result;
  106. for(auto & item : tasks)
  107. {
  108. result.push_back(taskptr(*item.task));
  109. }
  110. vstd::removeDuplicates(result);
  111. return result;
  112. }
  113. void TaskPlan::merge(const TSubgoal & task)
  114. {
  115. TGoalVec blockers;
  116. if (task->asTask()->priority <= 0)
  117. return;
  118. for(auto & item : tasks)
  119. {
  120. for(auto objid : item.affectedObjects)
  121. {
  122. if(task == item.task || task->asTask()->isObjectAffected(objid) || (task->asTask()->getHero() != nullptr && task->asTask()->getHero() == item.task->asTask()->getHero()))
  123. {
  124. if(item.task->asTask()->priority >= task->asTask()->priority)
  125. return;
  126. blockers.push_back(item.task);
  127. break;
  128. }
  129. }
  130. }
  131. vstd::erase_if(tasks, [&](const TaskPlanItem & task2)
  132. {
  133. return vstd::contains(blockers, task2.task);
  134. });
  135. tasks.emplace_back(task);
  136. }
  137. Goals::TTask Nullkiller::choseBestTask(Goals::TGoalVec & tasks) const
  138. {
  139. if(tasks.empty())
  140. {
  141. return taskptr(Invalid());
  142. }
  143. for(const TSubgoal & task : tasks)
  144. {
  145. if(task->asTask()->priority <= 0)
  146. task->asTask()->priority = priorityEvaluator->evaluate(task);
  147. }
  148. auto bestTask = *vstd::maxElementByFun(tasks, [](const Goals::TSubgoal& task) -> float
  149. {
  150. return task->asTask()->priority;
  151. });
  152. return taskptr(*bestTask);
  153. }
  154. Goals::TTaskVec Nullkiller::buildPlan(TGoalVec & tasks, int priorityTier) const
  155. {
  156. TaskPlan taskPlan;
  157. tbb::parallel_for(tbb::blocked_range<size_t>(0, tasks.size()), [this, &tasks, priorityTier](const tbb::blocked_range<size_t> & r)
  158. {
  159. auto evaluator = this->priorityEvaluators->acquire();
  160. for(size_t i = r.begin(); i != r.end(); i++)
  161. {
  162. const auto & task = tasks[i];
  163. if(task->asTask()->priority <= 0 || priorityTier != PriorityEvaluator::PriorityTier::BUILDINGS)
  164. task->asTask()->priority = evaluator->evaluate(task, priorityTier);
  165. }
  166. });
  167. boost::range::sort(tasks, [](const TSubgoal& g1, const TSubgoal& g2) -> bool
  168. {
  169. return g2->asTask()->priority < g1->asTask()->priority;
  170. });
  171. for(const TSubgoal & task : tasks)
  172. {
  173. taskPlan.merge(task);
  174. }
  175. return taskPlan.getTasks();
  176. }
  177. void Nullkiller::decompose(Goals::TGoalVec & results, const Goals::TSubgoal& behavior, int decompositionMaxDepth) const
  178. {
  179. makingTurnInterruption.interruptionPoint();
  180. logAi->debug("Decomposing behavior %s", behavior->toString());
  181. const auto start = std::chrono::high_resolution_clock::now();
  182. decomposer->decompose(results, behavior, decompositionMaxDepth);
  183. makingTurnInterruption.interruptionPoint();
  184. logAi->debug("Decomposing behavior %s done in %ld", behavior->toString(), timeElapsed(start));
  185. }
  186. void Nullkiller::resetState()
  187. {
  188. std::unique_lock lockGuard(aiStateMutex);
  189. lockedResources = TResources();
  190. scanDepth = ScanDepth::MAIN_FULL;
  191. lockedHeroes.clear();
  192. dangerHitMap->resetHitmap();
  193. useHeroChain = true;
  194. objectClusterizer->reset();
  195. if(!baseGraph && isObjectGraphAllowed())
  196. {
  197. baseGraph = std::make_unique<ObjectGraph>();
  198. baseGraph->updateGraph(this);
  199. }
  200. }
  201. void Nullkiller::invalidatePathfinderData()
  202. {
  203. pathfinderInvalidated = true;
  204. }
  205. void Nullkiller::updateState()
  206. {
  207. logAi->info("PERFORMANCE: AI updateState started");
  208. makingTurnInterruption.interruptionPoint();
  209. std::unique_lock lockGuard(aiStateMutex);
  210. const auto start = std::chrono::high_resolution_clock::now();
  211. activeHero = nullptr;
  212. setTargetObject(-1);
  213. decomposer->reset();
  214. buildAnalyzer->update();
  215. if(!pathfinderInvalidated && dangerHitMap->isHitMapUpToDate() && dangerHitMap->isTileOwnersUpToDate())
  216. logAi->trace("Skipping full state regeneration - up to date");
  217. else
  218. {
  219. memory->removeInvisibleOrDeletedObjects(*cc);
  220. dangerHitMap->updateHitMap();
  221. dangerHitMap->calculateTileOwners();
  222. makingTurnInterruption.interruptionPoint();
  223. heroManager->update();
  224. logAi->trace("Updating paths");
  225. PathfinderSettings cfg;
  226. cfg.useHeroChain = useHeroChain;
  227. cfg.allowBypassObjects = true;
  228. if(scanDepth == ScanDepth::SMALL || isObjectGraphAllowed())
  229. {
  230. cfg.mainTurnDistanceLimit = settings->getMainHeroTurnDistanceLimit();
  231. }
  232. if(scanDepth != ScanDepth::ALL_FULL || isObjectGraphAllowed())
  233. {
  234. cfg.scoutTurnDistanceLimit = settings->getScoutHeroTurnDistanceLimit();
  235. }
  236. makingTurnInterruption.interruptionPoint();
  237. const auto heroes = getHeroesForPathfinding();
  238. pathfinder->updatePaths(heroes, cfg);
  239. if(isObjectGraphAllowed())
  240. {
  241. pathfinder->updateGraphs(
  242. heroes,
  243. scanDepth == ScanDepth::SMALL ? PathfinderSettings::MaxTurnDistanceLimit : 10,
  244. scanDepth == ScanDepth::ALL_FULL ? PathfinderSettings::MaxTurnDistanceLimit : 3);
  245. }
  246. makingTurnInterruption.interruptionPoint();
  247. objectClusterizer->clusterize();
  248. pathfinderInvalidated = false;
  249. }
  250. armyManager->update();
  251. if(const auto timeElapsedMs = timeElapsed(start); timeElapsedMs > 999)
  252. {
  253. logAi->warn("PERFORMANCE: AI updateState took %ld ms", timeElapsedMs);
  254. }
  255. else
  256. {
  257. logAi->info("PERFORMANCE: AI updateState took %ld ms", timeElapsedMs);
  258. }
  259. }
  260. bool Nullkiller::isHeroLocked(const CGHeroInstance * hero) const
  261. {
  262. return getHeroLockedReason(hero) != HeroLockedReason::NOT_LOCKED;
  263. }
  264. bool Nullkiller::arePathHeroesLocked(const AIPath & path) const
  265. {
  266. if(getHeroLockedReason(path.targetHero) == HeroLockedReason::STARTUP)
  267. {
  268. #if NK2AI_TRACE_LEVEL >= 1
  269. logAi->trace("Hero %s is locked by STARTUP. Discarding %s", path.targetHero->getObjectName(), path.toString());
  270. #endif
  271. return true;
  272. }
  273. for(const auto & node : path.nodes)
  274. {
  275. auto lockReason = getHeroLockedReason(node.targetHero);
  276. if(lockReason != HeroLockedReason::NOT_LOCKED)
  277. {
  278. #if NK2AI_TRACE_LEVEL >= 1
  279. logAi->trace("Hero %s is locked by %d. Discarding %s", path.targetHero->getObjectName(), (int)lockReason, path.toString());
  280. #endif
  281. return true;
  282. }
  283. }
  284. return false;
  285. }
  286. HeroLockedReason Nullkiller::getHeroLockedReason(const CGHeroInstance * hero) const
  287. {
  288. auto found = lockedHeroes.find(hero);
  289. return found != lockedHeroes.end() ? found->second : HeroLockedReason::NOT_LOCKED;
  290. }
  291. void Nullkiller::makeTurn()
  292. {
  293. std::lock_guard<std::mutex> sharedStorageLock(AISharedStorage::locker);
  294. const int MAX_DEPTH = 10;
  295. resetState();
  296. Goals::TGoalVec tasks;
  297. tracePlayerStatus(true);
  298. for(int i = 1; i <= settings->getMaxPass() && cc->getPlayerStatus(playerID) == EPlayerStatus::INGAME; i++)
  299. {
  300. if (!updateStateAndExecutePriorityPass(tasks, i)) return;
  301. tasks.clear();
  302. decompose(tasks, sptr(CaptureObjectsBehavior()), 1);
  303. decompose(tasks, sptr(ClusterBehavior()), MAX_DEPTH);
  304. decompose(tasks, sptr(DefenceBehavior()), MAX_DEPTH);
  305. decompose(tasks, sptr(GatherArmyBehavior()), MAX_DEPTH);
  306. decompose(tasks, sptr(StayAtTownBehavior()), MAX_DEPTH);
  307. if(!isOpenMap())
  308. decompose(tasks, sptr(ExplorationBehavior()), MAX_DEPTH);
  309. TTaskVec selectedTasks;
  310. int prioOfTask = 0;
  311. for (int prio = PriorityEvaluator::PriorityTier::INSTAKILL; prio <= PriorityEvaluator::PriorityTier::MAX_PRIORITY_TIER; ++prio)
  312. {
  313. prioOfTask = prio;
  314. selectedTasks = buildPlan(tasks, prio);
  315. if (!selectedTasks.empty() || settings->isUseFuzzy())
  316. break;
  317. }
  318. boost::range::sort(selectedTasks, [](const TTask& a, const TTask& b)
  319. {
  320. return a->priority > b->priority;
  321. });
  322. if(selectedTasks.empty())
  323. {
  324. selectedTasks.push_back(taskptr(Goals::Invalid()));
  325. }
  326. bool hasAnySuccess = false;
  327. for(const auto& selectedTask : selectedTasks)
  328. {
  329. if(cc->getPlayerStatus(playerID) != EPlayerStatus::INGAME)
  330. return;
  331. if(!areAffectedObjectsPresent(selectedTask))
  332. {
  333. logAi->debug("Affected object not found. Canceling task.");
  334. continue;
  335. }
  336. std::string taskDescription = selectedTask->toString();
  337. HeroRole heroRole = getTaskRole(selectedTask);
  338. if(heroRole != HeroRole::MAIN || selectedTask->getHeroExchangeCount() <= 1)
  339. useHeroChain = false;
  340. // TODO: better to check turn distance here instead of priority
  341. if((heroRole != HeroRole::MAIN || selectedTask->priority < SMALL_SCAN_MIN_PRIORITY)
  342. && scanDepth == ScanDepth::MAIN_FULL)
  343. {
  344. useHeroChain = false;
  345. scanDepth = ScanDepth::SMALL;
  346. logAi->trace(
  347. "Goal %s has low priority %f so decreasing scan depth to gain performance.",
  348. taskDescription,
  349. selectedTask->priority);
  350. }
  351. if((settings->isUseFuzzy() && selectedTask->priority < MIN_PRIORITY) || (!settings->isUseFuzzy() && selectedTask->priority <= 0))
  352. {
  353. auto heroes = cc->getHeroesInfo();
  354. const auto hasMp = vstd::contains_if(heroes, [](const CGHeroInstance * h) -> bool
  355. {
  356. return h->movementPointsRemaining() > 100;
  357. });
  358. if(hasMp && scanDepth != ScanDepth::ALL_FULL)
  359. {
  360. logAi->trace(
  361. "Goal %s has too low priority %f so increasing scan depth to full.",
  362. taskDescription,
  363. selectedTask->priority);
  364. scanDepth = ScanDepth::ALL_FULL;
  365. useHeroChain = false;
  366. hasAnySuccess = true;
  367. break;
  368. }
  369. logAi->trace("Goal %s has too low priority. It is not worth doing it.", taskDescription);
  370. continue;
  371. }
  372. logAi->info("Pass %d: Performing task (prioOfTask %d) %s with prio: %d", i, prioOfTask, selectedTask->toString(), selectedTask->priority);
  373. if(HeroPtr heroPtr(selectedTask->getHero(), cc.get()); selectedTask->getHero() && !heroPtr.isVerified(false))
  374. {
  375. logAi->error("Nullkiller::makeTurn Skipping pass due to unverified hero: %s", heroPtr.nameOrDefault());
  376. }
  377. else
  378. {
  379. if(!executeTask(selectedTask))
  380. {
  381. if(hasAnySuccess)
  382. break;
  383. return;
  384. }
  385. hasAnySuccess = true;
  386. }
  387. }
  388. hasAnySuccess |= ResourceTrader::trade(*buildAnalyzer, *cc, getFreeResources());
  389. if(!hasAnySuccess)
  390. {
  391. logAi->trace("Nothing was done this turn pass. Ending turn.");
  392. tracePlayerStatus(false);
  393. return;
  394. }
  395. for(const auto * heroInfo : cc->getHeroesInfo())
  396. AIGateway::pickBestArtifacts(cc, heroInfo);
  397. if(i == settings->getMaxPass())
  398. logAi->warn("MaxPass reached. Terminating AI turn.");
  399. }
  400. }
  401. bool Nullkiller::updateStateAndExecutePriorityPass(Goals::TGoalVec & tempResults, const int passIndex)
  402. {
  403. updateState();
  404. Goals::TTask bestPrioPassTask = taskptr(Goals::Invalid());
  405. for(int i = 1; i <= settings->getMaxPriorityPass() && cc->getPlayerStatus(playerID) == EPlayerStatus::INGAME; i++)
  406. {
  407. tempResults.clear();
  408. // TODO: Mircea: Should merge recruiting from DefenseBehavior
  409. decompose(tempResults, sptr(RecruitHeroBehavior()), 1);
  410. // TODO: Mircea: Should merge recruiting from DefenseBehavior
  411. decompose(tempResults, sptr(BuyArmyBehavior()), 1);
  412. decompose(tempResults, sptr(BuildingBehavior()), 1);
  413. bestPrioPassTask = choseBestTask(tempResults);
  414. if(bestPrioPassTask->priority > 0)
  415. {
  416. logAi->info("Pass %d: priorityPass %d: Performing task %s with prio: %d", passIndex, i, bestPrioPassTask->toString(), bestPrioPassTask->priority);
  417. const bool isRecruitHeroGoal = dynamic_cast<RecruitHero*>(bestPrioPassTask.get()) != nullptr;
  418. HeroPtr heroPtr(bestPrioPassTask->getHero(), cc.get());
  419. if(!isRecruitHeroGoal && bestPrioPassTask->getHero() && !heroPtr.isVerified(false))
  420. {
  421. logAi->error("Nullkiller::updateStateAndExecutePriorityPass Skipping priorityPass due to unverified hero: %s", heroPtr.nameOrDefault());
  422. }
  423. else if(!executeTask(bestPrioPassTask))
  424. {
  425. logAi->warn("Task failed to execute");
  426. return false;
  427. }
  428. updateState();
  429. }
  430. else
  431. {
  432. break;
  433. }
  434. if(i == settings->getMaxPriorityPass())
  435. {
  436. logAi->warn("MaxPriorityPass reached. Terminating priorityPass loop.");
  437. }
  438. }
  439. return true;
  440. }
  441. bool Nullkiller::areAffectedObjectsPresent(const Goals::TTask & task) const
  442. {
  443. auto affectedObjs = task->getAffectedObjects();
  444. for(auto oid : affectedObjs)
  445. {
  446. if(!cc->getObj(oid, false))
  447. return false;
  448. }
  449. return true;
  450. }
  451. HeroRole Nullkiller::getTaskRole(const Goals::TTask & task) const
  452. {
  453. HeroPtr heroPtr(task->getHero(), cc.get());
  454. HeroRole heroRole = HeroRole::MAIN;
  455. if(heroPtr.isVerified())
  456. heroRole = heroManager->getHeroRoleOrDefault(heroPtr);
  457. return heroRole;
  458. }
  459. bool Nullkiller::executeTask(const Goals::TTask & task) const
  460. {
  461. auto start = std::chrono::high_resolution_clock::now();
  462. std::string taskDescr = task->toString();
  463. makingTurnInterruption.interruptionPoint();
  464. logAi->debug("Trying to realize %s (value %2.3f)", taskDescr, task->priority);
  465. try
  466. {
  467. task->accept(aiGw);
  468. logAi->trace("Task %s completed in %lld", taskDescr, timeElapsed(start));
  469. }
  470. catch(goalFulfilledException &)
  471. {
  472. logAi->trace("Task %s completed in %lld", taskDescr, timeElapsed(start));
  473. }
  474. catch(cannotFulfillGoalException & e)
  475. {
  476. logAi->error("Failed to realize subgoal of type %s, I will stop.", taskDescr);
  477. logAi->error("The error message was: %s", e.what());
  478. return false;
  479. }
  480. return true;
  481. }
  482. TResources Nullkiller::getFreeResources() const
  483. {
  484. auto freeRes = cc->getResourceAmount() - lockedResources;
  485. freeRes.positive();
  486. return freeRes;
  487. }
  488. void Nullkiller::lockResources(const TResources & res)
  489. {
  490. lockedResources += res;
  491. }
  492. std::shared_ptr<const CPathsInfo> Nullkiller::getPathsInfo(const CGHeroInstance * h) const
  493. {
  494. return pathfinderCache->getPathsInfo(h);
  495. }
  496. void Nullkiller::invalidatePaths()
  497. {
  498. pathfinderCache->invalidatePaths();
  499. }
  500. void Nullkiller::tracePlayerStatus(bool beginning) const
  501. {
  502. #if NK2AI_TRACE_LEVEL >= 1
  503. float totalHeroesStrength = 0;
  504. int totalTownsLevel = 0;
  505. for (const auto *heroInfo : cc->getHeroesInfo())
  506. {
  507. totalHeroesStrength += heroInfo->getTotalStrength();
  508. }
  509. for (const auto *townInfo : cc->getTownsInfo())
  510. {
  511. totalTownsLevel += townInfo->getTownLevel();
  512. }
  513. const auto *firstWord = beginning ? "Beginning:" : "End:";
  514. logAi->info("%s totalHeroesStrength: %f, totalTownsLevel: %d, resources: %s", firstWord, totalHeroesStrength, totalTownsLevel, cc->getResourceAmount().toString());
  515. #endif
  516. }
  517. std::map<const CGHeroInstance *, HeroRole> Nullkiller::getHeroesForPathfinding() const
  518. {
  519. std::map<const CGHeroInstance *, HeroRole> activeHeroes;
  520. for(auto hero : cc->getHeroesInfo())
  521. {
  522. if(getHeroLockedReason(hero) == HeroLockedReason::DEFENCE)
  523. continue;
  524. activeHeroes[hero] = heroManager->getHeroRoleOrDefaultInefficient(hero);
  525. }
  526. return activeHeroes;
  527. }
  528. }