NetPacks.h 64 KB

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