PacksForClient.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  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 SetResearchedSpells : public CPackForClient
  234. {
  235. void applyGs(CGameState * gs) override;
  236. void visitTyped(ICPackVisitor & visitor) override;
  237. ui8 level = 0;
  238. ObjectInstanceID tid;
  239. std::vector<SpellID> spells;
  240. bool accepted;
  241. template <typename Handler> void serialize(Handler & h)
  242. {
  243. h & level;
  244. h & tid;
  245. h & spells;
  246. h & accepted;
  247. }
  248. };
  249. struct DLL_LINKAGE SetMana : public CPackForClient
  250. {
  251. void applyGs(CGameState * gs) override;
  252. void visitTyped(ICPackVisitor & visitor) override;
  253. SetMana() = default;
  254. SetMana(ObjectInstanceID hid, si32 val, bool absolute)
  255. : hid(hid)
  256. , val(val)
  257. , absolute(absolute)
  258. {}
  259. ObjectInstanceID hid;
  260. si32 val = 0;
  261. bool absolute = true;
  262. template <typename Handler> void serialize(Handler & h)
  263. {
  264. h & val;
  265. h & hid;
  266. h & absolute;
  267. }
  268. };
  269. struct DLL_LINKAGE SetMovePoints : public CPackForClient
  270. {
  271. void applyGs(CGameState * gs) override;
  272. SetMovePoints() = default;
  273. SetMovePoints(ObjectInstanceID hid, si32 val, bool absolute)
  274. : hid(hid)
  275. , val(val)
  276. , absolute(absolute)
  277. {}
  278. ObjectInstanceID hid;
  279. si32 val = 0;
  280. bool absolute = true;
  281. void visitTyped(ICPackVisitor & visitor) override;
  282. template <typename Handler> void serialize(Handler & h)
  283. {
  284. h & val;
  285. h & hid;
  286. h & absolute;
  287. }
  288. };
  289. struct DLL_LINKAGE FoWChange : public CPackForClient
  290. {
  291. void applyGs(CGameState * gs) override;
  292. std::unordered_set<int3> tiles;
  293. PlayerColor player;
  294. ETileVisibility mode;
  295. bool waitForDialogs = false;
  296. void visitTyped(ICPackVisitor & visitor) override;
  297. template <typename Handler> void serialize(Handler & h)
  298. {
  299. h & tiles;
  300. h & player;
  301. h & mode;
  302. h & waitForDialogs;
  303. }
  304. };
  305. struct DLL_LINKAGE SetAvailableHero : public CPackForClient
  306. {
  307. SetAvailableHero()
  308. {
  309. army.clearSlots();
  310. }
  311. void applyGs(CGameState * gs) override;
  312. TavernHeroSlot slotID;
  313. TavernSlotRole roleID;
  314. PlayerColor player;
  315. HeroTypeID hid; //HeroTypeID::NONE if no hero
  316. CSimpleArmy army;
  317. bool replenishPoints;
  318. void visitTyped(ICPackVisitor & visitor) override;
  319. template <typename Handler> void serialize(Handler & h)
  320. {
  321. h & slotID;
  322. h & roleID;
  323. h & player;
  324. h & hid;
  325. h & army;
  326. h & replenishPoints;
  327. }
  328. };
  329. struct DLL_LINKAGE GiveBonus : public CPackForClient
  330. {
  331. using VariantType = VariantIdentifier<ObjectInstanceID, PlayerColor, BattleID>;
  332. enum class ETarget : int8_t
  333. {
  334. OBJECT,
  335. PLAYER,
  336. BATTLE,
  337. HERO_COMMANDER
  338. };
  339. explicit GiveBonus(ETarget Who = ETarget::OBJECT)
  340. :who(Who)
  341. {
  342. }
  343. GiveBonus(ETarget who, const VariantType & id, const Bonus & bonus)
  344. : who(who)
  345. , id(id)
  346. , bonus(bonus)
  347. {
  348. }
  349. void applyGs(CGameState * gs) override;
  350. ETarget who = ETarget::OBJECT;
  351. VariantType id;
  352. Bonus bonus;
  353. void visitTyped(ICPackVisitor & visitor) override;
  354. template <typename Handler> void serialize(Handler & h)
  355. {
  356. h & bonus;
  357. h & id;
  358. h & who;
  359. assert(id.getNum() != -1);
  360. }
  361. };
  362. struct DLL_LINKAGE ChangeObjPos : public CPackForClient
  363. {
  364. void applyGs(CGameState * gs) override;
  365. /// Object to move
  366. ObjectInstanceID objid;
  367. /// New position of visitable tile of an object
  368. int3 nPos;
  369. /// Player that initiated this action, if any
  370. PlayerColor initiator;
  371. void visitTyped(ICPackVisitor & visitor) override;
  372. template <typename Handler> void serialize(Handler & h)
  373. {
  374. h & objid;
  375. h & nPos;
  376. h & initiator;
  377. }
  378. };
  379. struct DLL_LINKAGE PlayerEndsTurn : public CPackForClient
  380. {
  381. void applyGs(CGameState * gs) override;
  382. PlayerColor player;
  383. void visitTyped(ICPackVisitor & visitor) override;
  384. template <typename Handler> void serialize(Handler & h)
  385. {
  386. h & player;
  387. }
  388. };
  389. struct DLL_LINKAGE PlayerEndsGame : public CPackForClient
  390. {
  391. void applyGs(CGameState * gs) override;
  392. PlayerColor player;
  393. EVictoryLossCheckResult victoryLossCheckResult;
  394. StatisticDataSet statistic;
  395. void visitTyped(ICPackVisitor & visitor) override;
  396. template <typename Handler> void serialize(Handler & h)
  397. {
  398. h & player;
  399. h & victoryLossCheckResult;
  400. h & statistic;
  401. }
  402. };
  403. struct DLL_LINKAGE PlayerReinitInterface : public CPackForClient
  404. {
  405. void applyGs(CGameState * gs) override;
  406. std::vector<PlayerColor> players;
  407. ui8 playerConnectionId; //PLAYER_AI for AI player
  408. void visitTyped(ICPackVisitor & visitor) override;
  409. template <typename Handler> void serialize(Handler & h)
  410. {
  411. h & players;
  412. h & playerConnectionId;
  413. }
  414. };
  415. struct DLL_LINKAGE RemoveBonus : public CPackForClient
  416. {
  417. explicit RemoveBonus(GiveBonus::ETarget Who = GiveBonus::ETarget::OBJECT)
  418. :who(Who)
  419. {
  420. }
  421. void applyGs(CGameState * gs) override;
  422. GiveBonus::ETarget who; //who receives bonus
  423. VariantIdentifier<HeroTypeID, PlayerColor, BattleID, ObjectInstanceID> whoID;
  424. //vars to identify bonus: its source
  425. BonusSource source;
  426. BonusSourceID id; //source id
  427. //used locally: copy of removed bonus
  428. Bonus bonus;
  429. void visitTyped(ICPackVisitor & visitor) override;
  430. template <typename Handler> void serialize(Handler & h)
  431. {
  432. h & source;
  433. h & id;
  434. h & who;
  435. h & whoID;
  436. }
  437. };
  438. struct DLL_LINKAGE SetCommanderProperty : public CPackForClient
  439. {
  440. enum ECommanderProperty { ALIVE, BONUS, SECONDARY_SKILL, EXPERIENCE, SPECIAL_SKILL };
  441. void applyGs(CGameState * gs) override;
  442. ObjectInstanceID heroid;
  443. ECommanderProperty which = ALIVE;
  444. TExpType amount = 0; //0 for dead, >0 for alive
  445. si32 additionalInfo = 0; //for secondary skills choice
  446. Bonus accumulatedBonus;
  447. void visitTyped(ICPackVisitor & visitor) override;
  448. template <typename Handler> void serialize(Handler & h)
  449. {
  450. h & heroid;
  451. h & which;
  452. h & amount;
  453. h & additionalInfo;
  454. h & accumulatedBonus;
  455. }
  456. };
  457. struct DLL_LINKAGE AddQuest : public CPackForClient
  458. {
  459. void applyGs(CGameState * gs) override;
  460. PlayerColor player;
  461. QuestInfo quest;
  462. void visitTyped(ICPackVisitor & visitor) override;
  463. template <typename Handler> void serialize(Handler & h)
  464. {
  465. h & player;
  466. h & quest;
  467. }
  468. };
  469. struct DLL_LINKAGE UpdateArtHandlerLists : public CPackForClient
  470. {
  471. std::map<ArtifactID, int> allocatedArtifacts;
  472. void applyGs(CGameState * gs) override;
  473. void visitTyped(ICPackVisitor & visitor) override;
  474. template <typename Handler> void serialize(Handler & h)
  475. {
  476. h & allocatedArtifacts;
  477. }
  478. };
  479. struct DLL_LINKAGE ChangeFormation : public CPackForClient
  480. {
  481. ObjectInstanceID hid;
  482. EArmyFormation formation{};
  483. void applyGs(CGameState * gs) override;
  484. void visitTyped(ICPackVisitor & visitor) override;
  485. template <typename Handler> void serialize(Handler & h)
  486. {
  487. h & hid;
  488. h & formation;
  489. }
  490. };
  491. struct DLL_LINKAGE RemoveObject : public CPackForClient
  492. {
  493. RemoveObject() = default;
  494. RemoveObject(const ObjectInstanceID & objectID, const PlayerColor & initiator)
  495. : objectID(objectID)
  496. , initiator(initiator)
  497. {
  498. }
  499. void applyGs(CGameState * gs) override;
  500. void visitTyped(ICPackVisitor & visitor) override;
  501. /// ID of removed object
  502. ObjectInstanceID objectID;
  503. /// Player that initiated this action, if any
  504. PlayerColor initiator;
  505. template <typename Handler> void serialize(Handler & h)
  506. {
  507. h & objectID;
  508. h & initiator;
  509. }
  510. };
  511. struct DLL_LINKAGE TryMoveHero : public CPackForClient
  512. {
  513. void applyGs(CGameState * gs) override;
  514. enum EResult
  515. {
  516. FAILED,
  517. SUCCESS,
  518. TELEPORTATION,
  519. BLOCKING_VISIT,
  520. EMBARK,
  521. DISEMBARK
  522. };
  523. /// ID of moved hero
  524. ObjectInstanceID id;
  525. /// Movement points that hero will have after movement
  526. ui32 movePoints = 0;
  527. /// Result of movement attempt. FAILED should generally never happen unless client requested invalid operation
  528. EResult result = FAILED;
  529. /// Hero anchor position from which hero moves
  530. int3 start;
  531. /// Hero anchor position to which hero moves
  532. int3 end;
  533. /// Tiles that were revealed by this move
  534. std::unordered_set<int3> fowRevealed;
  535. /// If hero moves on guarded tile, this field will be set to visitable pos of attacked wandering monster
  536. int3 attackedFrom;
  537. void visitTyped(ICPackVisitor & visitor) override;
  538. bool stopMovement() const
  539. {
  540. return result != SUCCESS && result != EMBARK && result != DISEMBARK && result != TELEPORTATION;
  541. }
  542. template <typename Handler> void serialize(Handler & h)
  543. {
  544. h & id;
  545. h & result;
  546. h & start;
  547. h & end;
  548. h & movePoints;
  549. h & fowRevealed;
  550. h & attackedFrom;
  551. }
  552. };
  553. struct DLL_LINKAGE NewStructures : public CPackForClient
  554. {
  555. void applyGs(CGameState * gs) override;
  556. ObjectInstanceID tid;
  557. std::set<BuildingID> bid;
  558. si16 built = 0;
  559. void visitTyped(ICPackVisitor & visitor) override;
  560. template <typename Handler> void serialize(Handler & h)
  561. {
  562. h & tid;
  563. h & bid;
  564. h & built;
  565. }
  566. };
  567. struct DLL_LINKAGE RazeStructures : public CPackForClient
  568. {
  569. void applyGs(CGameState * gs) override;
  570. ObjectInstanceID tid;
  571. std::set<BuildingID> bid;
  572. si16 destroyed = 0;
  573. void visitTyped(ICPackVisitor & visitor) override;
  574. template <typename Handler> void serialize(Handler & h)
  575. {
  576. h & tid;
  577. h & bid;
  578. h & destroyed;
  579. }
  580. };
  581. struct DLL_LINKAGE SetAvailableCreatures : public CPackForClient
  582. {
  583. void applyGs(CGameState * gs) override;
  584. ObjectInstanceID tid;
  585. std::vector<std::pair<ui32, std::vector<CreatureID> > > creatures;
  586. void visitTyped(ICPackVisitor & visitor) override;
  587. template <typename Handler> void serialize(Handler & h)
  588. {
  589. h & tid;
  590. h & creatures;
  591. }
  592. };
  593. struct DLL_LINKAGE SetHeroesInTown : public CPackForClient
  594. {
  595. void applyGs(CGameState * gs) override;
  596. ObjectInstanceID tid; //id of town
  597. ObjectInstanceID visiting; //id of visiting hero
  598. ObjectInstanceID garrison; //id of hero in garrison
  599. void visitTyped(ICPackVisitor & visitor) override;
  600. template <typename Handler> void serialize(Handler & h)
  601. {
  602. h & tid;
  603. h & visiting;
  604. h & garrison;
  605. }
  606. };
  607. struct DLL_LINKAGE HeroRecruited : public CPackForClient
  608. {
  609. void applyGs(CGameState * gs) override;
  610. HeroTypeID hid; //subID of hero
  611. ObjectInstanceID tid;
  612. ObjectInstanceID boatId;
  613. int3 tile;
  614. PlayerColor player;
  615. void visitTyped(ICPackVisitor & visitor) override;
  616. template <typename Handler> void serialize(Handler & h)
  617. {
  618. h & hid;
  619. h & tid;
  620. h & boatId;
  621. h & tile;
  622. h & player;
  623. }
  624. };
  625. struct DLL_LINKAGE GiveHero : public CPackForClient
  626. {
  627. void applyGs(CGameState * gs) override;
  628. ObjectInstanceID id; //object id
  629. ObjectInstanceID boatId;
  630. PlayerColor player;
  631. void visitTyped(ICPackVisitor & visitor) override;
  632. template <typename Handler> void serialize(Handler & h)
  633. {
  634. h & id;
  635. h & boatId;
  636. h & player;
  637. }
  638. };
  639. struct DLL_LINKAGE OpenWindow : public Query
  640. {
  641. EOpenWindowMode window;
  642. ObjectInstanceID object;
  643. ObjectInstanceID visitor;
  644. void visitTyped(ICPackVisitor & visitor) override;
  645. void applyGs(CGameState *gs) override {}
  646. template <typename Handler> void serialize(Handler & h)
  647. {
  648. h & queryID;
  649. h & window;
  650. h & object;
  651. h & visitor;
  652. }
  653. };
  654. struct DLL_LINKAGE NewObject : public CPackForClient
  655. {
  656. void applyGs(CGameState * gs) override;
  657. /// Object ID to create
  658. std::shared_ptr<CGObjectInstance> newObject;
  659. /// Which player initiated creation of this object
  660. PlayerColor initiator;
  661. void visitTyped(ICPackVisitor & visitor) override;
  662. template <typename Handler> void serialize(Handler & h)
  663. {
  664. h & newObject;
  665. h & initiator;
  666. }
  667. };
  668. struct DLL_LINKAGE SetAvailableArtifacts : public CPackForClient
  669. {
  670. void applyGs(CGameState * gs) override;
  671. //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)
  672. ObjectInstanceID id;
  673. std::vector<ArtifactID> arts;
  674. void visitTyped(ICPackVisitor & visitor) override;
  675. template <typename Handler> void serialize(Handler & h)
  676. {
  677. h & id;
  678. h & arts;
  679. }
  680. };
  681. struct DLL_LINKAGE CGarrisonOperationPack : CPackForClient
  682. {
  683. };
  684. struct DLL_LINKAGE ChangeStackCount : CGarrisonOperationPack
  685. {
  686. ObjectInstanceID army;
  687. SlotID slot;
  688. TQuantity count;
  689. bool absoluteValue; //if not -> count will be added (or subtracted if negative)
  690. void applyGs(CGameState * gs) override;
  691. void visitTyped(ICPackVisitor & visitor) override;
  692. template <typename Handler> void serialize(Handler & h)
  693. {
  694. h & army;
  695. h & slot;
  696. h & count;
  697. h & absoluteValue;
  698. }
  699. };
  700. struct DLL_LINKAGE SetStackType : CGarrisonOperationPack
  701. {
  702. ObjectInstanceID army;
  703. SlotID slot;
  704. CreatureID type;
  705. void applyGs(CGameState * gs) override;
  706. void visitTyped(ICPackVisitor & visitor) override;
  707. template <typename Handler> void serialize(Handler & h)
  708. {
  709. h & army;
  710. h & slot;
  711. h & type;
  712. }
  713. };
  714. struct DLL_LINKAGE EraseStack : CGarrisonOperationPack
  715. {
  716. ObjectInstanceID army;
  717. SlotID slot;
  718. void applyGs(CGameState * gs) override;
  719. void visitTyped(ICPackVisitor & visitor) override;
  720. template <typename Handler> void serialize(Handler & h)
  721. {
  722. h & army;
  723. h & slot;
  724. }
  725. };
  726. struct DLL_LINKAGE SwapStacks : CGarrisonOperationPack
  727. {
  728. ObjectInstanceID srcArmy;
  729. ObjectInstanceID dstArmy;
  730. SlotID srcSlot;
  731. SlotID dstSlot;
  732. void applyGs(CGameState * gs) override;
  733. void visitTyped(ICPackVisitor & visitor) override;
  734. template <typename Handler> void serialize(Handler & h)
  735. {
  736. h & srcArmy;
  737. h & dstArmy;
  738. h & srcSlot;
  739. h & dstSlot;
  740. }
  741. };
  742. struct DLL_LINKAGE InsertNewStack : CGarrisonOperationPack
  743. {
  744. ObjectInstanceID army;
  745. SlotID slot;
  746. CreatureID type;
  747. TQuantity count = 0;
  748. void applyGs(CGameState * gs) override;
  749. void visitTyped(ICPackVisitor & visitor) override;
  750. template <typename Handler> void serialize(Handler & h)
  751. {
  752. h & army;
  753. h & slot;
  754. h & type;
  755. h & count;
  756. }
  757. };
  758. ///moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  759. struct DLL_LINKAGE RebalanceStacks : CGarrisonOperationPack
  760. {
  761. ObjectInstanceID srcArmy;
  762. ObjectInstanceID dstArmy;
  763. SlotID srcSlot;
  764. SlotID dstSlot;
  765. TQuantity count;
  766. void applyGs(CGameState * gs) override;
  767. void visitTyped(ICPackVisitor & visitor) override;
  768. template <typename Handler> void serialize(Handler & h)
  769. {
  770. h & srcArmy;
  771. h & dstArmy;
  772. h & srcSlot;
  773. h & dstSlot;
  774. h & count;
  775. }
  776. };
  777. struct DLL_LINKAGE BulkRebalanceStacks : CGarrisonOperationPack
  778. {
  779. std::vector<RebalanceStacks> moves;
  780. void applyGs(CGameState * gs) override;
  781. void visitTyped(ICPackVisitor & visitor) override;
  782. template <typename Handler>
  783. void serialize(Handler & h)
  784. {
  785. h & moves;
  786. }
  787. };
  788. struct DLL_LINKAGE CArtifactOperationPack : CPackForClient
  789. {
  790. };
  791. struct DLL_LINKAGE PutArtifact : CArtifactOperationPack
  792. {
  793. PutArtifact() = default;
  794. explicit PutArtifact(const ArtifactInstanceID & id, const ArtifactLocation & dst, bool askAssemble = true)
  795. : al(dst), askAssemble(askAssemble), id(id)
  796. {
  797. }
  798. ArtifactLocation al;
  799. bool askAssemble;
  800. ArtifactInstanceID id;
  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. h & askAssemble;
  807. h & id;
  808. }
  809. };
  810. struct DLL_LINKAGE NewArtifact : public CArtifactOperationPack
  811. {
  812. ObjectInstanceID artHolder;
  813. ArtifactID artId;
  814. SpellID spellId;
  815. ArtifactPosition pos;
  816. void applyGs(CGameState * gs) override;
  817. void visitTyped(ICPackVisitor & visitor) override;
  818. template <typename Handler> void serialize(Handler & h)
  819. {
  820. h & artHolder;
  821. h & artId;
  822. h & spellId;
  823. h & pos;
  824. }
  825. };
  826. struct DLL_LINKAGE BulkEraseArtifacts : CArtifactOperationPack
  827. {
  828. ObjectInstanceID artHolder;
  829. std::vector<ArtifactPosition> posPack;
  830. std::optional<SlotID> creature;
  831. void applyGs(CGameState * gs) override;
  832. void visitTyped(ICPackVisitor & visitor) override;
  833. template <typename Handler> void serialize(Handler & h)
  834. {
  835. h & artHolder;
  836. h & posPack;
  837. h & creature;
  838. }
  839. };
  840. struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
  841. {
  842. PlayerColor interfaceOwner;
  843. ObjectInstanceID srcArtHolder;
  844. ObjectInstanceID dstArtHolder;
  845. std::optional<SlotID> srcCreature;
  846. std::optional<SlotID> dstCreature;
  847. BulkMoveArtifacts()
  848. : interfaceOwner(PlayerColor::NEUTRAL)
  849. , srcArtHolder(ObjectInstanceID::NONE)
  850. , dstArtHolder(ObjectInstanceID::NONE)
  851. , srcCreature(std::nullopt)
  852. , dstCreature(std::nullopt)
  853. {
  854. }
  855. BulkMoveArtifacts(const PlayerColor & interfaceOwner, const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
  856. : interfaceOwner(interfaceOwner)
  857. , srcArtHolder(srcArtHolder)
  858. , dstArtHolder(dstArtHolder)
  859. , srcCreature(std::nullopt)
  860. , dstCreature(std::nullopt)
  861. {
  862. }
  863. void applyGs(CGameState * gs) override;
  864. std::vector<MoveArtifactInfo> artsPack0;
  865. std::vector<MoveArtifactInfo> artsPack1;
  866. void visitTyped(ICPackVisitor & visitor) override;
  867. template <typename Handler> void serialize(Handler & h)
  868. {
  869. h & interfaceOwner;
  870. h & artsPack0;
  871. h & artsPack1;
  872. h & srcArtHolder;
  873. h & dstArtHolder;
  874. h & srcCreature;
  875. h & dstCreature;
  876. }
  877. };
  878. struct DLL_LINKAGE AssembledArtifact : CArtifactOperationPack
  879. {
  880. ArtifactLocation al;
  881. ArtifactID artId;
  882. void applyGs(CGameState * gs) override;
  883. void visitTyped(ICPackVisitor & visitor) override;
  884. template <typename Handler> void serialize(Handler & h)
  885. {
  886. h & al;
  887. h & artId;
  888. }
  889. };
  890. struct DLL_LINKAGE DisassembledArtifact : CArtifactOperationPack
  891. {
  892. ArtifactLocation al;
  893. void applyGs(CGameState * gs) override;
  894. void visitTyped(ICPackVisitor & visitor) override;
  895. template <typename Handler> void serialize(Handler & h)
  896. {
  897. h & al;
  898. }
  899. };
  900. struct DLL_LINKAGE HeroVisit : public CPackForClient
  901. {
  902. PlayerColor player;
  903. ObjectInstanceID heroId;
  904. ObjectInstanceID objId;
  905. bool starting; //false -> ending
  906. void applyGs(CGameState * gs) override;
  907. void visitTyped(ICPackVisitor & visitor) override;
  908. template <typename Handler> void serialize(Handler & h)
  909. {
  910. h & player;
  911. h & heroId;
  912. h & objId;
  913. h & starting;
  914. }
  915. };
  916. struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
  917. {
  918. EInfoWindowMode type = EInfoWindowMode::MODAL;
  919. MetaString text;
  920. std::vector<Component> components;
  921. PlayerColor player;
  922. ui16 soundID = 0;
  923. void visitTyped(ICPackVisitor & visitor) override;
  924. void applyGs(CGameState * gs) override {}
  925. template <typename Handler> void serialize(Handler & h)
  926. {
  927. h & type;
  928. h & text;
  929. h & components;
  930. h & player;
  931. h & soundID;
  932. }
  933. InfoWindow() = default;
  934. };
  935. struct DLL_LINKAGE NewTurn : public CPackForClient
  936. {
  937. void applyGs(CGameState * gs) override;
  938. void visitTyped(ICPackVisitor & visitor) override;
  939. ui32 day = 0;
  940. CreatureID creatureid; //for creature weeks
  941. EWeekType specialWeek = EWeekType::NORMAL;
  942. std::vector<SetMovePoints> heroesMovement;
  943. std::vector<SetMana> heroesMana;
  944. std::vector<SetAvailableCreatures> availableCreatures;
  945. std::map<PlayerColor, ResourceSet> playerIncome;
  946. std::optional<RumorState> newRumor; // only on new weeks
  947. std::optional<InfoWindow> newWeekNotification; // only on new week
  948. NewTurn() = default;
  949. template <typename Handler> void serialize(Handler & h)
  950. {
  951. h & day;
  952. h & creatureid;
  953. h & specialWeek;
  954. h & heroesMovement;
  955. h & heroesMana;
  956. h & availableCreatures;
  957. h & playerIncome;
  958. h & newRumor;
  959. h & newWeekNotification;
  960. }
  961. };
  962. struct DLL_LINKAGE SetObjectProperty : public CPackForClient
  963. {
  964. void applyGs(CGameState * gs) override;
  965. ObjectInstanceID id;
  966. ObjProperty what{};
  967. ObjPropertyID identifier;
  968. SetObjectProperty() = default;
  969. void visitTyped(ICPackVisitor & visitor) override;
  970. template <typename Handler> void serialize(Handler & h)
  971. {
  972. h & id;
  973. h & what;
  974. h & identifier;
  975. }
  976. };
  977. struct DLL_LINKAGE ChangeObjectVisitors : public CPackForClient
  978. {
  979. enum VisitMode
  980. {
  981. VISITOR_ADD_HERO, // mark hero as one that have visited this object
  982. VISITOR_ADD_PLAYER, // mark player as one that have visited this object instance
  983. VISITOR_SCOUTED, // marks targeted team as having scouted this object
  984. VISITOR_CLEAR, // clear all visitors from this object (object reset)
  985. };
  986. VisitMode mode = VISITOR_CLEAR; // uses VisitMode enum
  987. ObjectInstanceID object;
  988. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  989. void applyGs(CGameState * gs) override;
  990. void visitTyped(ICPackVisitor & visitor) override;
  991. ChangeObjectVisitors() = default;
  992. ChangeObjectVisitors(VisitMode mode, const ObjectInstanceID & object, const ObjectInstanceID & heroID = ObjectInstanceID(-1))
  993. : mode(mode)
  994. , object(object)
  995. , hero(heroID)
  996. {
  997. }
  998. template <typename Handler> void serialize(Handler & h)
  999. {
  1000. h & object;
  1001. h & hero;
  1002. h & mode;
  1003. }
  1004. };
  1005. struct DLL_LINKAGE ChangeArtifactsCostume : public CPackForClient
  1006. {
  1007. std::map<ArtifactPosition, ArtifactID> costumeSet;
  1008. uint32_t costumeIdx = 0;
  1009. const PlayerColor player = PlayerColor::NEUTRAL;
  1010. void applyGs(CGameState * gs) override;
  1011. void visitTyped(ICPackVisitor & visitor) override;
  1012. ChangeArtifactsCostume() = default;
  1013. ChangeArtifactsCostume(const PlayerColor & player, const uint32_t costumeIdx)
  1014. : costumeIdx(costumeIdx)
  1015. , player(player)
  1016. {
  1017. }
  1018. template <typename Handler> void serialize(Handler & h)
  1019. {
  1020. h & costumeSet;
  1021. h & costumeIdx;
  1022. h & player;
  1023. }
  1024. };
  1025. struct DLL_LINKAGE HeroLevelUp : public Query
  1026. {
  1027. PlayerColor player;
  1028. ObjectInstanceID heroId;
  1029. PrimarySkill primskill = PrimarySkill::ATTACK;
  1030. std::vector<SecondarySkill> skills;
  1031. void applyGs(CGameState * gs) override;
  1032. void visitTyped(ICPackVisitor & visitor) override;
  1033. template <typename Handler> void serialize(Handler & h)
  1034. {
  1035. h & queryID;
  1036. h & player;
  1037. h & heroId;
  1038. h & primskill;
  1039. h & skills;
  1040. }
  1041. };
  1042. struct DLL_LINKAGE CommanderLevelUp : public Query
  1043. {
  1044. PlayerColor player;
  1045. ObjectInstanceID heroId;
  1046. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1047. void applyGs(CGameState * gs) override;
  1048. void visitTyped(ICPackVisitor & visitor) override;
  1049. template <typename Handler> void serialize(Handler & h)
  1050. {
  1051. h & queryID;
  1052. h & player;
  1053. h & heroId;
  1054. h & skills;
  1055. }
  1056. };
  1057. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1058. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1059. //Until sending reply player won't be allowed to take any actions
  1060. struct DLL_LINKAGE BlockingDialog : public Query
  1061. {
  1062. enum { ALLOW_CANCEL = 1, SELECTION = 2, SAFE_TO_AUTOACCEPT = 4 };
  1063. MetaString text;
  1064. std::vector<Component> components;
  1065. PlayerColor player;
  1066. ui8 flags = 0;
  1067. ui16 soundID = 0;
  1068. bool cancel() const
  1069. {
  1070. return flags & ALLOW_CANCEL;
  1071. }
  1072. bool selection() const
  1073. {
  1074. return flags & SELECTION;
  1075. }
  1076. bool safeToAutoaccept() const
  1077. {
  1078. return flags & SAFE_TO_AUTOACCEPT;
  1079. }
  1080. BlockingDialog(bool yesno, bool Selection)
  1081. {
  1082. if(yesno) flags |= ALLOW_CANCEL;
  1083. if(Selection) flags |= SELECTION;
  1084. }
  1085. BlockingDialog() = default;
  1086. void visitTyped(ICPackVisitor & visitor) override;
  1087. void applyGs(CGameState * gs) override {}
  1088. template <typename Handler> void serialize(Handler & h)
  1089. {
  1090. h & queryID;
  1091. h & text;
  1092. h & components;
  1093. h & player;
  1094. h & flags;
  1095. h & soundID;
  1096. }
  1097. };
  1098. struct DLL_LINKAGE GarrisonDialog : public Query
  1099. {
  1100. ObjectInstanceID objid;
  1101. ObjectInstanceID hid;
  1102. bool removableUnits = false;
  1103. void visitTyped(ICPackVisitor & visitor) override;
  1104. void applyGs(CGameState * gs) override {}
  1105. template <typename Handler> void serialize(Handler & h)
  1106. {
  1107. h & queryID;
  1108. h & objid;
  1109. h & hid;
  1110. h & removableUnits;
  1111. }
  1112. };
  1113. struct DLL_LINKAGE ExchangeDialog : public Query
  1114. {
  1115. PlayerColor player;
  1116. ObjectInstanceID hero1;
  1117. ObjectInstanceID hero2;
  1118. void visitTyped(ICPackVisitor & visitor) override;
  1119. void applyGs(CGameState * gs) override {}
  1120. template <typename Handler> void serialize(Handler & h)
  1121. {
  1122. h & queryID;
  1123. h & player;
  1124. h & hero1;
  1125. h & hero2;
  1126. }
  1127. };
  1128. struct DLL_LINKAGE TeleportDialog : public Query
  1129. {
  1130. TeleportDialog() = default;
  1131. TeleportDialog(const ObjectInstanceID & hero, const TeleportChannelID & Channel)
  1132. : hero(hero)
  1133. , channel(Channel)
  1134. {
  1135. }
  1136. ObjectInstanceID hero;
  1137. TeleportChannelID channel;
  1138. TTeleportExitsList exits;
  1139. bool impassable = false;
  1140. void visitTyped(ICPackVisitor & visitor) override;
  1141. void applyGs(CGameState * gs) override {}
  1142. template <typename Handler> void serialize(Handler & h)
  1143. {
  1144. h & queryID;
  1145. h & hero;
  1146. h & channel;
  1147. h & exits;
  1148. h & impassable;
  1149. }
  1150. };
  1151. struct DLL_LINKAGE MapObjectSelectDialog : public Query
  1152. {
  1153. PlayerColor player;
  1154. Component icon;
  1155. MetaString title;
  1156. MetaString description;
  1157. std::vector<ObjectInstanceID> objects;
  1158. void visitTyped(ICPackVisitor & visitor) override;
  1159. void applyGs(CGameState * gs) override {}
  1160. template <typename Handler> void serialize(Handler & h)
  1161. {
  1162. h & queryID;
  1163. h & player;
  1164. h & icon;
  1165. h & title;
  1166. h & description;
  1167. h & objects;
  1168. }
  1169. };
  1170. struct DLL_LINKAGE AdvmapSpellCast : public CPackForClient
  1171. {
  1172. ObjectInstanceID casterID;
  1173. SpellID spellID;
  1174. template <typename Handler> void serialize(Handler & h)
  1175. {
  1176. h & casterID;
  1177. h & spellID;
  1178. }
  1179. protected:
  1180. void visitTyped(ICPackVisitor & visitor) override;
  1181. void applyGs(CGameState * gs) override {}
  1182. };
  1183. struct DLL_LINKAGE ShowWorldViewEx : public CPackForClient
  1184. {
  1185. PlayerColor player;
  1186. bool showTerrain; // TODO: send terrain state
  1187. std::vector<ObjectPosInfo> objectPositions;
  1188. void applyGs(CGameState * gs) override {}
  1189. template <typename Handler> void serialize(Handler & h)
  1190. {
  1191. h & player;
  1192. h & showTerrain;
  1193. h & objectPositions;
  1194. }
  1195. protected:
  1196. void visitTyped(ICPackVisitor & visitor) override;
  1197. };
  1198. struct DLL_LINKAGE PlayerMessageClient : public CPackForClient
  1199. {
  1200. PlayerMessageClient() = default;
  1201. PlayerMessageClient(const PlayerColor & Player, std::string Text)
  1202. : player(Player)
  1203. , text(std::move(Text))
  1204. {
  1205. }
  1206. void visitTyped(ICPackVisitor & visitor) override;
  1207. void applyGs(CGameState * gs) override {}
  1208. PlayerColor player;
  1209. std::string text;
  1210. template <typename Handler> void serialize(Handler & h)
  1211. {
  1212. h & player;
  1213. h & text;
  1214. }
  1215. };
  1216. struct DLL_LINKAGE CenterView : public CPackForClient
  1217. {
  1218. PlayerColor player;
  1219. int3 pos;
  1220. ui32 focusTime = 0; //ms
  1221. void visitTyped(ICPackVisitor & visitor) override;
  1222. void applyGs(CGameState * gs) override {}
  1223. template <typename Handler> void serialize(Handler & h)
  1224. {
  1225. h & pos;
  1226. h & player;
  1227. h & focusTime;
  1228. }
  1229. };
  1230. VCMI_LIB_NAMESPACE_END