NetPacks.h 60 KB

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