PacksForClient.h 31 KB

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