PacksForClient.h 30 KB

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