1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Add workaround for very common crash in BattleAI

This commit is contained in:
Ivan Savenko 2024-08-30 12:25:55 +00:00
parent 01697e4387
commit c3e76f19e1

View File

@ -376,11 +376,14 @@ MoveTarget BattleExchangeEvaluator::findMoveTowardsUnreachable(
logAi->trace("New high score");
#endif
for(BattleHex enemyHex : enemy->getAttackableHexes(activeStack))
for(const BattleHex & initialEnemyHex : enemy->getAttackableHexes(activeStack))
{
while(!flying && dists.distances[enemyHex] > speed)
BattleHex enemyHex = initialEnemyHex;
while(!flying && dists.distances[enemyHex] > speed && dists.predecessors.at(enemyHex).isValid())
{
enemyHex = dists.predecessors.at(enemyHex);
if(dists.accessibility[enemyHex] == EAccessibility::ALIVE_STACK)
{
auto defenderToBypass = hb->battleGetUnitByPos(enemyHex);