PacksForClient.h 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  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 UpdateArtHandlerLists : public CPackForClient
  445. {
  446. std::map<ArtifactID, int> allocatedArtifacts;
  447. void visitTyped(ICPackVisitor & visitor) override;
  448. template <typename Handler> void serialize(Handler & h)
  449. {
  450. h & allocatedArtifacts;
  451. }
  452. };
  453. struct DLL_LINKAGE ChangeFormation : public CPackForClient
  454. {
  455. ObjectInstanceID hid;
  456. EArmyFormation formation{};
  457. void visitTyped(ICPackVisitor & visitor) override;
  458. template <typename Handler> void serialize(Handler & h)
  459. {
  460. h & hid;
  461. h & formation;
  462. }
  463. };
  464. struct DLL_LINKAGE RemoveObject : public CPackForClient
  465. {
  466. RemoveObject() = default;
  467. RemoveObject(const ObjectInstanceID & objectID, const PlayerColor & initiator)
  468. : objectID(objectID)
  469. , initiator(initiator)
  470. {
  471. }
  472. void visitTyped(ICPackVisitor & visitor) override;
  473. /// ID of removed object
  474. ObjectInstanceID objectID;
  475. /// Player that initiated this action, if any
  476. PlayerColor initiator;
  477. template <typename Handler> void serialize(Handler & h)
  478. {
  479. h & objectID;
  480. h & initiator;
  481. }
  482. };
  483. struct DLL_LINKAGE TryMoveHero : public CPackForClient
  484. {
  485. enum EResult
  486. {
  487. FAILED,
  488. SUCCESS,
  489. TELEPORTATION,
  490. BLOCKING_VISIT,
  491. EMBARK,
  492. DISEMBARK
  493. };
  494. /// ID of moved hero
  495. ObjectInstanceID id;
  496. /// Movement points that hero will have after movement
  497. ui32 movePoints = 0;
  498. /// Result of movement attempt. FAILED should generally never happen unless client requested invalid operation
  499. EResult result = FAILED;
  500. /// Hero anchor position from which hero moves
  501. int3 start;
  502. /// Hero anchor position to which hero moves
  503. int3 end;
  504. /// Tiles that were revealed by this move
  505. std::unordered_set<int3> fowRevealed;
  506. /// If hero moves on guarded tile, this field will be set to visitable pos of attacked wandering monster
  507. int3 attackedFrom;
  508. void visitTyped(ICPackVisitor & visitor) override;
  509. bool stopMovement() const
  510. {
  511. return result != SUCCESS && result != EMBARK && result != DISEMBARK && result != TELEPORTATION;
  512. }
  513. template <typename Handler> void serialize(Handler & h)
  514. {
  515. h & id;
  516. h & result;
  517. h & start;
  518. h & end;
  519. h & movePoints;
  520. h & fowRevealed;
  521. h & attackedFrom;
  522. }
  523. };
  524. struct DLL_LINKAGE NewStructures : public CPackForClient
  525. {
  526. ObjectInstanceID tid;
  527. std::set<BuildingID> bid;
  528. si16 built = 0;
  529. void visitTyped(ICPackVisitor & visitor) override;
  530. template <typename Handler> void serialize(Handler & h)
  531. {
  532. h & tid;
  533. h & bid;
  534. h & built;
  535. }
  536. };
  537. struct DLL_LINKAGE RazeStructures : public CPackForClient
  538. {
  539. ObjectInstanceID tid;
  540. std::set<BuildingID> bid;
  541. si16 destroyed = 0;
  542. void visitTyped(ICPackVisitor & visitor) override;
  543. template <typename Handler> void serialize(Handler & h)
  544. {
  545. h & tid;
  546. h & bid;
  547. h & destroyed;
  548. }
  549. };
  550. struct DLL_LINKAGE SetAvailableCreatures : public CPackForClient
  551. {
  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. ObjectInstanceID tid; //id of town
  564. ObjectInstanceID visiting; //id of visiting hero
  565. ObjectInstanceID garrison; //id of hero in garrison
  566. void visitTyped(ICPackVisitor & visitor) override;
  567. template <typename Handler> void serialize(Handler & h)
  568. {
  569. h & tid;
  570. h & visiting;
  571. h & garrison;
  572. }
  573. };
  574. struct DLL_LINKAGE HeroRecruited : public CPackForClient
  575. {
  576. HeroTypeID hid; //subID of hero
  577. ObjectInstanceID tid;
  578. ObjectInstanceID boatId;
  579. int3 tile;
  580. PlayerColor player;
  581. void visitTyped(ICPackVisitor & visitor) override;
  582. template <typename Handler> void serialize(Handler & h)
  583. {
  584. h & hid;
  585. h & tid;
  586. h & boatId;
  587. h & tile;
  588. h & player;
  589. }
  590. };
  591. struct DLL_LINKAGE GiveHero : public CPackForClient
  592. {
  593. ObjectInstanceID id; //object id
  594. ObjectInstanceID boatId;
  595. PlayerColor player;
  596. void visitTyped(ICPackVisitor & visitor) override;
  597. template <typename Handler> void serialize(Handler & h)
  598. {
  599. h & id;
  600. h & boatId;
  601. h & player;
  602. }
  603. };
  604. struct DLL_LINKAGE OpenWindow : public Query
  605. {
  606. EOpenWindowMode window;
  607. ObjectInstanceID object;
  608. ObjectInstanceID visitor;
  609. void visitTyped(ICPackVisitor & visitor) override;
  610. template <typename Handler> void serialize(Handler & h)
  611. {
  612. h & queryID;
  613. h & window;
  614. h & object;
  615. h & visitor;
  616. }
  617. };
  618. struct DLL_LINKAGE NewObject : public CPackForClient
  619. {
  620. /// Object ID to create
  621. std::shared_ptr<CGObjectInstance> newObject;
  622. /// Which player initiated creation of this object
  623. PlayerColor initiator;
  624. void visitTyped(ICPackVisitor & visitor) override;
  625. template <typename Handler> void serialize(Handler & h)
  626. {
  627. h & newObject;
  628. h & initiator;
  629. }
  630. };
  631. struct DLL_LINKAGE SetAvailableArtifacts : public CPackForClient
  632. {
  633. //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)
  634. ObjectInstanceID id;
  635. std::vector<ArtifactID> arts;
  636. void visitTyped(ICPackVisitor & visitor) override;
  637. template <typename Handler> void serialize(Handler & h)
  638. {
  639. h & id;
  640. h & arts;
  641. }
  642. };
  643. struct DLL_LINKAGE CGarrisonOperationPack : CPackForClient
  644. {
  645. };
  646. struct DLL_LINKAGE ChangeStackCount : CGarrisonOperationPack
  647. {
  648. ObjectInstanceID army;
  649. SlotID slot;
  650. TQuantity count;
  651. ChangeValueMode mode = ChangeValueMode::RELATIVE;
  652. void visitTyped(ICPackVisitor & visitor) override;
  653. template <typename Handler> void serialize(Handler & h)
  654. {
  655. h & army;
  656. h & slot;
  657. h & count;
  658. h & mode;
  659. }
  660. };
  661. struct DLL_LINKAGE SetStackType : CGarrisonOperationPack
  662. {
  663. ObjectInstanceID army;
  664. SlotID slot;
  665. CreatureID type;
  666. void visitTyped(ICPackVisitor & visitor) override;
  667. template <typename Handler> void serialize(Handler & h)
  668. {
  669. h & army;
  670. h & slot;
  671. h & type;
  672. }
  673. };
  674. struct DLL_LINKAGE EraseStack : CGarrisonOperationPack
  675. {
  676. ObjectInstanceID army;
  677. SlotID slot;
  678. void visitTyped(ICPackVisitor & visitor) override;
  679. template <typename Handler> void serialize(Handler & h)
  680. {
  681. h & army;
  682. h & slot;
  683. }
  684. };
  685. struct DLL_LINKAGE SwapStacks : CGarrisonOperationPack
  686. {
  687. ObjectInstanceID srcArmy;
  688. ObjectInstanceID dstArmy;
  689. SlotID srcSlot;
  690. SlotID dstSlot;
  691. void visitTyped(ICPackVisitor & visitor) override;
  692. template <typename Handler> void serialize(Handler & h)
  693. {
  694. h & srcArmy;
  695. h & dstArmy;
  696. h & srcSlot;
  697. h & dstSlot;
  698. }
  699. };
  700. struct DLL_LINKAGE InsertNewStack : CGarrisonOperationPack
  701. {
  702. ObjectInstanceID army;
  703. SlotID slot;
  704. CreatureID type;
  705. TQuantity count = 0;
  706. void visitTyped(ICPackVisitor & visitor) override;
  707. template <typename Handler> void serialize(Handler & h)
  708. {
  709. h & army;
  710. h & slot;
  711. h & type;
  712. h & count;
  713. }
  714. };
  715. ///moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  716. struct DLL_LINKAGE RebalanceStacks : CGarrisonOperationPack
  717. {
  718. ObjectInstanceID srcArmy;
  719. ObjectInstanceID dstArmy;
  720. SlotID srcSlot;
  721. SlotID dstSlot;
  722. TQuantity count;
  723. void visitTyped(ICPackVisitor & visitor) override;
  724. template <typename Handler> void serialize(Handler & h)
  725. {
  726. h & srcArmy;
  727. h & dstArmy;
  728. h & srcSlot;
  729. h & dstSlot;
  730. h & count;
  731. }
  732. };
  733. struct DLL_LINKAGE BulkRebalanceStacks : CGarrisonOperationPack
  734. {
  735. std::vector<RebalanceStacks> moves;
  736. void visitTyped(ICPackVisitor & visitor) override;
  737. template <typename Handler>
  738. void serialize(Handler & h)
  739. {
  740. h & moves;
  741. }
  742. };
  743. struct DLL_LINKAGE CArtifactOperationPack : CPackForClient
  744. {
  745. };
  746. struct DLL_LINKAGE GrowUpArtifact : CArtifactOperationPack
  747. {
  748. ArtifactInstanceID id;
  749. GrowUpArtifact() = default;
  750. GrowUpArtifact(const ArtifactInstanceID & id)
  751. : id(id)
  752. {
  753. }
  754. void visitTyped(ICPackVisitor & visitor) override;
  755. template <typename Handler> void serialize(Handler & h)
  756. {
  757. h & id;
  758. }
  759. };
  760. struct DLL_LINKAGE PutArtifact : CArtifactOperationPack
  761. {
  762. PutArtifact() = default;
  763. explicit PutArtifact(const ArtifactInstanceID & id, const ArtifactLocation & dst, bool askAssemble = true)
  764. : al(dst), askAssemble(askAssemble), id(id)
  765. {
  766. }
  767. ArtifactLocation al;
  768. bool askAssemble;
  769. ArtifactInstanceID id;
  770. void visitTyped(ICPackVisitor & visitor) override;
  771. template <typename Handler> void serialize(Handler & h)
  772. {
  773. h & al;
  774. h & askAssemble;
  775. h & id;
  776. }
  777. };
  778. struct DLL_LINKAGE NewArtifact : public CArtifactOperationPack
  779. {
  780. ObjectInstanceID artHolder;
  781. ArtifactID artId;
  782. SpellID spellId;
  783. ArtifactPosition pos;
  784. void visitTyped(ICPackVisitor & visitor) override;
  785. template <typename Handler> void serialize(Handler & h)
  786. {
  787. h & artHolder;
  788. h & artId;
  789. h & spellId;
  790. h & pos;
  791. }
  792. };
  793. struct DLL_LINKAGE BulkEraseArtifacts : CArtifactOperationPack
  794. {
  795. ObjectInstanceID artHolder;
  796. std::vector<ArtifactPosition> posPack;
  797. std::optional<SlotID> creature;
  798. void visitTyped(ICPackVisitor & visitor) override;
  799. template <typename Handler> void serialize(Handler & h)
  800. {
  801. h & artHolder;
  802. h & posPack;
  803. h & creature;
  804. }
  805. };
  806. struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
  807. {
  808. PlayerColor interfaceOwner;
  809. ObjectInstanceID srcArtHolder;
  810. ObjectInstanceID dstArtHolder;
  811. std::optional<SlotID> srcCreature;
  812. std::optional<SlotID> dstCreature;
  813. BulkMoveArtifacts()
  814. : interfaceOwner(PlayerColor::NEUTRAL)
  815. , srcArtHolder(ObjectInstanceID::NONE)
  816. , dstArtHolder(ObjectInstanceID::NONE)
  817. , srcCreature(std::nullopt)
  818. , dstCreature(std::nullopt)
  819. {
  820. }
  821. BulkMoveArtifacts(const PlayerColor & interfaceOwner, const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
  822. : interfaceOwner(interfaceOwner)
  823. , srcArtHolder(srcArtHolder)
  824. , dstArtHolder(dstArtHolder)
  825. , srcCreature(std::nullopt)
  826. , dstCreature(std::nullopt)
  827. {
  828. }
  829. std::vector<MoveArtifactInfo> artsPack0;
  830. std::vector<MoveArtifactInfo> artsPack1;
  831. void visitTyped(ICPackVisitor & visitor) override;
  832. template <typename Handler> void serialize(Handler & h)
  833. {
  834. h & interfaceOwner;
  835. h & artsPack0;
  836. h & artsPack1;
  837. h & srcArtHolder;
  838. h & dstArtHolder;
  839. h & srcCreature;
  840. h & dstCreature;
  841. }
  842. };
  843. struct DLL_LINKAGE DischargeArtifact : CArtifactOperationPack
  844. {
  845. ArtifactInstanceID id;
  846. uint16_t charges;
  847. std::optional<ArtifactLocation> artLoc;
  848. DischargeArtifact() = default;
  849. DischargeArtifact(const ArtifactInstanceID & id, const uint16_t charges)
  850. : id(id)
  851. , charges(charges)
  852. {
  853. }
  854. void visitTyped(ICPackVisitor & visitor) override;
  855. template <typename Handler> void serialize(Handler & h)
  856. {
  857. h & id;
  858. h & charges;
  859. h & artLoc;
  860. }
  861. };
  862. struct DLL_LINKAGE AssembledArtifact : CArtifactOperationPack
  863. {
  864. ArtifactLocation al;
  865. ArtifactID artId;
  866. void visitTyped(ICPackVisitor & visitor) override;
  867. template <typename Handler> void serialize(Handler & h)
  868. {
  869. h & al;
  870. h & artId;
  871. }
  872. };
  873. struct DLL_LINKAGE DisassembledArtifact : CArtifactOperationPack
  874. {
  875. ArtifactLocation al;
  876. void visitTyped(ICPackVisitor & visitor) override;
  877. template <typename Handler> void serialize(Handler & h)
  878. {
  879. h & al;
  880. }
  881. };
  882. struct DLL_LINKAGE HeroVisit : public CPackForClient
  883. {
  884. PlayerColor player;
  885. ObjectInstanceID heroId;
  886. ObjectInstanceID objId;
  887. bool starting; //false -> ending
  888. void visitTyped(ICPackVisitor & visitor) override;
  889. template <typename Handler> void serialize(Handler & h)
  890. {
  891. h & player;
  892. h & heroId;
  893. h & objId;
  894. h & starting;
  895. }
  896. };
  897. struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
  898. {
  899. EInfoWindowMode type = EInfoWindowMode::MODAL;
  900. MetaString text;
  901. std::vector<Component> components;
  902. PlayerColor player;
  903. ui16 soundID = 0;
  904. void visitTyped(ICPackVisitor & visitor) override;
  905. template <typename Handler> void serialize(Handler & h)
  906. {
  907. h & type;
  908. h & text;
  909. h & components;
  910. h & player;
  911. h & soundID;
  912. }
  913. InfoWindow() = default;
  914. };
  915. struct DLL_LINKAGE NewTurn : public CPackForClient
  916. {
  917. void visitTyped(ICPackVisitor & visitor) override;
  918. ui32 day = 0;
  919. CreatureID creatureid; //for creature weeks
  920. EWeekType specialWeek = EWeekType::NORMAL;
  921. std::vector<SetMovePoints> heroesMovement;
  922. std::vector<SetMana> heroesMana;
  923. std::vector<SetAvailableCreatures> availableCreatures;
  924. std::map<PlayerColor, ResourceSet> playerIncome;
  925. std::optional<RumorState> newRumor; // only on new weeks
  926. std::optional<InfoWindow> newWeekNotification; // only on new week
  927. NewTurn() = default;
  928. template <typename Handler> void serialize(Handler & h)
  929. {
  930. h & day;
  931. h & creatureid;
  932. h & specialWeek;
  933. h & heroesMovement;
  934. h & heroesMana;
  935. h & availableCreatures;
  936. h & playerIncome;
  937. h & newRumor;
  938. h & newWeekNotification;
  939. }
  940. };
  941. struct DLL_LINKAGE SetObjectProperty : public CPackForClient
  942. {
  943. ObjectInstanceID id;
  944. ObjProperty what{};
  945. ObjPropertyID identifier;
  946. SetObjectProperty() = default;
  947. void visitTyped(ICPackVisitor & visitor) override;
  948. template <typename Handler> void serialize(Handler & h)
  949. {
  950. h & id;
  951. h & what;
  952. h & identifier;
  953. }
  954. };
  955. struct DLL_LINKAGE ChangeObjectVisitors : public CPackForClient
  956. {
  957. enum VisitMode
  958. {
  959. VISITOR_ADD_HERO, // mark hero as one that have visited this object
  960. VISITOR_ADD_PLAYER, // mark player as one that have visited this object instance
  961. VISITOR_SCOUTED, // marks targeted team as having scouted this object
  962. VISITOR_CLEAR, // clear all visitors from this object (object reset)
  963. };
  964. VisitMode mode = VISITOR_CLEAR; // uses VisitMode enum
  965. ObjectInstanceID object;
  966. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  967. void visitTyped(ICPackVisitor & visitor) override;
  968. ChangeObjectVisitors() = default;
  969. ChangeObjectVisitors(VisitMode mode, const ObjectInstanceID & object, const ObjectInstanceID & heroID = ObjectInstanceID(-1))
  970. : mode(mode)
  971. , object(object)
  972. , hero(heroID)
  973. {
  974. }
  975. template <typename Handler> void serialize(Handler & h)
  976. {
  977. h & object;
  978. h & hero;
  979. h & mode;
  980. }
  981. };
  982. struct DLL_LINKAGE ChangeArtifactsCostume : public CPackForClient
  983. {
  984. std::map<ArtifactPosition, ArtifactID> costumeSet;
  985. uint32_t costumeIdx = 0;
  986. const PlayerColor player = PlayerColor::NEUTRAL;
  987. void visitTyped(ICPackVisitor & visitor) override;
  988. ChangeArtifactsCostume() = default;
  989. ChangeArtifactsCostume(const PlayerColor & player, const uint32_t costumeIdx)
  990. : costumeIdx(costumeIdx)
  991. , player(player)
  992. {
  993. }
  994. template <typename Handler> void serialize(Handler & h)
  995. {
  996. h & costumeSet;
  997. h & costumeIdx;
  998. h & player;
  999. }
  1000. };
  1001. struct DLL_LINKAGE HeroLevelUp : public Query
  1002. {
  1003. PlayerColor player;
  1004. ObjectInstanceID heroId;
  1005. PrimarySkill primskill = PrimarySkill::ATTACK;
  1006. std::vector<SecondarySkill> skills;
  1007. void visitTyped(ICPackVisitor & visitor) override;
  1008. template <typename Handler> void serialize(Handler & h)
  1009. {
  1010. h & queryID;
  1011. h & player;
  1012. h & heroId;
  1013. h & primskill;
  1014. h & skills;
  1015. }
  1016. };
  1017. struct DLL_LINKAGE CommanderLevelUp : public Query
  1018. {
  1019. PlayerColor player;
  1020. ObjectInstanceID heroId;
  1021. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1022. void visitTyped(ICPackVisitor & visitor) override;
  1023. template <typename Handler> void serialize(Handler & h)
  1024. {
  1025. h & queryID;
  1026. h & player;
  1027. h & heroId;
  1028. h & skills;
  1029. }
  1030. };
  1031. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1032. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1033. //Until sending reply player won't be allowed to take any actions
  1034. struct DLL_LINKAGE BlockingDialog : public Query
  1035. {
  1036. enum { ALLOW_CANCEL = 1, SELECTION = 2, SAFE_TO_AUTOACCEPT = 4 };
  1037. MetaString text;
  1038. std::vector<Component> components;
  1039. PlayerColor player;
  1040. ui8 flags = 0;
  1041. ui16 soundID = 0;
  1042. bool cancel() const
  1043. {
  1044. return flags & ALLOW_CANCEL;
  1045. }
  1046. bool selection() const
  1047. {
  1048. return flags & SELECTION;
  1049. }
  1050. bool safeToAutoaccept() const
  1051. {
  1052. return flags & SAFE_TO_AUTOACCEPT;
  1053. }
  1054. BlockingDialog(bool yesno, bool Selection)
  1055. {
  1056. if(yesno) flags |= ALLOW_CANCEL;
  1057. if(Selection) flags |= SELECTION;
  1058. }
  1059. BlockingDialog() = default;
  1060. void visitTyped(ICPackVisitor & visitor) override;
  1061. template <typename Handler> void serialize(Handler & h)
  1062. {
  1063. h & queryID;
  1064. h & text;
  1065. h & components;
  1066. h & player;
  1067. h & flags;
  1068. h & soundID;
  1069. }
  1070. };
  1071. struct DLL_LINKAGE GarrisonDialog : public Query
  1072. {
  1073. ObjectInstanceID objid;
  1074. ObjectInstanceID hid;
  1075. bool removableUnits = false;
  1076. void visitTyped(ICPackVisitor & visitor) override;
  1077. template <typename Handler> void serialize(Handler & h)
  1078. {
  1079. h & queryID;
  1080. h & objid;
  1081. h & hid;
  1082. h & removableUnits;
  1083. }
  1084. };
  1085. struct DLL_LINKAGE ExchangeDialog : public Query
  1086. {
  1087. PlayerColor player;
  1088. ObjectInstanceID hero1;
  1089. ObjectInstanceID hero2;
  1090. void visitTyped(ICPackVisitor & visitor) override;
  1091. template <typename Handler> void serialize(Handler & h)
  1092. {
  1093. h & queryID;
  1094. h & player;
  1095. h & hero1;
  1096. h & hero2;
  1097. }
  1098. };
  1099. struct DLL_LINKAGE TeleportDialog : public Query
  1100. {
  1101. TeleportDialog() = default;
  1102. TeleportDialog(const ObjectInstanceID & hero, const TeleportChannelID & Channel)
  1103. : hero(hero)
  1104. , channel(Channel)
  1105. {
  1106. }
  1107. ObjectInstanceID hero;
  1108. TeleportChannelID channel;
  1109. TTeleportExitsList exits;
  1110. bool impassable = false;
  1111. void visitTyped(ICPackVisitor & visitor) override;
  1112. template <typename Handler> void serialize(Handler & h)
  1113. {
  1114. h & queryID;
  1115. h & hero;
  1116. h & channel;
  1117. h & exits;
  1118. h & impassable;
  1119. }
  1120. };
  1121. struct DLL_LINKAGE MapObjectSelectDialog : public Query
  1122. {
  1123. PlayerColor player;
  1124. Component icon;
  1125. MetaString title;
  1126. MetaString description;
  1127. std::vector<ObjectInstanceID> objects;
  1128. void visitTyped(ICPackVisitor & visitor) override;
  1129. template <typename Handler> void serialize(Handler & h)
  1130. {
  1131. h & queryID;
  1132. h & player;
  1133. h & icon;
  1134. h & title;
  1135. h & description;
  1136. h & objects;
  1137. }
  1138. };
  1139. struct DLL_LINKAGE AdvmapSpellCast : public CPackForClient
  1140. {
  1141. ObjectInstanceID casterID;
  1142. SpellID spellID;
  1143. template <typename Handler> void serialize(Handler & h)
  1144. {
  1145. h & casterID;
  1146. h & spellID;
  1147. }
  1148. protected:
  1149. void visitTyped(ICPackVisitor & visitor) override;
  1150. };
  1151. struct DLL_LINKAGE ShowWorldViewEx : public CPackForClient
  1152. {
  1153. PlayerColor player;
  1154. bool showTerrain; // TODO: send terrain state
  1155. std::vector<ObjectPosInfo> objectPositions;
  1156. template <typename Handler> void serialize(Handler & h)
  1157. {
  1158. h & player;
  1159. h & showTerrain;
  1160. h & objectPositions;
  1161. }
  1162. protected:
  1163. void visitTyped(ICPackVisitor & visitor) override;
  1164. };
  1165. struct DLL_LINKAGE PlayerMessageClient : public CPackForClient
  1166. {
  1167. PlayerMessageClient() = default;
  1168. PlayerMessageClient(const PlayerColor & Player, std::string Text)
  1169. : player(Player)
  1170. , text(std::move(Text))
  1171. {
  1172. }
  1173. void visitTyped(ICPackVisitor & visitor) override;
  1174. PlayerColor player;
  1175. std::string text;
  1176. template <typename Handler> void serialize(Handler & h)
  1177. {
  1178. h & player;
  1179. h & text;
  1180. }
  1181. };
  1182. struct DLL_LINKAGE CenterView : public CPackForClient
  1183. {
  1184. PlayerColor player;
  1185. int3 pos;
  1186. ui32 focusTime = 0; //ms
  1187. void visitTyped(ICPackVisitor & visitor) override;
  1188. template <typename Handler> void serialize(Handler & h)
  1189. {
  1190. h & pos;
  1191. h & player;
  1192. h & focusTime;
  1193. }
  1194. };
  1195. VCMI_LIB_NAMESPACE_END