NetPacks.h 64 KB

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