PacksForClient.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  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. h & statistic;
  388. }
  389. };
  390. struct DLL_LINKAGE PlayerReinitInterface : public CPackForClient
  391. {
  392. void applyGs(CGameState * gs) override;
  393. std::vector<PlayerColor> players;
  394. ui8 playerConnectionId; //PLAYER_AI for AI player
  395. void visitTyped(ICPackVisitor & visitor) override;
  396. template <typename Handler> void serialize(Handler & h)
  397. {
  398. h & players;
  399. h & playerConnectionId;
  400. }
  401. };
  402. struct DLL_LINKAGE RemoveBonus : public CPackForClient
  403. {
  404. explicit RemoveBonus(GiveBonus::ETarget Who = GiveBonus::ETarget::OBJECT)
  405. :who(Who)
  406. {
  407. }
  408. void applyGs(CGameState * gs) override;
  409. GiveBonus::ETarget who; //who receives bonus
  410. VariantIdentifier<HeroTypeID, PlayerColor, BattleID, ObjectInstanceID> whoID;
  411. //vars to identify bonus: its source
  412. BonusSource source;
  413. BonusSourceID id; //source id
  414. //used locally: copy of removed bonus
  415. Bonus bonus;
  416. void visitTyped(ICPackVisitor & visitor) override;
  417. template <typename Handler> void serialize(Handler & h)
  418. {
  419. h & source;
  420. h & id;
  421. h & who;
  422. h & whoID;
  423. }
  424. };
  425. struct DLL_LINKAGE SetCommanderProperty : public CPackForClient
  426. {
  427. enum ECommanderProperty { ALIVE, BONUS, SECONDARY_SKILL, EXPERIENCE, SPECIAL_SKILL };
  428. void applyGs(CGameState * gs) override;
  429. ObjectInstanceID heroid;
  430. ECommanderProperty which = ALIVE;
  431. TExpType amount = 0; //0 for dead, >0 for alive
  432. si32 additionalInfo = 0; //for secondary skills choice
  433. Bonus accumulatedBonus;
  434. void visitTyped(ICPackVisitor & visitor) override;
  435. template <typename Handler> void serialize(Handler & h)
  436. {
  437. h & heroid;
  438. h & which;
  439. h & amount;
  440. h & additionalInfo;
  441. h & accumulatedBonus;
  442. }
  443. };
  444. struct DLL_LINKAGE AddQuest : public CPackForClient
  445. {
  446. void applyGs(CGameState * gs) override;
  447. PlayerColor player;
  448. QuestInfo quest;
  449. void visitTyped(ICPackVisitor & visitor) override;
  450. template <typename Handler> void serialize(Handler & h)
  451. {
  452. h & player;
  453. h & quest;
  454. }
  455. };
  456. struct DLL_LINKAGE UpdateArtHandlerLists : public CPackForClient
  457. {
  458. std::map<ArtifactID, int> allocatedArtifacts;
  459. void applyGs(CGameState * gs) override;
  460. void visitTyped(ICPackVisitor & visitor) override;
  461. template <typename Handler> void serialize(Handler & h)
  462. {
  463. h & allocatedArtifacts;
  464. }
  465. };
  466. struct DLL_LINKAGE ChangeFormation : public CPackForClient
  467. {
  468. ObjectInstanceID hid;
  469. EArmyFormation formation{};
  470. void applyGs(CGameState * gs) override;
  471. void visitTyped(ICPackVisitor & visitor) override;
  472. template <typename Handler> void serialize(Handler & h)
  473. {
  474. h & hid;
  475. h & formation;
  476. }
  477. };
  478. struct DLL_LINKAGE RemoveObject : public CPackForClient
  479. {
  480. RemoveObject() = default;
  481. RemoveObject(const ObjectInstanceID & objectID, const PlayerColor & initiator)
  482. : objectID(objectID)
  483. , initiator(initiator)
  484. {
  485. }
  486. void applyGs(CGameState * gs) override;
  487. void visitTyped(ICPackVisitor & visitor) override;
  488. /// ID of removed object
  489. ObjectInstanceID objectID;
  490. /// Player that initiated this action, if any
  491. PlayerColor initiator;
  492. template <typename Handler> void serialize(Handler & h)
  493. {
  494. h & objectID;
  495. h & initiator;
  496. }
  497. };
  498. struct DLL_LINKAGE TryMoveHero : public CPackForClient
  499. {
  500. void applyGs(CGameState * gs) override;
  501. enum EResult
  502. {
  503. FAILED,
  504. SUCCESS,
  505. TELEPORTATION,
  506. BLOCKING_VISIT,
  507. EMBARK,
  508. DISEMBARK
  509. };
  510. /// ID of moved hero
  511. ObjectInstanceID id;
  512. /// Movement points that hero will have after movement
  513. ui32 movePoints = 0;
  514. /// Result of movement attempt. FAILED should generally never happen unless client requested invalid operation
  515. EResult result = FAILED;
  516. /// Hero anchor position from which hero moves
  517. int3 start;
  518. /// Hero anchor position to which hero moves
  519. int3 end;
  520. /// Tiles that were revealed by this move
  521. std::unordered_set<int3> fowRevealed;
  522. /// If hero moves on guarded tile, this field will be set to visitable pos of attacked wandering monster
  523. int3 attackedFrom;
  524. void visitTyped(ICPackVisitor & visitor) override;
  525. bool stopMovement() const
  526. {
  527. return result != SUCCESS && result != EMBARK && result != DISEMBARK && result != TELEPORTATION;
  528. }
  529. template <typename Handler> void serialize(Handler & h)
  530. {
  531. h & id;
  532. h & result;
  533. h & start;
  534. h & end;
  535. h & movePoints;
  536. h & fowRevealed;
  537. h & attackedFrom;
  538. }
  539. };
  540. struct DLL_LINKAGE NewStructures : public CPackForClient
  541. {
  542. void applyGs(CGameState * gs) override;
  543. ObjectInstanceID tid;
  544. std::set<BuildingID> bid;
  545. si16 built = 0;
  546. void visitTyped(ICPackVisitor & visitor) override;
  547. template <typename Handler> void serialize(Handler & h)
  548. {
  549. h & tid;
  550. h & bid;
  551. h & built;
  552. }
  553. };
  554. struct DLL_LINKAGE RazeStructures : public CPackForClient
  555. {
  556. void applyGs(CGameState * gs) override;
  557. ObjectInstanceID tid;
  558. std::set<BuildingID> bid;
  559. si16 destroyed = 0;
  560. void visitTyped(ICPackVisitor & visitor) override;
  561. template <typename Handler> void serialize(Handler & h)
  562. {
  563. h & tid;
  564. h & bid;
  565. h & destroyed;
  566. }
  567. };
  568. struct DLL_LINKAGE SetAvailableCreatures : public CPackForClient
  569. {
  570. void applyGs(CGameState * gs) override;
  571. ObjectInstanceID tid;
  572. std::vector<std::pair<ui32, std::vector<CreatureID> > > creatures;
  573. void visitTyped(ICPackVisitor & visitor) override;
  574. template <typename Handler> void serialize(Handler & h)
  575. {
  576. h & tid;
  577. h & creatures;
  578. }
  579. };
  580. struct DLL_LINKAGE SetHeroesInTown : public CPackForClient
  581. {
  582. void applyGs(CGameState * gs) override;
  583. ObjectInstanceID tid; //id of town
  584. ObjectInstanceID visiting; //id of visiting hero
  585. ObjectInstanceID garrison; //id of hero in garrison
  586. void visitTyped(ICPackVisitor & visitor) override;
  587. template <typename Handler> void serialize(Handler & h)
  588. {
  589. h & tid;
  590. h & visiting;
  591. h & garrison;
  592. }
  593. };
  594. struct DLL_LINKAGE HeroRecruited : public CPackForClient
  595. {
  596. void applyGs(CGameState * gs) override;
  597. HeroTypeID hid; //subID of hero
  598. ObjectInstanceID tid;
  599. ObjectInstanceID boatId;
  600. int3 tile;
  601. PlayerColor player;
  602. void visitTyped(ICPackVisitor & visitor) override;
  603. template <typename Handler> void serialize(Handler & h)
  604. {
  605. h & hid;
  606. h & tid;
  607. h & boatId;
  608. h & tile;
  609. h & player;
  610. }
  611. };
  612. struct DLL_LINKAGE GiveHero : public CPackForClient
  613. {
  614. void applyGs(CGameState * gs) override;
  615. ObjectInstanceID id; //object id
  616. ObjectInstanceID boatId;
  617. PlayerColor player;
  618. void visitTyped(ICPackVisitor & visitor) override;
  619. template <typename Handler> void serialize(Handler & h)
  620. {
  621. h & id;
  622. h & boatId;
  623. h & player;
  624. }
  625. };
  626. struct DLL_LINKAGE OpenWindow : public Query
  627. {
  628. EOpenWindowMode window;
  629. ObjectInstanceID object;
  630. ObjectInstanceID visitor;
  631. void visitTyped(ICPackVisitor & visitor) override;
  632. void applyGs(CGameState *gs) override {}
  633. template <typename Handler> void serialize(Handler & h)
  634. {
  635. h & queryID;
  636. h & window;
  637. h & object;
  638. h & visitor;
  639. }
  640. };
  641. struct DLL_LINKAGE NewObject : public CPackForClient
  642. {
  643. void applyGs(CGameState * gs) override;
  644. /// Object ID to create
  645. std::shared_ptr<CGObjectInstance> newObject;
  646. /// Which player initiated creation of this object
  647. PlayerColor initiator;
  648. void visitTyped(ICPackVisitor & visitor) override;
  649. template <typename Handler> void serialize(Handler & h)
  650. {
  651. h & newObject;
  652. h & initiator;
  653. }
  654. };
  655. struct DLL_LINKAGE SetAvailableArtifacts : public CPackForClient
  656. {
  657. void applyGs(CGameState * gs) override;
  658. //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)
  659. ObjectInstanceID id;
  660. std::vector<ArtifactID> arts;
  661. void visitTyped(ICPackVisitor & visitor) override;
  662. template <typename Handler> void serialize(Handler & h)
  663. {
  664. h & id;
  665. h & arts;
  666. }
  667. };
  668. struct DLL_LINKAGE CGarrisonOperationPack : CPackForClient
  669. {
  670. };
  671. struct DLL_LINKAGE ChangeStackCount : CGarrisonOperationPack
  672. {
  673. ObjectInstanceID army;
  674. SlotID slot;
  675. TQuantity count;
  676. bool absoluteValue; //if not -> count will be added (or subtracted if negative)
  677. void applyGs(CGameState * gs) override;
  678. void visitTyped(ICPackVisitor & visitor) override;
  679. template <typename Handler> void serialize(Handler & h)
  680. {
  681. h & army;
  682. h & slot;
  683. h & count;
  684. h & absoluteValue;
  685. }
  686. };
  687. struct DLL_LINKAGE SetStackType : CGarrisonOperationPack
  688. {
  689. ObjectInstanceID army;
  690. SlotID slot;
  691. CreatureID type;
  692. void applyGs(CGameState * gs) override;
  693. void visitTyped(ICPackVisitor & visitor) override;
  694. template <typename Handler> void serialize(Handler & h)
  695. {
  696. h & army;
  697. h & slot;
  698. h & type;
  699. }
  700. };
  701. struct DLL_LINKAGE EraseStack : CGarrisonOperationPack
  702. {
  703. ObjectInstanceID army;
  704. SlotID slot;
  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. }
  712. };
  713. struct DLL_LINKAGE SwapStacks : CGarrisonOperationPack
  714. {
  715. ObjectInstanceID srcArmy;
  716. ObjectInstanceID dstArmy;
  717. SlotID srcSlot;
  718. SlotID dstSlot;
  719. void applyGs(CGameState * gs) override;
  720. void visitTyped(ICPackVisitor & visitor) override;
  721. template <typename Handler> void serialize(Handler & h)
  722. {
  723. h & srcArmy;
  724. h & dstArmy;
  725. h & srcSlot;
  726. h & dstSlot;
  727. }
  728. };
  729. struct DLL_LINKAGE InsertNewStack : CGarrisonOperationPack
  730. {
  731. ObjectInstanceID army;
  732. SlotID slot;
  733. CreatureID type;
  734. TQuantity count = 0;
  735. void applyGs(CGameState * gs) override;
  736. void visitTyped(ICPackVisitor & visitor) override;
  737. template <typename Handler> void serialize(Handler & h)
  738. {
  739. h & army;
  740. h & slot;
  741. h & type;
  742. h & count;
  743. }
  744. };
  745. ///moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  746. struct DLL_LINKAGE RebalanceStacks : CGarrisonOperationPack
  747. {
  748. ObjectInstanceID srcArmy;
  749. ObjectInstanceID dstArmy;
  750. SlotID srcSlot;
  751. SlotID dstSlot;
  752. TQuantity count;
  753. void applyGs(CGameState * gs) override;
  754. void visitTyped(ICPackVisitor & visitor) override;
  755. template <typename Handler> void serialize(Handler & h)
  756. {
  757. h & srcArmy;
  758. h & dstArmy;
  759. h & srcSlot;
  760. h & dstSlot;
  761. h & count;
  762. }
  763. };
  764. struct DLL_LINKAGE BulkRebalanceStacks : CGarrisonOperationPack
  765. {
  766. std::vector<RebalanceStacks> moves;
  767. void applyGs(CGameState * gs) override;
  768. void visitTyped(ICPackVisitor & visitor) override;
  769. template <typename Handler>
  770. void serialize(Handler & h)
  771. {
  772. h & moves;
  773. }
  774. };
  775. struct DLL_LINKAGE BulkSmartRebalanceStacks : CGarrisonOperationPack
  776. {
  777. std::vector<RebalanceStacks> moves;
  778. std::vector<ChangeStackCount> changes;
  779. void applyGs(CGameState * gs) override;
  780. void visitTyped(ICPackVisitor & visitor) override;
  781. template <typename Handler>
  782. void serialize(Handler & h)
  783. {
  784. h & moves;
  785. h & changes;
  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_GLOBAL, // mark player as one that have visited object of this type
  984. VISITOR_SCOUTED, // marks targeted team as having scouted this object
  985. VISITOR_CLEAR, // clear all visitors from this object (object reset)
  986. };
  987. VisitMode mode = VISITOR_CLEAR; // uses VisitMode enum
  988. ObjectInstanceID object;
  989. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  990. void applyGs(CGameState * gs) override;
  991. void visitTyped(ICPackVisitor & visitor) override;
  992. ChangeObjectVisitors() = default;
  993. ChangeObjectVisitors(VisitMode mode, const ObjectInstanceID & object, const ObjectInstanceID & heroID = ObjectInstanceID(-1))
  994. : mode(mode)
  995. , object(object)
  996. , hero(heroID)
  997. {
  998. }
  999. template <typename Handler> void serialize(Handler & h)
  1000. {
  1001. h & object;
  1002. h & hero;
  1003. h & mode;
  1004. }
  1005. };
  1006. struct DLL_LINKAGE ChangeArtifactsCostume : public CPackForClient
  1007. {
  1008. std::map<ArtifactPosition, ArtifactID> costumeSet;
  1009. uint32_t costumeIdx = 0;
  1010. const PlayerColor player = PlayerColor::NEUTRAL;
  1011. void applyGs(CGameState * gs) override;
  1012. void visitTyped(ICPackVisitor & visitor) override;
  1013. ChangeArtifactsCostume() = default;
  1014. ChangeArtifactsCostume(const PlayerColor & player, const uint32_t costumeIdx)
  1015. : costumeIdx(costumeIdx)
  1016. , player(player)
  1017. {
  1018. }
  1019. template <typename Handler> void serialize(Handler & h)
  1020. {
  1021. h & costumeSet;
  1022. h & costumeIdx;
  1023. h & player;
  1024. }
  1025. };
  1026. struct DLL_LINKAGE HeroLevelUp : public Query
  1027. {
  1028. PlayerColor player;
  1029. ObjectInstanceID heroId;
  1030. PrimarySkill primskill = PrimarySkill::ATTACK;
  1031. std::vector<SecondarySkill> skills;
  1032. void applyGs(CGameState * gs) override;
  1033. void visitTyped(ICPackVisitor & visitor) override;
  1034. template <typename Handler> void serialize(Handler & h)
  1035. {
  1036. h & queryID;
  1037. h & player;
  1038. h & heroId;
  1039. h & primskill;
  1040. h & skills;
  1041. }
  1042. };
  1043. struct DLL_LINKAGE CommanderLevelUp : public Query
  1044. {
  1045. PlayerColor player;
  1046. ObjectInstanceID heroId;
  1047. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1048. void applyGs(CGameState * gs) override;
  1049. void visitTyped(ICPackVisitor & visitor) override;
  1050. template <typename Handler> void serialize(Handler & h)
  1051. {
  1052. h & queryID;
  1053. h & player;
  1054. h & heroId;
  1055. h & skills;
  1056. }
  1057. };
  1058. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1059. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1060. //Until sending reply player won't be allowed to take any actions
  1061. struct DLL_LINKAGE BlockingDialog : public Query
  1062. {
  1063. enum { ALLOW_CANCEL = 1, SELECTION = 2, SAFE_TO_AUTOACCEPT = 4 };
  1064. MetaString text;
  1065. std::vector<Component> components;
  1066. PlayerColor player;
  1067. ui8 flags = 0;
  1068. ui16 soundID = 0;
  1069. bool cancel() const
  1070. {
  1071. return flags & ALLOW_CANCEL;
  1072. }
  1073. bool selection() const
  1074. {
  1075. return flags & SELECTION;
  1076. }
  1077. bool safeToAutoaccept() const
  1078. {
  1079. return flags & SAFE_TO_AUTOACCEPT;
  1080. }
  1081. BlockingDialog(bool yesno, bool Selection)
  1082. {
  1083. if(yesno) flags |= ALLOW_CANCEL;
  1084. if(Selection) flags |= SELECTION;
  1085. }
  1086. BlockingDialog() = default;
  1087. void visitTyped(ICPackVisitor & visitor) override;
  1088. void applyGs(CGameState * gs) override {}
  1089. template <typename Handler> void serialize(Handler & h)
  1090. {
  1091. h & queryID;
  1092. h & text;
  1093. h & components;
  1094. h & player;
  1095. h & flags;
  1096. h & soundID;
  1097. }
  1098. };
  1099. struct DLL_LINKAGE GarrisonDialog : public Query
  1100. {
  1101. ObjectInstanceID objid;
  1102. ObjectInstanceID hid;
  1103. bool removableUnits = false;
  1104. void visitTyped(ICPackVisitor & visitor) override;
  1105. void applyGs(CGameState * gs) override {}
  1106. template <typename Handler> void serialize(Handler & h)
  1107. {
  1108. h & queryID;
  1109. h & objid;
  1110. h & hid;
  1111. h & removableUnits;
  1112. }
  1113. };
  1114. struct DLL_LINKAGE ExchangeDialog : public Query
  1115. {
  1116. PlayerColor player;
  1117. ObjectInstanceID hero1;
  1118. ObjectInstanceID hero2;
  1119. void visitTyped(ICPackVisitor & visitor) override;
  1120. void applyGs(CGameState * gs) override {}
  1121. template <typename Handler> void serialize(Handler & h)
  1122. {
  1123. h & queryID;
  1124. h & player;
  1125. h & hero1;
  1126. h & hero2;
  1127. }
  1128. };
  1129. struct DLL_LINKAGE TeleportDialog : public Query
  1130. {
  1131. TeleportDialog() = default;
  1132. TeleportDialog(const ObjectInstanceID & hero, const TeleportChannelID & Channel)
  1133. : hero(hero)
  1134. , channel(Channel)
  1135. {
  1136. }
  1137. ObjectInstanceID hero;
  1138. TeleportChannelID channel;
  1139. TTeleportExitsList exits;
  1140. bool impassable = false;
  1141. void visitTyped(ICPackVisitor & visitor) override;
  1142. void applyGs(CGameState * gs) override {}
  1143. template <typename Handler> void serialize(Handler & h)
  1144. {
  1145. h & queryID;
  1146. h & hero;
  1147. h & channel;
  1148. h & exits;
  1149. h & impassable;
  1150. }
  1151. };
  1152. struct DLL_LINKAGE MapObjectSelectDialog : public Query
  1153. {
  1154. PlayerColor player;
  1155. Component icon;
  1156. MetaString title;
  1157. MetaString description;
  1158. std::vector<ObjectInstanceID> objects;
  1159. void visitTyped(ICPackVisitor & visitor) override;
  1160. void applyGs(CGameState * gs) override {}
  1161. template <typename Handler> void serialize(Handler & h)
  1162. {
  1163. h & queryID;
  1164. h & player;
  1165. h & icon;
  1166. h & title;
  1167. h & description;
  1168. h & objects;
  1169. }
  1170. };
  1171. struct DLL_LINKAGE AdvmapSpellCast : public CPackForClient
  1172. {
  1173. ObjectInstanceID casterID;
  1174. SpellID spellID;
  1175. template <typename Handler> void serialize(Handler & h)
  1176. {
  1177. h & casterID;
  1178. h & spellID;
  1179. }
  1180. protected:
  1181. void visitTyped(ICPackVisitor & visitor) override;
  1182. void applyGs(CGameState * gs) override {}
  1183. };
  1184. struct DLL_LINKAGE ShowWorldViewEx : public CPackForClient
  1185. {
  1186. PlayerColor player;
  1187. bool showTerrain; // TODO: send terrain state
  1188. std::vector<ObjectPosInfo> objectPositions;
  1189. void applyGs(CGameState * gs) override {}
  1190. template <typename Handler> void serialize(Handler & h)
  1191. {
  1192. h & player;
  1193. h & showTerrain;
  1194. h & objectPositions;
  1195. }
  1196. protected:
  1197. void visitTyped(ICPackVisitor & visitor) override;
  1198. };
  1199. struct DLL_LINKAGE PlayerMessageClient : public CPackForClient
  1200. {
  1201. PlayerMessageClient() = default;
  1202. PlayerMessageClient(const PlayerColor & Player, std::string Text)
  1203. : player(Player)
  1204. , text(std::move(Text))
  1205. {
  1206. }
  1207. void visitTyped(ICPackVisitor & visitor) override;
  1208. void applyGs(CGameState * gs) override {}
  1209. PlayerColor player;
  1210. std::string text;
  1211. template <typename Handler> void serialize(Handler & h)
  1212. {
  1213. h & player;
  1214. h & text;
  1215. }
  1216. };
  1217. struct DLL_LINKAGE CenterView : public CPackForClient
  1218. {
  1219. PlayerColor player;
  1220. int3 pos;
  1221. ui32 focusTime = 0; //ms
  1222. void visitTyped(ICPackVisitor & visitor) override;
  1223. void applyGs(CGameState * gs) override {}
  1224. template <typename Handler> void serialize(Handler & h)
  1225. {
  1226. h & pos;
  1227. h & player;
  1228. h & focusTime;
  1229. }
  1230. };
  1231. VCMI_LIB_NAMESPACE_END