PacksForClient.h 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  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. VariantIdentifier<MapObjectSubID, HeroTypeID, CreatureID, BoatId> 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. h & subID;
  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 = false;
  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. BulkMoveArtifacts()
  852. : srcArtHolder(ObjectInstanceID::NONE)
  853. , dstArtHolder(ObjectInstanceID::NONE)
  854. , swap(false)
  855. {
  856. }
  857. BulkMoveArtifacts(const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
  858. : srcArtHolder(std::move(srcArtHolder))
  859. , dstArtHolder(std::move(dstArtHolder))
  860. , swap(swap)
  861. {
  862. }
  863. void applyGs(CGameState * gs);
  864. std::vector<LinkedSlots> artsPack0;
  865. std::vector<LinkedSlots> artsPack1;
  866. bool swap;
  867. void visitTyped(ICPackVisitor & visitor) override;
  868. template <typename Handler> void serialize(Handler & h, const int version)
  869. {
  870. h & artsPack0;
  871. h & artsPack1;
  872. h & srcArtHolder;
  873. h & dstArtHolder;
  874. h & swap;
  875. }
  876. };
  877. struct DLL_LINKAGE AssembledArtifact : CArtifactOperationPack
  878. {
  879. ArtifactLocation al; //where assembly will be put
  880. CArtifact * builtArt;
  881. void applyGs(CGameState * gs);
  882. void visitTyped(ICPackVisitor & visitor) override;
  883. template <typename Handler> void serialize(Handler & h, const int version)
  884. {
  885. h & al;
  886. h & builtArt;
  887. }
  888. };
  889. struct DLL_LINKAGE DisassembledArtifact : CArtifactOperationPack
  890. {
  891. ArtifactLocation al;
  892. void applyGs(CGameState * gs);
  893. void visitTyped(ICPackVisitor & visitor) override;
  894. template <typename Handler> void serialize(Handler & h, const int version)
  895. {
  896. h & al;
  897. }
  898. };
  899. struct DLL_LINKAGE HeroVisit : public CPackForClient
  900. {
  901. PlayerColor player;
  902. ObjectInstanceID heroId;
  903. ObjectInstanceID objId;
  904. bool starting; //false -> ending
  905. void applyGs(CGameState * gs);
  906. void visitTyped(ICPackVisitor & visitor) override;
  907. template <typename Handler> void serialize(Handler & h, const int version)
  908. {
  909. h & player;
  910. h & heroId;
  911. h & objId;
  912. h & starting;
  913. }
  914. };
  915. struct DLL_LINKAGE NewTurn : public CPackForClient
  916. {
  917. enum weekType { NORMAL, DOUBLE_GROWTH, BONUS_GROWTH, DEITYOFFIRE, PLAGUE, NO_ACTION };
  918. void applyGs(CGameState * gs);
  919. void visitTyped(ICPackVisitor & visitor) override;
  920. struct Hero
  921. {
  922. ObjectInstanceID id;
  923. ui32 move, mana; //id is a general serial id
  924. template <typename Handler> void serialize(Handler & h, const int version)
  925. {
  926. h & id;
  927. h & move;
  928. h & mana;
  929. }
  930. bool operator<(const Hero & h)const { return id < h.id; }
  931. };
  932. std::set<Hero> heroes; //updates movement and mana points
  933. std::map<PlayerColor, ResourceSet> res; //player ID => resource value[res_id]
  934. std::map<ObjectInstanceID, SetAvailableCreatures> cres;//creatures to be placed in towns
  935. ui32 day = 0;
  936. ui8 specialWeek = 0; //weekType
  937. CreatureID creatureid; //for creature weeks
  938. NewTurn() = default;
  939. template <typename Handler> void serialize(Handler & h, const int version)
  940. {
  941. h & heroes;
  942. h & cres;
  943. h & res;
  944. h & day;
  945. h & specialWeek;
  946. h & creatureid;
  947. }
  948. };
  949. struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
  950. {
  951. EInfoWindowMode type = EInfoWindowMode::MODAL;
  952. MetaString text;
  953. std::vector<Component> components;
  954. PlayerColor player;
  955. ui16 soundID = 0;
  956. void visitTyped(ICPackVisitor & visitor) override;
  957. template <typename Handler> void serialize(Handler & h, const int version)
  958. {
  959. h & type;
  960. h & text;
  961. h & components;
  962. h & player;
  963. h & soundID;
  964. }
  965. InfoWindow() = default;
  966. };
  967. struct DLL_LINKAGE SetObjectProperty : public CPackForClient
  968. {
  969. void applyGs(CGameState * gs) const;
  970. ObjectInstanceID id;
  971. ObjProperty what{};
  972. ObjPropertyID identifier;
  973. int32_t value = 0;
  974. SetObjectProperty() = default;
  975. void visitTyped(ICPackVisitor & visitor) override;
  976. template <typename Handler> void serialize(Handler & h, const int version)
  977. {
  978. h & id;
  979. h & what;
  980. h & identifier;
  981. h & value;
  982. }
  983. };
  984. struct DLL_LINKAGE ChangeObjectVisitors : public CPackForClient
  985. {
  986. enum VisitMode
  987. {
  988. VISITOR_ADD, // mark hero as one that have visited this object
  989. VISITOR_ADD_TEAM, // mark team as one that have visited this object
  990. VISITOR_REMOVE, // unmark visitor, reversed to ADD
  991. VISITOR_CLEAR // clear all visitors from this object (object reset)
  992. };
  993. ui32 mode = VISITOR_CLEAR; // uses VisitMode enum
  994. ObjectInstanceID object;
  995. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  996. void applyGs(CGameState * gs) const;
  997. void visitTyped(ICPackVisitor & visitor) override;
  998. ChangeObjectVisitors() = default;
  999. ChangeObjectVisitors(ui32 mode, const ObjectInstanceID & object, const ObjectInstanceID & heroID = ObjectInstanceID(-1))
  1000. : mode(mode)
  1001. , object(object)
  1002. , hero(heroID)
  1003. {
  1004. }
  1005. template <typename Handler> void serialize(Handler & h, const int version)
  1006. {
  1007. h & object;
  1008. h & hero;
  1009. h & mode;
  1010. }
  1011. };
  1012. struct DLL_LINKAGE PrepareHeroLevelUp : public CPackForClient
  1013. {
  1014. ObjectInstanceID heroId;
  1015. /// Do not serialize, used by server only
  1016. std::vector<SecondarySkill> skills;
  1017. void applyGs(CGameState * gs);
  1018. void visitTyped(ICPackVisitor & visitor) override;
  1019. template <typename Handler> void serialize(Handler & h, const int version)
  1020. {
  1021. h & heroId;
  1022. }
  1023. };
  1024. struct DLL_LINKAGE HeroLevelUp : public Query
  1025. {
  1026. PlayerColor player;
  1027. ObjectInstanceID heroId;
  1028. PrimarySkill primskill = PrimarySkill::ATTACK;
  1029. std::vector<SecondarySkill> skills;
  1030. void applyGs(CGameState * gs) const;
  1031. void visitTyped(ICPackVisitor & visitor) override;
  1032. template <typename Handler> void serialize(Handler & h, const int version)
  1033. {
  1034. h & queryID;
  1035. h & player;
  1036. h & heroId;
  1037. h & primskill;
  1038. h & skills;
  1039. }
  1040. };
  1041. struct DLL_LINKAGE CommanderLevelUp : public Query
  1042. {
  1043. PlayerColor player;
  1044. ObjectInstanceID heroId;
  1045. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1046. void applyGs(CGameState * gs) const;
  1047. void visitTyped(ICPackVisitor & visitor) override;
  1048. template <typename Handler> void serialize(Handler & h, const int version)
  1049. {
  1050. h & queryID;
  1051. h & player;
  1052. h & heroId;
  1053. h & skills;
  1054. }
  1055. };
  1056. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1057. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1058. //Until sending reply player won't be allowed to take any actions
  1059. struct DLL_LINKAGE BlockingDialog : public Query
  1060. {
  1061. enum { ALLOW_CANCEL = 1, SELECTION = 2 };
  1062. MetaString text;
  1063. std::vector<Component> components;
  1064. PlayerColor player;
  1065. ui8 flags = 0;
  1066. ui16 soundID = 0;
  1067. bool cancel() const
  1068. {
  1069. return flags & ALLOW_CANCEL;
  1070. }
  1071. bool selection() const
  1072. {
  1073. return flags & SELECTION;
  1074. }
  1075. BlockingDialog(bool yesno, bool Selection)
  1076. {
  1077. if(yesno) flags |= ALLOW_CANCEL;
  1078. if(Selection) flags |= SELECTION;
  1079. }
  1080. BlockingDialog() = default;
  1081. void visitTyped(ICPackVisitor & visitor) override;
  1082. template <typename Handler> void serialize(Handler & h, const int version)
  1083. {
  1084. h & queryID;
  1085. h & text;
  1086. h & components;
  1087. h & player;
  1088. h & flags;
  1089. h & soundID;
  1090. }
  1091. };
  1092. struct DLL_LINKAGE GarrisonDialog : public Query
  1093. {
  1094. ObjectInstanceID objid, hid;
  1095. bool removableUnits = false;
  1096. void visitTyped(ICPackVisitor & visitor) override;
  1097. template <typename Handler> void serialize(Handler & h, const int version)
  1098. {
  1099. h & queryID;
  1100. h & objid;
  1101. h & hid;
  1102. h & removableUnits;
  1103. }
  1104. };
  1105. struct DLL_LINKAGE ExchangeDialog : public Query
  1106. {
  1107. PlayerColor player;
  1108. ObjectInstanceID hero1;
  1109. ObjectInstanceID hero2;
  1110. void visitTyped(ICPackVisitor & visitor) override;
  1111. template <typename Handler> void serialize(Handler & h, const int version)
  1112. {
  1113. h & queryID;
  1114. h & player;
  1115. h & hero1;
  1116. h & hero2;
  1117. }
  1118. };
  1119. struct DLL_LINKAGE TeleportDialog : public Query
  1120. {
  1121. TeleportDialog() = default;
  1122. TeleportDialog(const ObjectInstanceID & hero, const TeleportChannelID & Channel)
  1123. : hero(hero)
  1124. , channel(Channel)
  1125. {
  1126. }
  1127. ObjectInstanceID hero;
  1128. TeleportChannelID channel;
  1129. TTeleportExitsList exits;
  1130. bool impassable = false;
  1131. void visitTyped(ICPackVisitor & visitor) override;
  1132. template <typename Handler> void serialize(Handler & h, const int version)
  1133. {
  1134. h & queryID;
  1135. h & hero;
  1136. h & channel;
  1137. h & exits;
  1138. h & impassable;
  1139. }
  1140. };
  1141. struct DLL_LINKAGE MapObjectSelectDialog : public Query
  1142. {
  1143. PlayerColor player;
  1144. Component icon;
  1145. MetaString title;
  1146. MetaString description;
  1147. std::vector<ObjectInstanceID> objects;
  1148. void visitTyped(ICPackVisitor & visitor) override;
  1149. template <typename Handler> void serialize(Handler & h, const int version)
  1150. {
  1151. h & queryID;
  1152. h & player;
  1153. h & icon;
  1154. h & title;
  1155. h & description;
  1156. h & objects;
  1157. }
  1158. };
  1159. struct DLL_LINKAGE AdvmapSpellCast : public CPackForClient
  1160. {
  1161. ObjectInstanceID casterID;
  1162. SpellID spellID;
  1163. template <typename Handler> void serialize(Handler & h, const int version)
  1164. {
  1165. h & casterID;
  1166. h & spellID;
  1167. }
  1168. protected:
  1169. void visitTyped(ICPackVisitor & visitor) 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. template <typename Handler> void serialize(Handler & h, const int version)
  1177. {
  1178. h & player;
  1179. h & showTerrain;
  1180. h & objectPositions;
  1181. }
  1182. protected:
  1183. void visitTyped(ICPackVisitor & visitor) override;
  1184. };
  1185. struct DLL_LINKAGE PlayerMessageClient : public CPackForClient
  1186. {
  1187. PlayerMessageClient() = default;
  1188. PlayerMessageClient(const PlayerColor & Player, std::string Text)
  1189. : player(Player)
  1190. , text(std::move(Text))
  1191. {
  1192. }
  1193. void visitTyped(ICPackVisitor & visitor) override;
  1194. PlayerColor player;
  1195. std::string text;
  1196. template <typename Handler> void serialize(Handler & h, const int version)
  1197. {
  1198. h & player;
  1199. h & text;
  1200. }
  1201. };
  1202. struct DLL_LINKAGE CenterView : public CPackForClient
  1203. {
  1204. PlayerColor player;
  1205. int3 pos;
  1206. ui32 focusTime = 0; //ms
  1207. void visitTyped(ICPackVisitor & visitor) override;
  1208. template <typename Handler> void serialize(Handler & h, const int version)
  1209. {
  1210. h & pos;
  1211. h & player;
  1212. h & focusTime;
  1213. }
  1214. };
  1215. VCMI_LIB_NAMESPACE_END