PacksForClient.h 32 KB

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