mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-24 03:47:18 +02:00
askToAssemble, askToDisassemble
This commit is contained in:
parent
1046964eef
commit
177523d972
@ -1925,7 +1925,7 @@ void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
|
||||
al.slot.num);
|
||||
return;
|
||||
}
|
||||
CHeroArtPlace::askToAssemble(hero, al.slot);
|
||||
ArtifactUtils::askToAssemble(hero, al.slot);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1056,3 +1056,44 @@ std::optional<CWindowWithArtifacts::CArtifactsOfHeroPtr> CWindowWithArtifacts::f
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ArtifactUtils::askToAssemble(const CGHeroInstance * hero, const ArtifactPosition & slot)
|
||||
{
|
||||
assert(hero);
|
||||
const auto art = hero->getArt(slot);
|
||||
assert(art);
|
||||
auto assemblyPossibilities = ArtifactUtils::assemblyPossibilities(hero, art->getTypeId(), ArtifactUtils::isSlotEquipment(slot));
|
||||
|
||||
for(const auto combinedArt : assemblyPossibilities)
|
||||
{
|
||||
LOCPLINT->showArtifactAssemblyDialog(
|
||||
art->artType,
|
||||
combinedArt,
|
||||
std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), hero, slot, true, combinedArt->getId()));
|
||||
|
||||
if(assemblyPossibilities.size() > 2)
|
||||
logGlobal->warn("More than one possibility of assembling on %s... taking only first", art->artType->getNameTranslated());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ArtifactUtils::askToDisassemble(const CGHeroInstance * hero, const ArtifactPosition & slot)
|
||||
{
|
||||
assert(hero);
|
||||
const auto art = hero->getArt(slot);
|
||||
assert(art);
|
||||
|
||||
if(art->canBeDisassembled())
|
||||
{
|
||||
if(ArtifactUtils::isSlotBackpack(slot) && !ArtifactUtils::isBackpackFreeSlots(hero, art->artType->constituents->size() - 1))
|
||||
return false;
|
||||
|
||||
LOCPLINT->showArtifactAssemblyDialog(
|
||||
art->artType,
|
||||
nullptr,
|
||||
std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), hero, slot, false, ArtifactID()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -220,3 +220,9 @@ private:
|
||||
std::optional<std::tuple<const CGHeroInstance*, const CArtifactInstance*>> getState();
|
||||
std::optional<CArtifactsOfHeroPtr> findAOHbyRef(CArtifactsOfHeroBase & artsInst);
|
||||
};
|
||||
|
||||
namespace ArtifactUtils
|
||||
{
|
||||
bool askToAssemble(const CGHeroInstance* hero, const ArtifactPosition& slot);
|
||||
bool askToDisassemble(const CGHeroInstance* hero, const ArtifactPosition& slot);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user