1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Bulk move artifacts. id

This commit is contained in:
SoundSSGood 2023-10-23 19:39:12 +03:00
parent 3c5527a222
commit c2f658d638
4 changed files with 25 additions and 39 deletions

View File

@ -295,7 +295,7 @@ void ApplyClientNetPackVisitor::visitMoveArtifact(MoveArtifact & pack)
void ApplyClientNetPackVisitor::visitBulkMoveArtifacts(BulkMoveArtifacts & pack)
{
/*auto applyMove = [this, &pack](std::vector<BulkMoveArtifacts::LinkedSlots> & artsPack) -> void
auto applyMove = [this, &pack](std::vector<BulkMoveArtifacts::LinkedSlots> & artsPack) -> void
{
for(auto & slotToMove : artsPack)
{
@ -306,8 +306,8 @@ void ApplyClientNetPackVisitor::visitBulkMoveArtifacts(BulkMoveArtifacts & pack)
}
};
auto srcOwner = std::get<ConstTransitivePtr<CGHeroInstance>>(pack.srcArtHolder)->tempOwner;
auto dstOwner = std::get<ConstTransitivePtr<CGHeroInstance>>(pack.dstArtHolder)->tempOwner;
auto srcOwner = cl.getOwner(pack.srcArtHolder);
auto dstOwner = cl.getOwner(pack.dstArtHolder);
// Begin a session of bulk movement of arts. It is not necessary but useful for the client optimization.
callInterfaceIfPresent(cl, srcOwner, &IGameEventsReceiver::bulkArtMovementStart, pack.artsPack0.size() + pack.artsPack1.size());
@ -316,7 +316,7 @@ void ApplyClientNetPackVisitor::visitBulkMoveArtifacts(BulkMoveArtifacts & pack)
applyMove(pack.artsPack0);
if(pack.swap)
applyMove(pack.artsPack1);*/
applyMove(pack.artsPack1);
}
void ApplyClientNetPackVisitor::visitAssembledArtifact(AssembledArtifact & pack)

View File

@ -1813,8 +1813,8 @@ void BulkMoveArtifacts::applyGs(CGameState * gs)
BULK_PUT
};
auto bulkArtsOperation = [this](std::vector<LinkedSlots> & artsPack,
CArtifactSet * artSet, EBulkArtsOp operation) -> void
auto bulkArtsOperation = [this, gs](std::vector<LinkedSlots> & artsPack,
CArtifactSet & artSet, EBulkArtsOp operation) -> void
{
int numBackpackArtifactsMoved = 0;
for(auto & slot : artsPack)
@ -1827,25 +1827,22 @@ void BulkMoveArtifacts::applyGs(CGameState * gs)
{
srcPos = ArtifactPosition(srcPos.num - numBackpackArtifactsMoved);
}
const auto * slotInfo = artSet->getSlot(srcPos);
assert(slotInfo);
auto * art = const_cast<CArtifactInstance *>(slotInfo->getArt());
auto * art = artSet.getArt(srcPos);
assert(art);
/*switch(operation)
switch(operation)
{
case EBulkArtsOp::BULK_MOVE:
const_cast<CArtifactInstance*>(art)->move(
ArtifactLocation(srcArtHolder, srcPos), ArtifactLocation(dstArtHolder, slot.dstPos));
art->move(artSet, srcPos, *gs->getHero(dstArtHolder), slot.dstPos);
break;
case EBulkArtsOp::BULK_REMOVE:
art->removeFrom(ArtifactLocation(dstArtHolder, srcPos));
art->removeFrom(artSet, srcPos);
break;
case EBulkArtsOp::BULK_PUT:
art->putAt(ArtifactLocation(srcArtHolder, slot.dstPos));
art->putAt(*gs->getHero(srcArtHolder), slot.dstPos);
break;
default:
break;
}*/
}
if(srcPos >= ArtifactPosition::BACKPACK_START)
{
@ -1854,23 +1851,23 @@ void BulkMoveArtifacts::applyGs(CGameState * gs)
}
};
auto * leftSet = gs->getArtSet(ArtifactLocation(srcArtHolder));
if(swap)
{
// Swap
auto * leftSet = getSrcHolderArtSet();
auto * rightSet = getDstHolderArtSet();
auto * rightSet = gs->getArtSet(ArtifactLocation(dstArtHolder));
CArtifactFittingSet artFittingSet(leftSet->bearerType());
artFittingSet.artifactsWorn = rightSet->artifactsWorn;
artFittingSet.artifactsInBackpack = rightSet->artifactsInBackpack;
bulkArtsOperation(artsPack1, rightSet, EBulkArtsOp::BULK_REMOVE);
bulkArtsOperation(artsPack0, leftSet, EBulkArtsOp::BULK_MOVE);
bulkArtsOperation(artsPack1, &artFittingSet, EBulkArtsOp::BULK_PUT);
bulkArtsOperation(artsPack1, *rightSet, EBulkArtsOp::BULK_REMOVE);
bulkArtsOperation(artsPack0, *leftSet, EBulkArtsOp::BULK_MOVE);
bulkArtsOperation(artsPack1, artFittingSet, EBulkArtsOp::BULK_PUT);
}
else
{
bulkArtsOperation(artsPack0, getSrcHolderArtSet(), EBulkArtsOp::BULK_MOVE);
bulkArtsOperation(artsPack0, *leftSet, EBulkArtsOp::BULK_MOVE);
}
}
@ -2549,14 +2546,4 @@ const CArtifactInstance * ArtSlotInfo::getArt() const
return artifact;
}
CArtifactSet * BulkMoveArtifacts::getSrcHolderArtSet()
{
return std::visit(GetBase<CArtifactSet>(), srcArtHolder);
}
CArtifactSet * BulkMoveArtifacts::getDstHolderArtSet()
{
return std::visit(GetBase<CArtifactSet>(), dstArtHolder);
}
VCMI_LIB_NAMESPACE_END

View File

@ -1060,14 +1060,16 @@ struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
}
};
TArtHolder srcArtHolder;
TArtHolder dstArtHolder;
ObjectInstanceID srcArtHolder;
ObjectInstanceID dstArtHolder;
BulkMoveArtifacts()
: swap(false)
: srcArtHolder(ObjectInstanceID::NONE)
, dstArtHolder(ObjectInstanceID::NONE)
, swap(false)
{
}
BulkMoveArtifacts(TArtHolder srcArtHolder, TArtHolder dstArtHolder, bool swap)
BulkMoveArtifacts(const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
: srcArtHolder(std::move(srcArtHolder))
, dstArtHolder(std::move(dstArtHolder))
, swap(swap)
@ -1079,8 +1081,6 @@ struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
std::vector<LinkedSlots> artsPack0;
std::vector<LinkedSlots> artsPack1;
bool swap;
CArtifactSet * getSrcHolderArtSet();
CArtifactSet * getDstHolderArtSet();
void visitTyped(ICPackVisitor & visitor) override;

View File

@ -2750,8 +2750,7 @@ bool CGameHandler::bulkMoveArtifacts(ObjectInstanceID srcHero, ObjectInstanceID
if((!psrcHero) || (!pdstHero))
COMPLAIN_RET("bulkMoveArtifacts: wrong hero's ID");
BulkMoveArtifacts ma(static_cast<ConstTransitivePtr<CGHeroInstance>>(psrcHero),
static_cast<ConstTransitivePtr<CGHeroInstance>>(pdstHero), swap);
BulkMoveArtifacts ma(srcHero, dstHero, swap);
auto & slotsSrcDst = ma.artsPack0;
auto & slotsDstSrc = ma.artsPack1;