PacksForClient.h 31 KB

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