PacksForClient.h 32 KB

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