PacksForClient.h 29 KB

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