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