2
0

Nullkiller.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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(cc.get(), 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. SET_GLOBAL_STATE_TBB(this->aiGw);
  160. auto evaluator = this->priorityEvaluators->acquire();
  161. for(size_t i = r.begin(); i != r.end(); i++)
  162. {
  163. const auto & task = tasks[i];
  164. if(task->asTask()->priority <= 0 || priorityTier != PriorityEvaluator::PriorityTier::BUILDINGS)
  165. task->asTask()->priority = evaluator->evaluate(task, priorityTier);
  166. }
  167. });
  168. boost::range::sort(tasks, [](const TSubgoal& g1, const TSubgoal& g2) -> bool
  169. {
  170. return g2->asTask()->priority < g1->asTask()->priority;
  171. });
  172. for(const TSubgoal & task : tasks)
  173. {
  174. taskPlan.merge(task);
  175. }
  176. return taskPlan.getTasks();
  177. }
  178. void Nullkiller::decompose(Goals::TGoalVec & results, const Goals::TSubgoal& behavior, int decompositionMaxDepth) const
  179. {
  180. makingTurnInterruption.interruptionPoint();
  181. logAi->debug("Decomposing behavior %s", behavior->toString());
  182. const auto start = std::chrono::high_resolution_clock::now();
  183. decomposer->decompose(results, behavior, decompositionMaxDepth);
  184. makingTurnInterruption.interruptionPoint();
  185. logAi->debug("Decomposing behavior %s done in %ld", behavior->toString(), timeElapsed(start));
  186. }
  187. void Nullkiller::resetState()
  188. {
  189. std::unique_lock lockGuard(aiStateMutex);
  190. lockedResources = TResources();
  191. scanDepth = ScanDepth::MAIN_FULL;
  192. lockedHeroes.clear();
  193. dangerHitMap->resetHitmap();
  194. useHeroChain = true;
  195. objectClusterizer->reset();
  196. if(!baseGraph && isObjectGraphAllowed())
  197. {
  198. baseGraph = std::make_unique<ObjectGraph>();
  199. baseGraph->updateGraph(this);
  200. }
  201. }
  202. void Nullkiller::invalidatePathfinderData()
  203. {
  204. pathfinderInvalidated = true;
  205. }
  206. void Nullkiller::updateState()
  207. {
  208. #if NK2AI_TRACE_LEVEL >= 1
  209. logAi->info("PERFORMANCE: AI updateState started");
  210. #endif
  211. makingTurnInterruption.interruptionPoint();
  212. std::unique_lock lockGuard(aiStateMutex);
  213. const auto start = std::chrono::high_resolution_clock::now();
  214. activeHero = nullptr;
  215. setTargetObject(-1);
  216. decomposer->reset();
  217. buildAnalyzer->update();
  218. if(!pathfinderInvalidated && dangerHitMap->isHitMapUpToDate() && dangerHitMap->isTileOwnersUpToDate())
  219. logAi->trace("Skipping full state regeneration - up to date");
  220. else
  221. {
  222. memory->removeInvisibleObjects(cc.get());
  223. dangerHitMap->updateHitMap();
  224. dangerHitMap->calculateTileOwners();
  225. makingTurnInterruption.interruptionPoint();
  226. heroManager->update();
  227. logAi->trace("Updating paths");
  228. PathfinderSettings cfg;
  229. cfg.useHeroChain = useHeroChain;
  230. cfg.allowBypassObjects = true;
  231. if(scanDepth == ScanDepth::SMALL || isObjectGraphAllowed())
  232. {
  233. cfg.mainTurnDistanceLimit = settings->getMainHeroTurnDistanceLimit();
  234. }
  235. if(scanDepth != ScanDepth::ALL_FULL || isObjectGraphAllowed())
  236. {
  237. cfg.scoutTurnDistanceLimit = settings->getScoutHeroTurnDistanceLimit();
  238. }
  239. makingTurnInterruption.interruptionPoint();
  240. const auto heroes = getHeroesForPathfinding();
  241. pathfinder->updatePaths(heroes, cfg);
  242. if(isObjectGraphAllowed())
  243. {
  244. pathfinder->updateGraphs(
  245. heroes,
  246. scanDepth == ScanDepth::SMALL ? PathfinderSettings::MaxTurnDistanceLimit : 10,
  247. scanDepth == ScanDepth::ALL_FULL ? PathfinderSettings::MaxTurnDistanceLimit : 3);
  248. }
  249. makingTurnInterruption.interruptionPoint();
  250. objectClusterizer->clusterize();
  251. pathfinderInvalidated = false;
  252. }
  253. armyManager->update();
  254. #if NK2AI_TRACE_LEVEL >= 1
  255. if(const auto timeElapsedMs = timeElapsed(start); timeElapsedMs > 499)
  256. {
  257. logAi->warn("PERFORMANCE: AI updateState took %ld ms", timeElapsedMs);
  258. }
  259. else
  260. {
  261. logAi->info("PERFORMANCE: AI updateState took %ld ms", timeElapsedMs);
  262. }
  263. #endif
  264. }
  265. bool Nullkiller::isHeroLocked(const CGHeroInstance * hero) const
  266. {
  267. return getHeroLockedReason(hero) != HeroLockedReason::NOT_LOCKED;
  268. }
  269. bool Nullkiller::arePathHeroesLocked(const AIPath & path) const
  270. {
  271. if(getHeroLockedReason(path.targetHero) == HeroLockedReason::STARTUP)
  272. {
  273. #if NK2AI_TRACE_LEVEL >= 1
  274. logAi->trace("Hero %s is locked by STARTUP. Discarding %s", path.targetHero->getObjectName(), path.toString());
  275. #endif
  276. return true;
  277. }
  278. for(const auto & node : path.nodes)
  279. {
  280. auto lockReason = getHeroLockedReason(node.targetHero);
  281. if(lockReason != HeroLockedReason::NOT_LOCKED)
  282. {
  283. #if NK2AI_TRACE_LEVEL >= 1
  284. logAi->trace("Hero %s is locked by %d. Discarding %s", path.targetHero->getObjectName(), (int)lockReason, path.toString());
  285. #endif
  286. return true;
  287. }
  288. }
  289. return false;
  290. }
  291. HeroLockedReason Nullkiller::getHeroLockedReason(const CGHeroInstance * hero) const
  292. {
  293. auto found = lockedHeroes.find(hero);
  294. return found != lockedHeroes.end() ? found->second : HeroLockedReason::NOT_LOCKED;
  295. }
  296. void Nullkiller::makeTurn()
  297. {
  298. std::lock_guard<std::mutex> sharedStorageLock(AISharedStorage::locker);
  299. const int MAX_DEPTH = 10;
  300. resetState();
  301. Goals::TGoalVec tasks;
  302. tracePlayerStatus(true);
  303. for(int i = 1; i <= settings->getMaxPass() && cc->getPlayerStatus(playerID) == EPlayerStatus::INGAME; i++)
  304. {
  305. if (!updateStateAndExecutePriorityPass(tasks, i)) return;
  306. tasks.clear();
  307. decompose(tasks, sptr(CaptureObjectsBehavior()), 1);
  308. decompose(tasks, sptr(ClusterBehavior()), MAX_DEPTH);
  309. decompose(tasks, sptr(DefenceBehavior()), MAX_DEPTH);
  310. decompose(tasks, sptr(GatherArmyBehavior()), MAX_DEPTH);
  311. decompose(tasks, sptr(StayAtTownBehavior()), MAX_DEPTH);
  312. if(!isOpenMap())
  313. decompose(tasks, sptr(ExplorationBehavior()), MAX_DEPTH);
  314. TTaskVec selectedTasks;
  315. #if NK2AI_TRACE_LEVEL >= 1
  316. int prioOfTask = 0;
  317. #endif
  318. for (int prio = PriorityEvaluator::PriorityTier::INSTAKILL; prio <= PriorityEvaluator::PriorityTier::MAX_PRIORITY_TIER; ++prio)
  319. {
  320. #if NK2AI_TRACE_LEVEL >= 1
  321. prioOfTask = prio;
  322. #endif
  323. selectedTasks = buildPlan(tasks, prio);
  324. if (!selectedTasks.empty() || settings->isUseFuzzy())
  325. break;
  326. }
  327. boost::range::sort(selectedTasks, [](const TTask& a, const TTask& b)
  328. {
  329. return a->priority > b->priority;
  330. });
  331. if(selectedTasks.empty())
  332. {
  333. selectedTasks.push_back(taskptr(Goals::Invalid()));
  334. }
  335. bool hasAnySuccess = false;
  336. for(const auto& selectedTask : selectedTasks)
  337. {
  338. if(cc->getPlayerStatus(playerID) != EPlayerStatus::INGAME)
  339. return;
  340. if(!areAffectedObjectsPresent(selectedTask))
  341. {
  342. logAi->debug("Affected object not found. Canceling task.");
  343. continue;
  344. }
  345. std::string taskDescription = selectedTask->toString();
  346. HeroRole heroRole = getTaskRole(selectedTask);
  347. if(heroRole != HeroRole::MAIN || selectedTask->getHeroExchangeCount() <= 1)
  348. useHeroChain = false;
  349. // TODO: better to check turn distance here instead of priority
  350. if((heroRole != HeroRole::MAIN || selectedTask->priority < SMALL_SCAN_MIN_PRIORITY)
  351. && scanDepth == ScanDepth::MAIN_FULL)
  352. {
  353. useHeroChain = false;
  354. scanDepth = ScanDepth::SMALL;
  355. logAi->trace(
  356. "Goal %s has low priority %f so decreasing scan depth to gain performance.",
  357. taskDescription,
  358. selectedTask->priority);
  359. }
  360. if((settings->isUseFuzzy() && selectedTask->priority < MIN_PRIORITY) || (!settings->isUseFuzzy() && selectedTask->priority <= 0))
  361. {
  362. auto heroes = cc->getHeroesInfo();
  363. const auto hasMp = vstd::contains_if(heroes, [](const CGHeroInstance * h) -> bool
  364. {
  365. return h->movementPointsRemaining() > 100;
  366. });
  367. if(hasMp && scanDepth != ScanDepth::ALL_FULL)
  368. {
  369. logAi->trace(
  370. "Goal %s has too low priority %f so increasing scan depth to full.",
  371. taskDescription,
  372. selectedTask->priority);
  373. scanDepth = ScanDepth::ALL_FULL;
  374. useHeroChain = false;
  375. hasAnySuccess = true;
  376. break;
  377. }
  378. logAi->trace("Goal %s has too low priority. It is not worth doing it.", taskDescription);
  379. continue;
  380. }
  381. logAi->info("Pass %d: Performing task (prioOfTask %d) %s with prio: %d", i, prioOfTask, selectedTask->toString(), selectedTask->priority);
  382. if(HeroPtr heroPtr(selectedTask->getHero(), cc); selectedTask->getHero() && !heroPtr.isVerified(false))
  383. {
  384. logAi->warn("Nullkiller::makeTurn Skipping pass due to unverified hero: %s", heroPtr.nameOrDefault());
  385. }
  386. else
  387. {
  388. if(!executeTask(selectedTask))
  389. {
  390. if(hasAnySuccess)
  391. break;
  392. return;
  393. }
  394. hasAnySuccess = true;
  395. }
  396. }
  397. hasAnySuccess |= ResourceTrader::trade(buildAnalyzer, cc, getFreeResources());
  398. if(!hasAnySuccess)
  399. {
  400. logAi->trace("Nothing was done this turn. Ending turn.");
  401. tracePlayerStatus(false);
  402. return;
  403. }
  404. for (const auto *heroInfo : cc->getHeroesInfo())
  405. AIGateway::pickBestArtifacts(cc, heroInfo);
  406. if(i == settings->getMaxPass())
  407. {
  408. logAi->warn("MaxPass reached. Terminating AI turn.");
  409. }
  410. }
  411. }
  412. bool Nullkiller::updateStateAndExecutePriorityPass(Goals::TGoalVec & tempResults, const int passIndex)
  413. {
  414. updateState();
  415. Goals::TTask bestPrioPassTask = taskptr(Goals::Invalid());
  416. for(int i = 1; i <= settings->getMaxPriorityPass() && cc->getPlayerStatus(playerID) == EPlayerStatus::INGAME; i++)
  417. {
  418. tempResults.clear();
  419. decompose(tempResults, sptr(RecruitHeroBehavior()), 1);
  420. decompose(tempResults, sptr(BuyArmyBehavior()), 1);
  421. decompose(tempResults, sptr(BuildingBehavior()), 1);
  422. bestPrioPassTask = choseBestTask(tempResults);
  423. if(bestPrioPassTask->priority > 0)
  424. {
  425. logAi->info("Pass %d: priorityPass %d: Performing task %s with prio: %d", passIndex, i, bestPrioPassTask->toString(), bestPrioPassTask->priority);
  426. const bool isRecruitHeroGoal = dynamic_cast<RecruitHero*>(bestPrioPassTask.get()) != nullptr;
  427. HeroPtr heroPtr(bestPrioPassTask->getHero(), cc);
  428. if(!isRecruitHeroGoal && bestPrioPassTask->getHero() && !heroPtr.isVerified(false))
  429. {
  430. logAi->warn("Nullkiller::updateStateAndExecutePriorityPass Skipping priorityPass due to unverified hero: %s", heroPtr.nameOrDefault());
  431. }
  432. else if(!executeTask(bestPrioPassTask))
  433. {
  434. logAi->warn("Task failed to execute");
  435. return false;
  436. }
  437. updateState();
  438. }
  439. else
  440. {
  441. break;
  442. }
  443. if(i == settings->getMaxPriorityPass())
  444. {
  445. logAi->warn("MaxPriorityPass reached. Terminating priorityPass loop.");
  446. }
  447. }
  448. return true;
  449. }
  450. bool Nullkiller::areAffectedObjectsPresent(const Goals::TTask & task) const
  451. {
  452. auto affectedObjs = task->getAffectedObjects();
  453. for(auto oid : affectedObjs)
  454. {
  455. if(!cc->getObj(oid, false))
  456. return false;
  457. }
  458. return true;
  459. }
  460. HeroRole Nullkiller::getTaskRole(const Goals::TTask & task) const
  461. {
  462. HeroPtr heroPtr(task->getHero(), cc);
  463. HeroRole heroRole = HeroRole::MAIN;
  464. if(heroPtr.isVerified())
  465. heroRole = heroManager->getHeroRoleOrDefault(heroPtr);
  466. return heroRole;
  467. }
  468. bool Nullkiller::executeTask(const Goals::TTask & task) const
  469. {
  470. auto start = std::chrono::high_resolution_clock::now();
  471. std::string taskDescr = task->toString();
  472. makingTurnInterruption.interruptionPoint();
  473. logAi->debug("Trying to realize %s (value %2.3f)", taskDescr, task->priority);
  474. try
  475. {
  476. task->accept(aiGw);
  477. logAi->trace("Task %s completed in %lld", taskDescr, timeElapsed(start));
  478. }
  479. catch(goalFulfilledException &)
  480. {
  481. logAi->trace("Task %s completed in %lld", taskDescr, timeElapsed(start));
  482. }
  483. catch(cannotFulfillGoalException & e)
  484. {
  485. logAi->error("Failed to realize subgoal of type %s, I will stop.", taskDescr);
  486. logAi->error("The error message was: %s", e.what());
  487. return false;
  488. }
  489. return true;
  490. }
  491. TResources Nullkiller::getFreeResources() const
  492. {
  493. auto freeRes = cc->getResourceAmount() - lockedResources;
  494. freeRes.positive();
  495. return freeRes;
  496. }
  497. void Nullkiller::lockResources(const TResources & res)
  498. {
  499. lockedResources += res;
  500. }
  501. std::shared_ptr<const CPathsInfo> Nullkiller::getPathsInfo(const CGHeroInstance * h) const
  502. {
  503. return pathfinderCache->getPathsInfo(h);
  504. }
  505. void Nullkiller::invalidatePaths()
  506. {
  507. pathfinderCache->invalidatePaths();
  508. }
  509. void Nullkiller::tracePlayerStatus(bool beginning) const
  510. {
  511. #if NK2AI_TRACE_LEVEL >= 1
  512. float totalHeroesStrength = 0;
  513. int totalTownsLevel = 0;
  514. for (const auto *heroInfo : cc->getHeroesInfo())
  515. {
  516. totalHeroesStrength += heroInfo->getTotalStrength();
  517. }
  518. for (const auto *townInfo : cc->getTownsInfo())
  519. {
  520. totalTownsLevel += townInfo->getTownLevel();
  521. }
  522. const auto *firstWord = beginning ? "Beginning:" : "End:";
  523. logAi->info("%s totalHeroesStrength: %f, totalTownsLevel: %d, resources: %s", firstWord, totalHeroesStrength, totalTownsLevel, cc->getResourceAmount().toString());
  524. #endif
  525. }
  526. std::map<const CGHeroInstance *, HeroRole> Nullkiller::getHeroesForPathfinding() const
  527. {
  528. std::map<const CGHeroInstance *, HeroRole> activeHeroes;
  529. for(auto hero : cc->getHeroesInfo())
  530. {
  531. if(getHeroLockedReason(hero) == HeroLockedReason::DEFENCE)
  532. continue;
  533. activeHeroes[hero] = heroManager->getHeroRoleOrDefaultInefficient(hero);
  534. }
  535. return activeHeroes;
  536. }
  537. }