PacksForClient.h 31 KB

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