NetPacks.h 64 KB

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