mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Merge pull request #1569 from SoundSSGood/contitutient-swap
combined arts swap
This commit is contained in:
@@ -752,9 +752,10 @@ void CArtifactsOfHero::artifactMoved(const ArtifactLocation & src, const Artifac
|
|||||||
assert(commonInfo->src.AOH);
|
assert(commonInfo->src.AOH);
|
||||||
CCS->curh->dragAndDropCursor("artifact", dst.getArt()->artType->getIconIndex());
|
CCS->curh->dragAndDropCursor("artifact", dst.getArt()->artType->getIconIndex());
|
||||||
}
|
}
|
||||||
auto art = dst.getArt();
|
if(!curHero->artifactsTransitionPos.empty())
|
||||||
if(art && dst.slot == ArtifactPosition::TRANSITION_POS)
|
{
|
||||||
markPossibleSlots(art);
|
markPossibleSlots(curHero->getArt(ArtifactPosition::TRANSITION_POS));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateParentWindow();
|
updateParentWindow();
|
||||||
|
@@ -1023,43 +1023,46 @@ 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(!CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved))
|
||||||
if(!canMainArtifactBePlaced)
|
return false;
|
||||||
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 artToRemove = fittingSet.getArt(slot);
|
||||||
|
if(assumeDestRemoved && artToRemove)
|
||||||
//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(artToRemove->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 combinedArtToRemove = dynamic_cast<CCombinedArtifactInstance*>(artToRemove);
|
||||||
if(art->art->canBePutAt(artSet, pos, pos == slot))
|
for(auto & part : combinedArtToRemove->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
|
||||||
@@ -1565,7 +1568,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