NetPacks.h 61 KB

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