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