NetPacks.h 63 KB

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