1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Artifacts swap check

This commit is contained in:
SoundSSGood 2024-04-09 23:58:35 +03:00
parent bcd4a8c961
commit e8a6308a15
2 changed files with 12 additions and 7 deletions

View File

@ -840,15 +840,18 @@ CArtifactSet::ArtPlacementMap CArtifactSet::putArtifact(ArtifactPosition slot, C
void CArtifactSet::removeArtifact(ArtifactPosition slot)
{
auto art = getArt(slot, false);
if(art)
if(const auto art = getArt(slot, false))
{
if(art->isCombined())
{
for(auto & part : art->getPartsInfo())
for(const auto & part : art->getPartsInfo())
{
if(getArt(part.slot, false))
eraseArtSlot(part.slot);
if(part.slot != ArtifactPosition::PRE_FIRST)
{
assert(getArt(part.slot, false));
assert(getArt(part.slot, false) == part.art);
}
eraseArtSlot(part.slot);
}
}
eraseArtSlot(slot);

View File

@ -2706,7 +2706,8 @@ bool CGameHandler::moveArtifact(const PlayerColor & player, const ArtifactLocati
COMPLAIN_RET("That heroes cannot make any exchange!");
const auto srcArtifact = srcArtSet->getArt(src.slot);
const bool isDstSlotOccupied = dstArtSet->bearerType() == ArtBearer::ALTAR ? false : dstArtSet->getArt(dst.slot) != nullptr;
const auto dstArtifact = dstArtSet->getArt(dst.slot);
const bool isDstSlotOccupied = dstArtSet->bearerType() == ArtBearer::ALTAR ? false : dstArtifact != nullptr;
const bool isDstSlotBackpack = dstArtSet->bearerType() == ArtBearer::HERO ? ArtifactUtils::isSlotBackpack(dst.slot) : false;
if(srcArtifact == nullptr)
@ -2744,7 +2745,8 @@ bool CGameHandler::moveArtifact(const PlayerColor & player, const ArtifactLocati
// Check if dst slot is occupied
if(!isDstSlotBackpack && isDstSlotOccupied)
{
// Previous artifact must be removed
// Previous artifact must be swapped
COMPLAIN_RET_FALSE_IF(!dstArtifact->canBePutAt(srcArtSet, src.slot, true), "Cannot swap artifacts!");
ma.artsPack1.push_back(BulkMoveArtifacts::LinkedSlots(dstSlot, src.slot));
ma.swap = true;
}