2
0

PacksForClient.h 31 KB

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