mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
Merge pull request #5652 from kdmcser/hang_fix
Prevent AI from repeatedly swapping the same artifacts
This commit is contained in:
@@ -1039,6 +1039,7 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
|
||||
auto equipBest = [](const CGHeroInstance * h, const CGHeroInstance * otherh, bool giveStuffToFirstHero) -> void
|
||||
{
|
||||
bool changeMade = false;
|
||||
std::set<std::pair<CArtifactInstance *, CArtifactInstance *> > swappedSet;
|
||||
do
|
||||
{
|
||||
changeMade = false;
|
||||
@@ -1119,6 +1120,15 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
|
||||
//combined artifacts are not always allowed to move
|
||||
if(artifactScore > otherArtifactScore && artifact->canBePutAt(target, slot, true))
|
||||
{
|
||||
auto swapPair = std::minmax(artifact, otherSlot->artifact);
|
||||
if (swappedSet.find(swapPair) != swappedSet.end())
|
||||
{
|
||||
logAi->warn(
|
||||
"Artifacts % s < -> % s have already swapped before, ignored.",
|
||||
artifact->getType()->getJsonKey(),
|
||||
otherSlot->artifact->getType()->getJsonKey());
|
||||
continue;
|
||||
}
|
||||
logAi->trace(
|
||||
"Exchange artifacts %s <-> %s",
|
||||
artifact->getType()->getJsonKey(),
|
||||
@@ -1138,6 +1148,7 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
|
||||
}
|
||||
|
||||
changeMade = true;
|
||||
swappedSet.insert(swapPair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user