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