NetPacks.h 63 KB

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