NetPacks.h 60 KB

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