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

record swap info, if A swap to B,not allow A <-> B in both side

This commit is contained in:
kdmcser
2025-04-27 00:34:44 +08:00
parent 1210f0bf99
commit 9dc07b00ff

View File

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