PacksForClient.h 31 KB

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