2
0

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