NetPacks.h 60 KB

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