PacksForClient.h 31 KB

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