PacksForClient.h 32 KB

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