NetPacks.h 64 KB

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