NetPacks.h 60 KB

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