PacksForClient.h 31 KB

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