1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Backpack limit part5. End of battle. Other stuff

This commit is contained in:
SoundSSGood 2023-03-21 12:13:53 +02:00
parent 9f8aa25297
commit f0f9eecf97
15 changed files with 117 additions and 118 deletions

View File

@ -646,7 +646,7 @@ CArtifactsOfHero::~CArtifactsOfHero()
if(!curHero->artifactsTransitionPos.empty()) if(!curHero->artifactsTransitionPos.empty())
{ {
auto artPlace = getArtPlace( auto artPlace = getArtPlace(
ArtifactUtils::getArtAnyPosition(curHero, curHero->artifactsTransitionPos.begin()->artifact->artType->getId())); ArtifactUtils::getArtAnyPosition(curHero, curHero->artifactsTransitionPos.begin()->artifact->getTypeId()));
if(artPlace) if(artPlace)
{ {
assert(artPlace->ourOwner); assert(artPlace->ourOwner);
@ -1005,8 +1005,13 @@ void CCommanderArtPlace::createImage()
void CCommanderArtPlace::returnArtToHeroCallback() void CCommanderArtPlace::returnArtToHeroCallback()
{ {
ArtifactPosition artifactPos = commanderSlotID; ArtifactPosition artifactPos = commanderSlotID;
ArtifactPosition freeSlot = ourArt->firstBackpackSlot(commanderOwner); ArtifactPosition freeSlot = ArtifactUtils::getArtBackpackPosition(commanderOwner, ourArt->getTypeId());
if(freeSlot == ArtifactPosition::PRE_FIRST)
{
LOCPLINT->showInfoDialog("no free slots");
}
else
{
ArtifactLocation src(commanderOwner->commander.get(), artifactPos); ArtifactLocation src(commanderOwner->commander.get(), artifactPos);
ArtifactLocation dst(commanderOwner, freeSlot); ArtifactLocation dst(commanderOwner, freeSlot);
@ -1017,6 +1022,7 @@ void CCommanderArtPlace::returnArtToHeroCallback()
parent->redraw(); parent->redraw();
} }
} }
}
void CCommanderArtPlace::setArtifact(const CArtifactInstance * art) void CCommanderArtPlace::setArtifact(const CArtifactInstance * art)
{ {

View File

@ -204,7 +204,8 @@ bool CGarrisonSlot::highlightOrDropArtifact()
{ {
//creature can wear only one active artifact //creature can wear only one active artifact
//if we are placing a new one, the old one will be returned to the hero's backpack //if we are placing a new one, the old one will be returned to the hero's backpack
LOCPLINT->cb->swapArtifacts(dst, ArtifactLocation(srcHero, dst.getArt()->firstBackpackSlot(srcHero))); LOCPLINT->cb->swapArtifacts(dst, ArtifactLocation(srcHero,
ArtifactUtils::getArtBackpackPosition(srcHero, dst.getArt()->getTypeId())));
} }
LOCPLINT->cb->swapArtifacts(src, dst); LOCPLINT->cb->swapArtifacts(src, dst);
} }

View File

@ -948,10 +948,14 @@ void CStackWindow::removeStackArtifact(ArtifactPosition pos)
logGlobal->error("Attempt to remove missing artifact"); logGlobal->error("Attempt to remove missing artifact");
return; return;
} }
LOCPLINT->cb->swapArtifacts(ArtifactLocation(info->stackNode, pos), ArtifactLocation(info->owner, art->firstBackpackSlot(info->owner))); const auto slot = ArtifactUtils::getArtBackpackPosition(info->owner, art->getTypeId());
if(slot != ArtifactPosition::PRE_FIRST)
{
LOCPLINT->cb->swapArtifacts(ArtifactLocation(info->stackNode, pos), ArtifactLocation(info->owner, slot));
stackArtifactButton.reset(); stackArtifactButton.reset();
stackArtifactHelp.reset(); stackArtifactHelp.reset();
stackArtifactIcon.reset(); stackArtifactIcon.reset();
redraw(); redraw();
} }
}

View File

