mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-28 23:06:24 +02:00
Fix for callback return. More code optimization
This commit is contained in:
parent
9647758812
commit
3142f32cbb
@ -181,11 +181,10 @@ bool CCallback::assembleArtifacts (const CGHeroInstance * hero, ArtifactPosition
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCallback::bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap)
|
||||
void CCallback::bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap)
|
||||
{
|
||||
BulkExchangeArtifacts bma(srcHero, dstHero, swap);
|
||||
sendRequest(&bma);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCallback::buildBuilding(const CGTownInstance *town, BuildingID buildingID)
|
||||
|
@ -97,7 +97,7 @@ public:
|
||||
|
||||
|
||||
// Moves all artifacts from one hero to another
|
||||
virtual bool bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap) = 0;
|
||||
virtual void bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap) = 0;
|
||||
};
|
||||
|
||||
class CBattleCallback : public IBattleCallback, public CPlayerBattleCallback
|
||||
@ -155,7 +155,7 @@ public:
|
||||
bool dismissHero(const CGHeroInstance * hero) override;
|
||||
bool swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2) override;
|
||||
bool assembleArtifacts(const CGHeroInstance * hero, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo) override;
|
||||
bool bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap) override;
|
||||
void bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap) override;
|
||||
bool buildBuilding(const CGTownInstance *town, BuildingID buildingID) override;
|
||||
void recruitCreatures(const CGDwelling * obj, const CArmedInstance * dst, CreatureID ID, ui32 amount, si32 level=-1) override;
|
||||
bool dismissCreature(const CArmedInstance *obj, SlotID stackPos) override;
|
||||
|
@ -1058,7 +1058,7 @@ void CExchangeController::moveArtifact(
|
||||
{
|
||||
auto srcLocation = ArtifactLocation(source, srcPosition);
|
||||
auto dstLocation = ArtifactLocation(target,
|
||||
ArtifactUtils::getArtifactDstPosition(source->getArt(srcPosition), target, target->bearerType()));
|
||||
ArtifactUtils::getArtifactDstPosition(source->getArt(srcPosition), target, target->bearerType()));
|
||||
|
||||
cb->swapArtifacts(srcLocation, dstLocation);
|
||||
}
|
||||
|
@ -3956,37 +3956,37 @@ bool CGameHandler::bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID
|
||||
giveHeroNewArtifact(dstHero, VLC->arth->objects[ArtifactID::SPELLBOOK], ArtifactPosition::SPELLBOOK);
|
||||
}
|
||||
};
|
||||
auto moveArtsInBackpack = [](const CGHeroInstance * pHero,
|
||||
std::vector<BulkMoveArtifacts::LinkedSlots> & slots) -> void
|
||||
{
|
||||
for(auto & slotInfo : pHero->artifactsInBackpack)
|
||||
{
|
||||
auto slot = pHero->getArtPos(slotInfo.artifact);
|
||||
slots.push_back(BulkMoveArtifacts::LinkedSlots(slot, slot));
|
||||
}
|
||||
};
|
||||
// Move over artifacts that are worn srcHero -> dstHero
|
||||
moveArtsWorn(psrcHero, pdstHero, slotsSrcDst);
|
||||
// Move over artifacts that are worn dstHero -> srcHero
|
||||
moveArtsWorn(pdstHero, psrcHero, slotsDstSrc);
|
||||
// Move over artifacts that are in backpack srcHero -> dstHero
|
||||
for(auto & slotInfo : psrcHero->artifactsInBackpack)
|
||||
{
|
||||
auto slot = psrcHero->getArtPos(slotInfo.artifact);
|
||||
slotsSrcDst.push_back(BulkMoveArtifacts::LinkedSlots(slot, slot));
|
||||
}
|
||||
moveArtsInBackpack(psrcHero, slotsSrcDst);
|
||||
// Move over artifacts that are in backpack dstHero -> srcHero
|
||||
for(auto & slotInfo : pdstHero->artifactsInBackpack)
|
||||
{
|
||||
auto slot = pdstHero->getArtPos(slotInfo.artifact);
|
||||
slotsDstSrc.push_back(BulkMoveArtifacts::LinkedSlots(slot, slot));
|
||||
}
|
||||
moveArtsInBackpack(pdstHero, slotsDstSrc);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto & slots = ma.artsPack0;
|
||||
// Temporary fitting set for artifacts. Used to select available slots before sending data.
|
||||
CArtifactFittingSet ArtFittingSet(pdstHero->bearerType());
|
||||
ArtFittingSet.artifactsInBackpack = pdstHero->artifactsInBackpack;
|
||||
ArtFittingSet.artifactsWorn = pdstHero->artifactsWorn;
|
||||
|
||||
auto moveArtifact = [this, &ArtFittingSet, &slots](const CArtifactInstance * artifact,
|
||||
auto moveArtifact = [this, &ArtFittingSet, &slotsSrcDst](const CArtifactInstance * artifact,
|
||||
ArtifactPosition srcSlot, const CGHeroInstance * pdstHero) -> void
|
||||
{
|
||||
auto dstSlot = ArtifactUtils::getArtifactDstPosition(artifact, &ArtFittingSet, pdstHero->bearerType());
|
||||
ArtFittingSet.putArtifact(dstSlot, static_cast<ConstTransitivePtr<CArtifactInstance>>(artifact));
|
||||
slots.push_back(BulkMoveArtifacts::LinkedSlots(srcSlot, dstSlot));
|
||||
slotsSrcDst.push_back(BulkMoveArtifacts::LinkedSlots(srcSlot, dstSlot));
|
||||
|
||||
if(ArtifactUtils::checkSpellbookIsNeeded(pdstHero, artifact->artType->id, dstSlot))
|
||||
giveHeroNewArtifact(pdstHero, VLC->arth->objects[ArtifactID::SPELLBOOK], ArtifactPosition::SPELLBOOK);
|
||||
|
Loading…
Reference in New Issue
Block a user