PacksForClient.h 30 KB

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