mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
contitutient arts swap
This commit is contained in:
@@ -1023,43 +1023,44 @@ bool CArtifactInstance::isPart(const CArtifactInstance *supposedPart) const
|
|||||||
return supposedPart == this;
|
return supposedPart == this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, ArtifactPosition slot, bool assumeDestRemoved) const
|
bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, bool assumeDestRemoved) const
|
||||||
{
|
{
|
||||||
if(slot == ArtifactPosition::TRANSITION_POS)
|
if(slot == ArtifactPosition::TRANSITION_POS)
|
||||||
return true;
|
return true;
|
||||||
bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved);
|
|
||||||
if(!canMainArtifactBePlaced)
|
|
||||||
return false; //no is no...
|
|
||||||
if(ArtifactUtils::isSlotBackpack(slot))
|
if(ArtifactUtils::isSlotBackpack(slot))
|
||||||
return true; //we can always remove combined art to the backapck
|
return true; //we can always remove combined art to the backapck
|
||||||
|
|
||||||
|
CArtifactFittingSet fittingSet(artSet->bearerType());
|
||||||
assert(artType->constituents);
|
fittingSet.artifactsWorn = artSet->artifactsWorn;
|
||||||
std::vector<ConstituentInfo> constituentsToBePlaced = constituentsInfo; //we'll remove constituents from that list, as we find a suitable slot for them
|
auto removedArt = fittingSet.getArt(slot);
|
||||||
|
if(assumeDestRemoved && removedArt)
|
||||||
//it may be that we picked a combined artifact in hero screen (though technically it's still there) to move it
|
|
||||||
//so we remove from the list all constituents that are already present on dst hero in the form of locks
|
|
||||||
for(const ConstituentInfo &constituent : constituentsInfo)
|
|
||||||
{
|
{
|
||||||
if(constituent.art == artSet->getArt(constituent.slot, false)) //no need to worry about locked constituent
|
if(removedArt->canBeDisassembled())
|
||||||
constituentsToBePlaced -= constituent;
|
|
||||||
}
|
|
||||||
|
|
||||||
//we iterate over all active slots and check if constituents fits them
|
|
||||||
for(const auto pos : ArtifactUtils::constituentWornSlots())
|
|
||||||
{
|
|
||||||
for(auto art = constituentsToBePlaced.begin(); art != constituentsToBePlaced.end(); art++)
|
|
||||||
{
|
{
|
||||||
// pos == slot because we can remove already worn artifact only from that slot. That is our main destination
|
auto contitutient = dynamic_cast<CCombinedArtifactInstance*>(removedArt);
|
||||||
if(art->art->canBePutAt(artSet, pos, pos == slot))
|
for(auto & part : contitutient->constituentsInfo)
|
||||||
{
|
{
|
||||||
constituentsToBePlaced.erase(art);
|
if(ArtifactUtils::isSlotEquipment(part.slot))
|
||||||
break;
|
{
|
||||||
|
fittingSet.eraseArtSlot(part.slot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fittingSet.eraseArtSlot(slot);
|
||||||
}
|
}
|
||||||
|
for(auto & art : constituentsInfo)
|
||||||
return constituentsToBePlaced.empty();
|
{
|
||||||
|
auto possibleSlot = art.art->firstAvailableSlot(&fittingSet);
|
||||||
|
if(ArtifactUtils::isSlotEquipment(possibleSlot))
|
||||||
|
{
|
||||||
|
fittingSet.setNewArtSlot(possibleSlot, nullptr, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCombinedArtifactInstance::canBeDisassembled() const
|
bool CCombinedArtifactInstance::canBeDisassembled() const
|
||||||
@@ -1563,7 +1564,7 @@ void CArtifactFittingSet::setNewArtSlot(ArtifactPosition slot, CArtifactInstance
|
|||||||
|
|
||||||
void CArtifactFittingSet::putArtifact(ArtifactPosition pos, CArtifactInstance * art)
|
void CArtifactFittingSet::putArtifact(ArtifactPosition pos, CArtifactInstance * art)
|
||||||
{
|
{
|
||||||
if(art && art->canBeDisassembled() && (pos < ArtifactPosition::AFTER_LAST))
|
if(art && art->canBeDisassembled() && ArtifactUtils::isSlotEquipment(pos))
|
||||||
{
|
{
|
||||||
for(auto & part : dynamic_cast<CCombinedArtifactInstance*>(art)->constituentsInfo)
|
for(auto & part : dynamic_cast<CCombinedArtifactInstance*>(art)->constituentsInfo)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user