NetPacks.h 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643
  1. /*
  2. * NetPacks.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "NetPacksBase.h"
  12. #include "ConstTransitivePtr.h"
  13. #include "MetaString.h"
  14. #include "ResourceSet.h"
  15. #include "TurnTimerInfo.h"
  16. #include "int3.h"
  17. #include "battle/BattleAction.h"
  18. #include "battle/CObstacleInstance.h"
  19. #include "gameState/EVictoryLossCheckResult.h"
  20. #include "gameState/TavernSlot.h"
  21. #include "gameState/QuestInfo.h"
  22. #include "mapObjects/CGHeroInstance.h"
  23. #include "mapping/CMapDefines.h"
  24. #include "spells/ViewSpellInt.h"
  25. class CClient;
  26. class CGameHandler;
  27. VCMI_LIB_NAMESPACE_BEGIN
  28. class CGameState;
  29. class CArtifact;
  30. class CGObjectInstance;
  31. class CArtifactInstance;
  32. struct StackLocation;
  33. struct ArtSlotInfo;
  34. struct QuestInfo;
  35. class IBattleState;
  36. // This one teleport-specific, but has to be available everywhere in callbacks and netpacks
  37. // For now it's will be there till teleports code refactored and moved into own file
  38. using TTeleportExitsList = std::vector<std::pair<ObjectInstanceID, int3>>;
  39. struct DLL_LINKAGE Query : public CPackForClient
  40. {
  41. QueryID queryID; // equals to -1 if it is not an actual query (and should not be answered)
  42. };
  43. struct StackLocation
  44. {
  45. ConstTransitivePtr<CArmedInstance> army;
  46. SlotID slot;
  47. StackLocation() = default;
  48. StackLocation(const CArmedInstance * Army, const SlotID & Slot)
  49. : army(const_cast<CArmedInstance *>(Army)) //we are allowed here to const cast -> change will go through one of our packages... do not abuse!
  50. , slot(Slot)
  51. {
  52. }
  53. DLL_LINKAGE const CStackInstance * getStack();
  54. template <typename Handler> void serialize(Handler & h, const int version)
  55. {
  56. h & army;
  57. h & slot;
  58. }
  59. };
  60. /***********************************************************************************************************/
  61. struct DLL_LINKAGE PackageApplied : public CPackForClient
  62. {
  63. PackageApplied() = default;
  64. PackageApplied(ui8 Result)
  65. : result(Result)
  66. {
  67. }
  68. virtual void visitTyped(ICPackVisitor & visitor) override;
  69. ui8 result = 0; //0 - something went wrong, request hasn't been realized; 1 - OK
  70. ui32 packType = 0; //type id of applied package
  71. ui32 requestID = 0; //an ID given by client to the request that was applied
  72. PlayerColor player;
  73. template <typename Handler> void serialize(Handler & h, const int version)
  74. {
  75. h & result;
  76. h & packType;
  77. h & requestID;
  78. h & player;
  79. }
  80. };
  81. struct DLL_LINKAGE SystemMessage : public CPackForClient
  82. {
  83. SystemMessage(std::string Text)
  84. : text(std::move(Text))
  85. {
  86. }
  87. SystemMessage() = default;
  88. virtual void visitTyped(ICPackVisitor & visitor) override;
  89. std::string text;
  90. template <typename Handler> void serialize(Handler & h, const int version)
  91. {
  92. h & text;
  93. }
  94. };
  95. struct DLL_LINKAGE PlayerBlocked : public CPackForClient
  96. {
  97. enum EReason { UPCOMING_BATTLE, ONGOING_MOVEMENT };
  98. enum EMode { BLOCKADE_STARTED, BLOCKADE_ENDED };
  99. EReason reason = UPCOMING_BATTLE;
  100. EMode startOrEnd = BLOCKADE_STARTED;
  101. PlayerColor player;
  102. virtual void visitTyped(ICPackVisitor & visitor) override;
  103. template <typename Handler> void serialize(Handler & h, const int version)
  104. {
  105. h & reason;
  106. h & startOrEnd;
  107. h & player;
  108. }
  109. };
  110. struct DLL_LINKAGE PlayerCheated : public CPackForClient
  111. {
  112. void applyGs(CGameState * gs) const;
  113. PlayerColor player;
  114. bool losingCheatCode = false;
  115. bool winningCheatCode = false;
  116. virtual void visitTyped(ICPackVisitor & visitor) override;
  117. template <typename Handler> void serialize(Handler & h, const int version)
  118. {
  119. h & player;
  120. h & losingCheatCode;
  121. h & winningCheatCode;
  122. }
  123. };
  124. struct DLL_LINKAGE TurnTimeUpdate : public CPackForClient
  125. {
  126. void applyGs(CGameState * gs) const;
  127. PlayerColor player;
  128. TurnTimerInfo turnTimer;
  129. template <typename Handler> void serialize(Handler & h, const int version)
  130. {
  131. h & player;
  132. h & turnTimer;
  133. }
  134. };
  135. struct DLL_LINKAGE YourTurn : public CPackForClient
  136. {
  137. void applyGs(CGameState * gs) const;
  138. PlayerColor player;
  139. std::optional<ui8> daysWithoutCastle;
  140. virtual void visitTyped(ICPackVisitor & visitor) override;
  141. template <typename Handler> void serialize(Handler & h, const int version)
  142. {
  143. h & player;
  144. h & daysWithoutCastle;
  145. }
  146. };
  147. struct DLL_LINKAGE EntitiesChanged : public CPackForClient
  148. {
  149. std::vector<EntityChanges> changes;
  150. void applyGs(CGameState * gs);
  151. virtual void visitTyped(ICPackVisitor & visitor) override;
  152. template <typename Handler> void serialize(Handler & h, const int version)
  153. {
  154. h & changes;
  155. }
  156. };
  157. struct DLL_LINKAGE SetResources : public CPackForClient
  158. {
  159. void applyGs(CGameState * gs) const;
  160. virtual void visitTyped(ICPackVisitor & visitor) override;
  161. bool abs = true; //false - changes by value; 1 - sets to value
  162. PlayerColor player;
  163. TResources res; //res[resid] => res amount
  164. template <typename Handler> void serialize(Handler & h, const int version)
  165. {
  166. h & abs;
  167. h & player;
  168. h & res;
  169. }
  170. };
  171. struct DLL_LINKAGE SetPrimSkill : public CPackForClient
  172. {
  173. void applyGs(CGameState * gs) const;
  174. virtual void visitTyped(ICPackVisitor & visitor) override;
  175. ui8 abs = 0; //0 - changes by value; 1 - sets to value
  176. ObjectInstanceID id;
  177. PrimarySkill::PrimarySkill which = PrimarySkill::ATTACK;
  178. si64 val = 0;
  179. template <typename Handler> void serialize(Handler & h, const int version)
  180. {
  181. h & abs;
  182. h & id;
  183. h & which;
  184. h & val;
  185. }
  186. };
  187. struct DLL_LINKAGE SetSecSkill : public CPackForClient
  188. {
  189. void applyGs(CGameState * gs) const;
  190. virtual void visitTyped(ICPackVisitor & visitor) override;
  191. ui8 abs = 0; //0 - changes by value; 1 - sets to value
  192. ObjectInstanceID id;
  193. SecondarySkill which;
  194. ui16 val = 0;
  195. template <typename Handler> void serialize(Handler & h, const int version)
  196. {
  197. h & abs;
  198. h & id;
  199. h & which;
  200. h & val;
  201. }
  202. };
  203. struct DLL_LINKAGE HeroVisitCastle : public CPackForClient
  204. {
  205. void applyGs(CGameState * gs) const;
  206. virtual void visitTyped(ICPackVisitor & visitor) override;
  207. ui8 flags = 0; //1 - start
  208. ObjectInstanceID tid, hid;
  209. bool start() const //if hero is entering castle (if false - leaving)
  210. {
  211. return flags & 1;
  212. }
  213. template <typename Handler> void serialize(Handler & h, const int version)
  214. {
  215. h & flags;
  216. h & tid;
  217. h & hid;
  218. }
  219. };
  220. struct DLL_LINKAGE ChangeSpells : public CPackForClient
  221. {
  222. void applyGs(CGameState * gs);
  223. virtual void visitTyped(ICPackVisitor & visitor) override;
  224. ui8 learn = 1; //1 - gives spell, 0 - takes
  225. ObjectInstanceID hid;
  226. std::set<SpellID> spells;
  227. template <typename Handler> void serialize(Handler & h, const int version)
  228. {
  229. h & learn;
  230. h & hid;
  231. h & spells;
  232. }
  233. };
  234. struct DLL_LINKAGE SetMana : public CPackForClient
  235. {
  236. void applyGs(CGameState * gs) const;
  237. virtual void visitTyped(ICPackVisitor & visitor) override;
  238. ObjectInstanceID hid;
  239. si32 val = 0;
  240. bool absolute = true;
  241. template <typename Handler> void serialize(Handler & h, const int version)
  242. {
  243. h & val;
  244. h & hid;
  245. h & absolute;
  246. }
  247. };
  248. struct DLL_LINKAGE SetMovePoints : public CPackForClient
  249. {
  250. void applyGs(CGameState * gs) const;
  251. ObjectInstanceID hid;
  252. si32 val = 0;
  253. bool absolute = true;
  254. virtual void visitTyped(ICPackVisitor & visitor) override;
  255. template <typename Handler> void serialize(Handler & h, const int version)
  256. {
  257. h & val;
  258. h & hid;
  259. h & absolute;
  260. }
  261. };
  262. struct DLL_LINKAGE FoWChange : public CPackForClient
  263. {
  264. void applyGs(CGameState * gs);
  265. std::unordered_set<int3> tiles;
  266. PlayerColor player;
  267. ui8 mode = 0; //mode==0 - hide, mode==1 - reveal
  268. bool waitForDialogs = false;
  269. virtual void visitTyped(ICPackVisitor & visitor) override;
  270. template <typename Handler> void serialize(Handler & h, const int version)
  271. {
  272. h & tiles;
  273. h & player;
  274. h & mode;
  275. h & waitForDialogs;
  276. }
  277. };
  278. struct DLL_LINKAGE SetAvailableHero : public CPackForClient
  279. {
  280. SetAvailableHero()
  281. {
  282. army.clearSlots();
  283. }
  284. void applyGs(CGameState * gs);
  285. TavernHeroSlot slotID;
  286. TavernSlotRole roleID;
  287. PlayerColor player;
  288. HeroTypeID hid; //HeroTypeID::NONE if no hero
  289. CSimpleArmy army;
  290. virtual void visitTyped(ICPackVisitor & visitor) override;
  291. template <typename Handler> void serialize(Handler & h, const int version)
  292. {
  293. h & slotID;
  294. h & roleID;
  295. h & player;
  296. h & hid;
  297. h & army;
  298. }
  299. };
  300. struct DLL_LINKAGE GiveBonus : public CPackForClient
  301. {
  302. enum class ETarget : ui8 { HERO, PLAYER, TOWN, BATTLE };
  303. GiveBonus(ETarget Who = ETarget::HERO)
  304. :who(Who)
  305. {
  306. }
  307. void applyGs(CGameState * gs);
  308. ETarget who = ETarget::HERO; //who receives bonus
  309. si32 id = 0; //hero. town or player id - whoever receives it
  310. Bonus bonus;
  311. MetaString bdescr;
  312. virtual void visitTyped(ICPackVisitor & visitor) override;
  313. template <typename Handler> void serialize(Handler & h, const int version)
  314. {
  315. h & bonus;
  316. h & id;
  317. h & bdescr;
  318. h & who;
  319. assert(id != -1);
  320. }
  321. };
  322. struct DLL_LINKAGE ChangeObjPos : public CPackForClient
  323. {
  324. void applyGs(CGameState * gs);
  325. /// Object to move
  326. ObjectInstanceID objid;
  327. /// New position of visitable tile of an object
  328. int3 nPos;
  329. virtual void visitTyped(ICPackVisitor & visitor) override;
  330. template <typename Handler> void serialize(Handler & h, const int version)
  331. {
  332. h & objid;
  333. h & nPos;
  334. }
  335. };
  336. struct DLL_LINKAGE PlayerEndsGame : public CPackForClient
  337. {
  338. void applyGs(CGameState * gs) const;
  339. PlayerColor player;
  340. EVictoryLossCheckResult victoryLossCheckResult;
  341. virtual void visitTyped(ICPackVisitor & visitor) override;
  342. template <typename Handler> void serialize(Handler & h, const int version)
  343. {
  344. h & player;
  345. h & victoryLossCheckResult;
  346. }
  347. };
  348. struct DLL_LINKAGE PlayerReinitInterface : public CPackForClient
  349. {
  350. void applyGs(CGameState * gs);
  351. std::vector<PlayerColor> players;
  352. ui8 playerConnectionId; //PLAYER_AI for AI player
  353. virtual void visitTyped(ICPackVisitor & visitor) override;
  354. template <typename Handler> void serialize(Handler & h, const int version)
  355. {
  356. h & players;
  357. h & playerConnectionId;
  358. }
  359. };
  360. struct DLL_LINKAGE RemoveBonus : public CPackForClient
  361. {
  362. RemoveBonus(GiveBonus::ETarget Who = GiveBonus::ETarget::HERO)
  363. :who(Who)
  364. {
  365. }
  366. void applyGs(CGameState * gs);
  367. GiveBonus::ETarget who; //who receives bonus
  368. ui32 whoID = 0; //hero, town or player id - whoever loses bonus
  369. //vars to identify bonus: its source
  370. ui8 source = 0;
  371. ui32 id = 0; //source id
  372. //used locally: copy of removed bonus
  373. Bonus bonus;
  374. virtual void visitTyped(ICPackVisitor & visitor) override;
  375. template <typename Handler> void serialize(Handler & h, const int version)
  376. {
  377. h & source;
  378. h & id;
  379. h & who;
  380. h & whoID;
  381. }
  382. };
  383. struct DLL_LINKAGE SetCommanderProperty : public CPackForClient
  384. {
  385. enum ECommanderProperty { ALIVE, BONUS, SECONDARY_SKILL, EXPERIENCE, SPECIAL_SKILL };
  386. void applyGs(CGameState * gs);
  387. ObjectInstanceID heroid;
  388. ECommanderProperty which = ALIVE;
  389. TExpType amount = 0; //0 for dead, >0 for alive
  390. si32 additionalInfo = 0; //for secondary skills choice
  391. Bonus accumulatedBonus;
  392. virtual void visitTyped(ICPackVisitor & visitor) override;
  393. template <typename Handler> void serialize(Handler & h, const int version)
  394. {
  395. h & heroid;
  396. h & which;
  397. h & amount;
  398. h & additionalInfo;
  399. h & accumulatedBonus;
  400. }
  401. };
  402. struct DLL_LINKAGE AddQuest : public CPackForClient
  403. {
  404. void applyGs(CGameState * gs) const;
  405. PlayerColor player;
  406. QuestInfo quest;
  407. virtual void visitTyped(ICPackVisitor & visitor) override;
  408. template <typename Handler> void serialize(Handler & h, const int version)
  409. {
  410. h & player;
  411. h & quest;
  412. }
  413. };
  414. struct DLL_LINKAGE UpdateArtHandlerLists : public CPackForClient
  415. {
  416. std::vector<CArtifact *> treasures, minors, majors, relics;
  417. void applyGs(CGameState * gs) const;
  418. virtual void visitTyped(ICPackVisitor & visitor) override;
  419. template <typename Handler> void serialize(Handler & h, const int version)
  420. {
  421. h & treasures;
  422. h & minors;
  423. h & majors;
  424. h & relics;
  425. }
  426. };
  427. struct DLL_LINKAGE UpdateMapEvents : public CPackForClient
  428. {
  429. std::list<CMapEvent> events;
  430. void applyGs(CGameState * gs) const;
  431. virtual void visitTyped(ICPackVisitor & visitor) override;
  432. template <typename Handler> void serialize(Handler & h, const int version)
  433. {
  434. h & events;
  435. }
  436. };
  437. struct DLL_LINKAGE UpdateCastleEvents : public CPackForClient
  438. {
  439. ObjectInstanceID town;
  440. std::list<CCastleEvent> events;
  441. void applyGs(CGameState * gs) const;
  442. virtual void visitTyped(ICPackVisitor & visitor) override;
  443. template <typename Handler> void serialize(Handler & h, const int version)
  444. {
  445. h & town;
  446. h & events;
  447. }
  448. };
  449. struct DLL_LINKAGE ChangeFormation : public CPackForClient
  450. {
  451. ObjectInstanceID hid;
  452. ui8 formation = 0;
  453. void applyGs(CGameState * gs) const;
  454. virtual void visitTyped(ICPackVisitor & visitor) override;
  455. template <typename Handler> void serialize(Handler & h, const int version)
  456. {
  457. h & hid;
  458. h & formation;
  459. }
  460. };
  461. struct DLL_LINKAGE RemoveObject : public CPackForClient
  462. {
  463. RemoveObject() = default;
  464. RemoveObject(const ObjectInstanceID & ID)
  465. : id(ID)
  466. {
  467. }
  468. void applyGs(CGameState * gs);
  469. virtual void visitTyped(ICPackVisitor & visitor) override;
  470. ObjectInstanceID id;
  471. template <typename Handler> void serialize(Handler & h, const int version)
  472. {
  473. h & id;
  474. }
  475. };
  476. struct DLL_LINKAGE TryMoveHero : public CPackForClient
  477. {
  478. void applyGs(CGameState * gs);
  479. enum EResult
  480. {
  481. FAILED,
  482. SUCCESS,
  483. TELEPORTATION,
  484. BLOCKING_VISIT,
  485. EMBARK,
  486. DISEMBARK
  487. };
  488. ObjectInstanceID id;
  489. ui32 movePoints = 0;
  490. EResult result = FAILED; //uses EResult
  491. int3 start, end; //h3m format
  492. std::unordered_set<int3> fowRevealed; //revealed tiles
  493. std::optional<int3> attackedFrom; // Set when stepping into endangered tile.
  494. virtual void visitTyped(ICPackVisitor & visitor) override;
  495. bool stopMovement() const
  496. {
  497. return result != SUCCESS && result != EMBARK && result != DISEMBARK && result != TELEPORTATION;
  498. }
  499. template <typename Handler> void serialize(Handler & h, const int version)
  500. {
  501. h & id;
  502. h & result;
  503. h & start;
  504. h & end;
  505. h & movePoints;
  506. h & fowRevealed;
  507. h & attackedFrom;
  508. }
  509. };
  510. struct DLL_LINKAGE NewStructures : public CPackForClient
  511. {
  512. void applyGs(CGameState * gs);
  513. ObjectInstanceID tid;
  514. std::set<BuildingID> bid;
  515. si16 builded = 0;
  516. virtual void visitTyped(ICPackVisitor & visitor) override;
  517. template <typename Handler> void serialize(Handler & h, const int version)
  518. {
  519. h & tid;
  520. h & bid;
  521. h & builded;
  522. }
  523. };
  524. struct DLL_LINKAGE RazeStructures : public CPackForClient
  525. {
  526. void applyGs(CGameState * gs);
  527. ObjectInstanceID tid;
  528. std::set<BuildingID> bid;
  529. si16 destroyed = 0;
  530. virtual void visitTyped(ICPackVisitor & visitor) override;
  531. template <typename Handler> void serialize(Handler & h, const int version)
  532. {
  533. h & tid;
  534. h & bid;
  535. h & destroyed;
  536. }
  537. };
  538. struct DLL_LINKAGE SetAvailableCreatures : public CPackForClient
  539. {
  540. void applyGs(CGameState * gs) const;
  541. ObjectInstanceID tid;
  542. std::vector<std::pair<ui32, std::vector<CreatureID> > > creatures;
  543. virtual void visitTyped(ICPackVisitor & visitor) override;
  544. template <typename Handler> void serialize(Handler & h, const int version)
  545. {
  546. h & tid;
  547. h & creatures;
  548. }
  549. };
  550. struct DLL_LINKAGE SetHeroesInTown : public CPackForClient
  551. {
  552. void applyGs(CGameState * gs) const;
  553. ObjectInstanceID tid, visiting, garrison; //id of town, visiting hero, hero in garrison
  554. virtual void visitTyped(ICPackVisitor & visitor) override;
  555. template <typename Handler> void serialize(Handler & h, const int version)
  556. {
  557. h & tid;
  558. h & visiting;
  559. h & garrison;
  560. }
  561. };
  562. struct DLL_LINKAGE HeroRecruited : public CPackForClient
  563. {
  564. void applyGs(CGameState * gs) const;
  565. HeroTypeID hid; //subID of hero
  566. ObjectInstanceID tid;
  567. ObjectInstanceID boatId;
  568. int3 tile;
  569. PlayerColor player;
  570. virtual void visitTyped(ICPackVisitor & visitor) override;
  571. template <typename Handler> void serialize(Handler & h, const int version)
  572. {
  573. h & hid;
  574. h & tid;
  575. h & boatId;
  576. h & tile;
  577. h & player;
  578. }
  579. };
  580. struct DLL_LINKAGE GiveHero : public CPackForClient
  581. {
  582. void applyGs(CGameState * gs) const;
  583. ObjectInstanceID id; //object id
  584. ObjectInstanceID boatId;
  585. PlayerColor player;
  586. virtual void visitTyped(ICPackVisitor & visitor) override;
  587. template <typename Handler> void serialize(Handler & h, const int version)
  588. {
  589. h & id;
  590. h & boatId;
  591. h & player;
  592. }
  593. };
  594. struct DLL_LINKAGE OpenWindow : public CPackForClient
  595. {
  596. EOpenWindowMode window;
  597. si32 id1 = -1;
  598. si32 id2 = -1;
  599. virtual void visitTyped(ICPackVisitor & visitor) override;
  600. template <typename Handler> void serialize(Handler & h, const int version)
  601. {
  602. h & window;
  603. h & id1;
  604. h & id2;
  605. }
  606. };
  607. struct DLL_LINKAGE NewObject : public CPackForClient
  608. {
  609. void applyGs(CGameState * gs);
  610. /// Object ID to create
  611. Obj ID;
  612. /// Object secondary ID to create
  613. ui32 subID = 0;
  614. /// Position of visitable tile of created object
  615. int3 targetPos;
  616. ObjectInstanceID createdObjectID; //used locally, filled during applyGs
  617. virtual void visitTyped(ICPackVisitor & visitor) override;
  618. template <typename Handler> void serialize(Handler & h, const int version)
  619. {
  620. h & ID;
  621. h & subID;
  622. h & targetPos;
  623. }
  624. };
  625. struct DLL_LINKAGE SetAvailableArtifacts : public CPackForClient
  626. {
  627. void applyGs(CGameState * gs) const;
  628. si32 id = 0; //two variants: id < 0: set artifact pool for Artifact Merchants in towns; id >= 0: set pool for adv. map Black Market (id is the id of Black Market instance then)
  629. std::vector<const CArtifact *> arts;
  630. virtual void visitTyped(ICPackVisitor & visitor) override;
  631. template <typename Handler> void serialize(Handler & h, const int version)
  632. {
  633. h & id;
  634. h & arts;
  635. }
  636. };
  637. struct DLL_LINKAGE CGarrisonOperationPack : CPackForClient
  638. {
  639. };
  640. struct DLL_LINKAGE ChangeStackCount : CGarrisonOperationPack
  641. {
  642. ObjectInstanceID army;
  643. SlotID slot;
  644. TQuantity count;
  645. bool absoluteValue; //if not -> count will be added (or subtracted if negative)
  646. void applyGs(CGameState * gs);
  647. virtual void visitTyped(ICPackVisitor & visitor) override;
  648. template <typename Handler> void serialize(Handler & h, const int version)
  649. {
  650. h & army;
  651. h & slot;
  652. h & count;
  653. h & absoluteValue;
  654. }
  655. };
  656. struct DLL_LINKAGE SetStackType : CGarrisonOperationPack
  657. {
  658. ObjectInstanceID army;
  659. SlotID slot;
  660. CreatureID type;
  661. void applyGs(CGameState * gs);
  662. virtual void visitTyped(ICPackVisitor & visitor) override;
  663. template <typename Handler> void serialize(Handler & h, const int version)
  664. {
  665. h & army;
  666. h & slot;
  667. h & type;
  668. }
  669. };
  670. struct DLL_LINKAGE EraseStack : CGarrisonOperationPack
  671. {
  672. ObjectInstanceID army;
  673. SlotID slot;
  674. void applyGs(CGameState * gs);
  675. virtual void visitTyped(ICPackVisitor & visitor) override;
  676. template <typename Handler> void serialize(Handler & h, const int version)
  677. {
  678. h & army;
  679. h & slot;
  680. }
  681. };
  682. struct DLL_LINKAGE SwapStacks : CGarrisonOperationPack
  683. {
  684. ObjectInstanceID srcArmy;
  685. ObjectInstanceID dstArmy;
  686. SlotID srcSlot;
  687. SlotID dstSlot;
  688. void applyGs(CGameState * gs);
  689. virtual void visitTyped(ICPackVisitor & visitor) override;
  690. template <typename Handler> void serialize(Handler & h, const int version)
  691. {
  692. h & srcArmy;
  693. h & dstArmy;
  694. h & srcSlot;
  695. h & dstSlot;
  696. }
  697. };
  698. struct DLL_LINKAGE InsertNewStack : CGarrisonOperationPack
  699. {
  700. ObjectInstanceID army;
  701. SlotID slot;
  702. CreatureID type;
  703. TQuantity count = 0;
  704. void applyGs(CGameState * gs);
  705. virtual void visitTyped(ICPackVisitor & visitor) override;
  706. template <typename Handler> void serialize(Handler & h, const int version)
  707. {
  708. h & army;
  709. h & slot;
  710. h & type;
  711. h & count;
  712. }
  713. };
  714. ///moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  715. struct DLL_LINKAGE RebalanceStacks : CGarrisonOperationPack
  716. {
  717. ObjectInstanceID srcArmy;
  718. ObjectInstanceID dstArmy;
  719. SlotID srcSlot;
  720. SlotID dstSlot;
  721. TQuantity count;
  722. void applyGs(CGameState * gs);
  723. virtual void visitTyped(ICPackVisitor & visitor) override;
  724. template <typename Handler> void serialize(Handler & h, const int version)
  725. {
  726. h & srcArmy;
  727. h & dstArmy;
  728. h & srcSlot;
  729. h & dstSlot;
  730. h & count;
  731. }
  732. };
  733. struct DLL_LINKAGE BulkRebalanceStacks : CGarrisonOperationPack
  734. {
  735. std::vector<RebalanceStacks> moves;
  736. void applyGs(CGameState * gs);
  737. virtual void visitTyped(ICPackVisitor & visitor) override;
  738. template <typename Handler>
  739. void serialize(Handler & h, const int version)
  740. {
  741. h & moves;
  742. }
  743. };
  744. struct DLL_LINKAGE BulkSmartRebalanceStacks : CGarrisonOperationPack
  745. {
  746. std::vector<RebalanceStacks> moves;
  747. std::vector<ChangeStackCount> changes;
  748. void applyGs(CGameState * gs);
  749. virtual void visitTyped(ICPackVisitor & visitor) override;
  750. template <typename Handler>
  751. void serialize(Handler & h, const int version)
  752. {
  753. h & moves;
  754. h & changes;
  755. }
  756. };
  757. struct GetEngagedHeroIds
  758. {
  759. std::optional<ObjectInstanceID> operator()(const ConstTransitivePtr<CGHeroInstance> & h) const
  760. {
  761. return h->id;
  762. }
  763. std::optional<ObjectInstanceID> operator()(const ConstTransitivePtr<CStackInstance> & s) const
  764. {
  765. if(s->armyObj && s->armyObj->ID == Obj::HERO)
  766. return s->armyObj->id;
  767. return std::optional<ObjectInstanceID>();
  768. }
  769. };
  770. struct DLL_LINKAGE CArtifactOperationPack : CPackForClient
  771. {
  772. };
  773. struct DLL_LINKAGE PutArtifact : CArtifactOperationPack
  774. {
  775. PutArtifact() = default;
  776. PutArtifact(ArtifactLocation * dst, bool askAssemble = true)
  777. : al(*dst), askAssemble(askAssemble)
  778. {
  779. }
  780. ArtifactLocation al;
  781. bool askAssemble = false;
  782. ConstTransitivePtr<CArtifactInstance> art;
  783. void applyGs(CGameState * gs);
  784. virtual void visitTyped(ICPackVisitor & visitor) override;
  785. template <typename Handler> void serialize(Handler & h, const int version)
  786. {
  787. h & al;
  788. h & askAssemble;
  789. h & art;
  790. }
  791. };
  792. struct DLL_LINKAGE NewArtifact : public CArtifactOperationPack
  793. {
  794. ConstTransitivePtr<CArtifactInstance> art;
  795. void applyGs(CGameState * gs);
  796. virtual void visitTyped(ICPackVisitor & visitor) override;
  797. template <typename Handler> void serialize(Handler & h, const int version)
  798. {
  799. h & art;
  800. }
  801. };
  802. struct DLL_LINKAGE EraseArtifact : CArtifactOperationPack
  803. {
  804. ArtifactLocation al;
  805. void applyGs(CGameState * gs);
  806. virtual void visitTyped(ICPackVisitor & visitor) override;
  807. template <typename Handler> void serialize(Handler & h, const int version)
  808. {
  809. h & al;
  810. }
  811. };
  812. struct DLL_LINKAGE MoveArtifact : CArtifactOperationPack
  813. {
  814. MoveArtifact() = default;
  815. MoveArtifact(ArtifactLocation * src, ArtifactLocation * dst, bool askAssemble = true)
  816. : src(*src), dst(*dst), askAssemble(askAssemble)
  817. {
  818. }
  819. ArtifactLocation src, dst;
  820. bool askAssemble = true;
  821. void applyGs(CGameState * gs);
  822. virtual void visitTyped(ICPackVisitor & visitor) override;
  823. template <typename Handler> void serialize(Handler & h, const int version)
  824. {
  825. h & src;
  826. h & dst;
  827. h & askAssemble;
  828. }
  829. };
  830. struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
  831. {
  832. struct LinkedSlots
  833. {
  834. ArtifactPosition srcPos;
  835. ArtifactPosition dstPos;
  836. LinkedSlots() = default;
  837. LinkedSlots(const ArtifactPosition & srcPos, const ArtifactPosition & dstPos)
  838. : srcPos(srcPos)
  839. , dstPos(dstPos)
  840. {
  841. }
  842. template <typename Handler> void serialize(Handler & h, const int version)
  843. {
  844. h & srcPos;
  845. h & dstPos;
  846. }
  847. };
  848. TArtHolder srcArtHolder;
  849. TArtHolder dstArtHolder;
  850. BulkMoveArtifacts()
  851. : swap(false)
  852. {
  853. }
  854. BulkMoveArtifacts(TArtHolder srcArtHolder, TArtHolder dstArtHolder, bool swap)
  855. : srcArtHolder(std::move(std::move(srcArtHolder)))
  856. , dstArtHolder(std::move(std::move(dstArtHolder)))
  857. , swap(swap)
  858. {
  859. }
  860. void applyGs(CGameState * gs);
  861. std::vector<LinkedSlots> artsPack0;
  862. std::vector<LinkedSlots> artsPack1;
  863. bool swap;
  864. CArtifactSet * getSrcHolderArtSet();
  865. CArtifactSet * getDstHolderArtSet();
  866. virtual void visitTyped(ICPackVisitor & visitor) override;
  867. template <typename Handler> void serialize(Handler & h, const int version)
  868. {
  869. h & artsPack0;
  870. h & artsPack1;
  871. h & srcArtHolder;
  872. h & dstArtHolder;
  873. h & swap;
  874. }
  875. };
  876. struct DLL_LINKAGE AssembledArtifact : CArtifactOperationPack
  877. {
  878. ArtifactLocation al; //where assembly will be put
  879. CArtifact * builtArt;
  880. void applyGs(CGameState * gs);
  881. virtual void visitTyped(ICPackVisitor & visitor) override;
  882. template <typename Handler> void serialize(Handler & h, const int version)
  883. {
  884. h & al;
  885. h & builtArt;
  886. }
  887. };
  888. struct DLL_LINKAGE DisassembledArtifact : CArtifactOperationPack
  889. {
  890. ArtifactLocation al;
  891. void applyGs(CGameState * gs);
  892. virtual void visitTyped(ICPackVisitor & visitor) override;
  893. template <typename Handler> void serialize(Handler & h, const int version)
  894. {
  895. h & al;
  896. }
  897. };
  898. struct DLL_LINKAGE HeroVisit : public CPackForClient
  899. {
  900. PlayerColor player;
  901. ObjectInstanceID heroId;
  902. ObjectInstanceID objId;
  903. bool starting; //false -> ending
  904. void applyGs(CGameState * gs);
  905. virtual void visitTyped(ICPackVisitor & visitor) override;
  906. template <typename Handler> void serialize(Handler & h, const int version)
  907. {
  908. h & player;
  909. h & heroId;
  910. h & objId;
  911. h & starting;
  912. }
  913. };
  914. struct DLL_LINKAGE NewTurn : public CPackForClient
  915. {
  916. enum weekType { NORMAL, DOUBLE_GROWTH, BONUS_GROWTH, DEITYOFFIRE, PLAGUE, NO_ACTION };
  917. void applyGs(CGameState * gs);
  918. virtual void visitTyped(ICPackVisitor & visitor) override;
  919. struct Hero
  920. {
  921. ObjectInstanceID id;
  922. ui32 move, mana; //id is a general serial id
  923. template <typename Handler> void serialize(Handler & h, const int version)
  924. {
  925. h & id;
  926. h & move;
  927. h & mana;
  928. }
  929. bool operator<(const Hero & h)const { return id < h.id; }
  930. };
  931. std::set<Hero> heroes; //updates movement and mana points
  932. std::map<PlayerColor, TResources> res; //player ID => resource value[res_id]
  933. std::map<ObjectInstanceID, SetAvailableCreatures> cres;//creatures to be placed in towns
  934. ui32 day = 0;
  935. ui8 specialWeek = 0; //weekType
  936. CreatureID creatureid; //for creature weeks
  937. NewTurn() = default;
  938. template <typename Handler> void serialize(Handler & h, const int version)
  939. {
  940. h & heroes;
  941. h & cres;
  942. h & res;
  943. h & day;
  944. h & specialWeek;
  945. h & creatureid;
  946. }
  947. };
  948. struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
  949. {
  950. EInfoWindowMode type = EInfoWindowMode::MODAL;
  951. MetaString text;
  952. std::vector<Component> components;
  953. PlayerColor player;
  954. ui16 soundID = 0;
  955. virtual void visitTyped(ICPackVisitor & visitor) override;
  956. template <typename Handler> void serialize(Handler & h, const int version)
  957. {
  958. h & type;
  959. h & text;
  960. h & components;
  961. h & player;
  962. h & soundID;
  963. }
  964. InfoWindow() = default;
  965. };
  966. namespace ObjProperty
  967. {
  968. enum
  969. {
  970. OWNER = 1, BLOCKVIS = 2, PRIMARY_STACK_COUNT = 3, VISITORS = 4, VISITED = 5, ID = 6, AVAILABLE_CREATURE = 7, SUBID = 8,
  971. MONSTER_COUNT = 10, MONSTER_POWER = 11, MONSTER_EXP = 12, MONSTER_RESTORE_TYPE = 13, MONSTER_REFUSED_JOIN,
  972. //town-specific
  973. STRUCTURE_ADD_VISITING_HERO, STRUCTURE_CLEAR_VISITORS, STRUCTURE_ADD_GARRISONED_HERO, //changing buildings state
  974. BONUS_VALUE_FIRST, BONUS_VALUE_SECOND, //used in Rampart for special building that generates resources (storing resource type and quantity)
  975. //creature-bank specific
  976. BANK_DAYCOUNTER, BANK_RESET, BANK_CLEAR,
  977. //object with reward
  978. REWARD_RANDOMIZE, REWARD_SELECT, REWARD_CLEARED
  979. };
  980. }
  981. struct DLL_LINKAGE SetObjectProperty : public CPackForClient
  982. {
  983. void applyGs(CGameState * gs) const;
  984. ObjectInstanceID id;
  985. ui8 what = 0; // see ObjProperty enum
  986. ui32 val = 0;
  987. SetObjectProperty() = default;
  988. SetObjectProperty(const ObjectInstanceID & ID, ui8 What, ui32 Val)
  989. : id(ID)
  990. , what(What)
  991. , val(Val)
  992. {
  993. }
  994. virtual void visitTyped(ICPackVisitor & visitor) override;
  995. template <typename Handler> void serialize(Handler & h, const int version)
  996. {
  997. h & id;
  998. h & what;
  999. h & val;
  1000. }
  1001. };
  1002. struct DLL_LINKAGE ChangeObjectVisitors : public CPackForClient
  1003. {
  1004. enum VisitMode
  1005. {
  1006. VISITOR_ADD, // mark hero as one that have visited this object
  1007. VISITOR_ADD_TEAM, // mark team as one that have visited this object
  1008. VISITOR_REMOVE, // unmark visitor, reversed to ADD
  1009. VISITOR_CLEAR // clear all visitors from this object (object reset)
  1010. };
  1011. ui32 mode = VISITOR_CLEAR; // uses VisitMode enum
  1012. ObjectInstanceID object;
  1013. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  1014. void applyGs(CGameState * gs) const;
  1015. virtual void visitTyped(ICPackVisitor & visitor) override;
  1016. ChangeObjectVisitors() = default;
  1017. ChangeObjectVisitors(ui32 mode, const ObjectInstanceID & object, const ObjectInstanceID & heroID = ObjectInstanceID(-1))
  1018. : mode(mode)
  1019. , object(object)
  1020. , hero(heroID)
  1021. {
  1022. }
  1023. template <typename Handler> void serialize(Handler & h, const int version)
  1024. {
  1025. h & object;
  1026. h & hero;
  1027. h & mode;
  1028. }
  1029. };
  1030. struct DLL_LINKAGE PrepareHeroLevelUp : public CPackForClient
  1031. {
  1032. ObjectInstanceID heroId;
  1033. /// Do not serialize, used by server only
  1034. std::vector<SecondarySkill> skills;
  1035. void applyGs(CGameState * gs);
  1036. virtual void visitTyped(ICPackVisitor & visitor) override;
  1037. template <typename Handler> void serialize(Handler & h, const int version)
  1038. {
  1039. h & heroId;
  1040. }
  1041. };
  1042. struct DLL_LINKAGE HeroLevelUp : public Query
  1043. {
  1044. PlayerColor player;
  1045. ObjectInstanceID heroId;
  1046. PrimarySkill::PrimarySkill primskill = PrimarySkill::ATTACK;
  1047. std::vector<SecondarySkill> skills;
  1048. void applyGs(CGameState * gs) const;
  1049. virtual void visitTyped(ICPackVisitor & visitor) override;
  1050. template <typename Handler> void serialize(Handler & h, const int version)
  1051. {
  1052. h & queryID;
  1053. h & player;
  1054. h & heroId;
  1055. h & primskill;
  1056. h & skills;
  1057. }
  1058. };
  1059. struct DLL_LINKAGE CommanderLevelUp : public Query
  1060. {
  1061. PlayerColor player;
  1062. ObjectInstanceID heroId;
  1063. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1064. void applyGs(CGameState * gs) const;
  1065. virtual void visitTyped(ICPackVisitor & visitor) override;
  1066. template <typename Handler> void serialize(Handler & h, const int version)
  1067. {
  1068. h & queryID;
  1069. h & player;
  1070. h & heroId;
  1071. h & skills;
  1072. }
  1073. };
  1074. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1075. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1076. //Until sending reply player won't be allowed to take any actions
  1077. struct DLL_LINKAGE BlockingDialog : public Query
  1078. {
  1079. enum { ALLOW_CANCEL = 1, SELECTION = 2 };
  1080. MetaString text;
  1081. std::vector<Component> components;
  1082. PlayerColor player;
  1083. ui8 flags = 0;
  1084. ui16 soundID = 0;
  1085. bool cancel() const
  1086. {
  1087. return flags & ALLOW_CANCEL;
  1088. }
  1089. bool selection() const
  1090. {
  1091. return flags & SELECTION;
  1092. }
  1093. BlockingDialog(bool yesno, bool Selection)
  1094. {
  1095. if(yesno) flags |= ALLOW_CANCEL;
  1096. if(Selection) flags |= SELECTION;
  1097. }
  1098. BlockingDialog() = default;
  1099. virtual void visitTyped(ICPackVisitor & visitor) override;
  1100. template <typename Handler> void serialize(Handler & h, const int version)
  1101. {
  1102. h & queryID;
  1103. h & text;
  1104. h & components;
  1105. h & player;
  1106. h & flags;
  1107. h & soundID;
  1108. }
  1109. };
  1110. struct DLL_LINKAGE GarrisonDialog : public Query
  1111. {
  1112. ObjectInstanceID objid, hid;
  1113. bool removableUnits = false;
  1114. virtual void visitTyped(ICPackVisitor & visitor) override;
  1115. template <typename Handler> void serialize(Handler & h, const int version)
  1116. {
  1117. h & queryID;
  1118. h & objid;
  1119. h & hid;
  1120. h & removableUnits;
  1121. }
  1122. };
  1123. struct DLL_LINKAGE ExchangeDialog : public Query
  1124. {
  1125. PlayerColor player;
  1126. ObjectInstanceID hero1;
  1127. ObjectInstanceID hero2;
  1128. virtual void visitTyped(ICPackVisitor & visitor) override;
  1129. template <typename Handler> void serialize(Handler & h, const int version)
  1130. {
  1131. h & queryID;
  1132. h & player;
  1133. h & hero1;
  1134. h & hero2;
  1135. }
  1136. };
  1137. struct DLL_LINKAGE TeleportDialog : public Query
  1138. {
  1139. TeleportDialog() = default;
  1140. TeleportDialog(const PlayerColor & Player, const TeleportChannelID & Channel)
  1141. : player(Player)
  1142. , channel(Channel)
  1143. {
  1144. }
  1145. PlayerColor player;
  1146. TeleportChannelID channel;
  1147. TTeleportExitsList exits;
  1148. bool impassable = false;
  1149. virtual void visitTyped(ICPackVisitor & visitor) override;
  1150. template <typename Handler> void serialize(Handler & h, const int version)
  1151. {
  1152. h & queryID;
  1153. h & player;
  1154. h & channel;
  1155. h & exits;
  1156. h & impassable;
  1157. }
  1158. };
  1159. struct DLL_LINKAGE MapObjectSelectDialog : public Query
  1160. {
  1161. PlayerColor player;
  1162. Component icon;
  1163. MetaString title;
  1164. MetaString description;
  1165. std::vector<ObjectInstanceID> objects;
  1166. virtual void visitTyped(ICPackVisitor & visitor) override;
  1167. template <typename Handler> void serialize(Handler & h, const int version)
  1168. {
  1169. h & queryID;
  1170. h & player;
  1171. h & icon;
  1172. h & title;
  1173. h & description;
  1174. h & objects;
  1175. }
  1176. };
  1177. class BattleInfo;
  1178. struct DLL_LINKAGE BattleStart : public CPackForClient
  1179. {
  1180. void applyGs(CGameState * gs) const;
  1181. BattleInfo * info = nullptr;
  1182. virtual void visitTyped(ICPackVisitor & visitor) override;
  1183. template <typename Handler> void serialize(Handler & h, const int version)
  1184. {
  1185. h & info;
  1186. }
  1187. };
  1188. struct DLL_LINKAGE BattleNextRound : public CPackForClient
  1189. {
  1190. void applyGs(CGameState * gs) const;
  1191. si32 round = 0;
  1192. virtual void visitTyped(ICPackVisitor & visitor) override;
  1193. template <typename Handler> void serialize(Handler & h, const int version)
  1194. {
  1195. h & round;
  1196. }
  1197. };
  1198. struct DLL_LINKAGE BattleSetActiveStack : public CPackForClient
  1199. {
  1200. void applyGs(CGameState * gs) const;
  1201. ui32 stack = 0;
  1202. ui8 askPlayerInterface = true;
  1203. virtual void visitTyped(ICPackVisitor & visitor) override;
  1204. template <typename Handler> void serialize(Handler & h, const int version)
  1205. {
  1206. h & stack;
  1207. h & askPlayerInterface;
  1208. }
  1209. };
  1210. struct DLL_LINKAGE BattleResultAccepted : public CPackForClient
  1211. {
  1212. void applyGs(CGameState * gs) const;
  1213. struct HeroBattleResults
  1214. {
  1215. HeroBattleResults()
  1216. : hero(nullptr), army(nullptr), exp(0) {}
  1217. CGHeroInstance * hero;
  1218. CArmedInstance * army;
  1219. TExpType exp;
  1220. template <typename Handler> void serialize(Handler & h, const int version)
  1221. {
  1222. h & hero;
  1223. h & army;
  1224. h & exp;
  1225. }
  1226. };
  1227. std::array<HeroBattleResults, 2> heroResult;
  1228. ui8 winnerSide;
  1229. template <typename Handler> void serialize(Handler & h, const int version)
  1230. {
  1231. h & heroResult;
  1232. h & winnerSide;
  1233. }
  1234. };
  1235. struct DLL_LINKAGE BattleResult : public Query
  1236. {
  1237. void applyFirstCl(CClient * cl);
  1238. EBattleResult result = EBattleResult::NORMAL;
  1239. ui8 winner = 2; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  1240. std::map<ui32, si32> casualties[2]; //first => casualties of attackers - map crid => number
  1241. TExpType exp[2] = {0, 0}; //exp for attacker and defender
  1242. std::set<ArtifactInstanceID> artifacts; //artifacts taken from loser to winner - currently unused
  1243. virtual void visitTyped(ICPackVisitor & visitor) override;
  1244. template <typename Handler> void serialize(Handler & h, const int version)
  1245. {
  1246. h & queryID;
  1247. h & result;
  1248. h & winner;
  1249. h & casualties[0];
  1250. h & casualties[1];
  1251. h & exp;
  1252. h & artifacts;
  1253. }
  1254. };
  1255. struct DLL_LINKAGE BattleLogMessage : public CPackForClient
  1256. {
  1257. std::vector<MetaString> lines;
  1258. void applyGs(CGameState * gs);
  1259. void applyBattle(IBattleState * battleState);
  1260. virtual void visitTyped(ICPackVisitor & visitor) override;
  1261. template <typename Handler> void serialize(Handler & h, const int version)
  1262. {
  1263. h & lines;
  1264. }
  1265. };
  1266. struct DLL_LINKAGE BattleStackMoved : public CPackForClient
  1267. {
  1268. ui32 stack = 0;
  1269. std::vector<BattleHex> tilesToMove;
  1270. int distance = 0;
  1271. bool teleporting = false;
  1272. void applyGs(CGameState * gs);
  1273. void applyBattle(IBattleState * battleState);
  1274. virtual void visitTyped(ICPackVisitor & visitor) override;
  1275. template <typename Handler> void serialize(Handler & h, const int version)
  1276. {
  1277. h & stack;
  1278. h & tilesToMove;
  1279. h & distance;
  1280. h & teleporting;
  1281. }
  1282. };
  1283. struct DLL_LINKAGE BattleUnitsChanged : public CPackForClient
  1284. {
  1285. void applyGs(CGameState * gs);
  1286. void applyBattle(IBattleState * battleState);
  1287. std::vector<UnitChanges> changedStacks;
  1288. virtual void visitTyped(ICPackVisitor & visitor) override;
  1289. template <typename Handler> void serialize(Handler & h, const int version)
  1290. {
  1291. h & changedStacks;
  1292. }
  1293. };
  1294. struct BattleStackAttacked
  1295. {
  1296. DLL_LINKAGE void applyGs(CGameState * gs);
  1297. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1298. ui32 stackAttacked = 0, attackerID = 0;
  1299. ui32 killedAmount = 0;
  1300. int64_t damageAmount = 0;
  1301. UnitChanges newState;
  1302. enum EFlags { KILLED = 1, SECONDARY = 2, REBIRTH = 4, CLONE_KILLED = 8, SPELL_EFFECT = 16, FIRE_SHIELD = 32, };
  1303. ui32 flags = 0; //uses EFlags (above)
  1304. SpellID spellID = SpellID::NONE; //only if flag SPELL_EFFECT is set
  1305. bool killed() const//if target stack was killed
  1306. {
  1307. return flags & KILLED || flags & CLONE_KILLED;
  1308. }
  1309. bool cloneKilled() const
  1310. {
  1311. return flags & CLONE_KILLED;
  1312. }
  1313. bool isSecondary() const//if stack was not a primary target (receives no spell effects)
  1314. {
  1315. return flags & SECONDARY;
  1316. }
  1317. ///Attacked with spell (SPELL_LIKE_ATTACK)
  1318. bool isSpell() const
  1319. {
  1320. return flags & SPELL_EFFECT;
  1321. }
  1322. bool willRebirth() const//resurrection, e.g. Phoenix
  1323. {
  1324. return flags & REBIRTH;
  1325. }
  1326. bool fireShield() const
  1327. {
  1328. return flags & FIRE_SHIELD;
  1329. }
  1330. template <typename Handler> void serialize(Handler & h, const int version)
  1331. {
  1332. h & stackAttacked;
  1333. h & attackerID;
  1334. h & newState;
  1335. h & flags;
  1336. h & killedAmount;
  1337. h & damageAmount;
  1338. h & spellID;
  1339. }
  1340. bool operator<(const BattleStackAttacked & b) const
  1341. {
  1342. return stackAttacked < b.stackAttacked;
  1343. }
  1344. };
  1345. struct DLL_LINKAGE BattleAttack : public CPackForClient
  1346. {
  1347. void applyGs(CGameState * gs);
  1348. BattleUnitsChanged attackerChanges;
  1349. std::vector<BattleStackAttacked> bsa;
  1350. ui32 stackAttacking = 0;
  1351. ui32 flags = 0; //uses Eflags (below)
  1352. enum EFlags { SHOT = 1, COUNTER = 2, LUCKY = 4, UNLUCKY = 8, BALLISTA_DOUBLE_DMG = 16, DEATH_BLOW = 32, SPELL_LIKE = 64, LIFE_DRAIN = 128 };
  1353. BattleHex tile;
  1354. SpellID spellID = SpellID::NONE; //for SPELL_LIKE
  1355. bool shot() const//distance attack - decrease number of shots
  1356. {
  1357. return flags & SHOT;
  1358. }
  1359. bool counter() const//is it counterattack?
  1360. {
  1361. return flags & COUNTER;
  1362. }
  1363. bool lucky() const
  1364. {
  1365. return flags & LUCKY;
  1366. }
  1367. bool unlucky() const
  1368. {
  1369. return flags & UNLUCKY;
  1370. }
  1371. bool ballistaDoubleDmg() const //if it's ballista attack and does double dmg
  1372. {
  1373. return flags & BALLISTA_DOUBLE_DMG;
  1374. }
  1375. bool deathBlow() const
  1376. {
  1377. return flags & DEATH_BLOW;
  1378. }
  1379. bool spellLike() const
  1380. {
  1381. return flags & SPELL_LIKE;
  1382. }
  1383. bool lifeDrain() const
  1384. {
  1385. return flags & LIFE_DRAIN;
  1386. }
  1387. virtual void visitTyped(ICPackVisitor & visitor) override;
  1388. template <typename Handler> void serialize(Handler & h, const int version)
  1389. {
  1390. h & bsa;
  1391. h & stackAttacking;
  1392. h & flags;
  1393. h & tile;
  1394. h & spellID;
  1395. h & attackerChanges;
  1396. }
  1397. };
  1398. struct DLL_LINKAGE StartAction : public CPackForClient
  1399. {
  1400. StartAction() = default;
  1401. StartAction(BattleAction act)
  1402. : ba(std::move(act))
  1403. {
  1404. }
  1405. void applyFirstCl(CClient * cl);
  1406. void applyGs(CGameState * gs);
  1407. BattleAction ba;
  1408. virtual void visitTyped(ICPackVisitor & visitor) override;
  1409. template <typename Handler> void serialize(Handler & h, const int version)
  1410. {
  1411. h & ba;
  1412. }
  1413. };
  1414. struct DLL_LINKAGE EndAction : public CPackForClient
  1415. {
  1416. virtual void visitTyped(ICPackVisitor & visitor) override;
  1417. template <typename Handler> void serialize(Handler & h, const int version)
  1418. {
  1419. }
  1420. };
  1421. struct DLL_LINKAGE BattleSpellCast : public CPackForClient
  1422. {
  1423. void applyGs(CGameState * gs) const;
  1424. bool activeCast = true;
  1425. ui8 side = 0; //which hero did cast spell: 0 - attacker, 1 - defender
  1426. SpellID spellID; //id of spell
  1427. ui8 manaGained = 0; //mana channeling ability
  1428. BattleHex tile; //destination tile (may not be set in some global/mass spells
  1429. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  1430. std::set<ui32> resistedCres; // creatures that resisted the spell (e.g. Dwarves)
  1431. std::set<ui32> reflectedCres; // creatures that reflected the spell (e.g. Magic Mirror spell)
  1432. si32 casterStack = -1; // -1 if not cated by creature, >=0 caster stack ID
  1433. bool castByHero = true; //if true - spell has been cast by hero, otherwise by a creature
  1434. virtual void visitTyped(ICPackVisitor & visitor) override;
  1435. template <typename Handler> void serialize(Handler & h, const int version)
  1436. {
  1437. h & side;
  1438. h & spellID;
  1439. h & manaGained;
  1440. h & tile;
  1441. h & affectedCres;
  1442. h & resistedCres;
  1443. h & reflectedCres;
  1444. h & casterStack;
  1445. h & castByHero;
  1446. h & activeCast;
  1447. }
  1448. };
  1449. struct DLL_LINKAGE SetStackEffect : public CPackForClient
  1450. {
  1451. void applyGs(CGameState * gs);
  1452. void applyBattle(IBattleState * battleState);
  1453. std::vector<std::pair<ui32, std::vector<Bonus>>> toAdd;
  1454. std::vector<std::pair<ui32, std::vector<Bonus>>> toUpdate;
  1455. std::vector<std::pair<ui32, std::vector<Bonus>>> toRemove;
  1456. virtual void visitTyped(ICPackVisitor & visitor) override;
  1457. template <typename Handler> void serialize(Handler & h, const int version)
  1458. {
  1459. h & toAdd;
  1460. h & toUpdate;
  1461. h & toRemove;
  1462. }
  1463. };
  1464. struct DLL_LINKAGE StacksInjured : public CPackForClient
  1465. {
  1466. void applyGs(CGameState * gs);
  1467. void applyBattle(IBattleState * battleState);
  1468. std::vector<BattleStackAttacked> stacks;
  1469. virtual void visitTyped(ICPackVisitor & visitor) override;
  1470. template <typename Handler> void serialize(Handler & h, const int version)
  1471. {
  1472. h & stacks;
  1473. }
  1474. };
  1475. struct DLL_LINKAGE BattleResultsApplied : public CPackForClient
  1476. {
  1477. PlayerColor player1, player2;
  1478. virtual void visitTyped(ICPackVisitor & visitor) override;
  1479. template <typename Handler> void serialize(Handler & h, const int version)
  1480. {
  1481. h & player1;
  1482. h & player2;
  1483. }
  1484. };
  1485. struct DLL_LINKAGE BattleObstaclesChanged : public CPackForClient
  1486. {
  1487. void applyGs(CGameState * gs);
  1488. void applyBattle(IBattleState * battleState);
  1489. std::vector<ObstacleChanges> changes;
  1490. virtual void visitTyped(ICPackVisitor & visitor) override;
  1491. template <typename Handler> void serialize(Handler & h, const int version)
  1492. {
  1493. h & changes;
  1494. }
  1495. };
  1496. struct DLL_LINKAGE CatapultAttack : public CPackForClient
  1497. {
  1498. struct AttackInfo
  1499. {
  1500. si16 destinationTile;
  1501. EWallPart attackedPart;
  1502. ui8 damageDealt;
  1503. template <typename Handler> void serialize(Handler & h, const int version)
  1504. {
  1505. h & destinationTile;
  1506. h & attackedPart;
  1507. h & damageDealt;
  1508. }
  1509. };
  1510. CatapultAttack();
  1511. ~CatapultAttack() override;
  1512. void applyGs(CGameState * gs);
  1513. void applyBattle(IBattleState * battleState);
  1514. std::vector< AttackInfo > attackedParts;
  1515. int attacker = -1; //if -1, then a spell caused this
  1516. virtual void visitTyped(ICPackVisitor & visitor) override;
  1517. template <typename Handler> void serialize(Handler & h, const int version)
  1518. {
  1519. h & attackedParts;
  1520. h & attacker;
  1521. }
  1522. };
  1523. struct DLL_LINKAGE BattleSetStackProperty : public CPackForClient
  1524. {
  1525. enum BattleStackProperty { CASTS, ENCHANTER_COUNTER, UNBIND, CLONED, HAS_CLONE };
  1526. void applyGs(CGameState * gs) const;
  1527. int stackID = 0;
  1528. BattleStackProperty which = CASTS;
  1529. int val = 0;
  1530. int absolute = 0;
  1531. template <typename Handler> void serialize(Handler & h, const int version)
  1532. {
  1533. h & stackID;
  1534. h & which;
  1535. h & val;
  1536. h & absolute;
  1537. }
  1538. protected:
  1539. virtual void visitTyped(ICPackVisitor & visitor) override;
  1540. };
  1541. ///activated at the beginning of turn
  1542. struct DLL_LINKAGE BattleTriggerEffect : public CPackForClient
  1543. {
  1544. void applyGs(CGameState * gs) const; //effect
  1545. int stackID = 0;
  1546. int effect = 0; //use corresponding Bonus type
  1547. int val = 0;
  1548. int additionalInfo = 0;
  1549. template <typename Handler> void serialize(Handler & h, const int version)
  1550. {
  1551. h & stackID;
  1552. h & effect;
  1553. h & val;
  1554. h & additionalInfo;
  1555. }
  1556. protected:
  1557. virtual void visitTyped(ICPackVisitor & visitor) override;
  1558. };
  1559. struct DLL_LINKAGE BattleUpdateGateState : public CPackForClient
  1560. {
  1561. void applyGs(CGameState * gs) const;
  1562. EGateState state = EGateState::NONE;
  1563. template <typename Handler> void serialize(Handler & h, const int version)
  1564. {
  1565. h & state;
  1566. }
  1567. protected:
  1568. virtual void visitTyped(ICPackVisitor & visitor) override;
  1569. };
  1570. struct DLL_LINKAGE AdvmapSpellCast : public CPackForClient
  1571. {
  1572. ObjectInstanceID casterID;
  1573. SpellID spellID;
  1574. template <typename Handler> void serialize(Handler & h, const int version)
  1575. {
  1576. h & casterID;
  1577. h & spellID;
  1578. }
  1579. protected:
  1580. virtual void visitTyped(ICPackVisitor & visitor) override;
  1581. };
  1582. struct DLL_LINKAGE ShowWorldViewEx : public CPackForClient
  1583. {
  1584. PlayerColor player;
  1585. bool showTerrain; // TODO: send terrain state
  1586. std::vector<ObjectPosInfo> objectPositions;
  1587. template <typename Handler> void serialize(Handler & h, const int version)
  1588. {
  1589. h & player;
  1590. h & showTerrain;
  1591. h & objectPositions;
  1592. }
  1593. protected:
  1594. virtual void visitTyped(ICPackVisitor & visitor) override;
  1595. };
  1596. /***********************************************************************************************************/
  1597. struct DLL_LINKAGE EndTurn : public CPackForServer
  1598. {
  1599. virtual void visitTyped(ICPackVisitor & visitor) override;
  1600. template <typename Handler> void serialize(Handler & h, const int version)
  1601. {
  1602. h & static_cast<CPackForServer &>(*this);
  1603. }
  1604. };
  1605. struct DLL_LINKAGE DismissHero : public CPackForServer
  1606. {
  1607. DismissHero() = default;
  1608. DismissHero(const ObjectInstanceID & HID)
  1609. : hid(HID)
  1610. {
  1611. }
  1612. ObjectInstanceID hid;
  1613. virtual void visitTyped(ICPackVisitor & visitor) override;
  1614. template <typename Handler> void serialize(Handler & h, const int version)
  1615. {
  1616. h & static_cast<CPackForServer &>(*this);
  1617. h & hid;
  1618. }
  1619. };
  1620. struct DLL_LINKAGE MoveHero : public CPackForServer
  1621. {
  1622. MoveHero() = default;
  1623. MoveHero(const int3 & Dest, const ObjectInstanceID & HID, bool Transit)
  1624. : dest(Dest)
  1625. , hid(HID)
  1626. , transit(Transit)
  1627. {
  1628. }
  1629. int3 dest;
  1630. ObjectInstanceID hid;
  1631. bool transit = false;
  1632. virtual void visitTyped(ICPackVisitor & visitor) override;
  1633. template <typename Handler> void serialize(Handler & h, const int version)
  1634. {
  1635. h & static_cast<CPackForServer &>(*this);
  1636. h & dest;
  1637. h & hid;
  1638. h & transit;
  1639. }
  1640. };
  1641. struct DLL_LINKAGE CastleTeleportHero : public CPackForServer
  1642. {
  1643. CastleTeleportHero() = default;
  1644. CastleTeleportHero(const ObjectInstanceID & HID, const ObjectInstanceID & Dest, ui8 Source)
  1645. : dest(Dest)
  1646. , hid(HID)
  1647. , source(Source)
  1648. {
  1649. }
  1650. ObjectInstanceID dest;
  1651. ObjectInstanceID hid;
  1652. si8 source = 0; //who give teleporting, 1=castle gate
  1653. virtual void visitTyped(ICPackVisitor & visitor) override;
  1654. template <typename Handler> void serialize(Handler & h, const int version)
  1655. {
  1656. h & static_cast<CPackForServer &>(*this);
  1657. h & dest;
  1658. h & hid;
  1659. }
  1660. };
  1661. struct DLL_LINKAGE ArrangeStacks : public CPackForServer
  1662. {
  1663. ArrangeStacks() = default;
  1664. ArrangeStacks(ui8 W, const SlotID & P1, const SlotID & P2, const ObjectInstanceID & ID1, const ObjectInstanceID & ID2, si32 VAL)
  1665. : what(W)
  1666. , p1(P1)
  1667. , p2(P2)
  1668. , id1(ID1)
  1669. , id2(ID2)
  1670. , val(VAL)
  1671. {
  1672. }
  1673. ui8 what = 0; //1 - swap; 2 - merge; 3 - split
  1674. SlotID p1, p2; //positions of first and second stack
  1675. ObjectInstanceID id1, id2; //ids of objects with garrison
  1676. si32 val = 0;
  1677. virtual void visitTyped(ICPackVisitor & visitor) override;
  1678. template <typename Handler> void serialize(Handler & h, const int version)
  1679. {
  1680. h & static_cast<CPackForServer &>(*this);
  1681. h & what;
  1682. h & p1;
  1683. h & p2;
  1684. h & id1;
  1685. h & id2;
  1686. h & val;
  1687. }
  1688. };
  1689. struct DLL_LINKAGE BulkMoveArmy : public CPackForServer
  1690. {
  1691. SlotID srcSlot;
  1692. ObjectInstanceID srcArmy;
  1693. ObjectInstanceID destArmy;
  1694. BulkMoveArmy() = default;
  1695. BulkMoveArmy(const ObjectInstanceID & srcArmy, const ObjectInstanceID & destArmy, const SlotID & srcSlot)
  1696. : srcArmy(srcArmy)
  1697. , destArmy(destArmy)
  1698. , srcSlot(srcSlot)
  1699. {
  1700. }
  1701. virtual void visitTyped(ICPackVisitor & visitor) override;
  1702. template <typename Handler>
  1703. void serialize(Handler & h, const int version)
  1704. {
  1705. h & static_cast<CPackForServer &>(*this);
  1706. h & srcSlot;
  1707. h & srcArmy;
  1708. h & destArmy;
  1709. }
  1710. };
  1711. struct DLL_LINKAGE BulkSplitStack : public CPackForServer
  1712. {
  1713. SlotID src;
  1714. ObjectInstanceID srcOwner;
  1715. si32 amount = 0;
  1716. BulkSplitStack() = default;
  1717. BulkSplitStack(const ObjectInstanceID & srcOwner, const SlotID & src, si32 howMany)
  1718. : src(src)
  1719. , srcOwner(srcOwner)
  1720. , amount(howMany)
  1721. {
  1722. }
  1723. virtual void visitTyped(ICPackVisitor & visitor) override;
  1724. template <typename Handler>
  1725. void serialize(Handler & h, const int version)
  1726. {
  1727. h & static_cast<CPackForServer &>(*this);
  1728. h & src;
  1729. h & srcOwner;
  1730. h & amount;
  1731. }
  1732. };
  1733. struct DLL_LINKAGE BulkMergeStacks : public CPackForServer
  1734. {
  1735. SlotID src;
  1736. ObjectInstanceID srcOwner;
  1737. BulkMergeStacks() = default;
  1738. BulkMergeStacks(const ObjectInstanceID & srcOwner, const SlotID & src)
  1739. : src(src)
  1740. , srcOwner(srcOwner)
  1741. {
  1742. }
  1743. virtual void visitTyped(ICPackVisitor & visitor) override;
  1744. template <typename Handler>
  1745. void serialize(Handler & h, const int version)
  1746. {
  1747. h & static_cast<CPackForServer &>(*this);
  1748. h & src;
  1749. h & srcOwner;
  1750. }
  1751. };
  1752. struct DLL_LINKAGE BulkSmartSplitStack : public CPackForServer
  1753. {
  1754. SlotID src;
  1755. ObjectInstanceID srcOwner;
  1756. BulkSmartSplitStack() = default;
  1757. BulkSmartSplitStack(const ObjectInstanceID & srcOwner, const SlotID & src)
  1758. : src(src)
  1759. , srcOwner(srcOwner)
  1760. {
  1761. }
  1762. virtual void visitTyped(ICPackVisitor & visitor) override;
  1763. template <typename Handler>
  1764. void serialize(Handler & h, const int version)
  1765. {
  1766. h & static_cast<CPackForServer &>(*this);
  1767. h & src;
  1768. h & srcOwner;
  1769. }
  1770. };
  1771. struct DLL_LINKAGE DisbandCreature : public CPackForServer
  1772. {
  1773. DisbandCreature() = default;
  1774. DisbandCreature(const SlotID & Pos, const ObjectInstanceID & ID)
  1775. : pos(Pos)
  1776. , id(ID)
  1777. {
  1778. }
  1779. SlotID pos; //stack pos
  1780. ObjectInstanceID id; //object id
  1781. virtual void visitTyped(ICPackVisitor & visitor) override;
  1782. template <typename Handler> void serialize(Handler & h, const int version)
  1783. {
  1784. h & static_cast<CPackForServer &>(*this);
  1785. h & pos;
  1786. h & id;
  1787. }
  1788. };
  1789. struct DLL_LINKAGE BuildStructure : public CPackForServer
  1790. {
  1791. BuildStructure() = default;
  1792. BuildStructure(const ObjectInstanceID & TID, const BuildingID & BID)
  1793. : tid(TID)
  1794. , bid(BID)
  1795. {
  1796. }
  1797. ObjectInstanceID tid; //town id
  1798. BuildingID bid; //structure id
  1799. virtual void visitTyped(ICPackVisitor & visitor) override;
  1800. template <typename Handler> void serialize(Handler & h, const int version)
  1801. {
  1802. h & static_cast<CPackForServer &>(*this);
  1803. h & tid;
  1804. h & bid;
  1805. }
  1806. };
  1807. struct DLL_LINKAGE RazeStructure : public BuildStructure
  1808. {
  1809. virtual void visitTyped(ICPackVisitor & visitor) override;
  1810. };
  1811. struct DLL_LINKAGE RecruitCreatures : public CPackForServer
  1812. {
  1813. RecruitCreatures() = default;
  1814. RecruitCreatures(const ObjectInstanceID & TID, const ObjectInstanceID & DST, const CreatureID & CRID, si32 Amount, si32 Level)
  1815. : tid(TID)
  1816. , dst(DST)
  1817. , crid(CRID)
  1818. , amount(Amount)
  1819. , level(Level)
  1820. {
  1821. }
  1822. ObjectInstanceID tid; //dwelling id, or town
  1823. ObjectInstanceID dst; //destination ID, e.g. hero
  1824. CreatureID crid;
  1825. ui32 amount = 0; //creature amount
  1826. si32 level = 0; //dwelling level to buy from, -1 if any
  1827. virtual void visitTyped(ICPackVisitor & visitor) override;
  1828. template <typename Handler> void serialize(Handler & h, const int version)
  1829. {
  1830. h & static_cast<CPackForServer &>(*this);
  1831. h & tid;
  1832. h & dst;
  1833. h & crid;
  1834. h & amount;
  1835. h & level;
  1836. }
  1837. };
  1838. struct DLL_LINKAGE UpgradeCreature : public CPackForServer
  1839. {
  1840. UpgradeCreature() = default;
  1841. UpgradeCreature(const SlotID & Pos, const ObjectInstanceID & ID, const CreatureID & CRID)
  1842. : pos(Pos)
  1843. , id(ID)
  1844. , cid(CRID)
  1845. {
  1846. }
  1847. SlotID pos; //stack pos
  1848. ObjectInstanceID id; //object id
  1849. CreatureID cid; //id of type to which we want make upgrade
  1850. virtual void visitTyped(ICPackVisitor & visitor) override;
  1851. template <typename Handler> void serialize(Handler & h, const int version)
  1852. {
  1853. h & static_cast<CPackForServer &>(*this);
  1854. h & pos;
  1855. h & id;
  1856. h & cid;
  1857. }
  1858. };
  1859. struct DLL_LINKAGE GarrisonHeroSwap : public CPackForServer
  1860. {
  1861. GarrisonHeroSwap() = default;
  1862. GarrisonHeroSwap(const ObjectInstanceID & TID)
  1863. : tid(TID)
  1864. {
  1865. }
  1866. ObjectInstanceID tid;
  1867. virtual void visitTyped(ICPackVisitor & visitor) override;
  1868. template <typename Handler> void serialize(Handler & h, const int version)
  1869. {
  1870. h & static_cast<CPackForServer &>(*this);
  1871. h & tid;
  1872. }
  1873. };
  1874. struct DLL_LINKAGE ExchangeArtifacts : public CPackForServer
  1875. {
  1876. ArtifactLocation src, dst;
  1877. virtual void visitTyped(ICPackVisitor & visitor) override;
  1878. template <typename Handler> void serialize(Handler & h, const int version)
  1879. {
  1880. h & static_cast<CPackForServer &>(*this);
  1881. h & src;
  1882. h & dst;
  1883. }
  1884. };
  1885. struct DLL_LINKAGE BulkExchangeArtifacts : public CPackForServer
  1886. {
  1887. ObjectInstanceID srcHero;
  1888. ObjectInstanceID dstHero;
  1889. bool swap = false;
  1890. BulkExchangeArtifacts() = default;
  1891. BulkExchangeArtifacts(const ObjectInstanceID & srcHero, const ObjectInstanceID & dstHero, bool swap)
  1892. : srcHero(srcHero)
  1893. , dstHero(dstHero)
  1894. , swap(swap)
  1895. {
  1896. }
  1897. virtual void visitTyped(ICPackVisitor & visitor) override;
  1898. template <typename Handler> void serialize(Handler & h, const int version)
  1899. {
  1900. h & static_cast<CPackForServer &>(*this);
  1901. h & srcHero;
  1902. h & dstHero;
  1903. h & swap;
  1904. }
  1905. };
  1906. struct DLL_LINKAGE AssembleArtifacts : public CPackForServer
  1907. {
  1908. AssembleArtifacts() = default;
  1909. AssembleArtifacts(const ObjectInstanceID & _heroID, const ArtifactPosition & _artifactSlot, bool _assemble, const ArtifactID & _assembleTo)
  1910. : heroID(_heroID)
  1911. , artifactSlot(_artifactSlot)
  1912. , assemble(_assemble)
  1913. , assembleTo(_assembleTo)
  1914. {
  1915. }
  1916. ObjectInstanceID heroID;
  1917. ArtifactPosition artifactSlot;
  1918. bool assemble = false; // True to assemble artifact, false to disassemble.
  1919. ArtifactID assembleTo; // Artifact to assemble into.
  1920. virtual void visitTyped(ICPackVisitor & visitor) override;
  1921. template <typename Handler> void serialize(Handler & h, const int version)
  1922. {
  1923. h & static_cast<CPackForServer &>(*this);
  1924. h & heroID;
  1925. h & artifactSlot;
  1926. h & assemble;
  1927. h & assembleTo;
  1928. }
  1929. };
  1930. struct DLL_LINKAGE EraseArtifactByClient : public CPackForServer
  1931. {
  1932. EraseArtifactByClient() = default;
  1933. EraseArtifactByClient(const ArtifactLocation & al)
  1934. : al(al)
  1935. {
  1936. }
  1937. ArtifactLocation al;
  1938. virtual void visitTyped(ICPackVisitor & visitor) override;
  1939. template <typename Handler> void serialize(Handler & h, const int version)
  1940. {
  1941. h & static_cast<CPackForServer&>(*this);
  1942. h & al;
  1943. }
  1944. };
  1945. struct DLL_LINKAGE BuyArtifact : public CPackForServer
  1946. {
  1947. BuyArtifact() = default;
  1948. BuyArtifact(const ObjectInstanceID & HID, const ArtifactID & AID)
  1949. : hid(HID)
  1950. , aid(AID)
  1951. {
  1952. }
  1953. ObjectInstanceID hid;
  1954. ArtifactID aid;
  1955. virtual void visitTyped(ICPackVisitor & visitor) override;
  1956. template <typename Handler> void serialize(Handler & h, const int version)
  1957. {
  1958. h & static_cast<CPackForServer &>(*this);
  1959. h & hid;
  1960. h & aid;
  1961. }
  1962. };
  1963. struct DLL_LINKAGE TradeOnMarketplace : public CPackForServer
  1964. {
  1965. ObjectInstanceID marketId;
  1966. ObjectInstanceID heroId;
  1967. EMarketMode::EMarketMode mode = EMarketMode::RESOURCE_RESOURCE;
  1968. std::vector<ui32> r1, r2; //mode 0: r1 - sold resource, r2 - bought res (exception: when sacrificing art r1 is art id [todo: make r2 preferred slot?]
  1969. std::vector<ui32> val; //units of sold resource
  1970. virtual void visitTyped(ICPackVisitor & visitor) override;
  1971. template <typename Handler> void serialize(Handler & h, const int version)
  1972. {
  1973. h & static_cast<CPackForServer &>(*this);
  1974. h & marketId;
  1975. h & heroId;
  1976. h & mode;
  1977. h & r1;
  1978. h & r2;
  1979. h & val;
  1980. }
  1981. };
  1982. struct DLL_LINKAGE SetFormation : public CPackForServer
  1983. {
  1984. SetFormation() = default;
  1985. ;
  1986. SetFormation(const ObjectInstanceID & HID, ui8 Formation)
  1987. : hid(HID)
  1988. , formation(Formation)
  1989. {
  1990. }
  1991. ObjectInstanceID hid;
  1992. ui8 formation = 0;
  1993. virtual void visitTyped(ICPackVisitor & visitor) override;
  1994. template <typename Handler> void serialize(Handler & h, const int version)
  1995. {
  1996. h & static_cast<CPackForServer &>(*this);
  1997. h & hid;
  1998. h & formation;
  1999. }
  2000. };
  2001. struct DLL_LINKAGE HireHero : public CPackForServer
  2002. {
  2003. HireHero() = default;
  2004. HireHero(HeroTypeID HID, const ObjectInstanceID & TID)
  2005. : hid(HID)
  2006. , tid(TID)
  2007. {
  2008. }
  2009. HeroTypeID hid; //available hero serial
  2010. ObjectInstanceID tid; //town (tavern) id
  2011. PlayerColor player;
  2012. virtual void visitTyped(ICPackVisitor & visitor) override;
  2013. template <typename Handler> void serialize(Handler & h, const int version)
  2014. {
  2015. h & static_cast<CPackForServer &>(*this);
  2016. h & hid;
  2017. h & tid;
  2018. h & player;
  2019. }
  2020. };
  2021. struct DLL_LINKAGE BuildBoat : public CPackForServer
  2022. {
  2023. ObjectInstanceID objid; //where player wants to buy a boat
  2024. virtual void visitTyped(ICPackVisitor & visitor) override;
  2025. template <typename Handler> void serialize(Handler & h, const int version)
  2026. {
  2027. h & static_cast<CPackForServer &>(*this);
  2028. h & objid;
  2029. }
  2030. };
  2031. struct DLL_LINKAGE QueryReply : public CPackForServer
  2032. {
  2033. QueryReply() = default;
  2034. QueryReply(const QueryID & QID, const JsonNode & Reply)
  2035. : qid(QID)
  2036. , reply(Reply)
  2037. {
  2038. }
  2039. QueryID qid;
  2040. PlayerColor player;
  2041. JsonNode reply;
  2042. virtual void visitTyped(ICPackVisitor & visitor) override;
  2043. template <typename Handler> void serialize(Handler & h, const int version)
  2044. {
  2045. h & static_cast<CPackForServer &>(*this);
  2046. h & qid;
  2047. h & player;
  2048. h & reply;
  2049. }
  2050. };
  2051. struct DLL_LINKAGE MakeAction : public CPackForServer
  2052. {
  2053. MakeAction() = default;
  2054. MakeAction(BattleAction BA)
  2055. : ba(std::move(BA))
  2056. {
  2057. }
  2058. BattleAction ba;
  2059. virtual void visitTyped(ICPackVisitor & visitor) override;
  2060. template <typename Handler> void serialize(Handler & h, const int version)
  2061. {
  2062. h & static_cast<CPackForServer &>(*this);
  2063. h & ba;
  2064. }
  2065. };
  2066. struct DLL_LINKAGE DigWithHero : public CPackForServer
  2067. {
  2068. ObjectInstanceID id; //digging hero id
  2069. virtual void visitTyped(ICPackVisitor & visitor) override;
  2070. template <typename Handler> void serialize(Handler & h, const int version)
  2071. {
  2072. h & static_cast<CPackForServer &>(*this);
  2073. h & id;
  2074. }
  2075. };
  2076. struct DLL_LINKAGE CastAdvSpell : public CPackForServer
  2077. {
  2078. ObjectInstanceID hid; //hero id
  2079. SpellID sid; //spell id
  2080. int3 pos; //selected tile (not always used)
  2081. virtual void visitTyped(ICPackVisitor & visitor) override;
  2082. template <typename Handler> void serialize(Handler & h, const int version)
  2083. {
  2084. h & static_cast<CPackForServer &>(*this);
  2085. h & hid;
  2086. h & sid;
  2087. h & pos;
  2088. }
  2089. };
  2090. /***********************************************************************************************************/
  2091. struct DLL_LINKAGE SaveGame : public CPackForServer
  2092. {
  2093. SaveGame() = default;
  2094. SaveGame(std::string Fname)
  2095. : fname(std::move(Fname))
  2096. {
  2097. }
  2098. std::string fname;
  2099. void applyGs(CGameState * gs) {};
  2100. virtual void visitTyped(ICPackVisitor & visitor) override;
  2101. template <typename Handler> void serialize(Handler & h, const int version)
  2102. {
  2103. h & static_cast<CPackForServer &>(*this);
  2104. h & fname;
  2105. }
  2106. };
  2107. struct DLL_LINKAGE PlayerMessage : public CPackForServer
  2108. {
  2109. PlayerMessage() = default;
  2110. PlayerMessage(std::string Text, const ObjectInstanceID & obj)
  2111. : text(std::move(Text))
  2112. , currObj(obj)
  2113. {
  2114. }
  2115. void applyGs(CGameState * gs) {};
  2116. virtual void visitTyped(ICPackVisitor & visitor) override;
  2117. std::string text;
  2118. ObjectInstanceID currObj; // optional parameter that specifies current object. For cheats :)
  2119. template <typename Handler> void serialize(Handler & h, const int version)
  2120. {
  2121. h & static_cast<CPackForServer &>(*this);
  2122. h & text;
  2123. h & currObj;
  2124. }
  2125. };
  2126. struct DLL_LINKAGE PlayerMessageClient : public CPackForClient
  2127. {
  2128. PlayerMessageClient() = default;
  2129. PlayerMessageClient(const PlayerColor & Player, std::string Text)
  2130. : player(Player)
  2131. , text(std::move(Text))
  2132. {
  2133. }
  2134. virtual void visitTyped(ICPackVisitor & visitor) override;
  2135. PlayerColor player;
  2136. std::string text;
  2137. template <typename Handler> void serialize(Handler & h, const int version)
  2138. {
  2139. h & player;
  2140. h & text;
  2141. }
  2142. };
  2143. struct DLL_LINKAGE CenterView : public CPackForClient
  2144. {
  2145. PlayerColor player;
  2146. int3 pos;
  2147. ui32 focusTime = 0; //ms
  2148. virtual void visitTyped(ICPackVisitor & visitor) override;
  2149. template <typename Handler> void serialize(Handler & h, const int version)
  2150. {
  2151. h & pos;
  2152. h & player;
  2153. h & focusTime;
  2154. }
  2155. };
  2156. VCMI_LIB_NAMESPACE_END