1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Merge pull request #2484 from vcmi/nkai-fix-freeze

NKAI: fix freeze on army gathering
This commit is contained in:
Ivan Savenko
2023-08-07 16:52:59 +03:00
committed by GitHub
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);
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
{

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