1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

ArtifactUtils::isSlotBackpack() func + refactoring

This commit is contained in:
SoundSSGood 2022-11-18 22:49:57 +02:00
parent 30bbb57619
commit e6e669d024
5 changed files with 15 additions and 17 deletions

View File

@ -208,11 +208,7 @@ bool CHeroArtPlace::askToAssemble(const CArtifactInstance *art, ArtifactPosition
{
assert(art);
assert(hero);
bool assembleEqipped = true;
if(slot >= GameConstants::BACKPACK_START)
{
assembleEqipped = false;
}
bool assembleEqipped = !ArtifactUtils::isSlotBackpack(slot);
auto assemblyPossibilities = art->assemblyPossibilities(hero, assembleEqipped);
// If the artifact can be assembled, display dialog.
@ -823,7 +819,7 @@ void CArtifactsOfHero::artifactUpdateSlots(const ArtifactLocation & al)
{
if(al.isHolder(curHero))
{
if(al.slot >= GameConstants::BACKPACK_START)
if(ArtifactUtils::isSlotBackpack(al.slot))
updateBackpackSlots();
else
updateWornSlots();
@ -841,7 +837,7 @@ void CArtifactsOfHero::updateWornSlots(bool redrawParent)
void CArtifactsOfHero::updateBackpackSlots(bool redrawParent)
{
for(auto * artPlace : backpack)
for(auto artPlace : backpack)
updateSlot(artPlace->slotID);
scrollBackpack(0);

View File

@ -883,7 +883,7 @@ std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CA
for(const auto * constituent : *artifact->constituents) //check if all constituents are available
{
if (equipped)
if(equipped)
{
// Search for equipped arts
if (!h->hasArt(constituent->id, true, false, false))
@ -1564,4 +1564,9 @@ DLL_LINKAGE bool ArtifactUtils::checkSpellbookIsNeeded(const CGHeroInstance * he
return false;
}
DLL_LINKAGE bool ArtifactUtils::isSlotBackpack(ArtifactPosition slot)
{
return slot >= GameConstants::BACKPACK_START;
}
VCMI_LIB_NAMESPACE_END

View File

@ -388,6 +388,7 @@ namespace ArtifactUtils
DLL_LINKAGE std::vector<ArtifactPosition> unmovablePositions(); // TODO: Make this constexpr when the toolset is upgraded
DLL_LINKAGE bool isArtRemovable(const std::pair<ArtifactPosition, ArtSlotInfo> & slot);
DLL_LINKAGE bool checkSpellbookIsNeeded(const CGHeroInstance * heroPtr, ArtifactID artID, ArtifactPosition slot);
DLL_LINKAGE bool isSlotBackpack(ArtifactPosition slot);
}
VCMI_LIB_NAMESPACE_END

View File

@ -1089,7 +1089,7 @@ DLL_LINKAGE void EraseArtifact::applyGs(CGameState *gs)
DLL_LINKAGE void MoveArtifact::applyGs(CGameState * gs)
{
CArtifactInstance * art = src.getArt();
if(dst.slot < GameConstants::BACKPACK_START)
if(!ArtifactUtils::isSlotBackpack(dst.slot))
assert(!dst.getArt());
art->move(src, dst);
@ -1114,7 +1114,7 @@ DLL_LINKAGE void BulkMoveArtifacts::applyGs(CGameState * gs)
// so all the following indices will be affected. Thus, we need to update
// the subsequent artifact slots to account for that
auto srcPos = slot.srcPos;
if((srcPos >= GameConstants::BACKPACK_START) && (operation != EBulkArtsOp::BULK_PUT))
if(ArtifactUtils::isSlotBackpack(srcPos) && (operation != EBulkArtsOp::BULK_PUT))
{
srcPos = ArtifactPosition(srcPos.num - numBackpackArtifactsMoved);
}
@ -1170,9 +1170,7 @@ DLL_LINKAGE void AssembledArtifact::applyGs(CGameState *gs)
CArtifactSet * artSet = al.getHolderArtSet();
const CArtifactInstance *transformedArt = al.getArt();
assert(transformedArt);
bool combineEquipped = true;
if(al.slot >= GameConstants::BACKPACK_START)
combineEquipped = false;
bool combineEquipped = !ArtifactUtils::isSlotBackpack(al.slot);
assert(vstd::contains(transformedArt->assemblyPossibilities(artSet, combineEquipped), builtArt));
UNUSED(transformedArt);
@ -1196,7 +1194,7 @@ DLL_LINKAGE void AssembledArtifact::applyGs(CGameState *gs)
}
else
{
al.slot = std::min(al.slot, pos)
al.slot = std::min(al.slot, pos);
}
}

View File

@ -4036,9 +4036,7 @@ bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition
CArtifact *combinedArt = VLC->arth->objects[assembleTo];
if(!combinedArt->constituents)
COMPLAIN_RET("assembleArtifacts: Artifact being attempted to assemble is not a combined artifacts!");
bool combineEquipped = true;
if(artifactSlot >= GameConstants::BACKPACK_START)
combineEquipped = false;
bool combineEquipped = !ArtifactUtils::isSlotBackpack(artifactSlot);
if(!vstd::contains(destArtifact->assemblyPossibilities(hero, combineEquipped), combinedArt))
COMPLAIN_RET("assembleArtifacts: It's impossible to assemble requested artifact!");