1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00
This commit is contained in:
Andrii Danylchenko
2024-04-27 13:57:50 +03:00
parent 2ead852f09
commit 39e19f79f4
3 changed files with 26 additions and 7 deletions

View File

@@ -1056,7 +1056,8 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
if(location.slot == ArtifactPosition::MACH4) // don't attempt to move catapult
continue;
auto s = cb->getHero(location.artHolder)->getSlot(location.slot);
auto artHolder = cb->getHero(location.artHolder);
auto s = artHolder->getSlot(location.slot);
if(!s || s->locked) //we can't move locks
continue;
auto artifact = s->artifact;
@@ -1084,10 +1085,27 @@ void AIGateway::pickBestArtifacts(const CGHeroInstance * h, const CGHeroInstance
if(otherSlot && otherSlot->artifact) //we need to exchange artifact for better one
{
//if that artifact is better than what we have, pick it
if(compareArtifacts(artifact, otherSlot->artifact) && artifact->canBePutAt(target, slot, true)) //combined artifacts are not always allowed to move
if(compareArtifacts(artifact, otherSlot->artifact)
&& artifact->canBePutAt(target, slot, true)) //combined artifacts are not always allowed to move
{
ArtifactLocation destLocation(target->id, slot);
cb->swapArtifacts(location, ArtifactLocation(target->id, target->getArtPos(otherSlot->artifact)));
logAi->trace(
"Exchange artifacts %s <-> %s",
artifact->artType->getNameTranslated(),
otherSlot->artifact->artType->getNameTranslated());
if(!otherSlot->artifact->canBePutAt(artHolder, location.slot, true))
{
ArtifactLocation destLocation(target->id, slot);
ArtifactLocation backpack(artHolder->id, ArtifactPosition::BACKPACK_START);
cb->swapArtifacts(destLocation, backpack);
cb->swapArtifacts(location, destLocation);
}
else
{
cb->swapArtifacts(location, ArtifactLocation(target->id, target->getArtPos(otherSlot->artifact)));
}
changeMade = true;
break;
}