NetPacks.h 61 KB

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