PacksForClient.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  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)
  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::list<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. MapObjectID ID;
  626. /// Object secondary ID to create
  627. MapObjectSubID subID;
  628. /// Position of visitable tile of created object
  629. int3 targetPos;
  630. /// Which player initiated creation of this object
  631. PlayerColor initiator;
  632. ObjectInstanceID createdObjectID; //used locally, filled during applyGs
  633. void visitTyped(ICPackVisitor & visitor) override;
  634. template <typename Handler> void serialize(Handler & h)
  635. {
  636. h & ID;
  637. subID.serializeIdentifier(h, ID);
  638. h & targetPos;
  639. h & initiator;
  640. }
  641. };
  642. struct DLL_LINKAGE SetAvailableArtifacts : public CPackForClient
  643. {
  644. void applyGs(CGameState * gs) const;
  645. //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)
  646. ObjectInstanceID id;
  647. std::vector<const CArtifact *> arts;
  648. void visitTyped(ICPackVisitor & visitor) override;
  649. template <typename Handler> void serialize(Handler & h)
  650. {
  651. h & id;
  652. h & arts;
  653. }
  654. };
  655. struct DLL_LINKAGE CGarrisonOperationPack : CPackForClient
  656. {
  657. };
  658. struct DLL_LINKAGE ChangeStackCount : CGarrisonOperationPack
  659. {
  660. ObjectInstanceID army;
  661. SlotID slot;
  662. TQuantity count;
  663. bool absoluteValue; //if not -> count will be added (or subtracted if negative)
  664. void applyGs(CGameState * gs);
  665. void visitTyped(ICPackVisitor & visitor) override;
  666. template <typename Handler> void serialize(Handler & h)
  667. {
  668. h & army;
  669. h & slot;
  670. h & count;
  671. h & absoluteValue;
  672. }
  673. };
  674. struct DLL_LINKAGE SetStackType : CGarrisonOperationPack
  675. {
  676. ObjectInstanceID army;
  677. SlotID slot;
  678. CreatureID type;
  679. void applyGs(CGameState * gs);
  680. void visitTyped(ICPackVisitor & visitor) override;
  681. template <typename Handler> void serialize(Handler & h)
  682. {
  683. h & army;
  684. h & slot;
  685. h & type;
  686. }
  687. };
  688. struct DLL_LINKAGE EraseStack : CGarrisonOperationPack
  689. {
  690. ObjectInstanceID army;
  691. SlotID slot;
  692. void applyGs(CGameState * gs);
  693. void visitTyped(ICPackVisitor & visitor) override;
  694. template <typename Handler> void serialize(Handler & h)
  695. {
  696. h & army;
  697. h & slot;
  698. }
  699. };
  700. struct DLL_LINKAGE SwapStacks : CGarrisonOperationPack
  701. {
  702. ObjectInstanceID srcArmy;
  703. ObjectInstanceID dstArmy;
  704. SlotID srcSlot;
  705. SlotID dstSlot;
  706. void applyGs(CGameState * gs);
  707. void visitTyped(ICPackVisitor & visitor) override;
  708. template <typename Handler> void serialize(Handler & h)
  709. {
  710. h & srcArmy;
  711. h & dstArmy;
  712. h & srcSlot;
  713. h & dstSlot;
  714. }
  715. };
  716. struct DLL_LINKAGE InsertNewStack : CGarrisonOperationPack
  717. {
  718. ObjectInstanceID army;
  719. SlotID slot;
  720. CreatureID type;
  721. TQuantity count = 0;
  722. void applyGs(CGameState * gs);
  723. void visitTyped(ICPackVisitor & visitor) override;
  724. template <typename Handler> void serialize(Handler & h)
  725. {
  726. h & army;
  727. h & slot;
  728. h & type;
  729. h & count;
  730. }
  731. };
  732. ///moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  733. struct DLL_LINKAGE RebalanceStacks : CGarrisonOperationPack
  734. {
  735. ObjectInstanceID srcArmy;
  736. ObjectInstanceID dstArmy;
  737. SlotID srcSlot;
  738. SlotID dstSlot;
  739. TQuantity count;
  740. void applyGs(CGameState * gs);
  741. void visitTyped(ICPackVisitor & visitor) override;
  742. template <typename Handler> void serialize(Handler & h)
  743. {
  744. h & srcArmy;
  745. h & dstArmy;
  746. h & srcSlot;
  747. h & dstSlot;
  748. h & count;
  749. }
  750. };
  751. struct DLL_LINKAGE BulkRebalanceStacks : CGarrisonOperationPack
  752. {
  753. std::vector<RebalanceStacks> moves;
  754. void applyGs(CGameState * gs);
  755. void visitTyped(ICPackVisitor & visitor) override;
  756. template <typename Handler>
  757. void serialize(Handler & h)
  758. {
  759. h & moves;
  760. }
  761. };
  762. struct DLL_LINKAGE BulkSmartRebalanceStacks : CGarrisonOperationPack
  763. {
  764. std::vector<RebalanceStacks> moves;
  765. std::vector<ChangeStackCount> changes;
  766. void applyGs(CGameState * gs);
  767. void visitTyped(ICPackVisitor & visitor) override;
  768. template <typename Handler>
  769. void serialize(Handler & h)
  770. {
  771. h & moves;
  772. h & changes;
  773. }
  774. };
  775. struct DLL_LINKAGE CArtifactOperationPack : CPackForClient
  776. {
  777. };
  778. struct DLL_LINKAGE PutArtifact : CArtifactOperationPack
  779. {
  780. PutArtifact() = default;
  781. explicit PutArtifact(ArtifactLocation & dst, bool askAssemble = true)
  782. : al(dst), askAssemble(askAssemble)
  783. {
  784. }
  785. ArtifactLocation al;
  786. bool askAssemble;
  787. ConstTransitivePtr<CArtifactInstance> art;
  788. void applyGs(CGameState * gs);
  789. void visitTyped(ICPackVisitor & visitor) override;
  790. template <typename Handler> void serialize(Handler & h)
  791. {
  792. h & al;
  793. h & askAssemble;
  794. h & art;
  795. }
  796. };
  797. struct DLL_LINKAGE NewArtifact : public CArtifactOperationPack
  798. {
  799. ConstTransitivePtr<CArtifactInstance> art;
  800. void applyGs(CGameState * gs);
  801. void visitTyped(ICPackVisitor & visitor) override;
  802. template <typename Handler> void serialize(Handler & h)
  803. {
  804. h & art;
  805. }
  806. };
  807. struct DLL_LINKAGE EraseArtifact : CArtifactOperationPack
  808. {
  809. ArtifactLocation al;
  810. void applyGs(CGameState * gs);
  811. void visitTyped(ICPackVisitor & visitor) override;
  812. template <typename Handler> void serialize(Handler & h)
  813. {
  814. h & al;
  815. }
  816. };
  817. struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
  818. {
  819. struct LinkedSlots
  820. {
  821. ArtifactPosition srcPos;
  822. ArtifactPosition dstPos;
  823. bool askAssemble;
  824. LinkedSlots() = default;
  825. LinkedSlots(const ArtifactPosition & srcPos, const ArtifactPosition & dstPos, bool askAssemble = false)
  826. : srcPos(srcPos)
  827. , dstPos(dstPos)
  828. , askAssemble(askAssemble)
  829. {
  830. }
  831. template <typename Handler> void serialize(Handler & h)
  832. {
  833. h & srcPos;
  834. h & dstPos;
  835. h & askAssemble;
  836. }
  837. };
  838. PlayerColor interfaceOwner;
  839. ObjectInstanceID srcArtHolder;
  840. ObjectInstanceID dstArtHolder;
  841. std::optional<SlotID> srcCreature;
  842. std::optional<SlotID> dstCreature;
  843. BulkMoveArtifacts()
  844. : interfaceOwner(PlayerColor::NEUTRAL)
  845. , srcArtHolder(ObjectInstanceID::NONE)
  846. , dstArtHolder(ObjectInstanceID::NONE)
  847. , srcCreature(std::nullopt)
  848. , dstCreature(std::nullopt)
  849. {
  850. }
  851. BulkMoveArtifacts(const PlayerColor & interfaceOwner, const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
  852. : interfaceOwner(interfaceOwner)
  853. , srcArtHolder(srcArtHolder)
  854. , dstArtHolder(dstArtHolder)
  855. , srcCreature(std::nullopt)
  856. , dstCreature(std::nullopt)
  857. {
  858. }
  859. void applyGs(CGameState * gs);
  860. std::vector<LinkedSlots> artsPack0;
  861. std::vector<LinkedSlots> artsPack1;
  862. void visitTyped(ICPackVisitor & visitor) override;
  863. template <typename Handler> void serialize(Handler & h)
  864. {
  865. h & interfaceOwner;
  866. h & artsPack0;
  867. h & artsPack1;
  868. h & srcArtHolder;
  869. h & dstArtHolder;
  870. h & srcCreature;
  871. h & dstCreature;
  872. }
  873. };
  874. struct DLL_LINKAGE AssembledArtifact : CArtifactOperationPack
  875. {
  876. ArtifactLocation al; //where assembly will be put
  877. const CArtifact * builtArt;
  878. void applyGs(CGameState * gs);
  879. void visitTyped(ICPackVisitor & visitor) override;
  880. template <typename Handler> void serialize(Handler & h)
  881. {
  882. h & al;
  883. h & builtArt;
  884. }
  885. };
  886. struct DLL_LINKAGE DisassembledArtifact : CArtifactOperationPack
  887. {
  888. ArtifactLocation al;
  889. void applyGs(CGameState * gs);
  890. void visitTyped(ICPackVisitor & visitor) override;
  891. template <typename Handler> void serialize(Handler & h)
  892. {
  893. h & al;
  894. }
  895. };
  896. struct DLL_LINKAGE HeroVisit : public CPackForClient
  897. {
  898. PlayerColor player;
  899. ObjectInstanceID heroId;
  900. ObjectInstanceID objId;
  901. bool starting; //false -> ending
  902. void applyGs(CGameState * gs);
  903. void visitTyped(ICPackVisitor & visitor) override;
  904. template <typename Handler> void serialize(Handler & h)
  905. {
  906. h & player;
  907. h & heroId;
  908. h & objId;
  909. h & starting;
  910. }
  911. };
  912. struct DLL_LINKAGE NewTurn : public CPackForClient
  913. {
  914. enum weekType { NORMAL, DOUBLE_GROWTH, BONUS_GROWTH, DEITYOFFIRE, PLAGUE, NO_ACTION };
  915. void applyGs(CGameState * gs);
  916. void visitTyped(ICPackVisitor & visitor) override;
  917. struct Hero
  918. {
  919. ObjectInstanceID id; //id is a general serial id
  920. ui32 move;
  921. ui32 mana;
  922. template <typename Handler> void serialize(Handler & h)
  923. {
  924. h & id;
  925. h & move;
  926. h & mana;
  927. }
  928. bool operator<(const Hero & h)const { return id < h.id; }
  929. };
  930. std::set<Hero> heroes; //updates movement and mana points
  931. std::map<PlayerColor, ResourceSet> res; //player ID => resource value[res_id]
  932. std::map<ObjectInstanceID, SetAvailableCreatures> cres;//creatures to be placed in towns
  933. ui32 day = 0;
  934. ui8 specialWeek = 0; //weekType
  935. CreatureID creatureid; //for creature weeks
  936. NewTurn() = default;
  937. template <typename Handler> void serialize(Handler & h)
  938. {
  939. h & heroes;
  940. h & cres;
  941. h & res;
  942. h & day;
  943. h & specialWeek;
  944. h & creatureid;
  945. }
  946. };
  947. struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
  948. {
  949. EInfoWindowMode type = EInfoWindowMode::MODAL;
  950. MetaString text;
  951. std::vector<Component> components;
  952. PlayerColor player;
  953. ui16 soundID = 0;
  954. void visitTyped(ICPackVisitor & visitor) override;
  955. template <typename Handler> void serialize(Handler & h)
  956. {
  957. h & type;
  958. h & text;
  959. h & components;
  960. h & player;
  961. h & soundID;
  962. }
  963. InfoWindow() = default;
  964. };
  965. struct DLL_LINKAGE SetObjectProperty : public CPackForClient
  966. {
  967. void applyGs(CGameState * gs) const;
  968. ObjectInstanceID id;
  969. ObjProperty what{};
  970. ObjPropertyID identifier;
  971. SetObjectProperty() = default;
  972. void visitTyped(ICPackVisitor & visitor) override;
  973. template <typename Handler> void serialize(Handler & h)
  974. {
  975. h & id;
  976. h & what;
  977. h & identifier;
  978. }
  979. };
  980. struct DLL_LINKAGE ChangeObjectVisitors : public CPackForClient
  981. {
  982. enum VisitMode
  983. {
  984. VISITOR_ADD, // mark hero as one that have visited this object
  985. VISITOR_ADD_TEAM, // mark team as one that have visited this object
  986. VISITOR_GLOBAL, // mark player as one that have visited object of this type
  987. VISITOR_REMOVE, // unmark visitor, reversed to ADD
  988. VISITOR_CLEAR // clear all visitors from this object (object reset)
  989. };
  990. VisitMode mode = VISITOR_CLEAR; // uses VisitMode enum
  991. ObjectInstanceID object;
  992. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  993. void applyGs(CGameState * gs) const;
  994. void visitTyped(ICPackVisitor & visitor) override;
  995. ChangeObjectVisitors() = default;
  996. ChangeObjectVisitors(VisitMode mode, const ObjectInstanceID & object, const ObjectInstanceID & heroID = ObjectInstanceID(-1))
  997. : mode(mode)
  998. , object(object)
  999. , hero(heroID)
  1000. {
  1001. }
  1002. template <typename Handler> void serialize(Handler & h)
  1003. {
  1004. h & object;
  1005. h & hero;
  1006. h & mode;
  1007. }
  1008. };
  1009. struct DLL_LINKAGE ChangeArtifactsCostume : public CPackForClient
  1010. {
  1011. std::map<ArtifactPosition, ArtifactID> costumeSet;
  1012. uint32_t costumeIdx = 0;
  1013. const PlayerColor player = PlayerColor::NEUTRAL;
  1014. void applyGs(CGameState * gs) const;
  1015. void visitTyped(ICPackVisitor & visitor) override;
  1016. ChangeArtifactsCostume() = default;
  1017. ChangeArtifactsCostume(const PlayerColor & player, const uint32_t costumeIdx)
  1018. : costumeIdx(costumeIdx)
  1019. , player(player)
  1020. {
  1021. }
  1022. template <typename Handler> void serialize(Handler & h)
  1023. {
  1024. h & costumeSet;
  1025. h & costumeIdx;
  1026. h & player;
  1027. }
  1028. };
  1029. struct DLL_LINKAGE HeroLevelUp : public Query
  1030. {
  1031. PlayerColor player;
  1032. ObjectInstanceID heroId;
  1033. PrimarySkill primskill = PrimarySkill::ATTACK;
  1034. std::vector<SecondarySkill> skills;
  1035. void applyGs(CGameState * gs) const;
  1036. void visitTyped(ICPackVisitor & visitor) override;
  1037. template <typename Handler> void serialize(Handler & h)
  1038. {
  1039. h & queryID;
  1040. h & player;
  1041. h & heroId;
  1042. h & primskill;
  1043. h & skills;
  1044. }
  1045. };
  1046. struct DLL_LINKAGE CommanderLevelUp : public Query
  1047. {
  1048. PlayerColor player;
  1049. ObjectInstanceID heroId;
  1050. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1051. void applyGs(CGameState * gs) const;
  1052. void visitTyped(ICPackVisitor & visitor) override;
  1053. template <typename Handler> void serialize(Handler & h)
  1054. {
  1055. h & queryID;
  1056. h & player;
  1057. h & heroId;
  1058. h & skills;
  1059. }
  1060. };
  1061. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1062. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1063. //Until sending reply player won't be allowed to take any actions
  1064. struct DLL_LINKAGE BlockingDialog : public Query
  1065. {
  1066. enum { ALLOW_CANCEL = 1, SELECTION = 2, SAFE_TO_AUTOACCEPT = 4 };
  1067. MetaString text;
  1068. std::vector<Component> components;
  1069. PlayerColor player;
  1070. ui8 flags = 0;
  1071. ui16 soundID = 0;
  1072. bool cancel() const
  1073. {
  1074. return flags & ALLOW_CANCEL;
  1075. }
  1076. bool selection() const
  1077. {
  1078. return flags & SELECTION;
  1079. }
  1080. bool safeToAutoaccept() const
  1081. {
  1082. return flags & SAFE_TO_AUTOACCEPT;
  1083. }
  1084. BlockingDialog(bool yesno, bool Selection)
  1085. {
  1086. if(yesno) flags |= ALLOW_CANCEL;
  1087. if(Selection) flags |= SELECTION;
  1088. }
  1089. BlockingDialog() = default;
  1090. void visitTyped(ICPackVisitor & visitor) override;
  1091. template <typename Handler> void serialize(Handler & h)
  1092. {
  1093. h & queryID;
  1094. h & text;
  1095. h & components;
  1096. h & player;
  1097. h & flags;
  1098. h & soundID;
  1099. }
  1100. };
  1101. struct DLL_LINKAGE GarrisonDialog : public Query
  1102. {
  1103. ObjectInstanceID objid;
  1104. ObjectInstanceID hid;
  1105. bool removableUnits = false;
  1106. void visitTyped(ICPackVisitor & visitor) override;
  1107. template <typename Handler> void serialize(Handler & h)
  1108. {
  1109. h & queryID;
  1110. h & objid;
  1111. h & hid;
  1112. h & removableUnits;
  1113. }
  1114. };
  1115. struct DLL_LINKAGE ExchangeDialog : public Query
  1116. {
  1117. PlayerColor player;
  1118. ObjectInstanceID hero1;
  1119. ObjectInstanceID hero2;
  1120. void visitTyped(ICPackVisitor & visitor) override;
  1121. template <typename Handler> void serialize(Handler & h)
  1122. {
  1123. h & queryID;
  1124. h & player;
  1125. h & hero1;
  1126. h & hero2;
  1127. }
  1128. };
  1129. struct DLL_LINKAGE TeleportDialog : public Query
  1130. {
  1131. TeleportDialog() = default;
  1132. TeleportDialog(const ObjectInstanceID & hero, const TeleportChannelID & Channel)
  1133. : hero(hero)
  1134. , channel(Channel)
  1135. {
  1136. }
  1137. ObjectInstanceID hero;
  1138. TeleportChannelID channel;
  1139. TTeleportExitsList exits;
  1140. bool impassable = false;
  1141. void visitTyped(ICPackVisitor & visitor) override;
  1142. template <typename Handler> void serialize(Handler & h)
  1143. {
  1144. h & queryID;
  1145. h & hero;
  1146. h & channel;
  1147. h & exits;
  1148. h & impassable;
  1149. }
  1150. };
  1151. struct DLL_LINKAGE MapObjectSelectDialog : public Query
  1152. {
  1153. PlayerColor player;
  1154. Component icon;
  1155. MetaString title;
  1156. MetaString description;
  1157. std::vector<ObjectInstanceID> objects;
  1158. void visitTyped(ICPackVisitor & visitor) override;
  1159. template <typename Handler> void serialize(Handler & h)
  1160. {
  1161. h & queryID;
  1162. h & player;
  1163. h & icon;
  1164. h & title;
  1165. h & description;
  1166. h & objects;
  1167. }
  1168. };
  1169. struct DLL_LINKAGE AdvmapSpellCast : public CPackForClient
  1170. {
  1171. ObjectInstanceID casterID;
  1172. SpellID spellID;
  1173. template <typename Handler> void serialize(Handler & h)
  1174. {
  1175. h & casterID;
  1176. h & spellID;
  1177. }
  1178. protected:
  1179. void visitTyped(ICPackVisitor & visitor) override;
  1180. };
  1181. struct DLL_LINKAGE ShowWorldViewEx : public CPackForClient
  1182. {
  1183. PlayerColor player;
  1184. bool showTerrain; // TODO: send terrain state
  1185. std::vector<ObjectPosInfo> objectPositions;
  1186. template <typename Handler> void serialize(Handler & h)
  1187. {
  1188. h & player;
  1189. h & showTerrain;
  1190. h & objectPositions;
  1191. }
  1192. protected:
  1193. void visitTyped(ICPackVisitor & visitor) override;
  1194. };
  1195. struct DLL_LINKAGE PlayerMessageClient : public CPackForClient
  1196. {
  1197. PlayerMessageClient() = default;
  1198. PlayerMessageClient(const PlayerColor & Player, std::string Text)
  1199. : player(Player)
  1200. , text(std::move(Text))
  1201. {
  1202. }
  1203. void visitTyped(ICPackVisitor & visitor) override;
  1204. PlayerColor player;
  1205. std::string text;
  1206. template <typename Handler> void serialize(Handler & h)
  1207. {
  1208. h & player;
  1209. h & text;
  1210. }
  1211. };
  1212. struct DLL_LINKAGE CenterView : public CPackForClient
  1213. {
  1214. PlayerColor player;
  1215. int3 pos;
  1216. ui32 focusTime = 0; //ms
  1217. void visitTyped(ICPackVisitor & visitor) override;
  1218. template <typename Handler> void serialize(Handler & h)
  1219. {
  1220. h & pos;
  1221. h & player;
  1222. h & focusTime;
  1223. }
  1224. };
  1225. VCMI_LIB_NAMESPACE_END