NetPacks.h 59 KB

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