PacksForClient.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  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. ObjectInstanceID hid;
  238. si32 val = 0;
  239. bool absolute = true;
  240. template <typename Handler> void serialize(Handler & h)
  241. {
  242. h & val;
  243. h & hid;
  244. h & absolute;
  245. }
  246. };
  247. struct DLL_LINKAGE SetMovePoints : public CPackForClient
  248. {
  249. void applyGs(CGameState * gs) override;
  250. ObjectInstanceID hid;
  251. si32 val = 0;
  252. bool absolute = true;
  253. void visitTyped(ICPackVisitor & visitor) override;
  254. template <typename Handler> void serialize(Handler & h)
  255. {
  256. h & val;
  257. h & hid;
  258. h & absolute;
  259. }
  260. };
  261. struct DLL_LINKAGE FoWChange : public CPackForClient
  262. {
  263. void applyGs(CGameState * gs) override;
  264. std::unordered_set<int3> tiles;
  265. PlayerColor player;
  266. ETileVisibility mode;
  267. bool waitForDialogs = false;
  268. void visitTyped(ICPackVisitor & visitor) override;
  269. template <typename Handler> void serialize(Handler & h)
  270. {
  271. h & tiles;
  272. h & player;
  273. h & mode;
  274. h & waitForDialogs;
  275. }
  276. };
  277. struct DLL_LINKAGE SetAvailableHero : public CPackForClient
  278. {
  279. SetAvailableHero()
  280. {
  281. army.clearSlots();
  282. }
  283. void applyGs(CGameState * gs) override;
  284. TavernHeroSlot slotID;
  285. TavernSlotRole roleID;
  286. PlayerColor player;
  287. HeroTypeID hid; //HeroTypeID::NONE if no hero
  288. CSimpleArmy army;
  289. bool replenishPoints;
  290. void visitTyped(ICPackVisitor & visitor) override;
  291. template <typename Handler> void serialize(Handler & h)
  292. {
  293. h & slotID;
  294. h & roleID;
  295. h & player;
  296. h & hid;
  297. h & army;
  298. h & replenishPoints;
  299. }
  300. };
  301. struct DLL_LINKAGE GiveBonus : public CPackForClient
  302. {
  303. enum class ETarget : int8_t { OBJECT, PLAYER, BATTLE };
  304. explicit GiveBonus(ETarget Who = ETarget::OBJECT)
  305. :who(Who)
  306. {
  307. }
  308. void applyGs(CGameState * gs) override;
  309. ETarget who = ETarget::OBJECT;
  310. VariantIdentifier<ObjectInstanceID, PlayerColor, BattleID> id;
  311. Bonus bonus;
  312. void visitTyped(ICPackVisitor & visitor) override;
  313. template <typename Handler> void serialize(Handler & h)
  314. {
  315. h & bonus;
  316. h & id;
  317. h & who;
  318. assert(id.getNum() != -1);
  319. }
  320. };
  321. struct DLL_LINKAGE ChangeObjPos : public CPackForClient
  322. {
  323. void applyGs(CGameState * gs) override;
  324. /// Object to move
  325. ObjectInstanceID objid;
  326. /// New position of visitable tile of an object
  327. int3 nPos;
  328. /// Player that initiated this action, if any
  329. PlayerColor initiator;
  330. void visitTyped(ICPackVisitor & visitor) override;
  331. template <typename Handler> void serialize(Handler & h)
  332. {
  333. h & objid;
  334. h & nPos;
  335. h & initiator;
  336. }
  337. };
  338. struct DLL_LINKAGE PlayerEndsTurn : public CPackForClient
  339. {
  340. void applyGs(CGameState * gs) override;
  341. PlayerColor player;
  342. void visitTyped(ICPackVisitor & visitor) override;
  343. template <typename Handler> void serialize(Handler & h)
  344. {
  345. h & player;
  346. }
  347. };
  348. struct DLL_LINKAGE PlayerEndsGame : public CPackForClient
  349. {
  350. void applyGs(CGameState * gs) override;
  351. PlayerColor player;
  352. EVictoryLossCheckResult victoryLossCheckResult;
  353. StatisticDataSet statistic;
  354. void visitTyped(ICPackVisitor & visitor) override;
  355. template <typename Handler> void serialize(Handler & h)
  356. {
  357. h & player;
  358. h & victoryLossCheckResult;
  359. if (h.version >= Handler::Version::STATISTICS_SCREEN)
  360. h & statistic;
  361. }
  362. };
  363. struct DLL_LINKAGE PlayerReinitInterface : public CPackForClient
  364. {
  365. void applyGs(CGameState * gs) override;
  366. std::vector<PlayerColor> players;
  367. ui8 playerConnectionId; //PLAYER_AI for AI player
  368. void visitTyped(ICPackVisitor & visitor) override;
  369. template <typename Handler> void serialize(Handler & h)
  370. {
  371. h & players;
  372. h & playerConnectionId;
  373. }
  374. };
  375. struct DLL_LINKAGE RemoveBonus : public CPackForClient
  376. {
  377. explicit RemoveBonus(GiveBonus::ETarget Who = GiveBonus::ETarget::OBJECT)
  378. :who(Who)
  379. {
  380. }
  381. void applyGs(CGameState * gs) override;
  382. GiveBonus::ETarget who; //who receives bonus
  383. VariantIdentifier<HeroTypeID, PlayerColor, BattleID, ObjectInstanceID> whoID;
  384. //vars to identify bonus: its source
  385. BonusSource source;
  386. BonusSourceID id; //source id
  387. //used locally: copy of removed bonus
  388. Bonus bonus;
  389. void visitTyped(ICPackVisitor & visitor) override;
  390. template <typename Handler> void serialize(Handler & h)
  391. {
  392. h & source;
  393. h & id;
  394. h & who;
  395. h & whoID;
  396. }
  397. };
  398. struct DLL_LINKAGE SetCommanderProperty : public CPackForClient
  399. {
  400. enum ECommanderProperty { ALIVE, BONUS, SECONDARY_SKILL, EXPERIENCE, SPECIAL_SKILL };
  401. void applyGs(CGameState * gs) override;
  402. ObjectInstanceID heroid;
  403. ECommanderProperty which = ALIVE;
  404. TExpType amount = 0; //0 for dead, >0 for alive
  405. si32 additionalInfo = 0; //for secondary skills choice
  406. Bonus accumulatedBonus;
  407. void visitTyped(ICPackVisitor & visitor) override;
  408. template <typename Handler> void serialize(Handler & h)
  409. {
  410. h & heroid;
  411. h & which;
  412. h & amount;
  413. h & additionalInfo;
  414. h & accumulatedBonus;
  415. }
  416. };
  417. struct DLL_LINKAGE AddQuest : public CPackForClient
  418. {
  419. void applyGs(CGameState * gs) override;
  420. PlayerColor player;
  421. QuestInfo quest;
  422. void visitTyped(ICPackVisitor & visitor) override;
  423. template <typename Handler> void serialize(Handler & h)
  424. {
  425. h & player;
  426. h & quest;
  427. }
  428. };
  429. struct DLL_LINKAGE UpdateArtHandlerLists : public CPackForClient
  430. {
  431. std::map<ArtifactID, int> allocatedArtifacts;
  432. void applyGs(CGameState * gs) override;
  433. void visitTyped(ICPackVisitor & visitor) override;
  434. template <typename Handler> void serialize(Handler & h)
  435. {
  436. h & allocatedArtifacts;
  437. }
  438. };
  439. struct DLL_LINKAGE ChangeFormation : public CPackForClient
  440. {
  441. ObjectInstanceID hid;
  442. EArmyFormation formation{};
  443. void applyGs(CGameState * gs) override;
  444. void visitTyped(ICPackVisitor & visitor) override;
  445. template <typename Handler> void serialize(Handler & h)
  446. {
  447. h & hid;
  448. h & formation;
  449. }
  450. };
  451. struct DLL_LINKAGE RemoveObject : public CPackForClient
  452. {
  453. RemoveObject() = default;
  454. RemoveObject(const ObjectInstanceID & objectID, const PlayerColor & initiator)
  455. : objectID(objectID)
  456. , initiator(initiator)
  457. {
  458. }
  459. void applyGs(CGameState * gs) override;
  460. void visitTyped(ICPackVisitor & visitor) override;
  461. /// ID of removed object
  462. ObjectInstanceID objectID;
  463. /// Player that initiated this action, if any
  464. PlayerColor initiator;
  465. template <typename Handler> void serialize(Handler & h)
  466. {
  467. h & objectID;
  468. h & initiator;
  469. }
  470. };
  471. struct DLL_LINKAGE TryMoveHero : public CPackForClient
  472. {
  473. void applyGs(CGameState * gs) override;
  474. enum EResult
  475. {
  476. FAILED,
  477. SUCCESS,
  478. TELEPORTATION,
  479. BLOCKING_VISIT,
  480. EMBARK,
  481. DISEMBARK
  482. };
  483. ObjectInstanceID id;
  484. ui32 movePoints = 0;
  485. EResult result = FAILED; //uses EResult
  486. int3 start; //h3m format
  487. int3 end;
  488. std::unordered_set<int3> fowRevealed; //revealed tiles
  489. std::optional<int3> attackedFrom; // Set when stepping into endangered tile.
  490. void visitTyped(ICPackVisitor & visitor) override;
  491. bool stopMovement() const
  492. {
  493. return result != SUCCESS && result != EMBARK && result != DISEMBARK && result != TELEPORTATION;
  494. }
  495. template <typename Handler> void serialize(Handler & h)
  496. {
  497. h & id;
  498. h & result;
  499. h & start;
  500. h & end;
  501. h & movePoints;
  502. h & fowRevealed;
  503. h & attackedFrom;
  504. }
  505. };
  506. struct DLL_LINKAGE NewStructures : public CPackForClient
  507. {
  508. void applyGs(CGameState * gs) override;
  509. ObjectInstanceID tid;
  510. std::set<BuildingID> bid;
  511. si16 built = 0;
  512. void visitTyped(ICPackVisitor & visitor) override;
  513. template <typename Handler> void serialize(Handler & h)
  514. {
  515. h & tid;
  516. h & bid;
  517. h & built;
  518. }
  519. };
  520. struct DLL_LINKAGE RazeStructures : public CPackForClient
  521. {
  522. void applyGs(CGameState * gs) override;
  523. ObjectInstanceID tid;
  524. std::set<BuildingID> bid;
  525. si16 destroyed = 0;
  526. void visitTyped(ICPackVisitor & visitor) override;
  527. template <typename Handler> void serialize(Handler & h)
  528. {
  529. h & tid;
  530. h & bid;
  531. h & destroyed;
  532. }
  533. };
  534. struct DLL_LINKAGE SetAvailableCreatures : public CPackForClient
  535. {
  536. void applyGs(CGameState * gs) override;
  537. ObjectInstanceID tid;
  538. std::vector<std::pair<ui32, std::vector<CreatureID> > > creatures;
  539. void visitTyped(ICPackVisitor & visitor) override;
  540. template <typename Handler> void serialize(Handler & h)
  541. {
  542. h & tid;
  543. h & creatures;
  544. }
  545. };
  546. struct DLL_LINKAGE SetHeroesInTown : public CPackForClient
  547. {
  548. void applyGs(CGameState * gs) override;
  549. ObjectInstanceID tid; //id of town
  550. ObjectInstanceID visiting; //id of visiting hero
  551. ObjectInstanceID garrison; //id of hero in garrison
  552. void visitTyped(ICPackVisitor & visitor) override;
  553. template <typename Handler> void serialize(Handler & h)
  554. {
  555. h & tid;
  556. h & visiting;
  557. h & garrison;
  558. }
  559. };
  560. struct DLL_LINKAGE HeroRecruited : public CPackForClient
  561. {
  562. void applyGs(CGameState * gs) override;
  563. HeroTypeID hid; //subID of hero
  564. ObjectInstanceID tid;
  565. ObjectInstanceID boatId;
  566. int3 tile;
  567. PlayerColor player;
  568. void visitTyped(ICPackVisitor & visitor) override;
  569. template <typename Handler> void serialize(Handler & h)
  570. {
  571. h & hid;
  572. h & tid;
  573. h & boatId;
  574. h & tile;
  575. h & player;
  576. }
  577. };
  578. struct DLL_LINKAGE GiveHero : public CPackForClient
  579. {
  580. void applyGs(CGameState * gs) override;
  581. ObjectInstanceID id; //object id
  582. ObjectInstanceID boatId;
  583. PlayerColor player;
  584. void visitTyped(ICPackVisitor & visitor) override;
  585. template <typename Handler> void serialize(Handler & h)
  586. {
  587. h & id;
  588. h & boatId;
  589. h & player;
  590. }
  591. };
  592. struct DLL_LINKAGE OpenWindow : public Query
  593. {
  594. EOpenWindowMode window;
  595. ObjectInstanceID object;
  596. ObjectInstanceID visitor;
  597. void visitTyped(ICPackVisitor & visitor) override;
  598. void applyGs(CGameState *gs) override {}
  599. template <typename Handler> void serialize(Handler & h)
  600. {
  601. h & queryID;
  602. h & window;
  603. h & object;
  604. h & visitor;
  605. }
  606. };
  607. struct DLL_LINKAGE NewObject : public CPackForClient
  608. {
  609. void applyGs(CGameState * gs) override;
  610. /// Object ID to create
  611. CGObjectInstance * newObject;
  612. /// Which player initiated creation of this object
  613. PlayerColor initiator;
  614. void visitTyped(ICPackVisitor & visitor) override;
  615. template <typename Handler> void serialize(Handler & h)
  616. {
  617. h & newObject;
  618. h & initiator;
  619. }
  620. };
  621. struct DLL_LINKAGE SetAvailableArtifacts : public CPackForClient
  622. {
  623. void applyGs(CGameState * gs) override;
  624. //two variants: id < 0: set artifact pool for Artifact Merchants in towns; id >= 0: set pool for adv. map Black Market (id is the id of Black Market instance then)
  625. ObjectInstanceID id;
  626. std::vector<const CArtifact *> arts;
  627. void visitTyped(ICPackVisitor & visitor) override;
  628. template <typename Handler> void serialize(Handler & h)
  629. {
  630. h & id;
  631. h & arts;
  632. }
  633. };
  634. struct DLL_LINKAGE CGarrisonOperationPack : CPackForClient
  635. {
  636. };
  637. struct DLL_LINKAGE ChangeStackCount : CGarrisonOperationPack
  638. {
  639. ObjectInstanceID army;
  640. SlotID slot;
  641. TQuantity count;
  642. bool absoluteValue; //if not -> count will be added (or subtracted if negative)
  643. void applyGs(CGameState * gs) override;
  644. void visitTyped(ICPackVisitor & visitor) override;
  645. template <typename Handler> void serialize(Handler & h)
  646. {
  647. h & army;
  648. h & slot;
  649. h & count;
  650. h & absoluteValue;
  651. }
  652. };
  653. struct DLL_LINKAGE SetStackType : CGarrisonOperationPack
  654. {
  655. ObjectInstanceID army;
  656. SlotID slot;
  657. CreatureID type;
  658. void applyGs(CGameState * gs) override;
  659. void visitTyped(ICPackVisitor & visitor) override;
  660. template <typename Handler> void serialize(Handler & h)
  661. {
  662. h & army;
  663. h & slot;
  664. h & type;
  665. }
  666. };
  667. struct DLL_LINKAGE EraseStack : CGarrisonOperationPack
  668. {
  669. ObjectInstanceID army;
  670. SlotID slot;
  671. void applyGs(CGameState * gs) override;
  672. void visitTyped(ICPackVisitor & visitor) override;
  673. template <typename Handler> void serialize(Handler & h)
  674. {
  675. h & army;
  676. h & slot;
  677. }
  678. };
  679. struct DLL_LINKAGE SwapStacks : CGarrisonOperationPack
  680. {
  681. ObjectInstanceID srcArmy;
  682. ObjectInstanceID dstArmy;
  683. SlotID srcSlot;
  684. SlotID dstSlot;
  685. void applyGs(CGameState * gs) override;
  686. void visitTyped(ICPackVisitor & visitor) override;
  687. template <typename Handler> void serialize(Handler & h)
  688. {
  689. h & srcArmy;
  690. h & dstArmy;
  691. h & srcSlot;
  692. h & dstSlot;
  693. }
  694. };
  695. struct DLL_LINKAGE InsertNewStack : CGarrisonOperationPack
  696. {
  697. ObjectInstanceID army;
  698. SlotID slot;
  699. CreatureID type;
  700. TQuantity count = 0;
  701. void applyGs(CGameState * gs) override;
  702. void visitTyped(ICPackVisitor & visitor) override;
  703. template <typename Handler> void serialize(Handler & h)
  704. {
  705. h & army;
  706. h & slot;
  707. h & type;
  708. h & count;
  709. }
  710. };
  711. ///moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  712. struct DLL_LINKAGE RebalanceStacks : CGarrisonOperationPack
  713. {
  714. ObjectInstanceID srcArmy;
  715. ObjectInstanceID dstArmy;
  716. SlotID srcSlot;
  717. SlotID dstSlot;
  718. TQuantity count;
  719. void applyGs(CGameState * gs) override;
  720. void visitTyped(ICPackVisitor & visitor) override;
  721. template <typename Handler> void serialize(Handler & h)
  722. {
  723. h & srcArmy;
  724. h & dstArmy;
  725. h & srcSlot;
  726. h & dstSlot;
  727. h & count;
  728. }
  729. };
  730. struct DLL_LINKAGE BulkRebalanceStacks : CGarrisonOperationPack
  731. {
  732. std::vector<RebalanceStacks> moves;
  733. void applyGs(CGameState * gs) override;
  734. void visitTyped(ICPackVisitor & visitor) override;
  735. template <typename Handler>
  736. void serialize(Handler & h)
  737. {
  738. h & moves;
  739. }
  740. };
  741. struct DLL_LINKAGE BulkSmartRebalanceStacks : CGarrisonOperationPack
  742. {
  743. std::vector<RebalanceStacks> moves;
  744. std::vector<ChangeStackCount> changes;
  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. h & changes;
  752. }
  753. };
  754. struct DLL_LINKAGE CArtifactOperationPack : CPackForClient
  755. {
  756. };
  757. struct DLL_LINKAGE PutArtifact : CArtifactOperationPack
  758. {
  759. PutArtifact() = default;
  760. explicit PutArtifact(ArtifactLocation & dst, bool askAssemble = true)
  761. : al(dst), askAssemble(askAssemble)
  762. {
  763. }
  764. ArtifactLocation al;
  765. bool askAssemble;
  766. ConstTransitivePtr<CArtifactInstance> art;
  767. void applyGs(CGameState * gs) override;
  768. void visitTyped(ICPackVisitor & visitor) override;
  769. template <typename Handler> void serialize(Handler & h)
  770. {
  771. h & al;
  772. h & askAssemble;
  773. h & art;
  774. }
  775. };
  776. struct DLL_LINKAGE NewArtifact : public CArtifactOperationPack
  777. {
  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 & art;
  784. }
  785. };
  786. struct DLL_LINKAGE EraseArtifact : CArtifactOperationPack
  787. {
  788. ArtifactLocation al;
  789. void applyGs(CGameState * gs) override;
  790. void visitTyped(ICPackVisitor & visitor) override;
  791. template <typename Handler> void serialize(Handler & h)
  792. {
  793. h & al;
  794. }
  795. };
  796. struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
  797. {
  798. struct LinkedSlots
  799. {
  800. ArtifactPosition srcPos;
  801. ArtifactPosition dstPos;
  802. bool askAssemble;
  803. LinkedSlots() = default;
  804. LinkedSlots(const ArtifactPosition & srcPos, const ArtifactPosition & dstPos, bool askAssemble = false)
  805. : srcPos(srcPos)
  806. , dstPos(dstPos)
  807. , askAssemble(askAssemble)
  808. {
  809. }
  810. template <typename Handler> void serialize(Handler & h)
  811. {
  812. h & srcPos;
  813. h & dstPos;
  814. h & askAssemble;
  815. }
  816. };
  817. PlayerColor interfaceOwner;
  818. ObjectInstanceID srcArtHolder;
  819. ObjectInstanceID dstArtHolder;
  820. std::optional<SlotID> srcCreature;
  821. std::optional<SlotID> dstCreature;
  822. BulkMoveArtifacts()
  823. : interfaceOwner(PlayerColor::NEUTRAL)
  824. , srcArtHolder(ObjectInstanceID::NONE)
  825. , dstArtHolder(ObjectInstanceID::NONE)
  826. , srcCreature(std::nullopt)
  827. , dstCreature(std::nullopt)
  828. {
  829. }
  830. BulkMoveArtifacts(const PlayerColor & interfaceOwner, const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
  831. : interfaceOwner(interfaceOwner)
  832. , srcArtHolder(srcArtHolder)
  833. , dstArtHolder(dstArtHolder)
  834. , srcCreature(std::nullopt)
  835. , dstCreature(std::nullopt)
  836. {
  837. }
  838. void applyGs(CGameState * gs) override;
  839. std::vector<LinkedSlots> artsPack0;
  840. std::vector<LinkedSlots> artsPack1;
  841. void visitTyped(ICPackVisitor & visitor) override;
  842. template <typename Handler> void serialize(Handler & h)
  843. {
  844. h & interfaceOwner;
  845. h & artsPack0;
  846. h & artsPack1;
  847. h & srcArtHolder;
  848. h & dstArtHolder;
  849. h & srcCreature;
  850. h & dstCreature;
  851. }
  852. };
  853. struct DLL_LINKAGE AssembledArtifact : CArtifactOperationPack
  854. {
  855. ArtifactLocation al; //where assembly will be put
  856. const CArtifact * builtArt;
  857. void applyGs(CGameState * gs) override;
  858. void visitTyped(ICPackVisitor & visitor) override;
  859. template <typename Handler> void serialize(Handler & h)
  860. {
  861. h & al;
  862. h & builtArt;
  863. }
  864. };
  865. struct DLL_LINKAGE DisassembledArtifact : CArtifactOperationPack
  866. {
  867. ArtifactLocation al;
  868. void applyGs(CGameState * gs) override;
  869. void visitTyped(ICPackVisitor & visitor) override;
  870. template <typename Handler> void serialize(Handler & h)
  871. {
  872. h & al;
  873. }
  874. };
  875. struct DLL_LINKAGE HeroVisit : public CPackForClient
  876. {
  877. PlayerColor player;
  878. ObjectInstanceID heroId;
  879. ObjectInstanceID objId;
  880. bool starting; //false -> ending
  881. void applyGs(CGameState * gs) override;
  882. void visitTyped(ICPackVisitor & visitor) override;
  883. template <typename Handler> void serialize(Handler & h)
  884. {
  885. h & player;
  886. h & heroId;
  887. h & objId;
  888. h & starting;
  889. }
  890. };
  891. struct DLL_LINKAGE NewTurn : public CPackForClient
  892. {
  893. void applyGs(CGameState * gs) override;
  894. void visitTyped(ICPackVisitor & visitor) override;
  895. struct Hero
  896. {
  897. ObjectInstanceID id; //id is a general serial id
  898. ui32 move;
  899. ui32 mana;
  900. template <typename Handler> void serialize(Handler & h)
  901. {
  902. h & id;
  903. h & move;
  904. h & mana;
  905. }
  906. bool operator<(const Hero & h)const { return id < h.id; }
  907. };
  908. std::set<Hero> heroes; //updates movement and mana points
  909. std::vector<SetAvailableCreatures> availableCreatures;//creatures to be placed in towns
  910. std::map<PlayerColor, ResourceSet> playerIncome; //player ID => resource value[res_id]
  911. ui32 day = 0;
  912. EWeekType specialWeek = EWeekType::NORMAL;
  913. CreatureID creatureid; //for creature weeks
  914. std::optional<RumorState> newRumor; // only on new weeks
  915. NewTurn() = default;
  916. template <typename Handler> void serialize(Handler & h)
  917. {
  918. h & heroes;
  919. h & availableCreatures;
  920. h & playerIncome;
  921. h & day;
  922. h & specialWeek;
  923. h & creatureid;
  924. h & newRumor;
  925. }
  926. };
  927. struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
  928. {
  929. EInfoWindowMode type = EInfoWindowMode::MODAL;
  930. MetaString text;
  931. std::vector<Component> components;
  932. PlayerColor player;
  933. ui16 soundID = 0;
  934. void visitTyped(ICPackVisitor & visitor) override;
  935. void applyGs(CGameState * gs) override {}
  936. template <typename Handler> void serialize(Handler & h)
  937. {
  938. h & type;
  939. h & text;
  940. h & components;
  941. h & player;
  942. h & soundID;
  943. }
  944. InfoWindow() = default;
  945. };
  946. struct DLL_LINKAGE SetObjectProperty : public CPackForClient
  947. {
  948. void applyGs(CGameState * gs) override;
  949. ObjectInstanceID id;
  950. ObjProperty what{};
  951. ObjPropertyID identifier;
  952. SetObjectProperty() = default;
  953. void visitTyped(ICPackVisitor & visitor) override;
  954. template <typename Handler> void serialize(Handler & h)
  955. {
  956. h & id;
  957. h & what;
  958. h & identifier;
  959. }
  960. };
  961. struct DLL_LINKAGE ChangeObjectVisitors : public CPackForClient
  962. {
  963. enum VisitMode
  964. {
  965. VISITOR_ADD, // mark hero as one that have visited this object
  966. VISITOR_ADD_TEAM, // mark team as one that have visited this object
  967. VISITOR_GLOBAL, // mark player as one that have visited object of this type
  968. VISITOR_REMOVE, // unmark visitor, reversed to ADD
  969. VISITOR_CLEAR // clear all visitors from this object (object reset)
  970. };
  971. VisitMode mode = VISITOR_CLEAR; // uses VisitMode enum
  972. ObjectInstanceID object;
  973. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  974. void applyGs(CGameState * gs) override;
  975. void visitTyped(ICPackVisitor & visitor) override;
  976. ChangeObjectVisitors() = default;
  977. ChangeObjectVisitors(VisitMode mode, const ObjectInstanceID & object, const ObjectInstanceID & heroID = ObjectInstanceID(-1))
  978. : mode(mode)
  979. , object(object)
  980. , hero(heroID)
  981. {
  982. }
  983. template <typename Handler> void serialize(Handler & h)
  984. {
  985. h & object;
  986. h & hero;
  987. h & mode;
  988. }
  989. };
  990. struct DLL_LINKAGE ChangeArtifactsCostume : public CPackForClient
  991. {
  992. std::map<ArtifactPosition, ArtifactID> costumeSet;
  993. uint32_t costumeIdx = 0;
  994. const PlayerColor player = PlayerColor::NEUTRAL;
  995. void applyGs(CGameState * gs) override;
  996. void visitTyped(ICPackVisitor & visitor) override;
  997. ChangeArtifactsCostume() = default;
  998. ChangeArtifactsCostume(const PlayerColor & player, const uint32_t costumeIdx)
  999. : costumeIdx(costumeIdx)
  1000. , player(player)
  1001. {
  1002. }
  1003. template <typename Handler> void serialize(Handler & h)
  1004. {
  1005. h & costumeSet;
  1006. h & costumeIdx;
  1007. h & player;
  1008. }
  1009. };
  1010. struct DLL_LINKAGE HeroLevelUp : public Query
  1011. {
  1012. PlayerColor player;
  1013. ObjectInstanceID heroId;
  1014. PrimarySkill primskill = PrimarySkill::ATTACK;
  1015. std::vector<SecondarySkill> skills;
  1016. void applyGs(CGameState * gs) override;
  1017. void visitTyped(ICPackVisitor & visitor) override;
  1018. template <typename Handler> void serialize(Handler & h)
  1019. {
  1020. h & queryID;
  1021. h & player;
  1022. h & heroId;
  1023. h & primskill;
  1024. h & skills;
  1025. }
  1026. };
  1027. struct DLL_LINKAGE CommanderLevelUp : public Query
  1028. {
  1029. PlayerColor player;
  1030. ObjectInstanceID heroId;
  1031. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1032. void applyGs(CGameState * gs) override;
  1033. void visitTyped(ICPackVisitor & visitor) override;
  1034. template <typename Handler> void serialize(Handler & h)
  1035. {
  1036. h & queryID;
  1037. h & player;
  1038. h & heroId;
  1039. h & skills;
  1040. }
  1041. };
  1042. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1043. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1044. //Until sending reply player won't be allowed to take any actions
  1045. struct DLL_LINKAGE BlockingDialog : public Query
  1046. {
  1047. enum { ALLOW_CANCEL = 1, SELECTION = 2, SAFE_TO_AUTOACCEPT = 4 };
  1048. MetaString text;
  1049. std::vector<Component> components;
  1050. PlayerColor player;
  1051. ui8 flags = 0;
  1052. ui16 soundID = 0;
  1053. bool cancel() const
  1054. {
  1055. return flags & ALLOW_CANCEL;
  1056. }
  1057. bool selection() const
  1058. {
  1059. return flags & SELECTION;
  1060. }
  1061. bool safeToAutoaccept() const
  1062. {
  1063. return flags & SAFE_TO_AUTOACCEPT;
  1064. }
  1065. BlockingDialog(bool yesno, bool Selection)
  1066. {
  1067. if(yesno) flags |= ALLOW_CANCEL;
  1068. if(Selection) flags |= SELECTION;
  1069. }
  1070. BlockingDialog() = default;
  1071. void visitTyped(ICPackVisitor & visitor) override;
  1072. void applyGs(CGameState * gs) override {}
  1073. template <typename Handler> void serialize(Handler & h)
  1074. {
  1075. h & queryID;
  1076. h & text;
  1077. h & components;
  1078. h & player;
  1079. h & flags;
  1080. h & soundID;
  1081. }
  1082. };
  1083. struct DLL_LINKAGE GarrisonDialog : public Query
  1084. {
  1085. ObjectInstanceID objid;
  1086. ObjectInstanceID hid;
  1087. bool removableUnits = false;
  1088. void visitTyped(ICPackVisitor & visitor) override;
  1089. void applyGs(CGameState * gs) override {}
  1090. template <typename Handler> void serialize(Handler & h)
  1091. {
  1092. h & queryID;
  1093. h & objid;
  1094. h & hid;
  1095. h & removableUnits;
  1096. }
  1097. };
  1098. struct DLL_LINKAGE ExchangeDialog : public Query
  1099. {
  1100. PlayerColor player;
  1101. ObjectInstanceID hero1;
  1102. ObjectInstanceID hero2;
  1103. void visitTyped(ICPackVisitor & visitor) override;
  1104. void applyGs(CGameState * gs) override {}
  1105. template <typename Handler> void serialize(Handler & h)
  1106. {
  1107. h & queryID;
  1108. h & player;
  1109. h & hero1;
  1110. h & hero2;
  1111. }
  1112. };
  1113. struct DLL_LINKAGE TeleportDialog : public Query
  1114. {
  1115. TeleportDialog() = default;
  1116. TeleportDialog(const ObjectInstanceID & hero, const TeleportChannelID & Channel)
  1117. : hero(hero)
  1118. , channel(Channel)
  1119. {
  1120. }
  1121. ObjectInstanceID hero;
  1122. TeleportChannelID channel;
  1123. TTeleportExitsList exits;
  1124. bool impassable = false;
  1125. void visitTyped(ICPackVisitor & visitor) override;
  1126. void applyGs(CGameState * gs) override {}
  1127. template <typename Handler> void serialize(Handler & h)
  1128. {
  1129. h & queryID;
  1130. h & hero;
  1131. h & channel;
  1132. h & exits;
  1133. h & impassable;
  1134. }
  1135. };
  1136. struct DLL_LINKAGE MapObjectSelectDialog : public Query
  1137. {
  1138. PlayerColor player;
  1139. Component icon;
  1140. MetaString title;
  1141. MetaString description;
  1142. std::vector<ObjectInstanceID> objects;
  1143. void visitTyped(ICPackVisitor & visitor) override;
  1144. void applyGs(CGameState * gs) override {}
  1145. template <typename Handler> void serialize(Handler & h)
  1146. {
  1147. h & queryID;
  1148. h & player;
  1149. h & icon;
  1150. h & title;
  1151. h & description;
  1152. h & objects;
  1153. }
  1154. };
  1155. struct DLL_LINKAGE AdvmapSpellCast : public CPackForClient
  1156. {
  1157. ObjectInstanceID casterID;
  1158. SpellID spellID;
  1159. template <typename Handler> void serialize(Handler & h)
  1160. {
  1161. h & casterID;
  1162. h & spellID;
  1163. }
  1164. protected:
  1165. void visitTyped(ICPackVisitor & visitor) override;
  1166. void applyGs(CGameState * gs) override {}
  1167. };
  1168. struct DLL_LINKAGE ShowWorldViewEx : public CPackForClient
  1169. {
  1170. PlayerColor player;
  1171. bool showTerrain; // TODO: send terrain state
  1172. std::vector<ObjectPosInfo> objectPositions;
  1173. void applyGs(CGameState * gs) override {}
  1174. template <typename Handler> void serialize(Handler & h)
  1175. {
  1176. h & player;
  1177. h & showTerrain;
  1178. h & objectPositions;
  1179. }
  1180. protected:
  1181. void visitTyped(ICPackVisitor & visitor) override;
  1182. };
  1183. struct DLL_LINKAGE PlayerMessageClient : public CPackForClient
  1184. {
  1185. PlayerMessageClient() = default;
  1186. PlayerMessageClient(const PlayerColor & Player, std::string Text)
  1187. : player(Player)
  1188. , text(std::move(Text))
  1189. {
  1190. }
  1191. void visitTyped(ICPackVisitor & visitor) override;
  1192. void applyGs(CGameState * gs) override {}
  1193. PlayerColor player;
  1194. std::string text;
  1195. template <typename Handler> void serialize(Handler & h)
  1196. {
  1197. h & player;
  1198. h & text;
  1199. }
  1200. };
  1201. struct DLL_LINKAGE CenterView : public CPackForClient
  1202. {
  1203. PlayerColor player;
  1204. int3 pos;
  1205. ui32 focusTime = 0; //ms
  1206. void visitTyped(ICPackVisitor & visitor) override;
  1207. void applyGs(CGameState * gs) override {}
  1208. template <typename Handler> void serialize(Handler & h)
  1209. {
  1210. h & pos;
  1211. h & player;
  1212. h & focusTime;
  1213. }
  1214. };
  1215. VCMI_LIB_NAMESPACE_END