NetPacks.h 60 KB

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