NetPacks.h 60 KB

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