|
|
@@ -1039,8 +1039,7 @@ 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;
|
|
|
+ std::set<std::pair<CArtifactInstance *, CArtifactInstance *> > swappedSet;
|
|
|
do
|
|
|
{
|
|
|
changeMade = false;
|
|
|
@@ -1102,7 +1101,6 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
|
|
|
cb->swapArtifacts(location, destLocation); //just put into empty slot
|
|
|
emptySlotFound = true;
|
|
|
changeMade = true;
|
|
|
- swapCount++;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -1122,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(),
|
|
|
@@ -1141,7 +1148,7 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
|
|
|
}
|
|
|
|
|
|
changeMade = true;
|
|
|
- swapCount++;
|
|
|
+ swappedSet.insert(swapPair);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -1151,9 +1158,7 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
|
|
|
break; //start evaluating artifacts from scratch
|
|
|
}
|
|
|
}
|
|
|
- while(changeMade && swapCount < maxSwapCount);
|
|
|
- if (swapCount >= maxSwapCount)
|
|
|
- logAi->warn("Maximum artifact swap count exceeded!");
|
|
|
+ while(changeMade);
|
|
|
};
|
|
|
|
|
|
equipBest(h, other, true);
|