1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

NKAI: fix freeze on army gathering

This commit is contained in:
Andrii Danylchenko 2023-08-05 13:49:49 +03:00 committed by Ivan Savenko
parent d7cbe4ecde
commit 04fe78d31c
3 changed files with 19 additions and 16 deletions

View File

@ -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);
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))
});
sptr(ExchangeSwapTownHeroes(hero->visitedTown, hero, lockReason))});
}
}
else
{

View File

@ -323,6 +323,11 @@ void Nullkiller::makeTurn()
}
executeTask(bestTask);
if(i == MAXPASS)
{
logAi->error("Goal %s exceeded maxpass. Terminating AI turn.", bestTask->toString());
}
}
}

View File

@ -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());