1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-02 22:05:43 +02:00

#913 fix artifact assembling check

This commit is contained in:
Andrii Danylchenko 2022-09-15 13:44:26 +03:00 committed by Andrii Danylchenko
parent a598925a0b
commit faccad7a15
2 changed files with 14 additions and 8 deletions

View File

@ -881,7 +881,10 @@ std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CA
for(const CArtifact * constituent : *artifact->constituents) //check if all constituents are available for(const CArtifact * constituent : *artifact->constituents) //check if all constituents are available
{ {
if(!h->hasArt(constituent->id, true)) //constituent must be equipped const bool noBackpack = false;
const bool notAlreadyAssembled = false;
if(!h->hasArt(constituent->id, true, noBackpack, notAlreadyAssembled)) //constituent must be equipped
{ {
possible = false; possible = false;
break; break;
@ -1184,10 +1187,10 @@ CArtifactInstance* CArtifactSet::getArt(ArtifactPosition pos, bool excludeLocked
return const_cast<CArtifactInstance*>((const_cast<const CArtifactSet*>(this))->getArt(pos, excludeLocked)); return const_cast<CArtifactInstance*>((const_cast<const CArtifactSet*>(this))->getArt(pos, excludeLocked));
} }
ArtifactPosition CArtifactSet::getArtPos(int aid, bool onlyWorn) const ArtifactPosition CArtifactSet::getArtPos(int aid, bool onlyWorn, bool allowLocked) const
{ {
for(auto i = artifactsWorn.cbegin(); i != artifactsWorn.cend(); i++) for(auto i = artifactsWorn.cbegin(); i != artifactsWorn.cend(); i++)
if(i->second.artifact->artType->id == aid) if(i->second.artifact->artType->id == aid && (allowLocked || !i->second.locked))
return i->first; return i->first;
if(onlyWorn) if(onlyWorn)
@ -1226,10 +1229,13 @@ const CArtifactInstance * CArtifactSet::getArtByInstanceId( ArtifactInstanceID a
return nullptr; return nullptr;
} }
bool CArtifactSet::hasArt(ui32 aid, bool onlyWorn, bool CArtifactSet::hasArt(
bool searchBackpackAssemblies) const ui32 aid,
bool onlyWorn,
bool searchBackpackAssemblies,
bool allowLocked) const
{ {
return getArtPos(aid, onlyWorn) != ArtifactPosition::PRE_FIRST || return getArtPos(aid, onlyWorn, allowLocked) != ArtifactPosition::PRE_FIRST ||
(searchBackpackAssemblies && getHiddenArt(aid)); (searchBackpackAssemblies && getHiddenArt(aid));
} }

View File

@ -324,14 +324,14 @@ public:
CArtifactInstance* getArt(ArtifactPosition pos, bool excludeLocked = true); //nullptr - no artifact CArtifactInstance* getArt(ArtifactPosition pos, bool excludeLocked = true); //nullptr - no artifact
/// Looks for equipped artifact with given ID and returns its slot ID or -1 if none /// Looks for equipped artifact with given ID and returns its slot ID or -1 if none
/// (if more than one such artifact lower ID is returned) /// (if more than one such artifact lower ID is returned)
ArtifactPosition getArtPos(int aid, bool onlyWorn = true) const; ArtifactPosition getArtPos(int aid, bool onlyWorn = true, bool allowLocked = true) const;
ArtifactPosition getArtPos(const CArtifactInstance *art) const; ArtifactPosition getArtPos(const CArtifactInstance *art) const;
const CArtifactInstance *getArtByInstanceId(ArtifactInstanceID artInstId) const; const CArtifactInstance *getArtByInstanceId(ArtifactInstanceID artInstId) const;
/// Search for constituents of assemblies in backpack which do not have an ArtifactPosition /// Search for constituents of assemblies in backpack which do not have an ArtifactPosition
const CArtifactInstance *getHiddenArt(int aid) const; const CArtifactInstance *getHiddenArt(int aid) const;
const CCombinedArtifactInstance *getAssemblyByConstituent(int aid) const; const CCombinedArtifactInstance *getAssemblyByConstituent(int aid) const;
/// Checks if hero possess artifact of given id (either in backack or worn) /// Checks if hero possess artifact of given id (either in backack or worn)
bool hasArt(ui32 aid, bool onlyWorn = false, bool searchBackpackAssemblies = false) const; bool hasArt(ui32 aid, bool onlyWorn = false, bool searchBackpackAssemblies = false, bool allowLocked = true) const;
bool isPositionFree(ArtifactPosition pos, bool onlyLockCheck = false) const; bool isPositionFree(ArtifactPosition pos, bool onlyLockCheck = false) const;
virtual ArtBearer::ArtBearer bearerType() const = 0; virtual ArtBearer::ArtBearer bearerType() const = 0;