@ -358,7 +358,7 @@ void CHeroWindow::commanderWindow()
{ {
const CGHeroInstance *srcHero = commonInfo->src.AOH->getHero(); const CGHeroInstance *srcHero = commonInfo->src.AOH->getHero();
//artSelected = true; //artSelected = true;
ArtifactPosition freeSlot = art->firstAvailableSlot (curHero->commander); const auto freeSlot = ArtifactUtils::getArtAnyPosition(curHero->commander, art->artType->getId());
if(freeSlot < ArtifactPosition::COMMANDER_AFTER_LAST) //we don't want to put it in commander's backpack! if(freeSlot < ArtifactPosition::COMMANDER_AFTER_LAST) //we don't want to put it in commander's backpack!
{ {
ArtifactLocation src(srcHero, commonInfo->src.slotID); ArtifactLocation src(srcHero, commonInfo->src.slotID);
@ -368,7 +368,8 @@ void CHeroWindow::commanderWindow()
{ //equip clicked stack { //equip clicked stack
if(dst.getArt()) if(dst.getArt())
{ {
LOCPLINT->cb->swapArtifacts (dst, ArtifactLocation(srcHero, dst.getArt()->firstBackpackSlot(srcHero))); LOCPLINT->cb->swapArtifacts (dst, ArtifactLocation(srcHero,
ArtifactUtils::getArtBackpackPosition(srcHero, art->getTypeId())));
} }
LOCPLINT->cb->swapArtifacts(src, dst); LOCPLINT->cb->swapArtifacts(src, dst);
} }

View File

@ -817,7 +817,7 @@ void CMarketplaceWindow::makeDeal()
leftIdToSend = hLeft->getArtInstance()->id.getNum(); leftIdToSend = hLeft->getArtInstance()->id.getNum();
break; break;
case EMarketMode::RESOURCE_ARTIFACT: case EMarketMode::RESOURCE_ARTIFACT:
if(!ArtifactUtils::isPossibleToGetArt(hero, ArtifactID(hRight->id))) if(!ArtifactID(hRight->id).toArtifact()->canBePutAt(hero))
{ {
LOCPLINT->showInfoDialog("no available slots"); LOCPLINT->showInfoDialog("no available slots");
madeTransaction = false; madeTransaction = false;

View File

@ -843,7 +843,7 @@ void CExchangeController::moveArtifact(
{ {
auto srcLocation = ArtifactLocation(source, srcPosition); auto srcLocation = ArtifactLocation(source, srcPosition);
auto dstLocation = ArtifactLocation(target, auto dstLocation = ArtifactLocation(target,
ArtifactUtils::getArtAnyPosition(target, source->getArt(srcPosition)->artType->getId())); ArtifactUtils::getArtAnyPosition(target, source->getArt(srcPosition)->getTypeId()));
cb->swapArtifacts(srcLocation, dstLocation); cb->swapArtifacts(srcLocation, dstLocation);
} }

View File

@ -146,31 +146,23 @@ bool CArtifact::canBeDisassembled() const
bool CArtifact::canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, bool assumeDestRemoved) const bool CArtifact::canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, bool assumeDestRemoved) const
{ {
if(slot == ArtifactPosition::TRANSITION_POS)
return true;
auto simpleArtCanBePutAt = [this](const CArtifactSet * artSet, ArtifactPosition slot, bool assumeDestRemoved) -> bool auto simpleArtCanBePutAt = [this](const CArtifactSet * artSet, ArtifactPosition slot, bool assumeDestRemoved) -> bool
{ {
if(ArtifactUtils::isSlotBackpack(slot)) if(ArtifactUtils::isSlotBackpack(slot))
{ {
if(isBig() || !ArtifactUtils::isBackpackFreeSlots(artSet)) if(isBig() || !ArtifactUtils::isBackpackFreeSlots(artSet))
return false; return false;
return true; return true;
} }
auto bearerPossibleSlots = possibleSlots.at(artSet->bearerType()); if(!vstd::contains(possibleSlots.at(artSet->bearerType()), slot))
if(bearerPossibleSlots.empty())
{
logMod->warn("Warning: artifact %s doesn't have defined allowed slots for bearer of type %s", getNameTranslated(), artSet->bearerType());
return false;
}
if(!vstd::contains(bearerPossibleSlots, slot))
return false; return false;
return artSet->isPositionFree(slot, assumeDestRemoved); return artSet->isPositionFree(slot, assumeDestRemoved);
}; };
auto artCanBePutAt = [this, simpleArtCanBePutAt](const CArtifactSet * artSet, ArtifactPosition slot, bool assumeDestRemoved) -> bool
{
if(canBeDisassembled()) if(canBeDisassembled())
{ {
if(!simpleArtCanBePutAt(artSet, slot, assumeDestRemoved)) if(!simpleArtCanBePutAt(artSet, slot, assumeDestRemoved))
@ -201,6 +193,28 @@ bool CArtifact::canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, b
{ {
return simpleArtCanBePutAt(artSet, slot, assumeDestRemoved); return simpleArtCanBePutAt(artSet, slot, assumeDestRemoved);
} }
};
if(slot == ArtifactPosition::TRANSITION_POS)
return true;
if(slot == ArtifactPosition::FIRST_AVAILABLE)
{
for(const auto & slot : possibleSlots.at(artSet->bearerType()))
{
if(artCanBePutAt(artSet, slot, assumeDestRemoved))
return true;
}
return artCanBePutAt(artSet, GameConstants::BACKPACK_START, assumeDestRemoved);
}
else if(ArtifactUtils::isSlotBackpack(slot))
{
return artCanBePutAt(artSet, GameConstants::BACKPACK_START, assumeDestRemoved);
}
else
{
return artCanBePutAt(artSet, slot, assumeDestRemoved);
}
} }
CArtifact::CArtifact() CArtifact::CArtifact()
@ -864,24 +878,9 @@ std::string CArtifactInstance::getEffectiveDescription(const CGHeroInstance * he
return text; return text;
} }
ArtifactPosition CArtifactInstance::firstAvailableSlot(const CArtifactSet * h) const ArtifactID CArtifactInstance::getTypeId() const
{ {
for(const auto & slot : artType->possibleSlots.at(h->bearerType())) return artType->getId();
{
if(artType->canBePutAt(h, slot))
return slot;
}
//if haven't find proper slot, use backpack
return firstBackpackSlot(h);
}
ArtifactPosition CArtifactInstance::firstBackpackSlot(const CArtifactSet *h) const
{
if(!artType->isBig()) //discard big artifact
return ArtifactPosition(GameConstants::BACKPACK_START + static_cast<si32>(h->artifactsInBackpack.size()));
return ArtifactPosition::PRE_FIRST;
} }
bool CArtifactInstance::canBePutAt(const ArtifactLocation & al, bool assumeDestRemoved) const bool CArtifactInstance::canBePutAt(const ArtifactLocation & al, bool assumeDestRemoved) const
@ -1091,7 +1090,7 @@ void CCombinedArtifactInstance::putAt(ArtifactLocation al)
const bool suggestedPosValid = ci.art->canBePutAt(suggestedPos); const bool suggestedPosValid = ci.art->canBePutAt(suggestedPos);
if(!(inActiveSlot && suggestedPosValid)) //there is a valid suggestion where to place lock if(!(inActiveSlot && suggestedPosValid)) //there is a valid suggestion where to place lock
ci.slot = ArtifactUtils::getArtAnyPosition(al.getHolderArtSet(), ci.art->artType->getId()); ci.slot = ArtifactUtils::getArtAnyPosition(al.getHolderArtSet(), ci.art->getTypeId());
assert(ArtifactUtils::isSlotEquipment(ci.slot)); assert(ArtifactUtils::isSlotEquipment(ci.slot));
al.getHolderArtSet()->setNewArtSlot(ci.slot, ci.art, true); //sets as lock al.getHolderArtSet()->setNewArtSlot(ci.slot, ci.art, true); //sets as lock
@ -1214,7 +1213,7 @@ std::vector<ArtifactPosition> CArtifactSet::getAllArtPositions(const ArtifactID
{ {
std::vector<ArtifactPosition> result; std::vector<ArtifactPosition> result;
for(const auto & slotInfo : artifactsWorn) for(const auto & slotInfo : artifactsWorn)
if(slotInfo.second.artifact->artType->getId() == aid && (allowLocked || !slotInfo.second.locked)) if(slotInfo.second.artifact->getTypeId() == aid && (allowLocked || !slotInfo.second.locked))
result.push_back(slotInfo.first); result.push_back(slotInfo.first);
if(onlyWorn) if(onlyWorn)
@ -1300,7 +1299,7 @@ std::pair<const CCombinedArtifactInstance *, const CArtifactInstance *> CArtifac
auto * ass = dynamic_cast<CCombinedArtifactInstance *>(art.get()); auto * ass = dynamic_cast<CCombinedArtifactInstance *>(art.get());
for(auto& ci : ass->constituentsInfo) for(auto& ci : ass->constituentsInfo)
{ {
if(ci.art->artType->getId() == aid) if(ci.art->getTypeId() == aid)
{ {
return {ass, ci.art}; return {ass, ci.art};
} }
@ -1452,7 +1451,7 @@ void CArtifactSet::serializeJsonHero(JsonSerializeFormat & handler, CMap * map)
{ {
backpackTemp.reserve(artifactsInBackpack.size()); backpackTemp.reserve(artifactsInBackpack.size());
for(const ArtSlotInfo & info : artifactsInBackpack) for(const ArtSlotInfo & info : artifactsInBackpack)
backpackTemp.push_back(info.artifact->artType->getId()); backpackTemp.push_back(info.artifact->getTypeId());
} }
handler.serializeIdArray(NArtifactPosition::backpack, backpackTemp); handler.serializeIdArray(NArtifactPosition::backpack, backpackTemp);
if(!handler.saving) if(!handler.saving)
@ -1487,7 +1486,7 @@ void CArtifactSet::serializeJsonSlot(JsonSerializeFormat & handler, const Artifa
if(info != nullptr && !info->locked) if(info != nullptr && !info->locked)
{ {
artifactID = info->artifact->artType->getId(); artifactID = info->artifact->getTypeId();
handler.serializeId(NArtifactPosition::namesHero[slot.num], artifactID, ArtifactID::NONE); handler.serializeId(NArtifactPosition::namesHero[slot.num], artifactID, ArtifactID::NONE);
} }
} }
@ -1522,7 +1521,7 @@ void CArtifactFittingSet::putArtifact(ArtifactPosition pos, CArtifactInstance *
{ {
for(auto & part : dynamic_cast<CCombinedArtifactInstance*>(art)->constituentsInfo) for(auto & part : dynamic_cast<CCombinedArtifactInstance*>(art)->constituentsInfo)
{ {
const auto slot = ArtifactUtils::getArtAnyPosition(this, part.art->artType->getId()); const auto slot = ArtifactUtils::getArtAnyPosition(this, part.art->getTypeId());
assert(slot != ArtifactPosition::PRE_FIRST); assert(slot != ArtifactPosition::PRE_FIRST);
// For the ArtFittingSet is no needed to do figureMainConstituent, just lock slots // For the ArtFittingSet is no needed to do figureMainConstituent, just lock slots
this->setNewArtSlot(slot, part.art, true); this->setNewArtSlot(slot, part.art, true);
@ -1655,14 +1654,4 @@ DLL_LINKAGE bool ArtifactUtils::isBackpackFreeSlots(const CArtifactSet * target,
return target->artifactsInBackpack.size() + reqSlots <= backpackCap; return target->artifactsInBackpack.size() + reqSlots <= backpackCap;
} }
DLL_LINKAGE bool ArtifactUtils::isPossibleToGetArt(const CArtifactSet * target, const ArtifactID & aid, ArtifactPosition slot)
{
if(slot == ArtifactPosition::FIRST_AVAILABLE)
slot = getArtAnyPosition(target, aid);
if(isSlotEquipment(slot) || (isSlotBackpack(slot) && isBackpackFreeSlots(target)))
return true;
else
return false;
}
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -91,7 +91,8 @@ public:
virtual void levelUpArtifact (CArtifactInstance * art){}; virtual void levelUpArtifact (CArtifactInstance * art){};
virtual bool canBeDisassembled() const; virtual bool canBeDisassembled() const;
virtual bool canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot, bool assumeDestRemoved = false) const; virtual bool canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot = ArtifactPosition::FIRST_AVAILABLE,
bool assumeDestRemoved = false) const;
void updateFrom(const JsonNode & data); void updateFrom(const JsonNode & data);
void serializeJson(JsonSerializeFormat & handler); void serializeJson(JsonSerializeFormat & handler);
@ -153,10 +154,9 @@ public:
void setType(CArtifact *Art); void setType(CArtifact *Art);
std::string getEffectiveDescription(const CGHeroInstance *hero = nullptr) const; std::string getEffectiveDescription(const CGHeroInstance *hero = nullptr) const;
ArtifactPosition firstAvailableSlot(const CArtifactSet *h) const;
ArtifactPosition firstBackpackSlot(const CArtifactSet *h) const;
SpellID getGivenSpellID() const; //to be used with scrolls (and similar arts), -1 if none SpellID getGivenSpellID() const; //to be used with scrolls (and similar arts), -1 if none
ArtifactID getTypeId() const;
bool canBePutAt(const ArtifactLocation & al, bool assumeDestRemoved = false) const; //forwards to the above one bool canBePutAt(const ArtifactLocation & al, bool assumeDestRemoved = false) const; //forwards to the above one
virtual bool canBeDisassembled() const; virtual bool canBeDisassembled() const;
virtual void putAt(ArtifactLocation al); virtual void putAt(ArtifactLocation al);
@ -390,8 +390,6 @@ namespace ArtifactUtils
DLL_LINKAGE bool isSlotBackpack(const ArtifactPosition & slot); DLL_LINKAGE bool isSlotBackpack(const ArtifactPosition & slot);
DLL_LINKAGE bool isSlotEquipment(const ArtifactPosition & slot); DLL_LINKAGE bool isSlotEquipment(const ArtifactPosition & slot);
DLL_LINKAGE bool isBackpackFreeSlots(const CArtifactSet * target, const size_t reqSlots = 1); DLL_LINKAGE bool isBackpackFreeSlots(const CArtifactSet * target, const size_t reqSlots = 1);
DLL_LINKAGE bool isPossibleToGetArt(const CArtifactSet * target, const ArtifactID & aid,
ArtifactPosition slot = ArtifactPosition::FIRST_AVAILABLE);
} }
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -1594,7 +1594,7 @@ void CGameState::giveCampaignBonusToHero(CGHeroInstance * hero)
case CScenarioTravel::STravelBonus::SPELL_SCROLL: case CScenarioTravel::STravelBonus::SPELL_SCROLL:
{ {
CArtifactInstance * scroll = CArtifactInstance::createScroll(SpellID(curBonus->info2)); CArtifactInstance * scroll = CArtifactInstance::createScroll(SpellID(curBonus->info2));
const auto slot = ArtifactUtils::getArtAnyPosition(hero, scroll->artType->getId()); const auto slot = ArtifactUtils::getArtAnyPosition(hero, scroll->getTypeId());
if(ArtifactUtils::isSlotEquipment(slot) || ArtifactUtils::isSlotBackpack(slot)) if(ArtifactUtils::isSlotEquipment(slot) || ArtifactUtils::isSlotBackpack(slot))
scroll->putAt(ArtifactLocation(hero, slot)); scroll->putAt(ArtifactLocation(hero, slot));
else else

View File

@ -1693,14 +1693,18 @@ void RebalanceStacks::applyGs(CGameState * gs)
if (alDest.getArt()) if (alDest.getArt())
{ {
auto * hero = dynamic_cast<CGHeroInstance *>(src.army.get()); auto * hero = dynamic_cast<CGHeroInstance *>(src.army.get());
if (hero) auto dstSlot = ArtifactUtils::getArtBackpackPosition(hero, alDest.getArt()->getTypeId());
if(hero && dstSlot != ArtifactPosition::PRE_FIRST)
{ {
artDest->move (alDest, ArtifactLocation (hero, alDest.getArt()->firstBackpackSlot (hero))); artDest->move (alDest, ArtifactLocation (hero, dstSlot));
} }
//else - artifact cna be lost :/ //else - artifact cna be lost :/
else else
{ {
logNetwork->warn("Artifact is present at destination slot!"); EraseArtifact ea;
ea.al = alDest;
ea.applyGs(gs);
logNetwork->warn("Cannot move artifact! No free slots");
} }
artHere->move (alHere, alDest); artHere->move (alHere, alDest);
//TODO: choose from dialog //TODO: choose from dialog

View File

@ -1023,11 +1023,6 @@ void CGHeroInstance::putArtifact(ArtifactPosition pos, CArtifactInstance *art)
art->putAt(ArtifactLocation(this, pos)); art->putAt(ArtifactLocation(this, pos));
} }
void CGHeroInstance::putInBackpack(CArtifactInstance *art)
{
putArtifact(art->firstBackpackSlot(this), art);
}
bool CGHeroInstance::hasSpellbook() const bool CGHeroInstance::hasSpellbook() const
{ {
return getArt(ArtifactPosition::SPELLBOOK); return getArt(ArtifactPosition::SPELLBOOK);

View File

@ -234,7 +234,6 @@ public:
void initHero(CRandomGenerator & rand, const HeroTypeID & SUBID); void initHero(CRandomGenerator & rand, const HeroTypeID & SUBID);
void putArtifact(ArtifactPosition pos, CArtifactInstance * art) override; void putArtifact(ArtifactPosition pos, CArtifactInstance * art) override;
void putInBackpack(CArtifactInstance *art);
void initExp(CRandomGenerator & rand); void initExp(CRandomGenerator & rand);
void initArmy(CRandomGenerator & rand, IArmyDescriptor *dst = nullptr); void initArmy(CRandomGenerator & rand, IArmyDescriptor *dst = nullptr);
//void giveArtifact (ui32 aid); //void giveArtifact (ui32 aid);

View File

@ -812,7 +812,7 @@ void CGSeerHut::finishQuest(const CGHeroInstance * h, ui32 accept) const
// Disassemble this backpack artifact // Disassemble this backpack artifact
for(const auto & ci : parts) for(const auto & ci : parts)
{ {
if(ci.art->artType->getId() != elem) if(ci.art->getTypeId() != elem)
cb->giveHeroNewArtifact(h, ci.art->artType, GameConstants::BACKPACK_START); cb->giveHeroNewArtifact(h, ci.art->artType, GameConstants::BACKPACK_START);
} }
} }

View File

@ -1301,7 +1301,7 @@ void CGArtifact::onHeroVisit(const CGHeroInstance * h) const
iw.type = EInfoWindowMode::AUTO; iw.type = EInfoWindowMode::AUTO;
iw.player = h->tempOwner; iw.player = h->tempOwner;
if(ArtifactUtils::isPossibleToGetArt(h, storedArtifact->artType->getId())) if(storedArtifact->artType->canBePutAt(h))
{ {
switch (ID) switch (ID)
{ {

View File

@ -757,13 +757,16 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance * heroAttacker, con
if (result == BattleResult::NORMAL && finishingBattle->winnerHero) if (result == BattleResult::NORMAL && finishingBattle->winnerHero)
{ {
auto sendMoveArtifact = [&](const CArtifactInstance *art, MoveArtifact *ma) auto sendMoveArtifact = [&](const CArtifactInstance *art, MoveArtifact *ma)
{
const auto slot = ArtifactUtils::getArtAnyPosition(finishingBattle->winnerHero, art->artType->getId());
if(slot != ArtifactPosition::PRE_FIRST)
{ {
arts.push_back(art); arts.push_back(art);
auto slot = art->firstAvailableSlot(finishingBattle->winnerHero);
ma->dst = ArtifactLocation(finishingBattle->winnerHero, slot); ma->dst = ArtifactLocation(finishingBattle->winnerHero, slot);
if(ArtifactUtils::isSlotBackpack(slot)) if(ArtifactUtils::isSlotBackpack(slot))
ma->askAssemble = false; ma->askAssemble = false;
sendAndApply(ma); sendAndApply(ma);
}
}; };
if (finishingBattle->loserHero) if (finishingBattle->loserHero)
@ -4007,13 +4010,13 @@ bool CGameHandler::bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID
std::vector<BulkMoveArtifacts::LinkedSlots> & slots) -> void std::vector<BulkMoveArtifacts::LinkedSlots> & slots) -> void
{ {
assert(artifact); assert(artifact);
auto dstSlot = ArtifactUtils::getArtAnyPosition(&artFittingSet, artifact->artType->getId()); auto dstSlot = ArtifactUtils::getArtAnyPosition(&artFittingSet, artifact->getTypeId());
if(dstSlot != ArtifactPosition::PRE_FIRST) if(dstSlot != ArtifactPosition::PRE_FIRST)
{ {
artFittingSet.putArtifact(dstSlot, static_cast<ConstTransitivePtr<CArtifactInstance>>(artifact)); artFittingSet.putArtifact(dstSlot, static_cast<ConstTransitivePtr<CArtifactInstance>>(artifact));
slots.push_back(BulkMoveArtifacts::LinkedSlots(srcSlot, dstSlot)); slots.push_back(BulkMoveArtifacts::LinkedSlots(srcSlot, dstSlot));
if(ArtifactUtils::checkSpellbookIsNeeded(dstHero, artifact->artType->getId(), dstSlot)) if(ArtifactUtils::checkSpellbookIsNeeded(dstHero, artifact->getTypeId(), dstSlot))
giveHeroNewArtifact(dstHero, VLC->arth->objects[ArtifactID::SPELLBOOK], ArtifactPosition::SPELLBOOK); giveHeroNewArtifact(dstHero, VLC->arth->objects[ArtifactID::SPELLBOOK], ArtifactPosition::SPELLBOOK);
} }
}; };
@ -5875,7 +5878,7 @@ bool CGameHandler::dig(const CGHeroInstance *h)
if (h->diggingStatus() != EDiggingStatus::CAN_DIG) //checks for terrain and movement if (h->diggingStatus() != EDiggingStatus::CAN_DIG) //checks for terrain and movement
COMPLAIN_RETF("Hero cannot dig (error code %d)!", h->diggingStatus()); COMPLAIN_RETF("Hero cannot dig (error code %d)!", h->diggingStatus());
const auto isHeroAbleGet = ArtifactUtils::isPossibleToGetArt(h, ArtifactID::GRAIL); const auto isHeroAbleGet = VLC->arth->objects[ArtifactID::GRAIL]->canBePutAt(h);
if(isHeroAbleGet) if(isHeroAbleGet)
{ {
@ -5903,7 +5906,7 @@ bool CGameHandler::dig(const CGHeroInstance *h)
iw.text.addTxt(MetaString::GENERAL_TXT, 58); //"Congratulations! After spending many hours digging here, your hero has uncovered the " iw.text.addTxt(MetaString::GENERAL_TXT, 58); //"Congratulations! After spending many hours digging here, your hero has uncovered the "
iw.text.addTxt(MetaString::ART_NAMES, ArtifactID::GRAIL); iw.text.addTxt(MetaString::ART_NAMES, ArtifactID::GRAIL);
iw.soundID = soundBase::ULTIMATEARTIFACT; iw.soundID = soundBase::ULTIMATEARTIFACT;
giveHeroNewArtifact(h, VLC->arth->objects[ArtifactID::GRAIL], ArtifactPosition::PRE_FIRST); //give grail giveHeroNewArtifact(h, VLC->arth->objects[ArtifactID::GRAIL], ArtifactPosition::FIRST_AVAILABLE); //give grail
sendAndApply(&iw); sendAndApply(&iw);
iw.soundID = soundBase::invalid; iw.soundID = soundBase::invalid;
@ -6837,19 +6840,18 @@ bool CGameHandler::giveHeroArtifact(const CGHeroInstance * h, const CArtifactIns
if(pos == ArtifactPosition::FIRST_AVAILABLE) if(pos == ArtifactPosition::FIRST_AVAILABLE)
{ {
al.slot = ArtifactUtils::getArtAnyPosition(h, a->artType->getId()); al.slot = ArtifactUtils::getArtAnyPosition(h, a->getTypeId());
} }
else if(pos == GameConstants::BACKPACK_START) else if(ArtifactUtils::isSlotBackpack(pos))
{ {
al.slot = ArtifactUtils::getArtBackpackPosition(h, a->artType->getId()); al.slot = ArtifactUtils::getArtBackpackPosition(h, a->getTypeId());
} }
else else
{ {
if(a->artType->canBePutAt(h, pos, false))
al.slot = pos; al.slot = pos;
} }
if(ArtifactUtils::isPossibleToGetArt(h, a->artType->getId(), al.slot)) if(a->canBePutAt(al))
putArtifact(al, a); putArtifact(al, a);
else else
return false; return false;
@ -7041,7 +7043,7 @@ void CGameHandler::handleCheatCode(std::string & cheat, PlayerColor player, cons
///Give hero all artifacts except war machines, spell scrolls and spell book ///Give hero all artifacts except war machines, spell scrolls and spell book
for(int g = 7; g < VLC->arth->objects.size(); ++g) //including artifacts from mods for(int g = 7; g < VLC->arth->objects.size(); ++g) //including artifacts from mods
{ {
if(ArtifactUtils::isPossibleToGetArt(hero, VLC->arth->objects[g]->getId())) if(VLC->arth->objects[g]->canBePutAt(hero))
giveHeroNewArtifact(hero, VLC->arth->objects[g], ArtifactPosition::FIRST_AVAILABLE); giveHeroNewArtifact(hero, VLC->arth->objects[g], ArtifactPosition::FIRST_AVAILABLE);
} }
} }