NetPacks.h 61 KB

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