NetPacks.h 61 KB

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