PacksForClient.h 31 KB

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