mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
assemble in backpack initial
This commit is contained in:
@@ -206,12 +206,17 @@ void CHeroArtPlace::clickLeft(tribool down, bool previousState)
|
|||||||
bool CHeroArtPlace::askToAssemble(const CArtifactInstance *art, ArtifactPosition slot,
|
bool CHeroArtPlace::askToAssemble(const CArtifactInstance *art, ArtifactPosition slot,
|
||||||
const CGHeroInstance *hero)
|
const CGHeroInstance *hero)
|
||||||
{
|
{
|
||||||
assert(art != nullptr);
|
assert(art);
|
||||||
assert(hero != nullptr);
|
assert(hero);
|
||||||
std::vector<const CArtifact *> assemblyPossibilities = art->assemblyPossibilities(hero);
|
bool assembleEqipped = true;
|
||||||
|
if(slot >= GameConstants::BACKPACK_START)
|
||||||
|
{
|
||||||
|
assembleEqipped = false;
|
||||||
|
}
|
||||||
|
auto assemblyPossibilities = art->assemblyPossibilities(hero, assembleEqipped);
|
||||||
|
|
||||||
// If the artifact can be assembled, display dialog.
|
// If the artifact can be assembled, display dialog.
|
||||||
for(const CArtifact *combination : assemblyPossibilities)
|
for(auto combination : assemblyPossibilities)
|
||||||
{
|
{
|
||||||
LOCPLINT->showArtifactAssemblyDialog(
|
LOCPLINT->showArtifactAssemblyDialog(
|
||||||
art->artType,
|
art->artType,
|
||||||
@@ -229,27 +234,22 @@ void CHeroArtPlace::clickRight(tribool down, bool previousState)
|
|||||||
{
|
{
|
||||||
if(ourArt && down && !locked && text.size() && !picked) //if there is no description or it's a lock, do nothing ;]
|
if(ourArt && down && !locked && text.size() && !picked) //if there is no description or it's a lock, do nothing ;]
|
||||||
{
|
{
|
||||||
if(slotID < GameConstants::BACKPACK_START)
|
if(ourOwner->allowedAssembling)
|
||||||
{
|
{
|
||||||
if(ourOwner->allowedAssembling)
|
// If the artifact can be assembled, display dialog.
|
||||||
|
if(askToAssemble(ourArt, slotID, ourOwner->curHero))
|
||||||
{
|
{
|
||||||
std::vector<const CArtifact *> assemblyPossibilities = ourArt->assemblyPossibilities(ourOwner->curHero);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If the artifact can be assembled, display dialog.
|
// Otherwise if the artifact can be diasassembled, display dialog.
|
||||||
if(askToAssemble(ourArt, slotID, ourOwner->curHero))
|
if(ourArt->canBeDisassembled())
|
||||||
{
|
{
|
||||||
return;
|
LOCPLINT->showArtifactAssemblyDialog(
|
||||||
}
|
ourArt->artType,
|
||||||
|
nullptr,
|
||||||
// Otherwise if the artifact can be diasassembled, display dialog.
|
std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), ourOwner->curHero, slotID, false, ArtifactID()));
|
||||||
if(ourArt->canBeDisassembled())
|
return;
|
||||||
{
|
|
||||||
LOCPLINT->showArtifactAssemblyDialog(
|
|
||||||
ourArt->artType,
|
|
||||||
nullptr,
|
|
||||||
std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), ourOwner->curHero, slotID, false, ArtifactID()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -870,26 +870,36 @@ bool CArtifactInstance::canBeDisassembled() const
|
|||||||
return bool(artType->constituents);
|
return bool(artType->constituents);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CArtifactSet *h) const
|
std::vector<const CArtifact *> CArtifactInstance::assemblyPossibilities(const CArtifactSet * h, bool equipped) const
|
||||||
{
|
{
|
||||||
std::vector<const CArtifact *> ret;
|
std::vector<const CArtifact *> ret;
|
||||||
if(artType->constituents) //combined artifact already: no combining of combined artifacts... for now.
|
if(artType->constituents) //combined artifact already: no combining of combined artifacts... for now.
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
for(const CArtifact * artifact : artType->constituentOf)
|
for(auto artifact : artType->constituentOf)
|
||||||
{
|
{
|
||||||
assert(artifact->constituents);
|
assert(artifact->constituents);
|
||||||
bool possible = true;
|
bool possible = true;
|
||||||
|
|
||||||
for(const CArtifact * constituent : *artifact->constituents) //check if all constituents are available
|
for(auto constituent : *artifact->constituents) //check if all constituents are available
|
||||||
{
|
{
|
||||||
const bool noBackpack = false;
|
if (equipped)
|
||||||
const bool notAlreadyAssembled = false;
|
|
||||||
|
|
||||||
if(!h->hasArt(constituent->id, true, noBackpack, notAlreadyAssembled)) //constituent must be equipped
|
|
||||||
{
|
{
|
||||||
possible = false;
|
// Search for equipped arts
|
||||||
break;
|
if (!h->hasArt(constituent->id, true, false, false))
|
||||||
|
{
|
||||||
|
possible = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Search in backpack
|
||||||
|
if(!h->hasArtBackpack(constituent->id))
|
||||||
|
{
|
||||||
|
possible = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1198,19 +1208,32 @@ ArtifactPosition CArtifactSet::getArtPos(int aid, bool onlyWorn, bool allowLocke
|
|||||||
std::vector<ArtifactPosition> CArtifactSet::getAllArtPositions(int aid, bool onlyWorn, bool allowLocked, bool getAll) const
|
std::vector<ArtifactPosition> CArtifactSet::getAllArtPositions(int aid, bool onlyWorn, bool allowLocked, bool getAll) const
|
||||||
{
|
{
|
||||||
std::vector<ArtifactPosition> result;
|
std::vector<ArtifactPosition> result;
|
||||||
for(auto i = artifactsWorn.cbegin(); i != artifactsWorn.cend(); i++)
|
for(auto & slotInfo : artifactsWorn)
|
||||||
if(i->second.artifact->artType->id == aid && (allowLocked || !i->second.locked))
|
if(slotInfo.second.artifact->artType->id == aid && (allowLocked || !slotInfo.second.locked))
|
||||||
result.push_back(i->first);
|
result.push_back(slotInfo.first);
|
||||||
|
|
||||||
if(onlyWorn)
|
if(onlyWorn)
|
||||||
return result;
|
return result;
|
||||||
if(!getAll && !result.empty())
|
if(!getAll && !result.empty())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
for(int i = 0; i < artifactsInBackpack.size(); i++)
|
auto backpackPositions = getBackpackArtPositions(aid);
|
||||||
if(artifactsInBackpack[i].artifact->artType->id == aid)
|
result.insert(result.end(), backpackPositions.begin(), backpackPositions.end());
|
||||||
result.push_back(ArtifactPosition(GameConstants::BACKPACK_START + i));
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ArtifactPosition> CArtifactSet::getBackpackArtPositions(int aid) const
|
||||||
|
{
|
||||||
|
std::vector<ArtifactPosition> result;
|
||||||
|
|
||||||
|
si32 backpackPosition = GameConstants::BACKPACK_START;
|
||||||
|
for(auto & artInfo : artifactsInBackpack)
|
||||||
|
{
|
||||||
|
auto art = artInfo.getArt();
|
||||||
|
if (art && art->artType->id == aid)
|
||||||
|
result.push_back(ArtifactPosition(backpackPosition));
|
||||||
|
backpackPosition++;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1249,6 +1272,11 @@ bool CArtifactSet::hasArt(
|
|||||||
return getArtPosCount(aid, onlyWorn, searchBackpackAssemblies, allowLocked) > 0;
|
return getArtPosCount(aid, onlyWorn, searchBackpackAssemblies, allowLocked) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CArtifactSet::hasArtBackpack(ui32 aid) const
|
||||||
|
{
|
||||||
|
return getBackpackArtPositions(aid).size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned CArtifactSet::getArtPosCount(int aid, bool onlyWorn, bool searchBackpackAssemblies, bool allowLocked) const
|
unsigned CArtifactSet::getArtPosCount(int aid, bool onlyWorn, bool searchBackpackAssemblies, bool allowLocked) const
|
||||||
{
|
{
|
||||||
const auto allPositions = getAllArtPositions(aid, onlyWorn, allowLocked, true);
|
const auto allPositions = getAllArtPositions(aid, onlyWorn, allowLocked, true);
|
||||||
|
@@ -163,7 +163,7 @@ public:
|
|||||||
/// of itself, additionally truth is returned for constituents of combined arts
|
/// of itself, additionally truth is returned for constituents of combined arts
|
||||||
virtual bool isPart(const CArtifactInstance *supposedPart) const;
|
virtual bool isPart(const CArtifactInstance *supposedPart) const;
|
||||||
|
|
||||||
std::vector<const CArtifact *> assemblyPossibilities(const CArtifactSet *h) const;
|
std::vector<const CArtifact *> assemblyPossibilities(const CArtifactSet * h, bool equipped) const;
|
||||||
void move(ArtifactLocation src, ArtifactLocation dst);
|
void move(ArtifactLocation src, ArtifactLocation dst);
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
@@ -330,12 +330,14 @@ public:
|
|||||||
ArtifactPosition getArtPos(int aid, bool onlyWorn = true, bool allowLocked = 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;
|
||||||
std::vector<ArtifactPosition> getAllArtPositions(int aid, bool onlyWorn, bool allowLocked, bool getAll) const;
|
std::vector<ArtifactPosition> getAllArtPositions(int aid, bool onlyWorn, bool allowLocked, bool getAll) const;
|
||||||
|
std::vector<ArtifactPosition> getBackpackArtPositions(int aid) 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, bool allowLocked = true) const;
|
bool hasArt(ui32 aid, bool onlyWorn = false, bool searchBackpackAssemblies = false, bool allowLocked = true) const;
|
||||||
|
bool hasArtBackpack(ui32 aid) const;
|
||||||
bool isPositionFree(ArtifactPosition pos, bool onlyLockCheck = false) const;
|
bool isPositionFree(ArtifactPosition pos, bool onlyLockCheck = false) const;
|
||||||
unsigned getArtPosCount(int aid, bool onlyWorn = true, bool searchBackpackAssemblies = true, bool allowLocked = true) const;
|
unsigned getArtPosCount(int aid, bool onlyWorn = true, bool searchBackpackAssemblies = true, bool allowLocked = true) const;
|
||||||
|
|
||||||
|
@@ -1170,7 +1170,7 @@ DLL_LINKAGE void AssembledArtifact::applyGs(CGameState *gs)
|
|||||||
CArtifactSet *artSet = al.getHolderArtSet();
|
CArtifactSet *artSet = al.getHolderArtSet();
|
||||||
const CArtifactInstance *transformedArt = al.getArt();
|
const CArtifactInstance *transformedArt = al.getArt();
|
||||||
assert(transformedArt);
|
assert(transformedArt);
|
||||||
assert(vstd::contains(transformedArt->assemblyPossibilities(artSet), builtArt));
|
assert(vstd::contains(transformedArt->assemblyPossibilities(artSet, true), builtArt));
|
||||||
UNUSED(transformedArt);
|
UNUSED(transformedArt);
|
||||||
|
|
||||||
auto combinedArt = new CCombinedArtifactInstance(builtArt);
|
auto combinedArt = new CCombinedArtifactInstance(builtArt);
|
||||||
|
@@ -4036,7 +4036,7 @@ bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition
|
|||||||
CArtifact *combinedArt = VLC->arth->objects[assembleTo];
|
CArtifact *combinedArt = VLC->arth->objects[assembleTo];
|
||||||
if (!combinedArt->constituents)
|
if (!combinedArt->constituents)
|
||||||
COMPLAIN_RET("assembleArtifacts: Artifact being attempted to assemble is not a combined artifacts!");
|
COMPLAIN_RET("assembleArtifacts: Artifact being attempted to assemble is not a combined artifacts!");
|
||||||
if (!vstd::contains(destArtifact->assemblyPossibilities(hero), combinedArt))
|
if (!vstd::contains(destArtifact->assemblyPossibilities(hero, true), combinedArt))
|
||||||
COMPLAIN_RET("assembleArtifacts: It's impossible to assemble requested artifact!");
|
COMPLAIN_RET("assembleArtifacts: It's impossible to assemble requested artifact!");
|
||||||
|
|
||||||
if(ArtifactUtils::checkSpellbookIsNeeded(hero, assembleTo, artifactSlot))
|
if(ArtifactUtils::checkSpellbookIsNeeded(hero, assembleTo, artifactSlot))
|
||||||
|
Reference in New Issue
Block a user