PacksForClient.h 32 KB

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