Skip to content

Commit 8cae339

Browse files
ShubusCorporationAndrii Danylchenko
authored and
Andrii Danylchenko
committed
Feature: Army Management Shortcuts should work as in HD+ Mod
1 parent 7faa691 commit 8cae339

15 files changed

+915
-55
lines changed

CCallback.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,42 @@ int CCallback::mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, S
109109
sendRequest(&pack);
110110
return 0;
111111
}
112+
112113
int CCallback::splitStack(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2, int val)
113114
{
114115
ArrangeStacks pack(3,p1,p2,s1->id,s2->id,val);
115116
sendRequest(&pack);
116117
return 0;
117118
}
118119

120+
int CCallback::bulkMoveArmy(ObjectInstanceID srcArmy, ObjectInstanceID destArmy, SlotID srcSlot)
121+
{
122+
BulkMoveArmy pack(srcArmy, destArmy, srcSlot);
123+
sendRequest(&pack);
124+
return 0;
125+
}
126+
127+
int CCallback::bulkSplitStack(ObjectInstanceID armyId, SlotID srcSlot, int howMany)
128+
{
129+
BulkSplitStack pack(armyId, srcSlot, howMany);
130+
sendRequest(&pack);
131+
return 0;
132+
}
133+
134+
int CCallback::bulkSmartSplitStack(ObjectInstanceID armyId, SlotID srcSlot)
135+
{
136+
BulkSmartSplitStack pack(armyId, srcSlot);
137+
sendRequest(&pack);
138+
return 0;
139+
}
140+
141+
int CCallback::bulkMergeStacks(ObjectInstanceID armyId, SlotID srcSlot)
142+
{
143+
BulkMergeStacks pack(armyId, srcSlot);
144+
sendRequest(&pack);
145+
return 0;
146+
}
147+
119148
bool CCallback::dismissHero(const CGHeroInstance *hero)
120149
{
121150
if(player!=hero->tempOwner) return false;

CCallback.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ class IGameActionCallback
7878
virtual void save(const std::string &fname) = 0;
7979
virtual void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) = 0;
8080
virtual void buildBoat(const IShipyard *obj) = 0;
81+
82+
// To implement high-level army management bulk actions
83+
virtual int bulkMoveArmy(ObjectInstanceID srcArmy, ObjectInstanceID destArmy, SlotID srcSlot) = 0;
84+
virtual int bulkSplitStack(ObjectInstanceID armyId, SlotID srcSlot, int howMany = 1) = 0;
85+
virtual int bulkSmartSplitStack(ObjectInstanceID armyId, SlotID srcSlot) = 0;
86+
virtual int bulkMergeStacks(ObjectInstanceID armyId, SlotID srcSlot) = 0;
8187
};
8288

8389
struct CPackForServer;
@@ -99,7 +105,9 @@ class CBattleCallback : public IBattleCallback, public CPlayerBattleCallback
99105
friend class CClient;
100106
};
101107

102-
class CCallback : public CPlayerSpecificInfoCallback, public IGameActionCallback, public CBattleCallback
108+
class CCallback : public CPlayerSpecificInfoCallback,
109+
public IGameActionCallback,
110+
public CBattleCallback
103111
{
104112
public:
105113
CCallback(CGameState * GS, boost::optional<PlayerColor> Player, CClient *C);
@@ -125,6 +133,10 @@ class CCallback : public CPlayerSpecificInfoCallback, public IGameActionCallback
125133
int mergeOrSwapStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2) override; //first goes to the second
126134
int mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2) override; //first goes to the second
127135
int splitStack(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2, int val) override;
136+
int bulkMoveArmy(ObjectInstanceID srcArmy, ObjectInstanceID destArmy, SlotID srcSlot) override;
137+
int bulkSplitStack(ObjectInstanceID armyId, SlotID srcSlot, int howMany = 1) override;
138+
int bulkSmartSplitStack(ObjectInstanceID armyId, SlotID srcSlot) override;
139+
int bulkMergeStacks(ObjectInstanceID armyId, SlotID srcSlot) override;
128140
bool dismissHero(const CGHeroInstance * hero) override;
129141
bool swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2) override;
130142
bool assembleArtifacts(const CGHeroInstance * hero, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo) override;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ Platform support is constantly tested by continuous integration and CMake config
3535
VCMI Project source code is licensed under GPL version 2 or later.
3636
VCMI Project assets are licensed under CC-BY-SA 4.0. Assets sources and information about contributors are available under following link: [https://github.com/vcmi/vcmi-assets]
3737

38-
Copyright (C) 2007-2020 VCMI Team (check AUTHORS file for the contributors list)
38+
Copyright (C) 2007-2022 VCMI Team (check AUTHORS file for the contributors list)

client/NetPacksClient.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,30 @@ void RebalanceStacks::applyCl(CClient * cl)
238238
dispatchGarrisonChange(cl, srcArmy, dstArmy);
239239
}
240240

241+
void BulkRebalanceStacks::applyCl(CClient * cl)
242+
{
243+
if(!moves.empty())
244+
{
245+
auto destArmy = moves[0].srcArmy == moves[0].dstArmy
246+
? ObjectInstanceID()
247+
: moves[0].dstArmy;
248+
dispatchGarrisonChange(cl, moves[0].srcArmy, destArmy);
249+
}
250+
}
251+
252+
void BulkSmartRebalanceStacks::applyCl(CClient * cl)
253+
{
254+
if(!moves.empty())
255+
{
256+
assert(moves[0].srcArmy == moves[0].dstArmy);
257+
dispatchGarrisonChange(cl, moves[0].srcArmy, ObjectInstanceID());
258+
}
259+
else if(!changes.empty())
260+
{
261+
dispatchGarrisonChange(cl, changes[0].army, ObjectInstanceID());
262+
}
263+
}
264+
241265
void PutArtifact::applyCl(CClient *cl)
242266
{
243267
callInterfaceIfPresent(cl, al.owningPlayer(), &IGameEventsReceiver::artifactPut, al);

0 commit comments

Comments
 (0)