PacksForClient.h 31 KB

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