NetPacks.h 64 KB

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