|
@@ -851,7 +851,7 @@ void CArtifactInstance::putAt(ArtifactLocation al)
|
|
assert(canBePutAt(al));
|
|
assert(canBePutAt(al));
|
|
|
|
|
|
al.getHolderArtSet()->setNewArtSlot(al.slot, this, false);
|
|
al.getHolderArtSet()->setNewArtSlot(al.slot, this, false);
|
|
- if(al.slot < GameConstants::BACKPACK_START)
|
|
|
|
|
|
+ if(!ArtifactUtils::isSlotBackpack(al.slot))
|
|
al.getHolderNode()->attachTo(*this);
|
|
al.getHolderNode()->attachTo(*this);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -859,7 +859,7 @@ void CArtifactInstance::removeFrom(ArtifactLocation al)
|
|
{
|
|
{
|
|
assert(al.getHolderArtSet()->getArt(al.slot) == this);
|
|
assert(al.getHolderArtSet()->getArt(al.slot) == this);
|
|
al.getHolderArtSet()->eraseArtSlot(al.slot);
|
|
al.getHolderArtSet()->eraseArtSlot(al.slot);
|
|
- if(al.slot < GameConstants::BACKPACK_START)
|
|
|
|
|
|
+ if(!ArtifactUtils::isSlotBackpack(al.slot))
|
|
al.getHolderNode()->detachFrom(*this);
|
|
al.getHolderNode()->detachFrom(*this);
|
|
|
|
|
|
//TODO delete me?
|
|
//TODO delete me?
|
|
@@ -1003,7 +1003,7 @@ bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, ArtifactP
|
|
bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved);
|
|
bool canMainArtifactBePlaced = CArtifactInstance::canBePutAt(artSet, slot, assumeDestRemoved);
|
|
if(!canMainArtifactBePlaced)
|
|
if(!canMainArtifactBePlaced)
|
|
return false; //no is no...
|
|
return false; //no is no...
|
|
- if(slot >= GameConstants::BACKPACK_START)
|
|
|
|
|
|
+ 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
|
|
|
|
|
|
|
|
|
|
@@ -1019,11 +1019,12 @@ bool CCombinedArtifactInstance::canBePutAt(const CArtifactSet *artSet, ArtifactP
|
|
}
|
|
}
|
|
|
|
|
|
//we iterate over all active slots and check if constituents fits them
|
|
//we iterate over all active slots and check if constituents fits them
|
|
- for (int i = 0; i < GameConstants::BACKPACK_START; i++)
|
|
|
|
|
|
+ for(const auto pos : ArtifactUtils::constituentWornSlots)
|
|
{
|
|
{
|
|
for(auto art = constituentsToBePlaced.begin(); art != constituentsToBePlaced.end(); art++)
|
|
for(auto art = constituentsToBePlaced.begin(); art != constituentsToBePlaced.end(); art++)
|
|
{
|
|
{
|
|
- if(art->art->canBePutAt(artSet, ArtifactPosition(i), i == slot)) // i == al.slot because we can remove already worn artifact only from that slot that is our main destination
|
|
|
|
|
|
+ // pos == slot because we can remove already worn artifact only from that slot. That is our main destination
|
|
|
|
+ if(art->art->canBePutAt(artSet, pos, pos == slot))
|
|
{
|
|
{
|
|
constituentsToBePlaced.erase(art);
|
|
constituentsToBePlaced.erase(art);
|
|
break;
|
|
break;
|
|
@@ -1069,7 +1070,7 @@ void CCombinedArtifactInstance::addAsConstituent(CArtifactInstance *art, Artifac
|
|
|
|
|
|
void CCombinedArtifactInstance::putAt(ArtifactLocation al)
|
|
void CCombinedArtifactInstance::putAt(ArtifactLocation al)
|
|
{
|
|
{
|
|
- if(al.slot >= GameConstants::BACKPACK_START)
|
|
|
|
|
|
+ if(ArtifactUtils::isSlotBackpack(al.slot))
|
|
{
|
|
{
|
|
CArtifactInstance::putAt(al);
|
|
CArtifactInstance::putAt(al);
|
|
for(ConstituentInfo &ci : constituentsInfo)
|
|
for(ConstituentInfo &ci : constituentsInfo)
|
|
@@ -1094,7 +1095,7 @@ void CCombinedArtifactInstance::putAt(ArtifactLocation al)
|
|
else
|
|
else
|
|
ci.slot = pos = ci.art->firstAvailableSlot(al.getHolderArtSet());
|
|
ci.slot = pos = ci.art->firstAvailableSlot(al.getHolderArtSet());
|
|
|
|
|
|
- assert(pos < GameConstants::BACKPACK_START);
|
|
|
|
|
|
+ assert(!ArtifactUtils::isSlotBackpack(pos));
|
|
al.getHolderArtSet()->setNewArtSlot(pos, ci.art, true); //sets as lock
|
|
al.getHolderArtSet()->setNewArtSlot(pos, ci.art, true); //sets as lock
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -1107,7 +1108,7 @@ void CCombinedArtifactInstance::putAt(ArtifactLocation al)
|
|
|
|
|
|
void CCombinedArtifactInstance::removeFrom(ArtifactLocation al)
|
|
void CCombinedArtifactInstance::removeFrom(ArtifactLocation al)
|
|
{
|
|
{
|
|
- if(al.slot >= GameConstants::BACKPACK_START)
|
|
|
|
|
|
+ if(ArtifactUtils::isSlotBackpack(al.slot))
|
|
{
|
|
{
|
|
CArtifactInstance::removeFrom(al);
|
|
CArtifactInstance::removeFrom(al);
|
|
}
|
|
}
|
|
@@ -1353,7 +1354,7 @@ bool CArtifactSet::isPositionFree(ArtifactPosition pos, bool onlyLockCheck) cons
|
|
ArtSlotInfo & CArtifactSet::retrieveNewArtSlot(ArtifactPosition slot)
|
|
ArtSlotInfo & CArtifactSet::retrieveNewArtSlot(ArtifactPosition slot)
|
|
{
|
|
{
|
|
assert(!vstd::contains(artifactsWorn, slot));
|
|
assert(!vstd::contains(artifactsWorn, slot));
|
|
- ArtSlotInfo &ret = slot < GameConstants::BACKPACK_START
|
|
|
|
|
|
+ ArtSlotInfo &ret = !ArtifactUtils::isSlotBackpack(slot)
|
|
? artifactsWorn[slot]
|
|
? artifactsWorn[slot]
|
|
: *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::BACKPACK_START), ArtSlotInfo());
|
|
: *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::BACKPACK_START), ArtSlotInfo());
|
|
|
|
|
|
@@ -1369,14 +1370,14 @@ void CArtifactSet::setNewArtSlot(ArtifactPosition slot, CArtifactInstance *art,
|
|
|
|
|
|
void CArtifactSet::eraseArtSlot(ArtifactPosition slot)
|
|
void CArtifactSet::eraseArtSlot(ArtifactPosition slot)
|
|
{
|
|
{
|
|
- if(slot < GameConstants::BACKPACK_START)
|
|
|
|
|
|
+ if(ArtifactUtils::isSlotBackpack(slot))
|
|
{
|
|
{
|
|
- artifactsWorn.erase(slot);
|
|
|
|
|
|
+ slot = ArtifactPosition(slot - GameConstants::BACKPACK_START);
|
|
|
|
+ artifactsInBackpack.erase(artifactsInBackpack.begin() + slot);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- slot = ArtifactPosition(slot - GameConstants::BACKPACK_START);
|
|
|
|
- artifactsInBackpack.erase(artifactsInBackpack.begin() + slot);
|
|
|
|
|
|
+ artifactsWorn.erase(slot);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1543,19 +1544,41 @@ DLL_LINKAGE ArtifactPosition ArtifactUtils::getArtifactDstPosition( const CArtif
|
|
return ArtifactPosition(GameConstants::BACKPACK_START);
|
|
return ArtifactPosition(GameConstants::BACKPACK_START);
|
|
}
|
|
}
|
|
|
|
|
|
-DLL_LINKAGE std::vector<ArtifactPosition> ArtifactUtils::unmovablePositions()
|
|
|
|
|
|
+namespace ArtifactUtils
|
|
{
|
|
{
|
|
- return { ArtifactPosition::SPELLBOOK, ArtifactPosition::MACH4 };
|
|
|
|
-}
|
|
|
|
|
|
|
|
-DLL_LINKAGE bool ArtifactUtils::isArtRemovable(const std::pair<ArtifactPosition, ArtSlotInfo> & slot)
|
|
|
|
|
|
+DLL_LINKAGE const std::array<ArtifactPosition::EArtifactPosition, 2> unmovableSlots =
|
|
|
|
+{
|
|
|
|
+ ArtifactPosition::SPELLBOOK,
|
|
|
|
+ ArtifactPosition::MACH4
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+DLL_LINKAGE const std::array<ArtifactPosition::EArtifactPosition, 14> constituentWornSlots =
|
|
|
|
+{
|
|
|
|
+ ArtifactPosition::HEAD,
|
|
|
|
+ ArtifactPosition::SHOULDERS,
|
|
|
|
+ ArtifactPosition::NECK,
|
|
|
|
+ ArtifactPosition::RIGHT_HAND,
|
|
|
|
+ ArtifactPosition::LEFT_HAND,
|
|
|
|
+ ArtifactPosition::TORSO,
|
|
|
|
+ ArtifactPosition::RIGHT_RING,
|
|
|
|
+ ArtifactPosition::LEFT_RING,
|
|
|
|
+ ArtifactPosition::FEET,
|
|
|
|
+ ArtifactPosition::MISC1,
|
|
|
|
+ ArtifactPosition::MISC2,
|
|
|
|
+ ArtifactPosition::MISC3,
|
|
|
|
+ ArtifactPosition::MISC4,
|
|
|
|
+ ArtifactPosition::MISC5,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+DLL_LINKAGE bool isArtRemovable(const std::pair<ArtifactPosition, ArtSlotInfo> & slot)
|
|
{
|
|
{
|
|
return slot.second.artifact
|
|
return slot.second.artifact
|
|
&& !slot.second.locked
|
|
&& !slot.second.locked
|
|
- && !vstd::contains(unmovablePositions(), slot.first);
|
|
|
|
|
|
+ && !vstd::contains(unmovableSlots, slot.first);
|
|
}
|
|
}
|
|
|
|
|
|
-DLL_LINKAGE bool ArtifactUtils::checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, ArtifactID artID, ArtifactPosition slot)
|
|
|
|
|
|
+DLL_LINKAGE bool checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, ArtifactID artID, ArtifactPosition slot)
|
|
{
|
|
{
|
|
// TODO what'll happen if Titan's thunder is equipped by pickin git up or the start of game?
|
|
// TODO what'll happen if Titan's thunder is equipped by pickin git up or the start of game?
|
|
// Titan's Thunder creates new spellbook on equip
|
|
// Titan's Thunder creates new spellbook on equip
|
|
@@ -1570,9 +1593,10 @@ DLL_LINKAGE bool ArtifactUtils::checkSpellbookIsNeeded(const CGHeroInstance * he
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
-DLL_LINKAGE bool ArtifactUtils::isSlotBackpack(ArtifactPosition slot)
|
|
|
|
|
|
+DLL_LINKAGE bool isSlotBackpack(ArtifactPosition slot)
|
|
{
|
|
{
|
|
return slot >= GameConstants::BACKPACK_START;
|
|
return slot >= GameConstants::BACKPACK_START;
|
|
}
|
|
}
|
|
|
|
+};
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
VCMI_LIB_NAMESPACE_END
|