diff --git a/AI/Nullkiller/Behaviors/GatherArmyBehavior.cpp b/AI/Nullkiller/Behaviors/GatherArmyBehavior.cpp index f5eb28c79..c73b374c0 100644 --- a/AI/Nullkiller/Behaviors/GatherArmyBehavior.cpp +++ b/AI/Nullkiller/Behaviors/GatherArmyBehavior.cpp @@ -92,15 +92,6 @@ Goals::TGoalVec GatherArmyBehavior::deliverArmyToHero(const CGHeroInstance * her continue; } - bool garrisoned = false; - - if(path.turn() == 0 && hero->inTownGarrison) - { -#if NKAI_TRACE_LEVEL >= 1 - garrisoned = true; -#endif - } - if(path.turn() > 0 && ai->nullkiller->dangerHitMap->enemyCanKillOurHeroesAlongThePath(path)) { #if NKAI_TRACE_LEVEL >= 2 @@ -184,15 +175,22 @@ Goals::TGoalVec GatherArmyBehavior::deliverArmyToHero(const CGHeroInstance * her composition.addNext(heroExchange); - if(garrisoned && path.turn() == 0) + if(hero->inTownGarrison && path.turn() == 0) { auto lockReason = ai->nullkiller->getHeroLockedReason(hero); - composition.addNextSequence({ - sptr(ExchangeSwapTownHeroes(hero->visitedTown)), - sptr(exchangePath), - sptr(ExchangeSwapTownHeroes(hero->visitedTown, hero, lockReason)) - }); + if(path.targetHero->visitedTown == hero->visitedTown) + { + composition.addNextSequence({ + sptr(ExchangeSwapTownHeroes(hero->visitedTown, hero, lockReason))}); + } + else + { + composition.addNextSequence({ + sptr(ExchangeSwapTownHeroes(hero->visitedTown)), + sptr(exchangePath), + sptr(ExchangeSwapTownHeroes(hero->visitedTown, hero, lockReason))}); + } } else { diff --git a/AI/Nullkiller/Engine/Nullkiller.cpp b/AI/Nullkiller/Engine/Nullkiller.cpp index 66b28ca8e..d6d7f41dc 100644 --- a/AI/Nullkiller/Engine/Nullkiller.cpp +++ b/AI/Nullkiller/Engine/Nullkiller.cpp @@ -323,6 +323,11 @@ void Nullkiller::makeTurn() } executeTask(bestTask); + + if(i == MAXPASS) + { + logAi->error("Goal %s exceeded maxpass. Terminating AI turn.", bestTask->toString()); + } } } diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index c3bd49b6d..f20ceda1f 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -1359,7 +1359,7 @@ void VCAI::wander(HeroPtr h) TimeCheck tc("looking for wander destination"); - while(h->movementPointsRemaining()) + for(int k = 0; k < 10 && h->movementPointsRemaining(); k++) { validateVisitableObjs(); ah->updatePaths(getMyHeroes());