1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00

MoveArtifact, BulkMoveArtifacts PlayerColor player field

This commit is contained in:
SoundSSGood 2024-03-07 16:52:50 +02:00
parent b1f52eec41
commit 9f688e6fb7
11 changed files with 37 additions and 28 deletions

View File

@ -191,7 +191,7 @@ public:
bool giveHeroNewArtifact(const CGHeroInstance * h, const CArtifact * artType, ArtifactPosition pos) override {return false;}
bool putArtifact(const ArtifactLocation & al, const CArtifactInstance * art, std::optional<bool> askAssemble) override {return false;};
void removeArtifact(const ArtifactLocation & al) override {};
bool moveArtifact(const ArtifactLocation & al1, const ArtifactLocation & al2) override {return false;};
bool moveArtifact(const PlayerColor & player, const ArtifactLocation & al1, const ArtifactLocation & al2) override {return false;};
void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero) override {};
void visitCastleObjects(const CGTownInstance * obj, const CGHeroInstance * hero) override {};

View File

@ -290,8 +290,8 @@ void ApplyClientNetPackVisitor::visitMoveArtifact(MoveArtifact & pack)
callInterfaceIfPresent(cl, player, &IGameEventsReceiver::askToAssembleArtifact, pack.dst);
};
moveArtifact(LOCPLINT->playerID);
if(cl.getOwner(pack.src.artHolder) != cl.getOwner(pack.dst.artHolder))
moveArtifact(pack.interfaceOwner);
if(pack.interfaceOwner != cl.getOwner(pack.dst.artHolder))
moveArtifact(cl.getOwner(pack.dst.artHolder));
cl.invalidatePaths(); // hero might have equipped/unequipped Angel Wings
@ -305,7 +305,7 @@ void ApplyClientNetPackVisitor::visitBulkMoveArtifacts(BulkMoveArtifacts & pack)
{
auto srcLoc = ArtifactLocation(pack.srcArtHolder, slotToMove.srcPos);
auto dstLoc = ArtifactLocation(pack.dstArtHolder, slotToMove.dstPos);
MoveArtifact ma(&srcLoc, &dstLoc, pack.askAssemble);
MoveArtifact ma(pack.interfaceOwner, srcLoc, dstLoc, pack.askAssemble);
visitMoveArtifact(ma);
}
};

View File

