mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
ArtifactUtils and CArtifactFittingSet class
This commit is contained in:
@@ -1457,4 +1457,67 @@ void CArtifactSet::serializeJsonSlot(JsonSerializeFormat & handler, const Artifa
|
||||
}
|
||||
}
|
||||
|
||||
CArtifactFittingSet::CArtifactFittingSet(ArtBearer::ArtBearer Bearer)
|
||||
{
|
||||
this->Bearer = Bearer;
|
||||
}
|
||||
|
||||
void CArtifactFittingSet::setNewArtSlot(ArtifactPosition slot, CArtifactInstance * art, bool locked)
|
||||
{
|
||||
ArtSlotInfo & asi = retrieveNewArtSlot(slot);
|
||||
asi.artifact = art;
|
||||
asi.locked = locked;
|
||||
}
|
||||
|
||||
void CArtifactFittingSet::putArtifact(ArtifactPosition pos, CArtifactInstance * art)
|
||||
{
|
||||
if (art->canBeDisassembled() && (pos < ArtifactPosition::AFTER_LAST))
|
||||
{
|
||||
for (auto part : dynamic_cast<CCombinedArtifactInstance*>(art)->constituentsInfo)
|
||||
{
|
||||
// For the ArtFittingSet is no needed to do figureMainConstituent, just lock slots
|
||||
this->setNewArtSlot(part.art->firstAvailableSlot(this), part.art, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setNewArtSlot(pos, art, false);
|
||||
}
|
||||
}
|
||||
|
||||
ArtBearer::ArtBearer CArtifactFittingSet::bearerType() const
|
||||
{
|
||||
return this->Bearer;
|
||||
}
|
||||
|
||||
DLL_LINKAGE ArtifactPosition ArtifactUtils::getArtifactDstPosition(const CArtifactInstance * artifact,
|
||||
const CArtifactSet * target, ArtBearer::ArtBearer barer)
|
||||
{
|
||||
for (auto slot : artifact->artType->possibleSlots.at(barer))
|
||||
{
|
||||
auto existingArtifact = target->getArt(slot);
|
||||
auto existingArtInfo = target->getSlot(slot);
|
||||
|
||||
if (!existingArtifact
|
||||
&& (!existingArtInfo || !existingArtInfo->locked)
|
||||
&& artifact->canBePutAt(target, slot))
|
||||
{
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return ArtifactPosition(GameConstants::BACKPACK_START);
|
||||
}
|
||||
|
||||
DLL_LINKAGE std::vector<ArtifactPosition> ArtifactUtils::unmovablePositions()
|
||||
{
|
||||
return { ArtifactPosition::SPELLBOOK, ArtifactPosition::MACH4 };
|
||||
}
|
||||
|
||||
DLL_LINKAGE bool ArtifactUtils::isArtRemovable(const std::pair<ArtifactPosition, ArtSlotInfo> & slot)
|
||||
{
|
||||
return slot.second.artifact
|
||||
&& !slot.second.locked
|
||||
&& !vstd::contains(unmovablePositions(), slot.first);
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
Reference in New Issue
Block a user