2
0

PacksForClient.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548
  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. 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. struct LinkedSlots
  843. {
  844. ArtifactPosition srcPos;
  845. ArtifactPosition dstPos;
  846. bool askAssemble;
  847. LinkedSlots() = default;
  848. LinkedSlots(const ArtifactPosition & srcPos, const ArtifactPosition & dstPos, bool askAssemble = false)
  849. : srcPos(srcPos)
  850. , dstPos(dstPos)
  851. , askAssemble(askAssemble)
  852. {
  853. }
  854. template <typename Handler> void serialize(Handler & h)
  855. {
  856. h & srcPos;
  857. h & dstPos;
  858. h & askAssemble;
  859. }
  860. };
  861. PlayerColor interfaceOwner;
  862. ObjectInstanceID srcArtHolder;
  863. ObjectInstanceID dstArtHolder;
  864. std::optional<SlotID> srcCreature;
  865. std::optional<SlotID> dstCreature;
  866. BulkMoveArtifacts()
  867. : interfaceOwner(PlayerColor::NEUTRAL)
  868. , srcArtHolder(ObjectInstanceID::NONE)
  869. , dstArtHolder(ObjectInstanceID::NONE)
  870. , srcCreature(std::nullopt)
  871. , dstCreature(std::nullopt)
  872. {
  873. }
  874. BulkMoveArtifacts(const PlayerColor & interfaceOwner, const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
  875. : interfaceOwner(interfaceOwner)
  876. , srcArtHolder(srcArtHolder)
  877. , dstArtHolder(dstArtHolder)
  878. , srcCreature(std::nullopt)
  879. , dstCreature(std::nullopt)
  880. {
  881. }
  882. void applyGs(CGameState * gs) override;
  883. std::vector<LinkedSlots> artsPack0;
  884. std::vector<LinkedSlots> artsPack1;
  885. void visitTyped(ICPackVisitor & visitor) override;
  886. template <typename Handler> void serialize(Handler & h)
  887. {
  888. h & interfaceOwner;
  889. h & artsPack0;
  890. h & artsPack1;
  891. h & srcArtHolder;
  892. h & dstArtHolder;
  893. h & srcCreature;
  894. h & dstCreature;
  895. }
  896. };
  897. struct DLL_LINKAGE AssembledArtifact : CArtifactOperationPack
  898. {
  899. ArtifactLocation al;
  900. ArtifactID artId;
  901. void applyGs(CGameState * gs) override;
  902. void visitTyped(ICPackVisitor & visitor) override;
  903. template <typename Handler> void serialize(Handler & h)
  904. {
  905. h & al;
  906. h & artId;
  907. }
  908. };
  909. struct DLL_LINKAGE DisassembledArtifact : CArtifactOperationPack
  910. {
  911. ArtifactLocation al;
  912. void applyGs(CGameState * gs) override;
  913. void visitTyped(ICPackVisitor & visitor) override;
  914. template <typename Handler> void serialize(Handler & h)
  915. {
  916. h & al;
  917. }
  918. };
  919. struct DLL_LINKAGE HeroVisit : public CPackForClient
  920. {
  921. PlayerColor player;
  922. ObjectInstanceID heroId;
  923. ObjectInstanceID objId;
  924. bool starting; //false -> ending
  925. void applyGs(CGameState * gs) override;
  926. void visitTyped(ICPackVisitor & visitor) override;
  927. template <typename Handler> void serialize(Handler & h)
  928. {
  929. h & player;
  930. h & heroId;
  931. h & objId;
  932. h & starting;
  933. }
  934. };
  935. struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
  936. {
  937. EInfoWindowMode type = EInfoWindowMode::MODAL;
  938. MetaString text;
  939. std::vector<Component> components;
  940. PlayerColor player;
  941. ui16 soundID = 0;
  942. void visitTyped(ICPackVisitor & visitor) override;
  943. void applyGs(CGameState * gs) override {}
  944. template <typename Handler> void serialize(Handler & h)
  945. {
  946. h & type;
  947. h & text;
  948. h & components;
  949. h & player;
  950. h & soundID;
  951. }
  952. InfoWindow() = default;
  953. };
  954. struct DLL_LINKAGE NewTurn : public CPackForClient
  955. {
  956. void applyGs(CGameState * gs) override;
  957. void visitTyped(ICPackVisitor & visitor) override;
  958. ui32 day = 0;
  959. CreatureID creatureid; //for creature weeks
  960. EWeekType specialWeek = EWeekType::NORMAL;
  961. std::vector<SetMovePoints> heroesMovement;
  962. std::vector<SetMana> heroesMana;
  963. std::vector<SetAvailableCreatures> availableCreatures;
  964. std::map<PlayerColor, ResourceSet> playerIncome;
  965. std::optional<RumorState> newRumor; // only on new weeks
  966. std::optional<InfoWindow> newWeekNotification; // only on new week
  967. NewTurn() = default;
  968. template <typename Handler> void serialize(Handler & h)
  969. {
  970. h & day;
  971. h & creatureid;
  972. h & specialWeek;
  973. h & heroesMovement;
  974. h & heroesMana;
  975. h & availableCreatures;
  976. h & playerIncome;
  977. h & newRumor;
  978. h & newWeekNotification;
  979. }
  980. };
  981. struct DLL_LINKAGE SetObjectProperty : public CPackForClient
  982. {
  983. void applyGs(CGameState * gs) override;
  984. ObjectInstanceID id;
  985. ObjProperty what{};
  986. ObjPropertyID identifier;
  987. SetObjectProperty() = default;
  988. void visitTyped(ICPackVisitor & visitor) override;
  989. template <typename Handler> void serialize(Handler & h)
  990. {
  991. h & id;
  992. h & what;
  993. h & identifier;
  994. }
  995. };
  996. struct DLL_LINKAGE ChangeObjectVisitors : public CPackForClient
  997. {
  998. enum VisitMode
  999. {
  1000. VISITOR_ADD_HERO, // mark hero as one that have visited this object
  1001. VISITOR_ADD_PLAYER, // mark player as one that have visited this object instance
  1002. VISITOR_GLOBAL, // mark player as one that have visited object of this type
  1003. VISITOR_SCOUTED, // marks targeted team as having scouted this object
  1004. VISITOR_CLEAR, // clear all visitors from this object (object reset)
  1005. };
  1006. VisitMode mode = VISITOR_CLEAR; // uses VisitMode enum
  1007. ObjectInstanceID object;
  1008. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  1009. void applyGs(CGameState * gs) override;
  1010. void visitTyped(ICPackVisitor & visitor) override;
  1011. ChangeObjectVisitors() = default;
  1012. ChangeObjectVisitors(VisitMode mode, const ObjectInstanceID & object, const ObjectInstanceID & heroID = ObjectInstanceID(-1))
  1013. : mode(mode)
  1014. , object(object)
  1015. , hero(heroID)
  1016. {
  1017. }
  1018. template <typename Handler> void serialize(Handler & h)
  1019. {
  1020. h & object;
  1021. h & hero;
  1022. h & mode;
  1023. }
  1024. };
  1025. struct DLL_LINKAGE ChangeArtifactsCostume : public CPackForClient
  1026. {
  1027. std::map<ArtifactPosition, ArtifactID> costumeSet;
  1028. uint32_t costumeIdx = 0;
  1029. const PlayerColor player = PlayerColor::NEUTRAL;
  1030. void applyGs(CGameState * gs) override;
  1031. void visitTyped(ICPackVisitor & visitor) override;
  1032. ChangeArtifactsCostume() = default;
  1033. ChangeArtifactsCostume(const PlayerColor & player, const uint32_t costumeIdx)
  1034. : costumeIdx(costumeIdx)
  1035. , player(player)
  1036. {
  1037. }
  1038. template <typename Handler> void serialize(Handler & h)
  1039. {
  1040. h & costumeSet;
  1041. h & costumeIdx;
  1042. h & player;
  1043. }
  1044. };
  1045. struct DLL_LINKAGE HeroLevelUp : public Query
  1046. {
  1047. PlayerColor player;
  1048. ObjectInstanceID heroId;
  1049. PrimarySkill primskill = PrimarySkill::ATTACK;
  1050. std::vector<SecondarySkill> skills;
  1051. void applyGs(CGameState * gs) override;
  1052. void visitTyped(ICPackVisitor & visitor) override;
  1053. template <typename Handler> void serialize(Handler & h)
  1054. {
  1055. h & queryID;
  1056. h & player;
  1057. h & heroId;
  1058. h & primskill;
  1059. h & skills;
  1060. }
  1061. };
  1062. struct DLL_LINKAGE CommanderLevelUp : public Query
  1063. {
  1064. PlayerColor player;
  1065. ObjectInstanceID heroId;
  1066. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1067. void applyGs(CGameState * gs) override;
  1068. void visitTyped(ICPackVisitor & visitor) override;
  1069. template <typename Handler> void serialize(Handler & h)
  1070. {
  1071. h & queryID;
  1072. h & player;
  1073. h & heroId;
  1074. h & skills;
  1075. }
  1076. };
  1077. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1078. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1079. //Until sending reply player won't be allowed to take any actions
  1080. struct DLL_LINKAGE BlockingDialog : public Query
  1081. {
  1082. enum { ALLOW_CANCEL = 1, SELECTION = 2, SAFE_TO_AUTOACCEPT = 4 };
  1083. MetaString text;
  1084. std::vector<Component> components;
  1085. PlayerColor player;
  1086. ui8 flags = 0;
  1087. ui16 soundID = 0;
  1088. bool cancel() const
  1089. {
  1090. return flags & ALLOW_CANCEL;
  1091. }
  1092. bool selection() const
  1093. {
  1094. return flags & SELECTION;
  1095. }
  1096. bool safeToAutoaccept() const
  1097. {
  1098. return flags & SAFE_TO_AUTOACCEPT;
  1099. }
  1100. BlockingDialog(bool yesno, bool Selection)
  1101. {
  1102. if(yesno) flags |= ALLOW_CANCEL;
  1103. if(Selection) flags |= SELECTION;
  1104. }
  1105. BlockingDialog() = default;
  1106. void visitTyped(ICPackVisitor & visitor) override;
  1107. void applyGs(CGameState * gs) override {}
  1108. template <typename Handler> void serialize(Handler & h)
  1109. {
  1110. h & queryID;
  1111. h & text;
  1112. h & components;
  1113. h & player;
  1114. h & flags;
  1115. h & soundID;
  1116. }
  1117. };
  1118. struct DLL_LINKAGE GarrisonDialog : public Query
  1119. {
  1120. ObjectInstanceID objid;
  1121. ObjectInstanceID hid;
  1122. bool removableUnits = false;
  1123. void visitTyped(ICPackVisitor & visitor) override;
  1124. void applyGs(CGameState * gs) override {}
  1125. template <typename Handler> void serialize(Handler & h)
  1126. {
  1127. h & queryID;
  1128. h & objid;
  1129. h & hid;
  1130. h & removableUnits;
  1131. }
  1132. };
  1133. struct DLL_LINKAGE ExchangeDialog : public Query
  1134. {
  1135. PlayerColor player;
  1136. ObjectInstanceID hero1;
  1137. ObjectInstanceID hero2;
  1138. void visitTyped(ICPackVisitor & visitor) override;
  1139. void applyGs(CGameState * gs) override {}
  1140. template <typename Handler> void serialize(Handler & h)
  1141. {
  1142. h & queryID;
  1143. h & player;
  1144. h & hero1;
  1145. h & hero2;
  1146. }
  1147. };
  1148. struct DLL_LINKAGE TeleportDialog : public Query
  1149. {
  1150. TeleportDialog() = default;
  1151. TeleportDialog(const ObjectInstanceID & hero, const TeleportChannelID & Channel)
  1152. : hero(hero)
  1153. , channel(Channel)
  1154. {
  1155. }
  1156. ObjectInstanceID hero;
  1157. TeleportChannelID channel;
  1158. TTeleportExitsList exits;
  1159. bool impassable = false;
  1160. void visitTyped(ICPackVisitor & visitor) override;
  1161. void applyGs(CGameState * gs) override {}
  1162. template <typename Handler> void serialize(Handler & h)
  1163. {
  1164. h & queryID;
  1165. h & hero;
  1166. h & channel;
  1167. h & exits;
  1168. h & impassable;
  1169. }
  1170. };
  1171. struct DLL_LINKAGE MapObjectSelectDialog : public Query
  1172. {
  1173. PlayerColor player;
  1174. Component icon;
  1175. MetaString title;
  1176. MetaString description;
  1177. std::vector<ObjectInstanceID> objects;
  1178. void visitTyped(ICPackVisitor & visitor) override;
  1179. void applyGs(CGameState * gs) override {}
  1180. template <typename Handler> void serialize(Handler & h)
  1181. {
  1182. h & queryID;
  1183. h & player;
  1184. h & icon;
  1185. h & title;
  1186. h & description;
  1187. h & objects;
  1188. }
  1189. };
  1190. struct DLL_LINKAGE AdvmapSpellCast : public CPackForClient
  1191. {
  1192. ObjectInstanceID casterID;
  1193. SpellID spellID;
  1194. template <typename Handler> void serialize(Handler & h)
  1195. {
  1196. h & casterID;
  1197. h & spellID;
  1198. }
  1199. protected:
  1200. void visitTyped(ICPackVisitor & visitor) override;
  1201. void applyGs(CGameState * gs) override {}
  1202. };
  1203. struct DLL_LINKAGE ShowWorldViewEx : public CPackForClient
  1204. {
  1205. PlayerColor player;
  1206. bool showTerrain; // TODO: send terrain state
  1207. std::vector<ObjectPosInfo> objectPositions;
  1208. void applyGs(CGameState * gs) override {}
  1209. template <typename Handler> void serialize(Handler & h)
  1210. {
  1211. h & player;
  1212. h & showTerrain;
  1213. h & objectPositions;
  1214. }
  1215. protected:
  1216. void visitTyped(ICPackVisitor & visitor) override;
  1217. };
  1218. struct DLL_LINKAGE PlayerMessageClient : public CPackForClient
  1219. {
  1220. PlayerMessageClient() = default;
  1221. PlayerMessageClient(const PlayerColor & Player, std::string Text)
  1222. : player(Player)
  1223. , text(std::move(Text))
  1224. {
  1225. }
  1226. void visitTyped(ICPackVisitor & visitor) override;
  1227. void applyGs(CGameState * gs) override {}
  1228. PlayerColor player;
  1229. std::string text;
  1230. template <typename Handler> void serialize(Handler & h)
  1231. {
  1232. h & player;
  1233. h & text;
  1234. }
  1235. };
  1236. struct DLL_LINKAGE CenterView : public CPackForClient
  1237. {
  1238. PlayerColor player;
  1239. int3 pos;
  1240. ui32 focusTime = 0; //ms
  1241. void visitTyped(ICPackVisitor & visitor) override;
  1242. void applyGs(CGameState * gs) override {}
  1243. template <typename Handler> void serialize(Handler & h)
  1244. {
  1245. h & pos;
  1246. h & player;
  1247. h & focusTime;
  1248. }
  1249. };
  1250. VCMI_LIB_NAMESPACE_END