mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Merge pull request #170 from vmarkovtsev/issue/1810
Fix 1810 suggest artifact assembly
This commit is contained in:
commit
090e946985
@ -2510,10 +2510,20 @@ void CPlayerInterface::stacksRebalanced(const StackLocation &src, const StackLoc
|
||||
garrisonsChanged(objects);
|
||||
}
|
||||
|
||||
void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
|
||||
{
|
||||
auto hero = dynamic_cast<const CGHeroInstance*>(al.relatedObj());
|
||||
if(hero)
|
||||
{
|
||||
CArtPlace::askToAssemble(hero->getArt(al.slot), al.slot, hero);
|
||||
}
|
||||
}
|
||||
|
||||
void CPlayerInterface::artifactPut(const ArtifactLocation &al)
|
||||
{
|
||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||
adventureInt->infoBar.showSelection();
|
||||
askToAssembleArtifact(al);
|
||||
}
|
||||
|
||||
void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
|
||||
@ -2538,6 +2548,7 @@ void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const Artifact
|
||||
if(artWin)
|
||||
artWin->artifactMoved(src, dst);
|
||||
}
|
||||
askToAssembleArtifact(dst);
|
||||
}
|
||||
|
||||
void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
|
||||
|
@ -296,6 +296,7 @@ private:
|
||||
|
||||
void doMoveHero(const CGHeroInstance *h, CGPath path);
|
||||
void setMovementStatus(bool value);
|
||||
void askToAssembleArtifact(const ArtifactLocation &al);
|
||||
};
|
||||
|
||||
extern CPlayerInterface * LOCPLINT;
|
||||
|
@ -214,6 +214,32 @@ void CArtPlace::clickLeft(tribool down, bool previousState)
|
||||
}
|
||||
}
|
||||
|
||||
bool CArtPlace::askToAssemble(const CArtifactInstance *art, ArtifactPosition slot,
|
||||
const CGHeroInstance *hero)
|
||||
{
|
||||
std::vector<const CArtifact *> assemblyPossibilities = art->assemblyPossibilities(hero);
|
||||
|
||||
// If the artifact can be assembled, display dialog.
|
||||
for(const CArtifact *combination : assemblyPossibilities)
|
||||
{
|
||||
LOCPLINT->showArtifactAssemblyDialog(
|
||||
art->artType->id,
|
||||
combination->id,
|
||||
true,
|
||||
std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), hero, slot, true, combination->id),
|
||||
0);
|
||||
|
||||
if(assemblyPossibilities.size() > 2)
|
||||
{
|
||||
logGlobal->warnStream() << boost::format(
|
||||
"More than one possibility of assembling on %s... taking only first")
|
||||
% art->artType->Name();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CArtPlace::clickRight(tribool down, bool previousState)
|
||||
{
|
||||
if(down && ourArt && !locked && text.size() && !picked) //if there is no description or it's a lock, do nothing ;]
|
||||
@ -225,20 +251,8 @@ void CArtPlace::clickRight(tribool down, bool previousState)
|
||||
std::vector<const CArtifact *> assemblyPossibilities = ourArt->assemblyPossibilities(ourOwner->curHero);
|
||||
|
||||
// If the artifact can be assembled, display dialog.
|
||||
for(const CArtifact *combination : assemblyPossibilities)
|
||||
if (askToAssemble(ourArt, slotID, ourOwner->curHero))
|
||||
{
|
||||
LOCPLINT->showArtifactAssemblyDialog(
|
||||
ourArt->artType->id,
|
||||
combination->id,
|
||||
true,
|
||||
std::bind(&CCallback::assembleArtifacts, LOCPLINT->cb.get(), ourOwner->curHero, slotID, true, combination->id),
|
||||
0);
|
||||
|
||||
if(assemblyPossibilities.size() > 2)
|
||||
{
|
||||
logGlobal->warnStream() << "More than one possibility of assembling... taking only first";
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -74,15 +74,17 @@ public:
|
||||
|
||||
void setMeAsDest(bool backpackAsVoid = true);
|
||||
void setArtifact(const CArtifactInstance *art);
|
||||
static bool askToAssemble(const CArtifactInstance *art, ArtifactPosition slot,
|
||||
const CGHeroInstance *hero);
|
||||
};
|
||||
|
||||
/// Contains artifacts of hero. Distincts which artifacts are worn or backpacked
|
||||
class CArtifactsOfHero : public CIntObject
|
||||
{
|
||||
const CGHeroInstance * curHero;
|
||||
|
||||
|
||||
std::map<ArtifactPosition, CArtPlace *> artWorn;
|
||||
|
||||
|
||||
std::vector<CArtPlace *> backpack; //hero's visible backpack (only 5 elements!)
|
||||
int backpackPos; //number of first art visible in backpack (in hero's vector)
|
||||
|
||||
|
@ -926,13 +926,16 @@ void CGameHandler::handleConnection(std::set<PlayerColor> players, CConnection &
|
||||
{
|
||||
const bool result = apply->applyOnGH(this,&c,pack, player);
|
||||
if(!result)
|
||||
complain("Got false in applying... that request must have been fishy!");
|
||||
logGlobal->traceStream() << "Message successfully applied (result=" << result << ")!";
|
||||
{
|
||||
complain((boost::format("Got false in applying %s... that request must have been fishy!")
|
||||
% typeid(*pack).name()).str());
|
||||
}
|
||||
logGlobal->traceStream() << "Message successfully applied (result=" << result << ")!";
|
||||
sendPackageResponse(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
logGlobal->errorStream() << "Message cannot be applied, cannot find applier (unregistered type)!";
|
||||
logGlobal->errorStream() << "Message cannot be applied, cannot find applier (unregistered type)!";
|
||||
sendPackageResponse(false);
|
||||
}
|
||||
|
||||
@ -3038,7 +3041,7 @@ bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition
|
||||
sendAndApply(&da);
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGameHandler::buyArtifact( ObjectInstanceID hid, ArtifactID aid )
|
||||
|
Loading…
Reference in New Issue
Block a user