NetPacks.h 60 KB

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