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