NetPacks.h 63 KB

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