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