1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-10 22:31:40 +02:00

fix hang in AI's turn

This commit is contained in:
kdmcser
2025-04-26 23:47:24 +08:00
parent 0b126ebc8b
commit 1210f0bf99

View File

@@ -1039,6 +1039,8 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
auto equipBest = [](const CGHeroInstance * h, const CGHeroInstance * otherh, bool giveStuffToFirstHero) -> void
{
bool changeMade = false;
int swapCount = 0;
const int maxSwapCount = 100;
do
{
changeMade = false;
@@ -1100,6 +1102,7 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
cb->swapArtifacts(location, destLocation); //just put into empty slot
emptySlotFound = true;
changeMade = true;
swapCount++;
break;
}
}
@@ -1138,6 +1141,7 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
}
changeMade = true;
swapCount++;
break;
}
}
@@ -1147,7 +1151,9 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
break; //start evaluating artifacts from scratch
}
}
while(changeMade);
while(changeMade && swapCount < maxSwapCount);
if (swapCount >= maxSwapCount)
logAi->warn("Maximum artifact swap count exceeded!");
};
equipBest(h, other, true);