NetPacks.h 60 KB

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