PacksForClient.h 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  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. 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. PlayerColor player;
  110. TurnTimerInfo turnTimer;
  111. void visitTyped(ICPackVisitor & visitor) override;
  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. PlayerColor player;
  121. void visitTyped(ICPackVisitor & visitor) override;
  122. template <typename Handler> void serialize(Handler & h)
  123. {
  124. h & queryID;
  125. h & player;
  126. }
  127. };
  128. struct DLL_LINKAGE DaysWithoutTown : public CPackForClient
  129. {
  130. PlayerColor player;
  131. std::optional<int32_t> daysWithoutCastle;
  132. void visitTyped(ICPackVisitor & visitor) override;
  133. template <typename Handler> void serialize(Handler & h)
  134. {
  135. h & player;
  136. h & daysWithoutCastle;
  137. }
  138. };
  139. struct DLL_LINKAGE EntitiesChanged : public CPackForClient
  140. {
  141. std::vector<EntityChanges> changes;
  142. void visitTyped(ICPackVisitor & visitor) override;
  143. template <typename Handler> void serialize(Handler & h)
  144. {
  145. h & changes;
  146. }
  147. };
  148. struct DLL_LINKAGE SetResources : public CPackForClient
  149. {
  150. void visitTyped(ICPackVisitor & visitor) override;
  151. ChangeValueMode mode = ChangeValueMode::ABSOLUTE;
  152. PlayerColor player;
  153. ResourceSet res; //res[resid] => res amount
  154. template <typename Handler> void serialize(Handler & h)
  155. {
  156. h & mode;
  157. h & player;
  158. h & res;
  159. }
  160. };
  161. struct DLL_LINKAGE SetPrimSkill : public CPackForClient
  162. {
  163. void visitTyped(ICPackVisitor & visitor) override;
  164. ChangeValueMode mode = ChangeValueMode::RELATIVE;
  165. ObjectInstanceID id;
  166. PrimarySkill which = PrimarySkill::ATTACK;
  167. si64 val = 0;
  168. template <typename Handler> void serialize(Handler & h)
  169. {
  170. h & mode;
  171. h & id;
  172. h & which;
  173. h & val;
  174. }
  175. };
  176. struct DLL_LINKAGE SetSecSkill : public CPackForClient
  177. {
  178. void visitTyped(ICPackVisitor & visitor) override;
  179. ChangeValueMode mode = ChangeValueMode::RELATIVE;
  180. ObjectInstanceID id;
  181. SecondarySkill which;
  182. ui16 val = 0;
  183. template <typename Handler> void serialize(Handler & h)
  184. {
  185. h & mode;
  186. h & id;
  187. h & which;
  188. h & val;
  189. }
  190. };
  191. struct DLL_LINKAGE HeroVisitCastle : public CPackForClient
  192. {
  193. void visitTyped(ICPackVisitor & visitor) override;
  194. ui8 flags = 0; //1 - start
  195. ObjectInstanceID tid;
  196. ObjectInstanceID hid;
  197. bool start() const //if hero is entering castle (if false - leaving)
  198. {
  199. return flags & 1;
  200. }
  201. template <typename Handler> void serialize(Handler & h)
  202. {
  203. h & flags;
  204. h & tid;
  205. h & hid;
  206. }
  207. };
  208. struct DLL_LINKAGE ChangeSpells : public CPackForClient
  209. {
  210. void visitTyped(ICPackVisitor & visitor) override;
  211. ui8 learn = 1; //1 - gives spell, 0 - takes
  212. ObjectInstanceID hid;
  213. std::set<SpellID> spells;
  214. template <typename Handler> void serialize(Handler & h)
  215. {
  216. h & learn;
  217. h & hid;
  218. h & spells;
  219. }
  220. };
  221. struct DLL_LINKAGE SetResearchedSpells : public CPackForClient
  222. {
  223. void visitTyped(ICPackVisitor & visitor) override;
  224. ui8 level = 0;
  225. ObjectInstanceID tid;
  226. std::vector<SpellID> spells;
  227. bool accepted;
  228. template <typename Handler> void serialize(Handler & h)
  229. {
  230. h & level;
  231. h & tid;
  232. h & spells;
  233. h & accepted;
  234. }
  235. };
  236. struct DLL_LINKAGE SetMana : public CPackForClient
  237. {
  238. void visitTyped(ICPackVisitor & visitor) override;
  239. SetMana() = default;
  240. SetMana(ObjectInstanceID hid, si32 val, ChangeValueMode mode)
  241. : hid(hid)
  242. , val(val)
  243. , mode(mode)
  244. {}
  245. ObjectInstanceID hid;
  246. si32 val = 0;
  247. ChangeValueMode mode = ChangeValueMode::RELATIVE;
  248. template <typename Handler> void serialize(Handler & h)
  249. {
  250. h & val;
  251. h & hid;
  252. h & mode;
  253. }
  254. };
  255. struct DLL_LINKAGE SetMovePoints : public CPackForClient
  256. {
  257. SetMovePoints() = default;
  258. SetMovePoints(ObjectInstanceID hid, si32 val, ChangeValueMode mode)
  259. : hid(hid)
  260. , val(val)
  261. , mode(mode)
  262. {}
  263. ObjectInstanceID hid;
  264. si32 val = 0;
  265. ChangeValueMode mode = ChangeValueMode::RELATIVE;
  266. void visitTyped(ICPackVisitor & visitor) override;
  267. template <typename Handler> void serialize(Handler & h)
  268. {
  269. h & val;
  270. h & hid;
  271. h & mode;
  272. }
  273. };
  274. struct DLL_LINKAGE FoWChange : public CPackForClient
  275. {
  276. std::unordered_set<int3> tiles;
  277. PlayerColor player;
  278. ETileVisibility mode;
  279. bool waitForDialogs = false;
  280. void visitTyped(ICPackVisitor & visitor) override;
  281. template <typename Handler> void serialize(Handler & h)
  282. {
  283. h & tiles;
  284. h & player;
  285. h & mode;
  286. h & waitForDialogs;
  287. }
  288. };
  289. struct DLL_LINKAGE SetAvailableHero : public CPackForClient
  290. {
  291. SetAvailableHero()
  292. {
  293. army.clearSlots();
  294. }
  295. TavernHeroSlot slotID;
  296. TavernSlotRole roleID;
  297. PlayerColor player;
  298. HeroTypeID hid; //HeroTypeID::NONE if no hero
  299. CSimpleArmy army;
  300. bool replenishPoints;
  301. void visitTyped(ICPackVisitor & visitor) override;
  302. template <typename Handler> void serialize(Handler & h)
  303. {
  304. h & slotID;
  305. h & roleID;
  306. h & player;
  307. h & hid;
  308. h & army;
  309. h & replenishPoints;
  310. }
  311. };
  312. struct DLL_LINKAGE GiveBonus : public CPackForClient
  313. {
  314. using VariantType = VariantIdentifier<ObjectInstanceID, PlayerColor, BattleID>;
  315. enum class ETarget : int8_t
  316. {
  317. OBJECT,
  318. PLAYER,
  319. BATTLE,
  320. HERO_COMMANDER
  321. };
  322. explicit GiveBonus(ETarget Who = ETarget::OBJECT)
  323. :who(Who)
  324. {
  325. }
  326. GiveBonus(ETarget who, const VariantType & id, const Bonus & bonus)
  327. : who(who)
  328. , id(id)
  329. , bonus(bonus)
  330. {
  331. }
  332. ETarget who = ETarget::OBJECT;
  333. VariantType id;
  334. Bonus bonus;
  335. void visitTyped(ICPackVisitor & visitor) override;
  336. template <typename Handler> void serialize(Handler & h)
  337. {
  338. h & bonus;
  339. h & id;
  340. h & who;
  341. assert(id.getNum() != -1);
  342. }
  343. };
  344. struct DLL_LINKAGE ChangeObjPos : public CPackForClient
  345. {
  346. /// Object to move
  347. ObjectInstanceID objid;
  348. /// New position of visitable tile of an object
  349. int3 nPos;
  350. /// Player that initiated this action, if any
  351. PlayerColor initiator;
  352. void visitTyped(ICPackVisitor & visitor) override;
  353. template <typename Handler> void serialize(Handler & h)
  354. {
  355. h & objid;
  356. h & nPos;
  357. h & initiator;
  358. }
  359. };
  360. struct DLL_LINKAGE PlayerEndsTurn : public CPackForClient
  361. {
  362. PlayerColor player;
  363. void visitTyped(ICPackVisitor & visitor) override;
  364. template <typename Handler> void serialize(Handler & h)
  365. {
  366. h & player;
  367. }
  368. };
  369. struct DLL_LINKAGE PlayerEndsGame : public CPackForClient
  370. {
  371. PlayerColor player;
  372. EVictoryLossCheckResult victoryLossCheckResult;
  373. StatisticDataSet statistic;
  374. void visitTyped(ICPackVisitor & visitor) override;
  375. template <typename Handler> void serialize(Handler & h)
  376. {
  377. h & player;
  378. h & victoryLossCheckResult;
  379. h & statistic;
  380. }
  381. };
  382. struct DLL_LINKAGE PlayerReinitInterface : public CPackForClient
  383. {
  384. std::vector<PlayerColor> players;
  385. ui8 playerConnectionId; //PLAYER_AI for AI player
  386. void visitTyped(ICPackVisitor & visitor) override;
  387. template <typename Handler> void serialize(Handler & h)
  388. {
  389. h & players;
  390. h & playerConnectionId;
  391. }
  392. };
  393. struct DLL_LINKAGE RemoveBonus : public CPackForClient
  394. {
  395. explicit RemoveBonus(GiveBonus::ETarget Who = GiveBonus::ETarget::OBJECT)
  396. :who(Who)
  397. {
  398. }
  399. GiveBonus::ETarget who; //who receives bonus
  400. VariantIdentifier<HeroTypeID, PlayerColor, BattleID, ObjectInstanceID> whoID;
  401. //vars to identify bonus: its source
  402. BonusSource source;
  403. BonusSourceID id; //source id
  404. //used locally: copy of removed bonus
  405. Bonus bonus;
  406. void visitTyped(ICPackVisitor & visitor) override;
  407. template <typename Handler> void serialize(Handler & h)
  408. {
  409. h & source;
  410. h & id;
  411. h & who;
  412. h & whoID;
  413. }
  414. };
  415. struct DLL_LINKAGE SetCommanderProperty : public CPackForClient
  416. {
  417. enum ECommanderProperty { ALIVE, BONUS, SECONDARY_SKILL, EXPERIENCE, SPECIAL_SKILL };
  418. ObjectInstanceID heroid;
  419. ECommanderProperty which = ALIVE;
  420. TExpType amount = 0; //0 for dead, >0 for alive
  421. si32 additionalInfo = 0; //for secondary skills choice
  422. Bonus accumulatedBonus;
  423. void visitTyped(ICPackVisitor & visitor) override;
  424. template <typename Handler> void serialize(Handler & h)
  425. {
  426. h & heroid;
  427. h & which;
  428. h & amount;
  429. h & additionalInfo;
  430. h & accumulatedBonus;
  431. }
  432. };
  433. struct DLL_LINKAGE AddQuest : public CPackForClient
  434. {
  435. PlayerColor player;
  436. QuestInfo quest;
  437. void visitTyped(ICPackVisitor & visitor) override;
  438. template <typename Handler> void serialize(Handler & h)
  439. {
  440. h & player;
  441. h & quest;
  442. }
  443. };
  444. struct DLL_LINKAGE ChangeFormation : public CPackForClient
  445. {
  446. ObjectInstanceID hid;
  447. EArmyFormation formation{};
  448. void visitTyped(ICPackVisitor & visitor) override;
  449. template <typename Handler> void serialize(Handler & h)
  450. {
  451. h & hid;
  452. h & formation;
  453. }
  454. };
  455. struct DLL_LINKAGE RemoveObject : public CPackForClient
  456. {
  457. RemoveObject() = default;
  458. RemoveObject(const ObjectInstanceID & objectID, const PlayerColor & initiator)
  459. : objectID(objectID)
  460. , initiator(initiator)
  461. {
  462. }
  463. void visitTyped(ICPackVisitor & visitor) override;
  464. /// ID of removed object
  465. ObjectInstanceID objectID;
  466. /// Player that initiated this action, if any
  467. PlayerColor initiator;
  468. template <typename Handler> void serialize(Handler & h)
  469. {
  470. h & objectID;
  471. h & initiator;
  472. }
  473. };
  474. struct DLL_LINKAGE TryMoveHero : public CPackForClient
  475. {
  476. enum EResult
  477. {
  478. FAILED,
  479. SUCCESS,
  480. TELEPORTATION,
  481. BLOCKING_VISIT,
  482. EMBARK,
  483. DISEMBARK
  484. };
  485. /// ID of moved hero
  486. ObjectInstanceID id;
  487. /// Movement points that hero will have after movement
  488. ui32 movePoints = 0;
  489. /// Result of movement attempt. FAILED should generally never happen unless client requested invalid operation
  490. EResult result = FAILED;
  491. /// Hero anchor position from which hero moves
  492. int3 start;
  493. /// Hero anchor position to which hero moves
  494. int3 end;
  495. /// Tiles that were revealed by this move
  496. std::unordered_set<int3> fowRevealed;
  497. /// If hero moves on guarded tile, this field will be set to visitable pos of attacked wandering monster
  498. int3 attackedFrom;
  499. void visitTyped(ICPackVisitor & visitor) override;
  500. bool stopMovement() const
  501. {
  502. return result != SUCCESS && result != EMBARK && result != DISEMBARK && result != TELEPORTATION;
  503. }
  504. template <typename Handler> void serialize(Handler & h)
  505. {
  506. h & id;
  507. h & result;
  508. h & start;
  509. h & end;
  510. h & movePoints;
  511. h & fowRevealed;
  512. h & attackedFrom;
  513. }
  514. };
  515. struct DLL_LINKAGE NewStructures : public CPackForClient
  516. {
  517. ObjectInstanceID tid;
  518. std::set<BuildingID> bid;
  519. si16 built = 0;
  520. void visitTyped(ICPackVisitor & visitor) override;
  521. template <typename Handler> void serialize(Handler & h)
  522. {
  523. h & tid;
  524. h & bid;
  525. h & built;
  526. }
  527. };
  528. struct DLL_LINKAGE RazeStructures : public CPackForClient
  529. {
  530. ObjectInstanceID tid;
  531. std::set<BuildingID> bid;
  532. si16 destroyed = 0;
  533. void visitTyped(ICPackVisitor & visitor) override;
  534. template <typename Handler> void serialize(Handler & h)
  535. {
  536. h & tid;
  537. h & bid;
  538. h & destroyed;
  539. }
  540. };
  541. struct DLL_LINKAGE SetAvailableCreatures : public CPackForClient
  542. {
  543. ObjectInstanceID tid;
  544. std::vector<std::pair<ui32, std::vector<CreatureID> > > creatures;
  545. void visitTyped(ICPackVisitor & visitor) override;
  546. template <typename Handler> void serialize(Handler & h)
  547. {
  548. h & tid;
  549. h & creatures;
  550. }
  551. };
  552. struct DLL_LINKAGE SetHeroesInTown : public CPackForClient
  553. {
  554. ObjectInstanceID tid; //id of town
  555. ObjectInstanceID visiting; //id of visiting hero
  556. ObjectInstanceID garrison; //id of hero in garrison
  557. void visitTyped(ICPackVisitor & visitor) override;
  558. template <typename Handler> void serialize(Handler & h)
  559. {
  560. h & tid;
  561. h & visiting;
  562. h & garrison;
  563. }
  564. };
  565. struct DLL_LINKAGE HeroRecruited : public CPackForClient
  566. {
  567. HeroTypeID hid; //subID of hero
  568. ObjectInstanceID tid;
  569. ObjectInstanceID boatId;
  570. int3 tile;
  571. PlayerColor player;
  572. void visitTyped(ICPackVisitor & visitor) override;
  573. template <typename Handler> void serialize(Handler & h)
  574. {
  575. h & hid;
  576. h & tid;
  577. h & boatId;
  578. h & tile;
  579. h & player;
  580. }
  581. };
  582. struct DLL_LINKAGE GiveHero : public CPackForClient
  583. {
  584. ObjectInstanceID id; //object id
  585. ObjectInstanceID boatId;
  586. PlayerColor player;
  587. void visitTyped(ICPackVisitor & visitor) override;
  588. template <typename Handler> void serialize(Handler & h)
  589. {
  590. h & id;
  591. h & boatId;
  592. h & player;
  593. }
  594. };
  595. struct DLL_LINKAGE OpenWindow : public Query
  596. {
  597. EOpenWindowMode window;
  598. ObjectInstanceID object;
  599. ObjectInstanceID visitor;
  600. void visitTyped(ICPackVisitor & visitor) override;
  601. template <typename Handler> void serialize(Handler & h)
  602. {
  603. h & queryID;
  604. h & window;
  605. h & object;
  606. h & visitor;
  607. }
  608. };
  609. struct DLL_LINKAGE NewObject : public CPackForClient
  610. {
  611. /// Object ID to create
  612. std::shared_ptr<CGObjectInstance> newObject;
  613. /// Which player initiated creation of this object
  614. PlayerColor initiator;
  615. void visitTyped(ICPackVisitor & visitor) override;
  616. template <typename Handler> void serialize(Handler & h)
  617. {
  618. h & newObject;
  619. h & initiator;
  620. }
  621. };
  622. struct DLL_LINKAGE SetAvailableArtifacts : public CPackForClient
  623. {
  624. //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)
  625. ObjectInstanceID id;
  626. std::vector<ArtifactID> arts;
  627. void visitTyped(ICPackVisitor & visitor) override;
  628. template <typename Handler> void serialize(Handler & h)
  629. {
  630. h & id;
  631. h & arts;
  632. }
  633. };
  634. struct DLL_LINKAGE CGarrisonOperationPack : CPackForClient
  635. {
  636. };
  637. struct DLL_LINKAGE ChangeStackCount : CGarrisonOperationPack
  638. {
  639. ObjectInstanceID army;
  640. SlotID slot;
  641. TQuantity count;
  642. ChangeValueMode mode = ChangeValueMode::RELATIVE;
  643. void visitTyped(ICPackVisitor & visitor) override;
  644. template <typename Handler> void serialize(Handler & h)
  645. {
  646. h & army;
  647. h & slot;
  648. h & count;
  649. h & mode;
  650. }
  651. };
  652. struct DLL_LINKAGE SetStackType : CGarrisonOperationPack
  653. {
  654. ObjectInstanceID army;
  655. SlotID slot;
  656. CreatureID type;
  657. void visitTyped(ICPackVisitor & visitor) override;
  658. template <typename Handler> void serialize(Handler & h)
  659. {
  660. h & army;
  661. h & slot;
  662. h & type;
  663. }
  664. };
  665. struct DLL_LINKAGE EraseStack : CGarrisonOperationPack
  666. {
  667. ObjectInstanceID army;
  668. SlotID slot;
  669. void visitTyped(ICPackVisitor & visitor) override;
  670. template <typename Handler> void serialize(Handler & h)
  671. {
  672. h & army;
  673. h & slot;
  674. }
  675. };
  676. struct DLL_LINKAGE SwapStacks : CGarrisonOperationPack
  677. {
  678. ObjectInstanceID srcArmy;
  679. ObjectInstanceID dstArmy;
  680. SlotID srcSlot;
  681. SlotID dstSlot;
  682. void visitTyped(ICPackVisitor & visitor) override;
  683. template <typename Handler> void serialize(Handler & h)
  684. {
  685. h & srcArmy;
  686. h & dstArmy;
  687. h & srcSlot;
  688. h & dstSlot;
  689. }
  690. };
  691. struct DLL_LINKAGE InsertNewStack : CGarrisonOperationPack
  692. {
  693. ObjectInstanceID army;
  694. SlotID slot;
  695. CreatureID type;
  696. TQuantity count = 0;
  697. void visitTyped(ICPackVisitor & visitor) override;
  698. template <typename Handler> void serialize(Handler & h)
  699. {
  700. h & army;
  701. h & slot;
  702. h & type;
  703. h & count;
  704. }
  705. };
  706. ///moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  707. struct DLL_LINKAGE RebalanceStacks : CGarrisonOperationPack
  708. {
  709. ObjectInstanceID srcArmy;
  710. ObjectInstanceID dstArmy;
  711. SlotID srcSlot;
  712. SlotID dstSlot;
  713. TQuantity count;
  714. void visitTyped(ICPackVisitor & visitor) override;
  715. template <typename Handler> void serialize(Handler & h)
  716. {
  717. h & srcArmy;
  718. h & dstArmy;
  719. h & srcSlot;
  720. h & dstSlot;
  721. h & count;
  722. }
  723. };
  724. struct DLL_LINKAGE BulkRebalanceStacks : CGarrisonOperationPack
  725. {
  726. std::vector<RebalanceStacks> moves;
  727. void visitTyped(ICPackVisitor & visitor) override;
  728. template <typename Handler>
  729. void serialize(Handler & h)
  730. {
  731. h & moves;
  732. }
  733. };
  734. struct DLL_LINKAGE CArtifactOperationPack : CPackForClient
  735. {
  736. };
  737. struct DLL_LINKAGE PutArtifact : CArtifactOperationPack
  738. {
  739. PutArtifact() = default;
  740. explicit PutArtifact(const ArtifactInstanceID & id, const ArtifactLocation & dst, bool askAssemble = true)
  741. : al(dst), askAssemble(askAssemble), id(id)
  742. {
  743. }
  744. ArtifactLocation al;
  745. bool askAssemble;
  746. ArtifactInstanceID id;
  747. void visitTyped(ICPackVisitor & visitor) override;
  748. template <typename Handler> void serialize(Handler & h)
  749. {
  750. h & al;
  751. h & askAssemble;
  752. h & id;
  753. }
  754. };
  755. struct DLL_LINKAGE NewArtifact : public CArtifactOperationPack
  756. {
  757. ObjectInstanceID artHolder;
  758. ArtifactID artId;
  759. SpellID spellId;
  760. ArtifactPosition pos;
  761. void visitTyped(ICPackVisitor & visitor) override;
  762. template <typename Handler> void serialize(Handler & h)
  763. {
  764. h & artHolder;
  765. h & artId;
  766. h & spellId;
  767. h & pos;
  768. }
  769. };
  770. struct DLL_LINKAGE BulkEraseArtifacts : CArtifactOperationPack
  771. {
  772. ObjectInstanceID artHolder;
  773. std::vector<ArtifactPosition> posPack;
  774. std::optional<SlotID> creature;
  775. void visitTyped(ICPackVisitor & visitor) override;
  776. template <typename Handler> void serialize(Handler & h)
  777. {
  778. h & artHolder;
  779. h & posPack;
  780. h & creature;
  781. }
  782. };
  783. struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
  784. {
  785. PlayerColor interfaceOwner;
  786. ObjectInstanceID srcArtHolder;
  787. ObjectInstanceID dstArtHolder;
  788. std::optional<SlotID> srcCreature;
  789. std::optional<SlotID> dstCreature;
  790. BulkMoveArtifacts()
  791. : interfaceOwner(PlayerColor::NEUTRAL)
  792. , srcArtHolder(ObjectInstanceID::NONE)
  793. , dstArtHolder(ObjectInstanceID::NONE)
  794. , srcCreature(std::nullopt)
  795. , dstCreature(std::nullopt)
  796. {
  797. }
  798. BulkMoveArtifacts(const PlayerColor & interfaceOwner, const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
  799. : interfaceOwner(interfaceOwner)
  800. , srcArtHolder(srcArtHolder)
  801. , dstArtHolder(dstArtHolder)
  802. , srcCreature(std::nullopt)
  803. , dstCreature(std::nullopt)
  804. {
  805. }
  806. std::vector<MoveArtifactInfo> artsPack0;
  807. std::vector<MoveArtifactInfo> artsPack1;
  808. void visitTyped(ICPackVisitor & visitor) override;
  809. template <typename Handler> void serialize(Handler & h)
  810. {
  811. h & interfaceOwner;
  812. h & artsPack0;
  813. h & artsPack1;
  814. h & srcArtHolder;
  815. h & dstArtHolder;
  816. h & srcCreature;
  817. h & dstCreature;
  818. }
  819. };
  820. struct DLL_LINKAGE AssembledArtifact : CArtifactOperationPack
  821. {
  822. ArtifactLocation al;
  823. ArtifactID artId;
  824. void visitTyped(ICPackVisitor & visitor) override;
  825. template <typename Handler> void serialize(Handler & h)
  826. {
  827. h & al;
  828. h & artId;
  829. }
  830. };
  831. struct DLL_LINKAGE DisassembledArtifact : CArtifactOperationPack
  832. {
  833. ArtifactLocation al;
  834. void visitTyped(ICPackVisitor & visitor) override;
  835. template <typename Handler> void serialize(Handler & h)
  836. {
  837. h & al;
  838. }
  839. };
  840. struct DLL_LINKAGE HeroVisit : public CPackForClient
  841. {
  842. PlayerColor player;
  843. ObjectInstanceID heroId;
  844. ObjectInstanceID objId;
  845. bool starting; //false -> ending
  846. void visitTyped(ICPackVisitor & visitor) override;
  847. template <typename Handler> void serialize(Handler & h)
  848. {
  849. h & player;
  850. h & heroId;
  851. h & objId;
  852. h & starting;
  853. }
  854. };
  855. struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
  856. {
  857. EInfoWindowMode type = EInfoWindowMode::MODAL;
  858. MetaString text;
  859. std::vector<Component> components;
  860. PlayerColor player;
  861. ui16 soundID = 0;
  862. void visitTyped(ICPackVisitor & visitor) override;
  863. template <typename Handler> void serialize(Handler & h)
  864. {
  865. h & type;
  866. h & text;
  867. h & components;
  868. h & player;
  869. h & soundID;
  870. }
  871. InfoWindow() = default;
  872. };
  873. struct DLL_LINKAGE NewTurn : public CPackForClient
  874. {
  875. void visitTyped(ICPackVisitor & visitor) override;
  876. ui32 day = 0;
  877. CreatureID creatureid; //for creature weeks
  878. EWeekType specialWeek = EWeekType::NORMAL;
  879. std::vector<SetMovePoints> heroesMovement;
  880. std::vector<SetMana> heroesMana;
  881. std::vector<SetAvailableCreatures> availableCreatures;
  882. std::map<PlayerColor, ResourceSet> playerIncome;
  883. std::optional<RumorState> newRumor; // only on new weeks
  884. std::optional<InfoWindow> newWeekNotification; // only on new week
  885. NewTurn() = default;
  886. template <typename Handler> void serialize(Handler & h)
  887. {
  888. h & day;
  889. h & creatureid;
  890. h & specialWeek;
  891. h & heroesMovement;
  892. h & heroesMana;
  893. h & availableCreatures;
  894. h & playerIncome;
  895. h & newRumor;
  896. h & newWeekNotification;
  897. }
  898. };
  899. struct DLL_LINKAGE SetObjectProperty : public CPackForClient
  900. {
  901. ObjectInstanceID id;
  902. ObjProperty what{};
  903. ObjPropertyID identifier;
  904. SetObjectProperty() = default;
  905. void visitTyped(ICPackVisitor & visitor) override;
  906. template <typename Handler> void serialize(Handler & h)
  907. {
  908. h & id;
  909. h & what;
  910. h & identifier;
  911. }
  912. };
  913. struct DLL_LINKAGE ChangeObjectVisitors : public CPackForClient
  914. {
  915. enum VisitMode
  916. {
  917. VISITOR_ADD_HERO, // mark hero as one that have visited this object
  918. VISITOR_ADD_PLAYER, // mark player as one that have visited this object instance
  919. VISITOR_SCOUTED, // marks targeted team as having scouted this object
  920. VISITOR_CLEAR, // clear all visitors from this object (object reset)
  921. };
  922. VisitMode mode = VISITOR_CLEAR; // uses VisitMode enum
  923. ObjectInstanceID object;
  924. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  925. void visitTyped(ICPackVisitor & visitor) override;
  926. ChangeObjectVisitors() = default;
  927. ChangeObjectVisitors(VisitMode mode, const ObjectInstanceID & object, const ObjectInstanceID & heroID = ObjectInstanceID(-1))
  928. : mode(mode)
  929. , object(object)
  930. , hero(heroID)
  931. {
  932. }
  933. template <typename Handler> void serialize(Handler & h)
  934. {
  935. h & object;
  936. h & hero;
  937. h & mode;
  938. }
  939. };
  940. struct DLL_LINKAGE ChangeArtifactsCostume : public CPackForClient
  941. {
  942. std::map<ArtifactPosition, ArtifactID> costumeSet;
  943. uint32_t costumeIdx = 0;
  944. const PlayerColor player = PlayerColor::NEUTRAL;
  945. void visitTyped(ICPackVisitor & visitor) override;
  946. ChangeArtifactsCostume() = default;
  947. ChangeArtifactsCostume(const PlayerColor & player, const uint32_t costumeIdx)
  948. : costumeIdx(costumeIdx)
  949. , player(player)
  950. {
  951. }
  952. template <typename Handler> void serialize(Handler & h)
  953. {
  954. h & costumeSet;
  955. h & costumeIdx;
  956. h & player;
  957. }
  958. };
  959. struct DLL_LINKAGE HeroLevelUp : public Query
  960. {
  961. PlayerColor player;
  962. ObjectInstanceID heroId;
  963. PrimarySkill primskill = PrimarySkill::ATTACK;
  964. std::vector<SecondarySkill> skills;
  965. void visitTyped(ICPackVisitor & visitor) override;
  966. template <typename Handler> void serialize(Handler & h)
  967. {
  968. h & queryID;
  969. h & player;
  970. h & heroId;
  971. h & primskill;
  972. h & skills;
  973. }
  974. };
  975. struct DLL_LINKAGE CommanderLevelUp : public Query
  976. {
  977. PlayerColor player;
  978. ObjectInstanceID heroId;
  979. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  980. void visitTyped(ICPackVisitor & visitor) override;
  981. template <typename Handler> void serialize(Handler & h)
  982. {
  983. h & queryID;
  984. h & player;
  985. h & heroId;
  986. h & skills;
  987. }
  988. };
  989. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  990. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  991. //Until sending reply player won't be allowed to take any actions
  992. struct DLL_LINKAGE BlockingDialog : public Query
  993. {
  994. enum { ALLOW_CANCEL = 1, SELECTION = 2, SAFE_TO_AUTOACCEPT = 4 };
  995. MetaString text;
  996. std::vector<Component> components;
  997. PlayerColor player;
  998. ui8 flags = 0;
  999. ui16 soundID = 0;
  1000. bool cancel() const
  1001. {
  1002. return flags & ALLOW_CANCEL;
  1003. }
  1004. bool selection() const
  1005. {
  1006. return flags & SELECTION;
  1007. }
  1008. bool safeToAutoaccept() const
  1009. {
  1010. return flags & SAFE_TO_AUTOACCEPT;
  1011. }
  1012. BlockingDialog(bool yesno, bool Selection)
  1013. {
  1014. if(yesno) flags |= ALLOW_CANCEL;
  1015. if(Selection) flags |= SELECTION;
  1016. }
  1017. BlockingDialog() = default;
  1018. void visitTyped(ICPackVisitor & visitor) override;
  1019. template <typename Handler> void serialize(Handler & h)
  1020. {
  1021. h & queryID;
  1022. h & text;
  1023. h & components;
  1024. h & player;
  1025. h & flags;
  1026. h & soundID;
  1027. }
  1028. };
  1029. struct DLL_LINKAGE GarrisonDialog : public Query
  1030. {
  1031. ObjectInstanceID objid;
  1032. ObjectInstanceID hid;
  1033. bool removableUnits = false;
  1034. void visitTyped(ICPackVisitor & visitor) override;
  1035. template <typename Handler> void serialize(Handler & h)
  1036. {
  1037. h & queryID;
  1038. h & objid;
  1039. h & hid;
  1040. h & removableUnits;
  1041. }
  1042. };
  1043. struct DLL_LINKAGE ExchangeDialog : public Query
  1044. {
  1045. PlayerColor player;
  1046. ObjectInstanceID hero1;
  1047. ObjectInstanceID hero2;
  1048. void visitTyped(ICPackVisitor & visitor) override;
  1049. template <typename Handler> void serialize(Handler & h)
  1050. {
  1051. h & queryID;
  1052. h & player;
  1053. h & hero1;
  1054. h & hero2;
  1055. }
  1056. };
  1057. struct DLL_LINKAGE TeleportDialog : public Query
  1058. {
  1059. TeleportDialog() = default;
  1060. TeleportDialog(const ObjectInstanceID & hero, const TeleportChannelID & Channel)
  1061. : hero(hero)
  1062. , channel(Channel)
  1063. {
  1064. }
  1065. ObjectInstanceID hero;
  1066. TeleportChannelID channel;
  1067. TTeleportExitsList exits;
  1068. bool impassable = false;
  1069. void visitTyped(ICPackVisitor & visitor) override;
  1070. template <typename Handler> void serialize(Handler & h)
  1071. {
  1072. h & queryID;
  1073. h & hero;
  1074. h & channel;
  1075. h & exits;
  1076. h & impassable;
  1077. }
  1078. };
  1079. struct DLL_LINKAGE MapObjectSelectDialog : public Query
  1080. {
  1081. PlayerColor player;
  1082. Component icon;
  1083. MetaString title;
  1084. MetaString description;
  1085. std::vector<ObjectInstanceID> objects;
  1086. void visitTyped(ICPackVisitor & visitor) override;
  1087. template <typename Handler> void serialize(Handler & h)
  1088. {
  1089. h & queryID;
  1090. h & player;
  1091. h & icon;
  1092. h & title;
  1093. h & description;
  1094. h & objects;
  1095. }
  1096. };
  1097. struct DLL_LINKAGE AdvmapSpellCast : public CPackForClient
  1098. {
  1099. ObjectInstanceID casterID;
  1100. SpellID spellID;
  1101. template <typename Handler> void serialize(Handler & h)
  1102. {
  1103. h & casterID;
  1104. h & spellID;
  1105. }
  1106. protected:
  1107. void visitTyped(ICPackVisitor & visitor) override;
  1108. };
  1109. struct DLL_LINKAGE ShowWorldViewEx : public CPackForClient
  1110. {
  1111. PlayerColor player;
  1112. bool showTerrain; // TODO: send terrain state
  1113. std::vector<ObjectPosInfo> objectPositions;
  1114. template <typename Handler> void serialize(Handler & h)
  1115. {
  1116. h & player;
  1117. h & showTerrain;
  1118. h & objectPositions;
  1119. }
  1120. protected:
  1121. void visitTyped(ICPackVisitor & visitor) override;
  1122. };
  1123. struct DLL_LINKAGE PlayerMessageClient : public CPackForClient
  1124. {
  1125. PlayerMessageClient() = default;
  1126. PlayerMessageClient(const PlayerColor & Player, std::string Text)
  1127. : player(Player)
  1128. , text(std::move(Text))
  1129. {
  1130. }
  1131. void visitTyped(ICPackVisitor & visitor) override;
  1132. PlayerColor player;
  1133. std::string text;
  1134. template <typename Handler> void serialize(Handler & h)
  1135. {
  1136. h & player;
  1137. h & text;
  1138. }
  1139. };
  1140. struct DLL_LINKAGE CenterView : public CPackForClient
  1141. {
  1142. PlayerColor player;
  1143. int3 pos;
  1144. ui32 focusTime = 0; //ms
  1145. void visitTyped(ICPackVisitor & visitor) override;
  1146. template <typename Handler> void serialize(Handler & h)
  1147. {
  1148. h & pos;
  1149. h & player;
  1150. h & focusTime;
  1151. }
  1152. };
  1153. VCMI_LIB_NAMESPACE_END