PacksForClient.h 31 KB

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