NetPacks.h 61 KB

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