NetPacks.h 61 KB

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