@ -42,11 +42,11 @@ CArtifactsOfHeroBackpack::CArtifactsOfHeroBackpack()
initAOHbackpack(visibleCapacityMax, backpackCap < 0 || visibleCapacityMax < backpackCap);
}
void CArtifactsOfHeroBackpack::scrollBackpack(int offset)
void CArtifactsOfHeroBackpack::onSliderMoved(int newVal)
{
if(backpackListBox)
backpackListBox->resize(getActiveSlotRowsNum());
backpackPos += offset;
backpackPos += newVal;
auto slot = ArtifactPosition::BACKPACK_START + backpackPos;
for(auto artPlace : backpack)
{
@ -99,7 +99,7 @@ void CArtifactsOfHeroBackpack::initAOHbackpack(size_t slots, bool slider)
};
CListBoxWithCallback::MovedPosCallback posMoved = [this](size_t pos) -> void
{
scrollBackpack(static_cast<int>(pos) * slotsColumnsMax - backpackPos);
onSliderMoved(static_cast<int>(pos) * slotsColumnsMax - backpackPos);
};
backpackListBox = std::make_shared<CListBoxWithCallback>(
posMoved, onCreate, Point(0, 0), Point(0, 0), slotsRowsMax, 0, 0, 1,

View File

@ -24,7 +24,7 @@ class CArtifactsOfHeroBackpack : public CArtifactsOfHeroBase
public:
CArtifactsOfHeroBackpack(size_t slotsColumnsMax, size_t slotsRowsMax);
CArtifactsOfHeroBackpack();
void scrollBackpack(int offset);
void onSliderMoved(int newVal);
void updateBackpackSlots() override;
size_t getActiveSlotRowsNum();
size_t getSlotsNum();

View File

@ -110,7 +110,7 @@ public:
virtual bool giveHeroNewArtifact(const CGHeroInstance * h, const CArtifact * artType, ArtifactPosition pos) = 0;
virtual bool putArtifact(const ArtifactLocation & al, const CArtifactInstance * art, std::optional<bool> askAssemble = std::nullopt) = 0;
virtual void removeArtifact(const ArtifactLocation &al) = 0;
virtual bool moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2) = 0;
virtual bool moveArtifact(const PlayerColor & player, const ArtifactLocation & al1, const ArtifactLocation & al2) = 0;
virtual void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
virtual void visitCastleObjects(const CGTownInstance * obj, const CGHeroInstance * hero)=0;

View File

@ -1030,10 +1030,11 @@ struct DLL_LINKAGE EraseArtifact : CArtifactOperationPack
struct DLL_LINKAGE MoveArtifact : CArtifactOperationPack
{
MoveArtifact() = default;
MoveArtifact(ArtifactLocation * src, ArtifactLocation * dst, bool askAssemble = true)
: src(*src), dst(*dst), askAssemble(askAssemble)
MoveArtifact(const PlayerColor & interfaceOwner, const ArtifactLocation & src, ArtifactLocation & dst, bool askAssemble = true)
: interfaceOwner(interfaceOwner), src(src), dst(dst), askAssemble(askAssemble)
{
}
PlayerColor interfaceOwner;
ArtifactLocation src;
ArtifactLocation dst;
bool askAssemble = true;
@ -1043,6 +1044,7 @@ struct DLL_LINKAGE MoveArtifact : CArtifactOperationPack
template <typename Handler> void serialize(Handler & h)
{
h & interfaceOwner;
h & src;
h & dst;
h & askAssemble;
@ -1069,13 +1071,15 @@ struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
}
};
PlayerColor interfaceOwner;
ObjectInstanceID srcArtHolder;
ObjectInstanceID dstArtHolder;
std::optional<SlotID> srcCreature;
std::optional<SlotID> dstCreature;
BulkMoveArtifacts()
: srcArtHolder(ObjectInstanceID::NONE)
: interfaceOwner(PlayerColor::NEUTRAL)
, srcArtHolder(ObjectInstanceID::NONE)
, dstArtHolder(ObjectInstanceID::NONE)
, swap(false)
, askAssemble(false)
@ -1083,8 +1087,9 @@ struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
, dstCreature(std::nullopt)
{
}
BulkMoveArtifacts(const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
: srcArtHolder(std::move(srcArtHolder))
BulkMoveArtifacts(const PlayerColor & interfaceOwner, const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
: interfaceOwner(interfaceOwner)
, srcArtHolder(std::move(srcArtHolder))
, dstArtHolder(std::move(dstArtHolder))
, swap(swap)
, askAssemble(false)
@ -1104,6 +1109,7 @@ struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
template <typename Handler> void serialize(Handler & h)
{
h & interfaceOwner;
h & artsPack0;
h & artsPack1;
h & srcArtHolder;

View File

@ -2690,7 +2690,7 @@ bool CGameHandler::garrisonSwap(ObjectInstanceID tid)
// With the amount of changes done to the function, it's more like transferArtifacts.
// Function moves artifact from src to dst. If dst is not a backpack and is already occupied, old dst art goes to backpack and is replaced.
bool CGameHandler::moveArtifact(const ArtifactLocation & src, const ArtifactLocation & dst)
bool CGameHandler::moveArtifact(const PlayerColor & player, const ArtifactLocation & src, const ArtifactLocation & dst)
{
const auto srcArtSet = getArtSet(src);
const auto dstArtSet = getArtSet(dst);
@ -2733,7 +2733,7 @@ bool CGameHandler::moveArtifact(const ArtifactLocation & src, const ArtifactLoca
if(src.slot == dstSlot && src.artHolder == dst.artHolder)
COMPLAIN_RET("Won't move artifact: Dest same as source!");
BulkMoveArtifacts ma(src.artHolder, dst.artHolder, false);
BulkMoveArtifacts ma(player, src.artHolder, dst.artHolder, false);
ma.srcCreature = src.creature;
ma.dstCreature = dst.creature;
@ -2756,7 +2756,7 @@ bool CGameHandler::moveArtifact(const ArtifactLocation & src, const ArtifactLoca
return true;
}
bool CGameHandler::bulkMoveArtifacts(ObjectInstanceID srcId, ObjectInstanceID dstId, bool swap, bool equipped, bool backpack)
bool CGameHandler::bulkMoveArtifacts(const PlayerColor & player, ObjectInstanceID srcId, ObjectInstanceID dstId, bool swap, bool equipped, bool backpack)
{
// Make sure exchange is even possible between the two heroes.
if(!isAllowedExchange(srcId, dstId))
@ -2767,7 +2767,7 @@ bool CGameHandler::bulkMoveArtifacts(ObjectInstanceID srcId, ObjectInstanceID ds
if((!psrcSet) || (!pdstSet))
COMPLAIN_RET("bulkMoveArtifacts: wrong hero's ID");
BulkMoveArtifacts ma(srcId, dstId, swap);
BulkMoveArtifacts ma(player, srcId, dstId, swap);
auto & slotsSrcDst = ma.artsPack0;
auto & slotsDstSrc = ma.artsPack1;
@ -2857,12 +2857,12 @@ bool CGameHandler::bulkMoveArtifacts(ObjectInstanceID srcId, ObjectInstanceID ds
return true;
}
bool CGameHandler::scrollBackpackArtifacts(const ObjectInstanceID heroID, bool left)
bool CGameHandler::scrollBackpackArtifacts(const PlayerColor & player, const ObjectInstanceID heroID, bool left)
{
auto artSet = getArtSet(heroID);
COMPLAIN_RET_FALSE_IF(artSet == nullptr, "scrollBackpackArtifacts: wrong hero's ID");
BulkMoveArtifacts bma(heroID, heroID, false);
BulkMoveArtifacts bma(player, heroID, heroID, false);
const auto backpackEnd = ArtifactPosition(ArtifactPosition::BACKPACK_START + artSet->artifactsInBackpack.size() - 1);
if(backpackEnd > ArtifactPosition::BACKPACK_START)

View File

@ -128,9 +128,9 @@ public:
bool giveHeroNewArtifact(const CGHeroInstance * h, const CArtifact * artType, ArtifactPosition pos = ArtifactPosition::FIRST_AVAILABLE) override;
bool putArtifact(const ArtifactLocation & al, const CArtifactInstance * art, std::optional<bool> askAssemble) override;
void removeArtifact(const ArtifactLocation &al) override;
bool moveArtifact(const ArtifactLocation & src, const ArtifactLocation & dst) override;
bool bulkMoveArtifacts(ObjectInstanceID srcId, ObjectInstanceID dstId, bool swap, bool equipped, bool backpack);
bool scrollBackpackArtifacts(const ObjectInstanceID heroID, bool left);
bool moveArtifact(const PlayerColor & player, const ArtifactLocation & src, const ArtifactLocation & dst) override;
bool bulkMoveArtifacts(const PlayerColor & player, ObjectInstanceID srcId, ObjectInstanceID dstId, bool swap, bool equipped, bool backpack);
bool scrollBackpackArtifacts(const PlayerColor & player, const ObjectInstanceID heroID, bool left);
bool eraseArtifactByClient(const ArtifactLocation & al);
void synchronizeArtifactHandlerLists();

View File

@ -136,7 +136,7 @@ void ApplyGhNetPackVisitor::visitExchangeArtifacts(ExchangeArtifacts & pack)
{
if(gh.getHero(pack.src.artHolder))
gh.throwIfWrongPlayer(&pack, gh.getOwner(pack.src.artHolder)); //second hero can be ally
result = gh.moveArtifact(pack.src, pack.dst);
result = gh.moveArtifact(pack.player, pack.src, pack.dst);
}
void ApplyGhNetPackVisitor::visitBulkExchangeArtifacts(BulkExchangeArtifacts & pack)
@ -145,7 +145,7 @@ void ApplyGhNetPackVisitor::visitBulkExchangeArtifacts(BulkExchangeArtifacts & p
gh.throwIfWrongOwner(&pack, pack.srcHero);
if(pack.swap)
gh.throwIfWrongOwner(&pack, pack.dstHero);
result = gh.bulkMoveArtifacts(pack.srcHero, pack.dstHero, pack.swap, pack.equipped, pack.backpack);
result = gh.bulkMoveArtifacts(pack.player, pack.srcHero, pack.dstHero, pack.swap, pack.equipped, pack.backpack);
}
void ApplyGhNetPackVisitor::visitManageBackpackArtifacts(ManageBackpackArtifacts & pack)
@ -153,9 +153,9 @@ void ApplyGhNetPackVisitor::visitManageBackpackArtifacts(ManageBackpackArtifacts
if(gh.getPlayerRelations(pack.player, gh.getOwner(pack.artHolder)) != PlayerRelations::ENEMIES)
{
if(pack.cmd == ManageBackpackArtifacts::ManageCmd::SCROLL_LEFT)
result = gh.scrollBackpackArtifacts(pack.artHolder, true);
result = gh.scrollBackpackArtifacts(pack.player, pack.artHolder, true);
else if(pack.cmd == ManageBackpackArtifacts::ManageCmd::SCROLL_RIGHT)
result = gh.scrollBackpackArtifacts(pack.artHolder, false);
result = gh.scrollBackpackArtifacts(pack.player, pack.artHolder, false);
else
{
gh.throwIfWrongOwner(&pack, pack.artHolder);

View File

@ -206,6 +206,9 @@ bool OpenWindowQuery::blocksPack(const CPack *pack) const
if(dynamic_ptr_cast<BulkExchangeArtifacts>(pack) != nullptr)
return false;
if(dynamic_ptr_cast<ManageBackpackArtifacts>(pack) != nullptr)
return false;
if(dynamic_ptr_cast<AssembleArtifacts>(pack))
return false;

View File

@ -70,7 +70,7 @@ public:
bool giveHeroNewArtifact(const CGHeroInstance * h, const CArtifact * artType, ArtifactPosition pos) override {return false;}
bool putArtifact(const ArtifactLocation & al, const CArtifactInstance * art, std::optional<bool> askAssemble) override {return false;}
void removeArtifact(const ArtifactLocation &al) override {}
bool moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2) override {return false;}
bool moveArtifact(const PlayerColor & player, const ArtifactLocation & al1, const ArtifactLocation & al2) override {return false;}
void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero) override {}
void stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero) override {}