NetPacks.h 60 KB

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