2
0

PacksForClient.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536
  1. /*
  2. * PacksForClient.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 "ArtifactLocation.h"
  12. #include "Component.h"
  13. #include "EInfoWindowMode.h"
  14. #include "EOpenWindowMode.h"
  15. #include "EntityChanges.h"
  16. #include "NetPacksBase.h"
  17. #include "../CCreatureSet.h"
  18. #include "../MetaString.h"
  19. #include "../ResourceSet.h"
  20. #include "../TurnTimerInfo.h"
  21. #include "../gameState/EVictoryLossCheckResult.h"
  22. #include "../gameState/QuestInfo.h"
  23. #include "../gameState/TavernSlot.h"
  24. #include "../int3.h"
  25. #include "../mapping/CMapDefines.h"
  26. #include "../spells/ViewSpellInt.h"
  27. class CClient;
  28. class CGameHandler;
  29. VCMI_LIB_NAMESPACE_BEGIN
  30. class CGameState;
  31. class CArtifact;
  32. class CGObjectInstance;
  33. class CArtifactInstance;
  34. struct StackLocation;
  35. struct ArtSlotInfo;
  36. struct QuestInfo;
  37. class IBattleState;
  38. class BattleInfo;
  39. // This one teleport-specific, but has to be available everywhere in callbacks and netpacks
  40. // For now it's will be there till teleports code refactored and moved into own file
  41. using TTeleportExitsList = std::vector<std::pair<ObjectInstanceID, int3>>;
  42. /***********************************************************************************************************/
  43. struct DLL_LINKAGE PackageApplied : public CPackForClient
  44. {
  45. PackageApplied() = default;
  46. explicit PackageApplied(ui8 Result)
  47. : result(Result)
  48. {
  49. }
  50. void visitTyped(ICPackVisitor & visitor) override;
  51. ui8 result = 0; //0 - something went wrong, request hasn't been realized; 1 - OK
  52. ui32 packType = 0; //type id of applied package
  53. ui32 requestID = 0; //an ID given by client to the request that was applied
  54. PlayerColor player;
  55. template <typename Handler> void serialize(Handler & h, const int version)
  56. {
  57. h & result;
  58. h & packType;
  59. h & requestID;
  60. h & player;
  61. }
  62. };
  63. struct DLL_LINKAGE SystemMessage : public CPackForClient
  64. {
  65. explicit SystemMessage(std::string Text)
  66. : text(std::move(Text))
  67. {
  68. }
  69. SystemMessage() = default;
  70. void visitTyped(ICPackVisitor & visitor) override;
  71. std::string text;
  72. template <typename Handler> void serialize(Handler & h, const int version)
  73. {
  74. h & text;
  75. }
  76. };
  77. struct DLL_LINKAGE PlayerBlocked : public CPackForClient
  78. {
  79. enum EReason { UPCOMING_BATTLE, ONGOING_MOVEMENT };
  80. enum EMode { BLOCKADE_STARTED, BLOCKADE_ENDED };
  81. EReason reason = UPCOMING_BATTLE;
  82. EMode startOrEnd = BLOCKADE_STARTED;
  83. PlayerColor player;
  84. void visitTyped(ICPackVisitor & visitor) override;
  85. template <typename Handler> void serialize(Handler & h, const int version)
  86. {
  87. h & reason;
  88. h & startOrEnd;
  89. h & player;
  90. }
  91. };
  92. struct DLL_LINKAGE PlayerCheated : public CPackForClient
  93. {
  94. void applyGs(CGameState * gs) const;
  95. PlayerColor player;
  96. bool losingCheatCode = false;
  97. bool winningCheatCode = false;
  98. void visitTyped(ICPackVisitor & visitor) override;
  99. template <typename Handler> void serialize(Handler & h, const int version)
  100. {
  101. h & player;
  102. h & losingCheatCode;
  103. h & winningCheatCode;
  104. }
  105. };
  106. struct DLL_LINKAGE TurnTimeUpdate : public CPackForClient
  107. {
  108. void applyGs(CGameState * gs) const;
  109. PlayerColor player;
  110. TurnTimerInfo turnTimer;
  111. template <typename Handler> void serialize(Handler & h, const int version)
  112. {
  113. h & player;
  114. h & turnTimer;
  115. }
  116. };
  117. struct DLL_LINKAGE PlayerStartsTurn : public Query
  118. {
  119. void applyGs(CGameState * gs) const;
  120. PlayerColor player;
  121. void visitTyped(ICPackVisitor & visitor) override;
  122. template <typename Handler> void serialize(Handler & h, const int version)
  123. {
  124. h & queryID;
  125. h & player;
  126. }
  127. };
  128. struct DLL_LINKAGE DaysWithoutTown : public CPackForClient
  129. {
  130. void applyGs(CGameState * gs) const;
  131. PlayerColor player;
  132. std::optional<int32_t> daysWithoutCastle;
  133. void visitTyped(ICPackVisitor & visitor) override;
  134. template <typename Handler> void serialize(Handler & h, const int version)
  135. {
  136. h & player;
  137. h & daysWithoutCastle;
  138. }
  139. };
  140. struct DLL_LINKAGE EntitiesChanged : public CPackForClient
  141. {
  142. std::vector<EntityChanges> changes;
  143. void applyGs(CGameState * gs);
  144. void visitTyped(ICPackVisitor & visitor) override;
  145. template <typename Handler> void serialize(Handler & h, const int version)
  146. {
  147. h & changes;
  148. }
  149. };
  150. struct DLL_LINKAGE SetResources : public CPackForClient
  151. {
  152. void applyGs(CGameState * gs) const;
  153. void visitTyped(ICPackVisitor & visitor) override;
  154. bool abs = true; //false - changes by value; 1 - sets to value
  155. PlayerColor player;
  156. ResourceSet res; //res[resid] => res amount
  157. template <typename Handler> void serialize(Handler & h, const int version)
  158. {
  159. h & abs;
  160. h & player;
  161. h & res;
  162. }
  163. };
  164. struct DLL_LINKAGE SetPrimSkill : public CPackForClient
  165. {
  166. void applyGs(CGameState * gs) const;
  167. void visitTyped(ICPackVisitor & visitor) override;
  168. ui8 abs = 0; //0 - changes by value; 1 - sets to value
  169. ObjectInstanceID id;
  170. PrimarySkill which = PrimarySkill::ATTACK;
  171. si64 val = 0;
  172. template <typename Handler> void serialize(Handler & h, const int version)
  173. {
  174. h & abs;
  175. h & id;
  176. h & which;
  177. h & val;
  178. }
  179. };
  180. struct DLL_LINKAGE SetSecSkill : public CPackForClient
  181. {
  182. void applyGs(CGameState * gs) const;
  183. void visitTyped(ICPackVisitor & visitor) override;
  184. ui8 abs = 0; //0 - changes by value; 1 - sets to value
  185. ObjectInstanceID id;
  186. SecondarySkill which;
  187. ui16 val = 0;
  188. template <typename Handler> void serialize(Handler & h, const int version)
  189. {
  190. h & abs;
  191. h & id;
  192. h & which;
  193. h & val;
  194. }
  195. };
  196. struct DLL_LINKAGE HeroVisitCastle : public CPackForClient
  197. {
  198. void applyGs(CGameState * gs) const;
  199. void visitTyped(ICPackVisitor & visitor) override;
  200. ui8 flags = 0; //1 - start
  201. ObjectInstanceID tid, hid;
  202. bool start() const //if hero is entering castle (if false - leaving)
  203. {
  204. return flags & 1;
  205. }
  206. template <typename Handler> void serialize(Handler & h, const int version)
  207. {
  208. h & flags;
  209. h & tid;
  210. h & hid;
  211. }
  212. };
  213. struct DLL_LINKAGE ChangeSpells : public CPackForClient
  214. {
  215. void applyGs(CGameState * gs);
  216. void visitTyped(ICPackVisitor & visitor) override;
  217. ui8 learn = 1; //1 - gives spell, 0 - takes
  218. ObjectInstanceID hid;
  219. std::set<SpellID> spells;
  220. template <typename Handler> void serialize(Handler & h, const int version)
  221. {
  222. h & learn;
  223. h & hid;
  224. h & spells;
  225. }
  226. };
  227. struct DLL_LINKAGE SetMana : public CPackForClient
  228. {
  229. void applyGs(CGameState * gs) const;
  230. void visitTyped(ICPackVisitor & visitor) override;
  231. ObjectInstanceID hid;
  232. si32 val = 0;
  233. bool absolute = true;
  234. template <typename Handler> void serialize(Handler & h, const int version)
  235. {
  236. h & val;
  237. h & hid;
  238. h & absolute;
  239. }
  240. };
  241. struct DLL_LINKAGE SetMovePoints : public CPackForClient
  242. {
  243. void applyGs(CGameState * gs) const;
  244. ObjectInstanceID hid;
  245. si32 val = 0;
  246. bool absolute = true;
  247. void visitTyped(ICPackVisitor & visitor) override;
  248. template <typename Handler> void serialize(Handler & h, const int version)
  249. {
  250. h & val;
  251. h & hid;
  252. h & absolute;
  253. }
  254. };
  255. struct DLL_LINKAGE FoWChange : public CPackForClient
  256. {
  257. void applyGs(CGameState * gs);
  258. std::unordered_set<int3> tiles;
  259. PlayerColor player;
  260. ETileVisibility mode;
  261. bool waitForDialogs = false;
  262. void visitTyped(ICPackVisitor & visitor) override;
  263. template <typename Handler> void serialize(Handler & h, const int version)
  264. {
  265. h & tiles;
  266. h & player;
  267. h & mode;
  268. h & waitForDialogs;
  269. }
  270. };
  271. struct DLL_LINKAGE SetAvailableHero : public CPackForClient
  272. {
  273. SetAvailableHero()
  274. {
  275. army.clearSlots();
  276. }
  277. void applyGs(CGameState * gs);
  278. TavernHeroSlot slotID;
  279. TavernSlotRole roleID;
  280. PlayerColor player;
  281. HeroTypeID hid; //HeroTypeID::NONE if no hero
  282. CSimpleArmy army;
  283. void visitTyped(ICPackVisitor & visitor) override;
  284. template <typename Handler> void serialize(Handler & h, const int version)
  285. {
  286. h & slotID;
  287. h & roleID;
  288. h & player;
  289. h & hid;
  290. h & army;
  291. }
  292. };
  293. struct DLL_LINKAGE GiveBonus : public CPackForClient
  294. {
  295. enum class ETarget : ui8 { HERO, PLAYER, TOWN, BATTLE };
  296. explicit GiveBonus(ETarget Who = ETarget::HERO)
  297. :who(Who)
  298. {
  299. }
  300. void applyGs(CGameState * gs);
  301. ETarget who = ETarget::HERO; //who receives bonus
  302. si32 id = 0; //hero. town or player id - whoever receives it
  303. Bonus bonus;
  304. MetaString bdescr;
  305. void visitTyped(ICPackVisitor & visitor) override;
  306. template <typename Handler> void serialize(Handler & h, const int version)
  307. {
  308. h & bonus;
  309. h & id;
  310. h & bdescr;
  311. h & who;
  312. assert(id != -1);
  313. }
  314. };
  315. struct DLL_LINKAGE ChangeObjPos : public CPackForClient
  316. {
  317. void applyGs(CGameState * gs);
  318. /// Object to move
  319. ObjectInstanceID objid;
  320. /// New position of visitable tile of an object
  321. int3 nPos;
  322. /// Player that initiated this action, if any
  323. PlayerColor initiator;
  324. void visitTyped(ICPackVisitor & visitor) override;
  325. template <typename Handler> void serialize(Handler & h, const int version)
  326. {
  327. h & objid;
  328. h & nPos;
  329. h & initiator;
  330. }
  331. };
  332. struct DLL_LINKAGE PlayerEndsTurn : public CPackForClient
  333. {
  334. void applyGs(CGameState * gs) const;
  335. PlayerColor player;
  336. void visitTyped(ICPackVisitor & visitor) override;
  337. template <typename Handler> void serialize(Handler & h, const int version)
  338. {
  339. h & player;
  340. }
  341. };
  342. struct DLL_LINKAGE PlayerEndsGame : public CPackForClient
  343. {
  344. void applyGs(CGameState * gs) const;
  345. PlayerColor player;
  346. EVictoryLossCheckResult victoryLossCheckResult;
  347. void visitTyped(ICPackVisitor & visitor) override;
  348. template <typename Handler> void serialize(Handler & h, const int version)
  349. {
  350. h & player;
  351. h & victoryLossCheckResult;
  352. }
  353. };
  354. struct DLL_LINKAGE PlayerReinitInterface : public CPackForClient
  355. {
  356. void applyGs(CGameState * gs);
  357. std::vector<PlayerColor> players;
  358. ui8 playerConnectionId; //PLAYER_AI for AI player
  359. void visitTyped(ICPackVisitor & visitor) override;
  360. template <typename Handler> void serialize(Handler & h, const int version)
  361. {
  362. h & players;
  363. h & playerConnectionId;
  364. }
  365. };
  366. struct DLL_LINKAGE RemoveBonus : public CPackForClient
  367. {
  368. explicit RemoveBonus(GiveBonus::ETarget Who = GiveBonus::ETarget::HERO)
  369. :who(Who)
  370. {
  371. }
  372. void applyGs(CGameState * gs);
  373. GiveBonus::ETarget who; //who receives bonus
  374. ui32 whoID = 0; //hero, town or player id - whoever loses bonus
  375. //vars to identify bonus: its source
  376. BonusSource source;
  377. BonusSourceID id; //source id
  378. //used locally: copy of removed bonus
  379. Bonus bonus;
  380. void visitTyped(ICPackVisitor & visitor) override;
  381. template <typename Handler> void serialize(Handler & h, const int version)
  382. {
  383. h & source;
  384. h & id;
  385. h & who;
  386. h & whoID;
  387. }
  388. };
  389. struct DLL_LINKAGE SetCommanderProperty : public CPackForClient
  390. {
  391. enum ECommanderProperty { ALIVE, BONUS, SECONDARY_SKILL, EXPERIENCE, SPECIAL_SKILL };
  392. void applyGs(CGameState * gs);
  393. ObjectInstanceID heroid;
  394. ECommanderProperty which = ALIVE;
  395. TExpType amount = 0; //0 for dead, >0 for alive
  396. si32 additionalInfo = 0; //for secondary skills choice
  397. Bonus accumulatedBonus;
  398. void visitTyped(ICPackVisitor & visitor) override;
  399. template <typename Handler> void serialize(Handler & h, const int version)
  400. {
  401. h & heroid;
  402. h & which;
  403. h & amount;
  404. h & additionalInfo;
  405. h & accumulatedBonus;
  406. }
  407. };
  408. struct DLL_LINKAGE AddQuest : public CPackForClient
  409. {
  410. void applyGs(CGameState * gs) const;
  411. PlayerColor player;
  412. QuestInfo quest;
  413. void visitTyped(ICPackVisitor & visitor) override;
  414. template <typename Handler> void serialize(Handler & h, const int version)
  415. {
  416. h & player;
  417. h & quest;
  418. }
  419. };
  420. struct DLL_LINKAGE UpdateArtHandlerLists : public CPackForClient
  421. {
  422. std::map<ArtifactID, int> allocatedArtifacts;
  423. void applyGs(CGameState * gs) const;
  424. void visitTyped(ICPackVisitor & visitor) override;
  425. template <typename Handler> void serialize(Handler & h, const int version)
  426. {
  427. h & allocatedArtifacts;
  428. }
  429. };
  430. struct DLL_LINKAGE UpdateMapEvents : public CPackForClient
  431. {
  432. std::list<CMapEvent> events;
  433. void applyGs(CGameState * gs) const;
  434. void visitTyped(ICPackVisitor & visitor) override;
  435. template <typename Handler> void serialize(Handler & h, const int version)
  436. {
  437. h & events;
  438. }
  439. };
  440. struct DLL_LINKAGE UpdateCastleEvents : public CPackForClient
  441. {
  442. ObjectInstanceID town;
  443. std::list<CCastleEvent> events;
  444. void applyGs(CGameState * gs) const;
  445. void visitTyped(ICPackVisitor & visitor) override;
  446. template <typename Handler> void serialize(Handler & h, const int version)
  447. {
  448. h & town;
  449. h & events;
  450. }
  451. };
  452. struct DLL_LINKAGE ChangeFormation : public CPackForClient
  453. {
  454. ObjectInstanceID hid;
  455. ui8 formation = 0;
  456. void applyGs(CGameState * gs) const;
  457. void visitTyped(ICPackVisitor & visitor) override;
  458. template <typename Handler> void serialize(Handler & h, const int version)
  459. {
  460. h & hid;
  461. h & formation;
  462. }
  463. };
  464. struct DLL_LINKAGE RemoveObject : public CPackForClient
  465. {
  466. RemoveObject() = default;
  467. RemoveObject(const ObjectInstanceID & objectID, const PlayerColor & initiator)
  468. : objectID(objectID)
  469. , initiator(initiator)
  470. {
  471. }
  472. void applyGs(CGameState * gs);
  473. void visitTyped(ICPackVisitor & visitor) override;
  474. /// ID of removed object
  475. ObjectInstanceID objectID;
  476. /// Player that initiated this action, if any
  477. PlayerColor initiator;
  478. template <typename Handler> void serialize(Handler & h, const int version)
  479. {
  480. h & objectID;
  481. h & initiator;
  482. }
  483. };
  484. struct DLL_LINKAGE TryMoveHero : public CPackForClient
  485. {
  486. void applyGs(CGameState * gs);
  487. enum EResult
  488. {
  489. FAILED,
  490. SUCCESS,
  491. TELEPORTATION,
  492. BLOCKING_VISIT,
  493. EMBARK,
  494. DISEMBARK
  495. };
  496. ObjectInstanceID id;
  497. ui32 movePoints = 0;
  498. EResult result = FAILED; //uses EResult
  499. int3 start, end; //h3m format
  500. std::unordered_set<int3> fowRevealed; //revealed tiles
  501. std::optional<int3> attackedFrom; // Set when stepping into endangered tile.
  502. void visitTyped(ICPackVisitor & visitor) override;
  503. bool stopMovement() const
  504. {
  505. return result != SUCCESS && result != EMBARK && result != DISEMBARK && result != TELEPORTATION;
  506. }
  507. template <typename Handler> void serialize(Handler & h, const int version)
  508. {
  509. h & id;
  510. h & result;
  511. h & start;
  512. h & end;
  513. h & movePoints;
  514. h & fowRevealed;
  515. h & attackedFrom;
  516. }
  517. };
  518. struct DLL_LINKAGE NewStructures : public CPackForClient
  519. {
  520. void applyGs(CGameState * gs);
  521. ObjectInstanceID tid;
  522. std::set<BuildingID> bid;
  523. si16 builded = 0;
  524. void visitTyped(ICPackVisitor & visitor) override;
  525. template <typename Handler> void serialize(Handler & h, const int version)
  526. {
  527. h & tid;
  528. h & bid;
  529. h & builded;
  530. }
  531. };
  532. struct DLL_LINKAGE RazeStructures : public CPackForClient
  533. {
  534. void applyGs(CGameState * gs);
  535. ObjectInstanceID tid;
  536. std::set<BuildingID> bid;
  537. si16 destroyed = 0;
  538. void visitTyped(ICPackVisitor & visitor) override;
  539. template <typename Handler> void serialize(Handler & h, const int version)
  540. {
  541. h & tid;
  542. h & bid;
  543. h & destroyed;
  544. }
  545. };
  546. struct DLL_LINKAGE SetAvailableCreatures : public CPackForClient
  547. {
  548. void applyGs(CGameState * gs) const;
  549. ObjectInstanceID tid;
  550. std::vector<std::pair<ui32, std::vector<CreatureID> > > creatures;
  551. void visitTyped(ICPackVisitor & visitor) override;
  552. template <typename Handler> void serialize(Handler & h, const int version)
  553. {
  554. h & tid;
  555. h & creatures;
  556. }
  557. };
  558. struct DLL_LINKAGE SetHeroesInTown : public CPackForClient
  559. {
  560. void applyGs(CGameState * gs) const;
  561. ObjectInstanceID tid, visiting, garrison; //id of town, visiting hero, hero in garrison
  562. void visitTyped(ICPackVisitor & visitor) override;
  563. template <typename Handler> void serialize(Handler & h, const int version)
  564. {
  565. h & tid;
  566. h & visiting;
  567. h & garrison;
  568. }
  569. };
  570. struct DLL_LINKAGE HeroRecruited : public CPackForClient
  571. {
  572. void applyGs(CGameState * gs) const;
  573. HeroTypeID hid; //subID of hero
  574. ObjectInstanceID tid;
  575. ObjectInstanceID boatId;
  576. int3 tile;
  577. PlayerColor player;
  578. void visitTyped(ICPackVisitor & visitor) override;
  579. template <typename Handler> void serialize(Handler & h, const int version)
  580. {
  581. h & hid;
  582. h & tid;
  583. h & boatId;
  584. h & tile;
  585. h & player;
  586. }
  587. };
  588. struct DLL_LINKAGE GiveHero : public CPackForClient
  589. {
  590. void applyGs(CGameState * gs) const;
  591. ObjectInstanceID id; //object id
  592. ObjectInstanceID boatId;
  593. PlayerColor player;
  594. void visitTyped(ICPackVisitor & visitor) override;
  595. template <typename Handler> void serialize(Handler & h, const int version)
  596. {
  597. h & id;
  598. h & boatId;
  599. h & player;
  600. }
  601. };
  602. struct DLL_LINKAGE OpenWindow : public Query
  603. {
  604. EOpenWindowMode window;
  605. ObjectInstanceID object;
  606. ObjectInstanceID visitor;
  607. void visitTyped(ICPackVisitor & visitor) override;
  608. template <typename Handler> void serialize(Handler & h, const int version)
  609. {
  610. h & queryID;
  611. h & window;
  612. h & object;
  613. h & visitor;
  614. }
  615. };
  616. struct DLL_LINKAGE NewObject : public CPackForClient
  617. {
  618. void applyGs(CGameState * gs);
  619. /// Object ID to create
  620. Obj ID;
  621. /// Object secondary ID to create
  622. ui32 subID = 0;
  623. /// Position of visitable tile of created object
  624. int3 targetPos;
  625. /// Which player initiated creation of this object
  626. PlayerColor initiator;
  627. ObjectInstanceID createdObjectID; //used locally, filled during applyGs
  628. void visitTyped(ICPackVisitor & visitor) override;
  629. template <typename Handler> void serialize(Handler & h, const int version)
  630. {
  631. h & ID;
  632. h & subID;
  633. h & targetPos;
  634. h & initiator;
  635. }
  636. };
  637. struct DLL_LINKAGE SetAvailableArtifacts : public CPackForClient
  638. {
  639. void applyGs(CGameState * gs) const;
  640. 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)
  641. std::vector<const CArtifact *> arts;
  642. void visitTyped(ICPackVisitor & visitor) override;
  643. template <typename Handler> void serialize(Handler & h, const int version)
  644. {
  645. h & id;
  646. h & arts;
  647. }
  648. };
  649. struct DLL_LINKAGE CGarrisonOperationPack : CPackForClient
  650. {
  651. };
  652. struct DLL_LINKAGE ChangeStackCount : CGarrisonOperationPack
  653. {
  654. ObjectInstanceID army;
  655. SlotID slot;
  656. TQuantity count;
  657. bool absoluteValue; //if not -> count will be added (or subtracted if negative)
  658. void applyGs(CGameState * gs);
  659. void visitTyped(ICPackVisitor & visitor) override;
  660. template <typename Handler> void serialize(Handler & h, const int version)
  661. {
  662. h & army;
  663. h & slot;
  664. h & count;
  665. h & absoluteValue;
  666. }
  667. };
  668. struct DLL_LINKAGE SetStackType : CGarrisonOperationPack
  669. {
  670. ObjectInstanceID army;
  671. SlotID slot;
  672. CreatureID type;
  673. void applyGs(CGameState * gs);
  674. void visitTyped(ICPackVisitor & visitor) override;
  675. template <typename Handler> void serialize(Handler & h, const int version)
  676. {
  677. h & army;
  678. h & slot;
  679. h & type;
  680. }
  681. };
  682. struct DLL_LINKAGE EraseStack : CGarrisonOperationPack
  683. {
  684. ObjectInstanceID army;
  685. SlotID slot;
  686. void applyGs(CGameState * gs);
  687. void visitTyped(ICPackVisitor & visitor) override;
  688. template <typename Handler> void serialize(Handler & h, const int version)
  689. {
  690. h & army;
  691. h & slot;
  692. }
  693. };
  694. struct DLL_LINKAGE SwapStacks : CGarrisonOperationPack
  695. {
  696. ObjectInstanceID srcArmy;
  697. ObjectInstanceID dstArmy;
  698. SlotID srcSlot;
  699. SlotID dstSlot;
  700. void applyGs(CGameState * gs);
  701. void visitTyped(ICPackVisitor & visitor) override;
  702. template <typename Handler> void serialize(Handler & h, const int version)
  703. {
  704. h & srcArmy;
  705. h & dstArmy;
  706. h & srcSlot;
  707. h & dstSlot;
  708. }
  709. };
  710. struct DLL_LINKAGE InsertNewStack : CGarrisonOperationPack
  711. {
  712. ObjectInstanceID army;
  713. SlotID slot;
  714. CreatureID type;
  715. TQuantity count = 0;
  716. void applyGs(CGameState * gs);
  717. void visitTyped(ICPackVisitor & visitor) override;
  718. template <typename Handler> void serialize(Handler & h, const int version)
  719. {
  720. h & army;
  721. h & slot;
  722. h & type;
  723. h & count;
  724. }
  725. };
  726. ///moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  727. struct DLL_LINKAGE RebalanceStacks : CGarrisonOperationPack
  728. {
  729. ObjectInstanceID srcArmy;
  730. ObjectInstanceID dstArmy;
  731. SlotID srcSlot;
  732. SlotID dstSlot;
  733. TQuantity count;
  734. void applyGs(CGameState * gs);
  735. void visitTyped(ICPackVisitor & visitor) override;
  736. template <typename Handler> void serialize(Handler & h, const int version)
  737. {
  738. h & srcArmy;
  739. h & dstArmy;
  740. h & srcSlot;
  741. h & dstSlot;
  742. h & count;
  743. }
  744. };
  745. struct DLL_LINKAGE BulkRebalanceStacks : CGarrisonOperationPack
  746. {
  747. std::vector<RebalanceStacks> moves;
  748. void applyGs(CGameState * gs);
  749. void visitTyped(ICPackVisitor & visitor) override;
  750. template <typename Handler>
  751. void serialize(Handler & h, const int version)
  752. {
  753. h & moves;
  754. }
  755. };
  756. struct DLL_LINKAGE BulkSmartRebalanceStacks : CGarrisonOperationPack
  757. {
  758. std::vector<RebalanceStacks> moves;
  759. std::vector<ChangeStackCount> changes;
  760. void applyGs(CGameState * gs);
  761. void visitTyped(ICPackVisitor & visitor) override;
  762. template <typename Handler>
  763. void serialize(Handler & h, const int version)
  764. {
  765. h & moves;
  766. h & changes;
  767. }
  768. };
  769. struct DLL_LINKAGE CArtifactOperationPack : CPackForClient
  770. {
  771. };
  772. struct DLL_LINKAGE PutArtifact : CArtifactOperationPack
  773. {
  774. PutArtifact() = default;
  775. explicit PutArtifact(ArtifactLocation * dst, bool askAssemble = true)
  776. : al(*dst), askAssemble(askAssemble)
  777. {
  778. }
  779. ArtifactLocation al;
  780. bool askAssemble = false;
  781. ConstTransitivePtr<CArtifactInstance> art;
  782. void applyGs(CGameState * gs);
  783. void visitTyped(ICPackVisitor & visitor) override;
  784. template <typename Handler> void serialize(Handler & h, const int version)
  785. {
  786. h & al;
  787. h & askAssemble;
  788. h & art;
  789. }
  790. };
  791. struct DLL_LINKAGE NewArtifact : public CArtifactOperationPack
  792. {
  793. ConstTransitivePtr<CArtifactInstance> art;
  794. void applyGs(CGameState * gs);
  795. void visitTyped(ICPackVisitor & visitor) override;
  796. template <typename Handler> void serialize(Handler & h, const int version)
  797. {
  798. h & art;
  799. }
  800. };
  801. struct DLL_LINKAGE EraseArtifact : CArtifactOperationPack
  802. {
  803. ArtifactLocation al;
  804. void applyGs(CGameState * gs);
  805. void visitTyped(ICPackVisitor & visitor) override;
  806. template <typename Handler> void serialize(Handler & h, const int version)
  807. {
  808. h & al;
  809. }
  810. };
  811. struct DLL_LINKAGE MoveArtifact : CArtifactOperationPack
  812. {
  813. MoveArtifact() = default;
  814. MoveArtifact(ArtifactLocation * src, ArtifactLocation * dst, bool askAssemble = true)
  815. : src(*src), dst(*dst), askAssemble(askAssemble)
  816. {
  817. }
  818. ArtifactLocation src, dst;
  819. bool askAssemble = true;
  820. void applyGs(CGameState * gs);
  821. void visitTyped(ICPackVisitor & visitor) override;
  822. template <typename Handler> void serialize(Handler & h, const int version)
  823. {
  824. h & src;
  825. h & dst;
  826. h & askAssemble;
  827. }
  828. };
  829. struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
  830. {
  831. struct LinkedSlots
  832. {
  833. ArtifactPosition srcPos;
  834. ArtifactPosition dstPos;
  835. LinkedSlots() = default;
  836. LinkedSlots(const ArtifactPosition & srcPos, const ArtifactPosition & dstPos)
  837. : srcPos(srcPos)
  838. , dstPos(dstPos)
  839. {
  840. }
  841. template <typename Handler> void serialize(Handler & h, const int version)
  842. {
  843. h & srcPos;
  844. h & dstPos;
  845. }
  846. };
  847. ObjectInstanceID srcArtHolder;
  848. ObjectInstanceID dstArtHolder;
  849. BulkMoveArtifacts()
  850. : srcArtHolder(ObjectInstanceID::NONE)
  851. , dstArtHolder(ObjectInstanceID::NONE)
  852. , swap(false)
  853. {
  854. }
  855. BulkMoveArtifacts(const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
  856. : srcArtHolder(std::move(srcArtHolder))
  857. , dstArtHolder(std::move(dstArtHolder))
  858. , swap(swap)
  859. {
  860. }
  861. void applyGs(CGameState * gs);
  862. std::vector<LinkedSlots> artsPack0;
  863. std::vector<LinkedSlots> artsPack1;
  864. bool swap;
  865. void visitTyped(ICPackVisitor & visitor) override;
  866. template <typename Handler> void serialize(Handler & h, const int version)
  867. {
  868. h & artsPack0;
  869. h & artsPack1;
  870. h & srcArtHolder;
  871. h & dstArtHolder;
  872. h & swap;
  873. }
  874. };
  875. struct DLL_LINKAGE AssembledArtifact : CArtifactOperationPack
  876. {
  877. ArtifactLocation al; //where assembly will be put
  878. CArtifact * builtArt;
  879. void applyGs(CGameState * gs);
  880. void visitTyped(ICPackVisitor & visitor) override;
  881. template <typename Handler> void serialize(Handler & h, const int version)
  882. {
  883. h & al;
  884. h & builtArt;
  885. }
  886. };
  887. struct DLL_LINKAGE DisassembledArtifact : CArtifactOperationPack
  888. {
  889. ArtifactLocation al;
  890. void applyGs(CGameState * gs);
  891. void visitTyped(ICPackVisitor & visitor) override;
  892. template <typename Handler> void serialize(Handler & h, const int version)
  893. {
  894. h & al;
  895. }
  896. };
  897. struct DLL_LINKAGE HeroVisit : public CPackForClient
  898. {
  899. PlayerColor player;
  900. ObjectInstanceID heroId;
  901. ObjectInstanceID objId;
  902. bool starting; //false -> ending
  903. void applyGs(CGameState * gs);
  904. void visitTyped(ICPackVisitor & visitor) override;
  905. template <typename Handler> void serialize(Handler & h, const int version)
  906. {
  907. h & player;
  908. h & heroId;
  909. h & objId;
  910. h & starting;
  911. }
  912. };
  913. struct DLL_LINKAGE NewTurn : public CPackForClient
  914. {
  915. enum weekType { NORMAL, DOUBLE_GROWTH, BONUS_GROWTH, DEITYOFFIRE, PLAGUE, NO_ACTION };
  916. void applyGs(CGameState * gs);
  917. void visitTyped(ICPackVisitor & visitor) override;
  918. struct Hero
  919. {
  920. ObjectInstanceID id;
  921. ui32 move, mana; //id is a general serial id
  922. template <typename Handler> void serialize(Handler & h, const int version)
  923. {
  924. h & id;
  925. h & move;
  926. h & mana;
  927. }
  928. bool operator<(const Hero & h)const { return id < h.id; }
  929. };
  930. std::set<Hero> heroes; //updates movement and mana points
  931. std::map<PlayerColor, ResourceSet> res; //player ID => resource value[res_id]
  932. std::map<ObjectInstanceID, SetAvailableCreatures> cres;//creatures to be placed in towns
  933. ui32 day = 0;
  934. ui8 specialWeek = 0; //weekType
  935. CreatureID creatureid; //for creature weeks
  936. NewTurn() = default;
  937. template <typename Handler> void serialize(Handler & h, const int version)
  938. {
  939. h & heroes;
  940. h & cres;
  941. h & res;
  942. h & day;
  943. h & specialWeek;
  944. h & creatureid;
  945. }
  946. };
  947. struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
  948. {
  949. EInfoWindowMode type = EInfoWindowMode::MODAL;
  950. MetaString text;
  951. std::vector<Component> components;
  952. PlayerColor player;
  953. ui16 soundID = 0;
  954. void visitTyped(ICPackVisitor & visitor) override;
  955. template <typename Handler> void serialize(Handler & h, const int version)
  956. {
  957. h & type;
  958. h & text;
  959. h & components;
  960. h & player;
  961. h & soundID;
  962. }
  963. InfoWindow() = default;
  964. };
  965. namespace ObjProperty
  966. {
  967. enum
  968. {
  969. OWNER = 1, BLOCKVIS = 2, PRIMARY_STACK_COUNT = 3, VISITORS = 4, VISITED = 5, ID = 6, AVAILABLE_CREATURE = 7, SUBID = 8,
  970. MONSTER_COUNT = 10, MONSTER_POWER = 11, MONSTER_EXP = 12, MONSTER_RESTORE_TYPE = 13, MONSTER_REFUSED_JOIN,
  971. //town-specific
  972. STRUCTURE_ADD_VISITING_HERO, STRUCTURE_CLEAR_VISITORS, STRUCTURE_ADD_GARRISONED_HERO, //changing buildings state
  973. BONUS_VALUE_FIRST, BONUS_VALUE_SECOND, //used in Rampart for special building that generates resources (storing resource type and quantity)
  974. //creature-bank specific
  975. BANK_DAYCOUNTER, BANK_RESET, BANK_CLEAR,
  976. //object with reward
  977. REWARD_RANDOMIZE, REWARD_SELECT, REWARD_CLEARED
  978. };
  979. }
  980. struct DLL_LINKAGE SetObjectProperty : public CPackForClient
  981. {
  982. void applyGs(CGameState * gs) const;
  983. ObjectInstanceID id;
  984. ui8 what = 0; // see ObjProperty enum
  985. ui32 val = 0;
  986. SetObjectProperty() = default;
  987. SetObjectProperty(const ObjectInstanceID & ID, ui8 What, ui32 Val)
  988. : id(ID)
  989. , what(What)
  990. , val(Val)
  991. {
  992. }
  993. void visitTyped(ICPackVisitor & visitor) override;
  994. template <typename Handler> void serialize(Handler & h, const int version)
  995. {
  996. h & id;
  997. h & what;
  998. h & val;
  999. }
  1000. };
  1001. struct DLL_LINKAGE ChangeObjectVisitors : public CPackForClient
  1002. {
  1003. enum VisitMode
  1004. {
  1005. VISITOR_ADD, // mark hero as one that have visited this object
  1006. VISITOR_ADD_TEAM, // mark team as one that have visited this object
  1007. VISITOR_REMOVE, // unmark visitor, reversed to ADD
  1008. VISITOR_CLEAR // clear all visitors from this object (object reset)
  1009. };
  1010. ui32 mode = VISITOR_CLEAR; // uses VisitMode enum
  1011. ObjectInstanceID object;
  1012. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  1013. void applyGs(CGameState * gs) const;
  1014. void visitTyped(ICPackVisitor & visitor) override;
  1015. ChangeObjectVisitors() = default;
  1016. ChangeObjectVisitors(ui32 mode, const ObjectInstanceID & object, const ObjectInstanceID & heroID = ObjectInstanceID(-1))
  1017. : mode(mode)
  1018. , object(object)
  1019. , hero(heroID)
  1020. {
  1021. }
  1022. template <typename Handler> void serialize(Handler & h, const int version)
  1023. {
  1024. h & object;
  1025. h & hero;
  1026. h & mode;
  1027. }
  1028. };
  1029. struct DLL_LINKAGE PrepareHeroLevelUp : public CPackForClient
  1030. {
  1031. ObjectInstanceID heroId;
  1032. /// Do not serialize, used by server only
  1033. std::vector<SecondarySkill> skills;
  1034. void applyGs(CGameState * gs);
  1035. void visitTyped(ICPackVisitor & visitor) override;
  1036. template <typename Handler> void serialize(Handler & h, const int version)
  1037. {
  1038. h & heroId;
  1039. }
  1040. };
  1041. struct DLL_LINKAGE HeroLevelUp : public Query
  1042. {
  1043. PlayerColor player;
  1044. ObjectInstanceID heroId;
  1045. PrimarySkill primskill = PrimarySkill::ATTACK;
  1046. std::vector<SecondarySkill> skills;
  1047. void applyGs(CGameState * gs) const;
  1048. void visitTyped(ICPackVisitor & visitor) override;
  1049. template <typename Handler> void serialize(Handler & h, const int version)
  1050. {
  1051. h & queryID;
  1052. h & player;
  1053. h & heroId;
  1054. h & primskill;
  1055. h & skills;
  1056. }
  1057. };
  1058. struct DLL_LINKAGE CommanderLevelUp : public Query
  1059. {
  1060. PlayerColor player;
  1061. ObjectInstanceID heroId;
  1062. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1063. void applyGs(CGameState * gs) const;
  1064. void visitTyped(ICPackVisitor & visitor) override;
  1065. template <typename Handler> void serialize(Handler & h, const int version)
  1066. {
  1067. h & queryID;
  1068. h & player;
  1069. h & heroId;
  1070. h & skills;
  1071. }
  1072. };
  1073. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1074. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1075. //Until sending reply player won't be allowed to take any actions
  1076. struct DLL_LINKAGE BlockingDialog : public Query
  1077. {
  1078. enum { ALLOW_CANCEL = 1, SELECTION = 2 };
  1079. MetaString text;
  1080. std::vector<Component> components;
  1081. PlayerColor player;
  1082. ui8 flags = 0;
  1083. ui16 soundID = 0;
  1084. bool cancel() const
  1085. {
  1086. return flags & ALLOW_CANCEL;
  1087. }
  1088. bool selection() const
  1089. {
  1090. return flags & SELECTION;
  1091. }
  1092. BlockingDialog(bool yesno, bool Selection)
  1093. {
  1094. if(yesno) flags |= ALLOW_CANCEL;
  1095. if(Selection) flags |= SELECTION;
  1096. }
  1097. BlockingDialog() = default;
  1098. void visitTyped(ICPackVisitor & visitor) override;
  1099. template <typename Handler> void serialize(Handler & h, const int version)
  1100. {
  1101. h & queryID;
  1102. h & text;
  1103. h & components;
  1104. h & player;
  1105. h & flags;
  1106. h & soundID;
  1107. }
  1108. };
  1109. struct DLL_LINKAGE GarrisonDialog : public Query
  1110. {
  1111. ObjectInstanceID objid, hid;
  1112. bool removableUnits = false;
  1113. void visitTyped(ICPackVisitor & visitor) override;
  1114. template <typename Handler> void serialize(Handler & h, const int version)
  1115. {
  1116. h & queryID;
  1117. h & objid;
  1118. h & hid;
  1119. h & removableUnits;
  1120. }
  1121. };
  1122. struct DLL_LINKAGE ExchangeDialog : public Query
  1123. {
  1124. PlayerColor player;
  1125. ObjectInstanceID hero1;
  1126. ObjectInstanceID hero2;
  1127. void visitTyped(ICPackVisitor & visitor) override;
  1128. template <typename Handler> void serialize(Handler & h, const int version)
  1129. {
  1130. h & queryID;
  1131. h & player;
  1132. h & hero1;
  1133. h & hero2;
  1134. }
  1135. };
  1136. struct DLL_LINKAGE TeleportDialog : public Query
  1137. {
  1138. TeleportDialog() = default;
  1139. TeleportDialog(const ObjectInstanceID & hero, const TeleportChannelID & Channel)
  1140. : hero(hero)
  1141. , channel(Channel)
  1142. {
  1143. }
  1144. ObjectInstanceID hero;
  1145. TeleportChannelID channel;
  1146. TTeleportExitsList exits;
  1147. bool impassable = false;
  1148. void visitTyped(ICPackVisitor & visitor) override;
  1149. template <typename Handler> void serialize(Handler & h, const int version)
  1150. {
  1151. h & queryID;
  1152. h & hero;
  1153. h & channel;
  1154. h & exits;
  1155. h & impassable;
  1156. }
  1157. };
  1158. struct DLL_LINKAGE MapObjectSelectDialog : public Query
  1159. {
  1160. PlayerColor player;
  1161. Component icon;
  1162. MetaString title;
  1163. MetaString description;
  1164. std::vector<ObjectInstanceID> objects;
  1165. void visitTyped(ICPackVisitor & visitor) override;
  1166. template <typename Handler> void serialize(Handler & h, const int version)
  1167. {
  1168. h & queryID;
  1169. h & player;
  1170. h & icon;
  1171. h & title;
  1172. h & description;
  1173. h & objects;
  1174. }
  1175. };
  1176. struct DLL_LINKAGE AdvmapSpellCast : public CPackForClient
  1177. {
  1178. ObjectInstanceID casterID;
  1179. SpellID spellID;
  1180. template <typename Handler> void serialize(Handler & h, const int version)
  1181. {
  1182. h & casterID;
  1183. h & spellID;
  1184. }
  1185. protected:
  1186. void visitTyped(ICPackVisitor & visitor) override;
  1187. };
  1188. struct DLL_LINKAGE ShowWorldViewEx : public CPackForClient
  1189. {
  1190. PlayerColor player;
  1191. bool showTerrain; // TODO: send terrain state
  1192. std::vector<ObjectPosInfo> objectPositions;
  1193. template <typename Handler> void serialize(Handler & h, const int version)
  1194. {
  1195. h & player;
  1196. h & showTerrain;
  1197. h & objectPositions;
  1198. }
  1199. protected:
  1200. void visitTyped(ICPackVisitor & visitor) override;
  1201. };
  1202. struct DLL_LINKAGE PlayerMessageClient : public CPackForClient
  1203. {
  1204. PlayerMessageClient() = default;
  1205. PlayerMessageClient(const PlayerColor & Player, std::string Text)
  1206. : player(Player)
  1207. , text(std::move(Text))
  1208. {
  1209. }
  1210. void visitTyped(ICPackVisitor & visitor) override;
  1211. PlayerColor player;
  1212. std::string text;
  1213. template <typename Handler> void serialize(Handler & h, const int version)
  1214. {
  1215. h & player;
  1216. h & text;
  1217. }
  1218. };
  1219. struct DLL_LINKAGE CenterView : public CPackForClient
  1220. {
  1221. PlayerColor player;
  1222. int3 pos;
  1223. ui32 focusTime = 0; //ms
  1224. void visitTyped(ICPackVisitor & visitor) override;
  1225. template <typename Handler> void serialize(Handler & h, const int version)
  1226. {
  1227. h & pos;
  1228. h & player;
  1229. h & focusTime;
  1230. }
  1231. };
  1232. VCMI_LIB_NAMESPACE_END