PacksForClient.h 31 KB

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