PacksForClient.h 32 KB

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