mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Regressions fixed
This commit is contained in:
parent
c706b4d419
commit
4005b48360
@ -670,6 +670,16 @@ CArtifactsOfHero::CArtifactsOfHero(const Point & position, bool createCommonPart
|
||||
CArtifactsOfHero::~CArtifactsOfHero()
|
||||
{
|
||||
dispose();
|
||||
// Artifact located in artifactsTransitionPos should be returned
|
||||
if(!curHero->artifactsTransitionPos.empty())
|
||||
{
|
||||
auto artPlace = getArtPlace(
|
||||
ArtifactUtils::getArtifactDstPosition(curHero->artifactsTransitionPos.begin()->artifact, curHero, curHero->bearerType()));
|
||||
assert(artPlace);
|
||||
assert(artPlace->ourOwner);
|
||||
artPlace->setMeAsDest();
|
||||
artPlace->ourOwner->realizeCurrentTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
void CArtifactsOfHero::updateParentWindow()
|
||||
@ -735,8 +745,21 @@ void CArtifactsOfHero::artifactMoved(const ArtifactLocation & src, const Artifac
|
||||
// however after first movement we pick the art from TRANSITION_POS and the second movement coming when
|
||||
// we have a different artifact may look surprising... but it's valid.
|
||||
|
||||
// Used when doing dragAndDrop and artifact swap multiple times
|
||||
if(src.slot == ArtifactPosition::TRANSITION_POS &&
|
||||
commonInfo->src.slotID == ArtifactPosition::TRANSITION_POS &&
|
||||
commonInfo->dst.slotID == ArtifactPosition::PRE_FIRST)
|
||||
{
|
||||
auto art = curHero->getArt(ArtifactPosition::TRANSITION_POS);
|
||||
assert(art);
|
||||
CCS->curh->dragAndDropCursor(make_unique<CAnimImage>("artifact", art->artType->getIconIndex()));
|
||||
markPossibleSlots(art);
|
||||
|
||||
commonInfo->src.art = art;
|
||||
commonInfo->src.slotID = src.slot;
|
||||
}
|
||||
// Artifact was taken from us
|
||||
if(commonInfo->src == src)
|
||||
else if(commonInfo->src == src)
|
||||
{
|
||||
// Expected movement from slot ot slot
|
||||
assert(commonInfo->dst == dst
|
||||
@ -746,13 +769,12 @@ void CArtifactsOfHero::artifactMoved(const ArtifactLocation & src, const Artifac
|
||||
commonInfo->reset();
|
||||
unmarkSlots();
|
||||
}
|
||||
// The dest artifact was moved -> we are picking it
|
||||
// The dest artifact was moved after the swap -> we are picking it
|
||||
else if(commonInfo->dst == src)
|
||||
{
|
||||
assert(dst.slot == ArtifactPosition::TRANSITION_POS);
|
||||
commonInfo->reset();
|
||||
|
||||
CArtifactsOfHero::ArtPlacePtr ap;
|
||||
for(CArtifactsOfHero * aoh : commonInfo->participants)
|
||||
{
|
||||
if(dst.isHolder(aoh->curHero))
|
||||
@ -795,6 +817,10 @@ void CArtifactsOfHero::artifactRemoved(const ArtifactLocation &al)
|
||||
|
||||
CArtifactsOfHero::ArtPlacePtr CArtifactsOfHero::getArtPlace(int slot)
|
||||
{
|
||||
if(slot == ArtifactPosition::TRANSITION_POS)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
if(slot < GameConstants::BACKPACK_START)
|
||||
{
|
||||
if(artWorn.find(ArtifactPosition(slot)) == artWorn.end())
|
||||
|
@ -1249,8 +1249,6 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
||||
|
||||
CExchangeWindow::~CExchangeWindow()
|
||||
{
|
||||
artifs[0]->commonInfo = nullptr;
|
||||
artifs[1]->commonInfo = nullptr;
|
||||
}
|
||||
|
||||
const CGarrisonSlot * CExchangeWindow::getSelectedSlotID() const
|
||||
|
@ -864,7 +864,7 @@ void CArtifactInstance::removeFrom(ArtifactLocation al)
|
||||
{
|
||||
assert(al.getHolderArtSet()->getArt(al.slot) == this);
|
||||
al.getHolderArtSet()->eraseArtSlot(al.slot);
|
||||
if(!ArtifactUtils::isSlotBackpack(al.slot))
|
||||
if(!ArtifactUtils::isSlotBackpack(al.slot) && (al.slot != ArtifactPosition::TRANSITION_POS))
|
||||
al.getHolderNode()->detachFrom(*this);
|
||||
}
|
||||
|
||||
@ -1335,7 +1335,11 @@ const CCombinedArtifactInstance *CArtifactSet::getAssemblyByConstituent(Artifact
|
||||
const ArtSlotInfo * CArtifactSet::getSlot(ArtifactPosition pos) const
|
||||
{
|
||||
if(pos == ArtifactPosition::TRANSITION_POS)
|
||||
return &artifactTransitionPos;
|
||||
{
|
||||
// Always add to the end. Always take from the beginning.
|
||||
assert(!artifactsTransitionPos.empty());
|
||||
return &(*artifactsTransitionPos.begin());
|
||||
}
|
||||
if(vstd::contains(artifactsWorn, pos))
|
||||
return &artifactsWorn.at(pos);
|
||||
if(pos >= ArtifactPosition::AFTER_LAST )
|
||||
@ -1363,7 +1367,11 @@ ArtSlotInfo & CArtifactSet::retrieveNewArtSlot(ArtifactPosition slot)
|
||||
assert(!vstd::contains(artifactsWorn, slot));
|
||||
|
||||
if(slot == ArtifactPosition::TRANSITION_POS)
|
||||
return artifactTransitionPos;
|
||||
{
|
||||
// Always add to the end. Always take from the beginning.
|
||||
artifactsTransitionPos.push_back(ArtSlotInfo());
|
||||
return artifactsTransitionPos.back();
|
||||
}
|
||||
if(!ArtifactUtils::isSlotBackpack(slot))
|
||||
return artifactsWorn[slot];
|
||||
|
||||
@ -1384,7 +1392,12 @@ void CArtifactSet::setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art,
|
||||
|
||||
void CArtifactSet::eraseArtSlot(ArtifactPosition slot)
|
||||
{
|
||||
if(ArtifactUtils::isSlotBackpack(slot))
|
||||
if(slot == ArtifactPosition::TRANSITION_POS)
|
||||
{
|
||||
assert(!artifactsTransitionPos.empty());
|
||||
artifactsTransitionPos.erase(artifactsTransitionPos.begin());
|
||||
}
|
||||
else if(ArtifactUtils::isSlotBackpack(slot))
|
||||
{
|
||||
auto backpackSlot = ArtifactPosition(slot - GameConstants::BACKPACK_START);
|
||||
|
||||
|
@ -317,7 +317,7 @@ class DLL_LINKAGE CArtifactSet
|
||||
public:
|
||||
std::vector<ArtSlotInfo> artifactsInBackpack; //hero's artifacts from bag
|
||||
std::map<ArtifactPosition, ArtSlotInfo> artifactsWorn; //map<position,artifact_id>; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
|
||||
ArtSlotInfo artifactTransitionPos; // Used as transition position for manual artifact exchange
|
||||
std::vector<ArtSlotInfo> artifactsTransitionPos; // Used as transition position for dragAndDrop artifact exchange
|
||||
|
||||
ArtSlotInfo & retrieveNewArtSlot(ArtifactPosition slot);
|
||||
void setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art, bool locked);
|
||||
|
@ -3910,21 +3910,24 @@ bool CGameHandler::moveArtifact(const ArtifactLocation &al1, const ArtifactLocat
|
||||
if(ArtifactUtils::isSlotBackpack(dst.slot))
|
||||
vstd::amin(dst.slot, ArtifactPosition(GameConstants::BACKPACK_START + (si32)dst.getHolderArtSet()->artifactsInBackpack.size()));
|
||||
|
||||
if(src.slot == dst.slot && src.artHolder == dst.artHolder)
|
||||
COMPLAIN_RET("Won't move artifact: Dest same as source!");
|
||||
|
||||
// Check if dst slot is occupied
|
||||
if(!ArtifactUtils::isSlotBackpack(dst.slot) && destArtifact)
|
||||
if(!(src.slot == ArtifactPosition::TRANSITION_POS && dst.slot == ArtifactPosition::TRANSITION_POS))
|
||||
{
|
||||
// Previous artifact must be removed first
|
||||
moveArtifact(dst, ArtifactLocation(dst.artHolder, ArtifactPosition::TRANSITION_POS));
|
||||
}
|
||||
auto hero = boost::get<ConstTransitivePtr<CGHeroInstance>>(dst.artHolder);
|
||||
if(ArtifactUtils::checkSpellbookIsNeeded(hero, srcArtifact->artType->id, dst.slot))
|
||||
giveHeroNewArtifact(hero, VLC->arth->objects[ArtifactID::SPELLBOOK], ArtifactPosition::SPELLBOOK);
|
||||
if(src.slot == dst.slot && src.artHolder == dst.artHolder)
|
||||
COMPLAIN_RET("Won't move artifact: Dest same as source!");
|
||||
|
||||
MoveArtifact ma(&src, &dst);
|
||||
sendAndApply(&ma);
|
||||
// Check if dst slot is occupied
|
||||
if(!ArtifactUtils::isSlotBackpack(dst.slot) && destArtifact)
|
||||
{
|
||||
// Previous artifact must be removed first
|
||||
moveArtifact(dst, ArtifactLocation(dst.artHolder, ArtifactPosition::TRANSITION_POS));
|
||||
}
|
||||
auto hero = boost::get<ConstTransitivePtr<CGHeroInstance>>(dst.artHolder);
|
||||
if(ArtifactUtils::checkSpellbookIsNeeded(hero, srcArtifact->artType->id, dst.slot))
|
||||
giveHeroNewArtifact(hero, VLC->arth->objects[ArtifactID::SPELLBOOK], ArtifactPosition::SPELLBOOK);
|
||||
|
||||
MoveArtifact ma(&src, &dst);
|
||||
sendAndApply(&ma);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user