PacksForClient.h 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490
  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 "../ResourceSet.h"
  20. #include "../TurnTimerInfo.h"
  21. #include "../gameState/EVictoryLossCheckResult.h"
  22. #include "../gameState/RumorState.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(MetaString Text)
  67. : text(std::move(Text))
  68. {
  69. }
  70. SystemMessage() = default;
  71. void visitTyped(ICPackVisitor & visitor) override;
  72. MetaString 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 ChangeFormation : public CPackForClient
  433. {
  434. ObjectInstanceID hid;
  435. EArmyFormation formation{};
  436. void applyGs(CGameState * gs) const;
  437. void visitTyped(ICPackVisitor & visitor) override;
  438. template <typename Handler> void serialize(Handler & h)
  439. {
  440. h & hid;
  441. h & formation;
  442. }
  443. };
  444. struct DLL_LINKAGE RemoveObject : public CPackForClient
  445. {
  446. RemoveObject() = default;
  447. RemoveObject(const ObjectInstanceID & objectID, const PlayerColor & initiator)
  448. : objectID(objectID)
  449. , initiator(initiator)
  450. {
  451. }
  452. void applyGs(CGameState * gs);
  453. void visitTyped(ICPackVisitor & visitor) override;
  454. /// ID of removed object
  455. ObjectInstanceID objectID;
  456. /// Player that initiated this action, if any
  457. PlayerColor initiator;
  458. template <typename Handler> void serialize(Handler & h)
  459. {
  460. h & objectID;
  461. h & initiator;
  462. }
  463. };
  464. struct DLL_LINKAGE TryMoveHero : public CPackForClient
  465. {
  466. void applyGs(CGameState * gs);
  467. enum EResult
  468. {
  469. FAILED,
  470. SUCCESS,
  471. TELEPORTATION,
  472. BLOCKING_VISIT,
  473. EMBARK,
  474. DISEMBARK
  475. };
  476. ObjectInstanceID id;
  477. ui32 movePoints = 0;
  478. EResult result = FAILED; //uses EResult
  479. int3 start; //h3m format
  480. int3 end;
  481. std::unordered_set<int3> fowRevealed; //revealed tiles
  482. std::optional<int3> attackedFrom; // Set when stepping into endangered tile.
  483. void visitTyped(ICPackVisitor & visitor) override;
  484. bool stopMovement() const
  485. {
  486. return result != SUCCESS && result != EMBARK && result != DISEMBARK && result != TELEPORTATION;
  487. }
  488. template <typename Handler> void serialize(Handler & h)
  489. {
  490. h & id;
  491. h & result;
  492. h & start;
  493. h & end;
  494. h & movePoints;
  495. h & fowRevealed;
  496. h & attackedFrom;
  497. }
  498. };
  499. struct DLL_LINKAGE NewStructures : public CPackForClient
  500. {
  501. void applyGs(CGameState * gs);
  502. ObjectInstanceID tid;
  503. std::set<BuildingID> bid;
  504. si16 built = 0;
  505. void visitTyped(ICPackVisitor & visitor) override;
  506. template <typename Handler> void serialize(Handler & h)
  507. {
  508. h & tid;
  509. h & bid;
  510. h & built;
  511. }
  512. };
  513. struct DLL_LINKAGE RazeStructures : public CPackForClient
  514. {
  515. void applyGs(CGameState * gs);
  516. ObjectInstanceID tid;
  517. std::set<BuildingID> bid;
  518. si16 destroyed = 0;
  519. void visitTyped(ICPackVisitor & visitor) override;
  520. template <typename Handler> void serialize(Handler & h)
  521. {
  522. h & tid;
  523. h & bid;
  524. h & destroyed;
  525. }
  526. };
  527. struct DLL_LINKAGE SetAvailableCreatures : public CPackForClient
  528. {
  529. void applyGs(CGameState * gs) const;
  530. ObjectInstanceID tid;
  531. std::vector<std::pair<ui32, std::vector<CreatureID> > > creatures;
  532. void visitTyped(ICPackVisitor & visitor) override;
  533. template <typename Handler> void serialize(Handler & h)
  534. {
  535. h & tid;
  536. h & creatures;
  537. }
  538. };
  539. struct DLL_LINKAGE SetHeroesInTown : public CPackForClient
  540. {
  541. void applyGs(CGameState * gs) const;
  542. ObjectInstanceID tid; //id of town
  543. ObjectInstanceID visiting; //id of visiting hero
  544. ObjectInstanceID garrison; //id of hero in garrison
  545. void visitTyped(ICPackVisitor & visitor) override;
  546. template <typename Handler> void serialize(Handler & h)
  547. {
  548. h & tid;
  549. h & visiting;
  550. h & garrison;
  551. }
  552. };
  553. struct DLL_LINKAGE HeroRecruited : public CPackForClient
  554. {
  555. void applyGs(CGameState * gs) const;
  556. HeroTypeID hid; //subID of hero
  557. ObjectInstanceID tid;
  558. ObjectInstanceID boatId;
  559. int3 tile;
  560. PlayerColor player;
  561. void visitTyped(ICPackVisitor & visitor) override;
  562. template <typename Handler> void serialize(Handler & h)
  563. {
  564. h & hid;
  565. h & tid;
  566. h & boatId;
  567. h & tile;
  568. h & player;
  569. }
  570. };
  571. struct DLL_LINKAGE GiveHero : public CPackForClient
  572. {
  573. void applyGs(CGameState * gs) const;
  574. ObjectInstanceID id; //object id
  575. ObjectInstanceID boatId;
  576. PlayerColor player;
  577. void visitTyped(ICPackVisitor & visitor) override;
  578. template <typename Handler> void serialize(Handler & h)
  579. {
  580. h & id;
  581. h & boatId;
  582. h & player;
  583. }
  584. };
  585. struct DLL_LINKAGE OpenWindow : public Query
  586. {
  587. EOpenWindowMode window;
  588. ObjectInstanceID object;
  589. ObjectInstanceID visitor;
  590. void visitTyped(ICPackVisitor & visitor) override;
  591. template <typename Handler> void serialize(Handler & h)
  592. {
  593. h & queryID;
  594. h & window;
  595. h & object;
  596. h & visitor;
  597. }
  598. };
  599. struct DLL_LINKAGE NewObject : public CPackForClient
  600. {
  601. void applyGs(CGameState * gs);
  602. /// Object ID to create
  603. CGObjectInstance * newObject;
  604. /// Which player initiated creation of this object
  605. PlayerColor initiator;
  606. void visitTyped(ICPackVisitor & visitor) override;
  607. template <typename Handler> void serialize(Handler & h)
  608. {
  609. h & newObject;
  610. h & initiator;
  611. }
  612. };
  613. struct DLL_LINKAGE SetAvailableArtifacts : public CPackForClient
  614. {
  615. void applyGs(CGameState * gs) const;
  616. //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)
  617. ObjectInstanceID id;
  618. std::vector<const CArtifact *> arts;
  619. void visitTyped(ICPackVisitor & visitor) override;
  620. template <typename Handler> void serialize(Handler & h)
  621. {
  622. h & id;
  623. h & arts;
  624. }
  625. };
  626. struct DLL_LINKAGE CGarrisonOperationPack : CPackForClient
  627. {
  628. };
  629. struct DLL_LINKAGE ChangeStackCount : CGarrisonOperationPack
  630. {
  631. ObjectInstanceID army;
  632. SlotID slot;
  633. TQuantity count;
  634. bool absoluteValue; //if not -> count will be added (or subtracted if negative)
  635. void applyGs(CGameState * gs);
  636. void visitTyped(ICPackVisitor & visitor) override;
  637. template <typename Handler> void serialize(Handler & h)
  638. {
  639. h & army;
  640. h & slot;
  641. h & count;
  642. h & absoluteValue;
  643. }
  644. };
  645. struct DLL_LINKAGE SetStackType : CGarrisonOperationPack
  646. {
  647. ObjectInstanceID army;
  648. SlotID slot;
  649. CreatureID type;
  650. void applyGs(CGameState * gs);
  651. void visitTyped(ICPackVisitor & visitor) override;
  652. template <typename Handler> void serialize(Handler & h)
  653. {
  654. h & army;
  655. h & slot;
  656. h & type;
  657. }
  658. };
  659. struct DLL_LINKAGE EraseStack : CGarrisonOperationPack
  660. {
  661. ObjectInstanceID army;
  662. SlotID slot;
  663. void applyGs(CGameState * gs);
  664. void visitTyped(ICPackVisitor & visitor) override;
  665. template <typename Handler> void serialize(Handler & h)
  666. {
  667. h & army;
  668. h & slot;
  669. }
  670. };
  671. struct DLL_LINKAGE SwapStacks : CGarrisonOperationPack
  672. {
  673. ObjectInstanceID srcArmy;
  674. ObjectInstanceID dstArmy;
  675. SlotID srcSlot;
  676. SlotID dstSlot;
  677. void applyGs(CGameState * gs);
  678. void visitTyped(ICPackVisitor & visitor) override;
  679. template <typename Handler> void serialize(Handler & h)
  680. {
  681. h & srcArmy;
  682. h & dstArmy;
  683. h & srcSlot;
  684. h & dstSlot;
  685. }
  686. };
  687. struct DLL_LINKAGE InsertNewStack : CGarrisonOperationPack
  688. {
  689. ObjectInstanceID army;
  690. SlotID slot;
  691. CreatureID type;
  692. TQuantity count = 0;
  693. void applyGs(CGameState * gs);
  694. void visitTyped(ICPackVisitor & visitor) override;
  695. template <typename Handler> void serialize(Handler & h)
  696. {
  697. h & army;
  698. h & slot;
  699. h & type;
  700. h & count;
  701. }
  702. };
  703. ///moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  704. struct DLL_LINKAGE RebalanceStacks : CGarrisonOperationPack
  705. {
  706. ObjectInstanceID srcArmy;
  707. ObjectInstanceID dstArmy;
  708. SlotID srcSlot;
  709. SlotID dstSlot;
  710. TQuantity count;
  711. void applyGs(CGameState * gs);
  712. void visitTyped(ICPackVisitor & visitor) override;
  713. template <typename Handler> void serialize(Handler & h)
  714. {
  715. h & srcArmy;
  716. h & dstArmy;
  717. h & srcSlot;
  718. h & dstSlot;
  719. h & count;
  720. }
  721. };
  722. struct DLL_LINKAGE BulkRebalanceStacks : CGarrisonOperationPack
  723. {
  724. std::vector<RebalanceStacks> moves;
  725. void applyGs(CGameState * gs);
  726. void visitTyped(ICPackVisitor & visitor) override;
  727. template <typename Handler>
  728. void serialize(Handler & h)
  729. {
  730. h & moves;
  731. }
  732. };
  733. struct DLL_LINKAGE BulkSmartRebalanceStacks : CGarrisonOperationPack
  734. {
  735. std::vector<RebalanceStacks> moves;
  736. std::vector<ChangeStackCount> changes;
  737. void applyGs(CGameState * gs);
  738. void visitTyped(ICPackVisitor & visitor) override;
  739. template <typename Handler>
  740. void serialize(Handler & h)
  741. {
  742. h & moves;
  743. h & changes;
  744. }
  745. };
  746. struct DLL_LINKAGE CArtifactOperationPack : CPackForClient
  747. {
  748. };
  749. struct DLL_LINKAGE PutArtifact : CArtifactOperationPack
  750. {
  751. PutArtifact() = default;
  752. explicit PutArtifact(ArtifactLocation & dst, bool askAssemble = true)
  753. : al(dst), askAssemble(askAssemble)
  754. {
  755. }
  756. ArtifactLocation al;
  757. bool askAssemble;
  758. ConstTransitivePtr<CArtifactInstance> art;
  759. void applyGs(CGameState * gs);
  760. void visitTyped(ICPackVisitor & visitor) override;
  761. template <typename Handler> void serialize(Handler & h)
  762. {
  763. h & al;
  764. h & askAssemble;
  765. h & art;
  766. }
  767. };
  768. struct DLL_LINKAGE NewArtifact : public CArtifactOperationPack
  769. {
  770. ConstTransitivePtr<CArtifactInstance> art;
  771. void applyGs(CGameState * gs);
  772. void visitTyped(ICPackVisitor & visitor) override;
  773. template <typename Handler> void serialize(Handler & h)
  774. {
  775. h & art;
  776. }
  777. };
  778. struct DLL_LINKAGE EraseArtifact : CArtifactOperationPack
  779. {
  780. ArtifactLocation al;
  781. void applyGs(CGameState * gs);
  782. void visitTyped(ICPackVisitor & visitor) override;
  783. template <typename Handler> void serialize(Handler & h)
  784. {
  785. h & al;
  786. }
  787. };
  788. struct DLL_LINKAGE BulkMoveArtifacts : CArtifactOperationPack
  789. {
  790. struct LinkedSlots
  791. {
  792. ArtifactPosition srcPos;
  793. ArtifactPosition dstPos;
  794. bool askAssemble;
  795. LinkedSlots() = default;
  796. LinkedSlots(const ArtifactPosition & srcPos, const ArtifactPosition & dstPos, bool askAssemble = false)
  797. : srcPos(srcPos)
  798. , dstPos(dstPos)
  799. , askAssemble(askAssemble)
  800. {
  801. }
  802. template <typename Handler> void serialize(Handler & h)
  803. {
  804. h & srcPos;
  805. h & dstPos;
  806. h & askAssemble;
  807. }
  808. };
  809. PlayerColor interfaceOwner;
  810. ObjectInstanceID srcArtHolder;
  811. ObjectInstanceID dstArtHolder;
  812. std::optional<SlotID> srcCreature;
  813. std::optional<SlotID> dstCreature;
  814. BulkMoveArtifacts()
  815. : interfaceOwner(PlayerColor::NEUTRAL)
  816. , srcArtHolder(ObjectInstanceID::NONE)
  817. , dstArtHolder(ObjectInstanceID::NONE)
  818. , srcCreature(std::nullopt)
  819. , dstCreature(std::nullopt)
  820. {
  821. }
  822. BulkMoveArtifacts(const PlayerColor & interfaceOwner, const ObjectInstanceID srcArtHolder, const ObjectInstanceID dstArtHolder, bool swap)
  823. : interfaceOwner(interfaceOwner)
  824. , srcArtHolder(srcArtHolder)
  825. , dstArtHolder(dstArtHolder)
  826. , srcCreature(std::nullopt)
  827. , dstCreature(std::nullopt)
  828. {
  829. }
  830. void applyGs(CGameState * gs);
  831. std::vector<LinkedSlots> artsPack0;
  832. std::vector<LinkedSlots> artsPack1;
  833. void visitTyped(ICPackVisitor & visitor) override;
  834. template <typename Handler> void serialize(Handler & h)
  835. {
  836. h & interfaceOwner;
  837. h & artsPack0;
  838. h & artsPack1;
  839. h & srcArtHolder;
  840. h & dstArtHolder;
  841. h & srcCreature;
  842. h & dstCreature;
  843. }
  844. };
  845. struct DLL_LINKAGE AssembledArtifact : CArtifactOperationPack
  846. {
  847. ArtifactLocation al; //where assembly will be put
  848. const CArtifact * builtArt;
  849. void applyGs(CGameState * gs);
  850. void visitTyped(ICPackVisitor & visitor) override;
  851. template <typename Handler> void serialize(Handler & h)
  852. {
  853. h & al;
  854. h & builtArt;
  855. }
  856. };
  857. struct DLL_LINKAGE DisassembledArtifact : CArtifactOperationPack
  858. {
  859. ArtifactLocation al;
  860. void applyGs(CGameState * gs);
  861. void visitTyped(ICPackVisitor & visitor) override;
  862. template <typename Handler> void serialize(Handler & h)
  863. {
  864. h & al;
  865. }
  866. };
  867. struct DLL_LINKAGE HeroVisit : public CPackForClient
  868. {
  869. PlayerColor player;
  870. ObjectInstanceID heroId;
  871. ObjectInstanceID objId;
  872. bool starting; //false -> ending
  873. void applyGs(CGameState * gs);
  874. void visitTyped(ICPackVisitor & visitor) override;
  875. template <typename Handler> void serialize(Handler & h)
  876. {
  877. h & player;
  878. h & heroId;
  879. h & objId;
  880. h & starting;
  881. }
  882. };
  883. struct DLL_LINKAGE NewTurn : public CPackForClient
  884. {
  885. enum weekType { NORMAL, DOUBLE_GROWTH, BONUS_GROWTH, DEITYOFFIRE, PLAGUE, NO_ACTION };
  886. void applyGs(CGameState * gs);
  887. void visitTyped(ICPackVisitor & visitor) override;
  888. struct Hero
  889. {
  890. ObjectInstanceID id; //id is a general serial id
  891. ui32 move;
  892. ui32 mana;
  893. template <typename Handler> void serialize(Handler & h)
  894. {
  895. h & id;
  896. h & move;
  897. h & mana;
  898. }
  899. bool operator<(const Hero & h)const { return id < h.id; }
  900. };
  901. std::set<Hero> heroes; //updates movement and mana points
  902. std::map<PlayerColor, ResourceSet> res; //player ID => resource value[res_id]
  903. std::map<ObjectInstanceID, SetAvailableCreatures> cres;//creatures to be placed in towns
  904. ui32 day = 0;
  905. ui8 specialWeek = 0; //weekType
  906. CreatureID creatureid; //for creature weeks
  907. std::optional<RumorState> newRumor; // only on new weeks
  908. NewTurn() = default;
  909. template <typename Handler> void serialize(Handler & h)
  910. {
  911. h & heroes;
  912. h & cres;
  913. h & res;
  914. h & day;
  915. h & specialWeek;
  916. h & creatureid;
  917. h & newRumor;
  918. }
  919. };
  920. struct DLL_LINKAGE InfoWindow : public CPackForClient //103 - displays simple info window
  921. {
  922. EInfoWindowMode type = EInfoWindowMode::MODAL;
  923. MetaString text;
  924. std::vector<Component> components;
  925. PlayerColor player;
  926. ui16 soundID = 0;
  927. void visitTyped(ICPackVisitor & visitor) override;
  928. template <typename Handler> void serialize(Handler & h)
  929. {
  930. h & type;
  931. h & text;
  932. h & components;
  933. h & player;
  934. h & soundID;
  935. }
  936. InfoWindow() = default;
  937. };
  938. struct DLL_LINKAGE SetObjectProperty : public CPackForClient
  939. {
  940. void applyGs(CGameState * gs) const;
  941. ObjectInstanceID id;
  942. ObjProperty what{};
  943. ObjPropertyID identifier;
  944. SetObjectProperty() = default;
  945. void visitTyped(ICPackVisitor & visitor) override;
  946. template <typename Handler> void serialize(Handler & h)
  947. {
  948. h & id;
  949. h & what;
  950. h & identifier;
  951. }
  952. };
  953. struct DLL_LINKAGE ChangeObjectVisitors : public CPackForClient
  954. {
  955. enum VisitMode
  956. {
  957. VISITOR_ADD, // mark hero as one that have visited this object
  958. VISITOR_ADD_TEAM, // mark team as one that have visited this object
  959. VISITOR_GLOBAL, // mark player as one that have visited object of this type
  960. VISITOR_REMOVE, // unmark visitor, reversed to ADD
  961. VISITOR_CLEAR // clear all visitors from this object (object reset)
  962. };
  963. VisitMode mode = VISITOR_CLEAR; // uses VisitMode enum
  964. ObjectInstanceID object;
  965. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  966. void applyGs(CGameState * gs) const;
  967. void visitTyped(ICPackVisitor & visitor) override;
  968. ChangeObjectVisitors() = default;
  969. ChangeObjectVisitors(VisitMode mode, const ObjectInstanceID & object, const ObjectInstanceID & heroID = ObjectInstanceID(-1))
  970. : mode(mode)
  971. , object(object)
  972. , hero(heroID)
  973. {
  974. }
  975. template <typename Handler> void serialize(Handler & h)
  976. {
  977. h & object;
  978. h & hero;
  979. h & mode;
  980. }
  981. };
  982. struct DLL_LINKAGE ChangeArtifactsCostume : public CPackForClient
  983. {
  984. std::map<ArtifactPosition, ArtifactID> costumeSet;
  985. uint32_t costumeIdx = 0;
  986. const PlayerColor player = PlayerColor::NEUTRAL;
  987. void applyGs(CGameState * gs) const;
  988. void visitTyped(ICPackVisitor & visitor) override;
  989. ChangeArtifactsCostume() = default;
  990. ChangeArtifactsCostume(const PlayerColor & player, const uint32_t costumeIdx)
  991. : costumeIdx(costumeIdx)
  992. , player(player)
  993. {
  994. }
  995. template <typename Handler> void serialize(Handler & h)
  996. {
  997. h & costumeSet;
  998. h & costumeIdx;
  999. h & player;
  1000. }
  1001. };
  1002. struct DLL_LINKAGE HeroLevelUp : public Query
  1003. {
  1004. PlayerColor player;
  1005. ObjectInstanceID heroId;
  1006. PrimarySkill primskill = PrimarySkill::ATTACK;
  1007. std::vector<SecondarySkill> skills;
  1008. void applyGs(CGameState * gs) const;
  1009. void visitTyped(ICPackVisitor & visitor) override;
  1010. template <typename Handler> void serialize(Handler & h)
  1011. {
  1012. h & queryID;
  1013. h & player;
  1014. h & heroId;
  1015. h & primskill;
  1016. h & skills;
  1017. }
  1018. };
  1019. struct DLL_LINKAGE CommanderLevelUp : public Query
  1020. {
  1021. PlayerColor player;
  1022. ObjectInstanceID heroId;
  1023. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1024. void applyGs(CGameState * gs) const;
  1025. void visitTyped(ICPackVisitor & visitor) override;
  1026. template <typename Handler> void serialize(Handler & h)
  1027. {
  1028. h & queryID;
  1029. h & player;
  1030. h & heroId;
  1031. h & skills;
  1032. }
  1033. };
  1034. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1035. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1036. //Until sending reply player won't be allowed to take any actions
  1037. struct DLL_LINKAGE BlockingDialog : public Query
  1038. {
  1039. enum { ALLOW_CANCEL = 1, SELECTION = 2, SAFE_TO_AUTOACCEPT = 4 };
  1040. MetaString text;
  1041. std::vector<Component> components;
  1042. PlayerColor player;
  1043. ui8 flags = 0;
  1044. ui16 soundID = 0;
  1045. bool cancel() const
  1046. {
  1047. return flags & ALLOW_CANCEL;
  1048. }
  1049. bool selection() const
  1050. {
  1051. return flags & SELECTION;
  1052. }
  1053. bool safeToAutoaccept() const
  1054. {
  1055. return flags & SAFE_TO_AUTOACCEPT;
  1056. }
  1057. BlockingDialog(bool yesno, bool Selection)
  1058. {
  1059. if(yesno) flags |= ALLOW_CANCEL;
  1060. if(Selection) flags |= SELECTION;
  1061. }
  1062. BlockingDialog() = default;
  1063. void visitTyped(ICPackVisitor & visitor) override;
  1064. template <typename Handler> void serialize(Handler & h)
  1065. {
  1066. h & queryID;
  1067. h & text;
  1068. h & components;
  1069. h & player;
  1070. h & flags;
  1071. h & soundID;
  1072. }
  1073. };
  1074. struct DLL_LINKAGE GarrisonDialog : public Query
  1075. {
  1076. ObjectInstanceID objid;
  1077. ObjectInstanceID hid;
  1078. bool removableUnits = false;
  1079. void visitTyped(ICPackVisitor & visitor) override;
  1080. template <typename Handler> void serialize(Handler & h)
  1081. {
  1082. h & queryID;
  1083. h & objid;
  1084. h & hid;
  1085. h & removableUnits;
  1086. }
  1087. };
  1088. struct DLL_LINKAGE ExchangeDialog : public Query
  1089. {
  1090. PlayerColor player;
  1091. ObjectInstanceID hero1;
  1092. ObjectInstanceID hero2;
  1093. void visitTyped(ICPackVisitor & visitor) override;
  1094. template <typename Handler> void serialize(Handler & h)
  1095. {
  1096. h & queryID;
  1097. h & player;
  1098. h & hero1;
  1099. h & hero2;
  1100. }
  1101. };
  1102. struct DLL_LINKAGE TeleportDialog : public Query
  1103. {
  1104. TeleportDialog() = default;
  1105. TeleportDialog(const ObjectInstanceID & hero, const TeleportChannelID & Channel)
  1106. : hero(hero)
  1107. , channel(Channel)
  1108. {
  1109. }
  1110. ObjectInstanceID hero;
  1111. TeleportChannelID channel;
  1112. TTeleportExitsList exits;
  1113. bool impassable = false;
  1114. void visitTyped(ICPackVisitor & visitor) override;
  1115. template <typename Handler> void serialize(Handler & h)
  1116. {
  1117. h & queryID;
  1118. h & hero;
  1119. h & channel;
  1120. h & exits;
  1121. h & impassable;
  1122. }
  1123. };
  1124. struct DLL_LINKAGE MapObjectSelectDialog : public Query
  1125. {
  1126. PlayerColor player;
  1127. Component icon;
  1128. MetaString title;
  1129. MetaString description;
  1130. std::vector<ObjectInstanceID> objects;
  1131. void visitTyped(ICPackVisitor & visitor) override;
  1132. template <typename Handler> void serialize(Handler & h)
  1133. {
  1134. h & queryID;
  1135. h & player;
  1136. h & icon;
  1137. h & title;
  1138. h & description;
  1139. h & objects;
  1140. }
  1141. };
  1142. struct DLL_LINKAGE AdvmapSpellCast : public CPackForClient
  1143. {
  1144. ObjectInstanceID casterID;
  1145. SpellID spellID;
  1146. template <typename Handler> void serialize(Handler & h)
  1147. {
  1148. h & casterID;
  1149. h & spellID;
  1150. }
  1151. protected:
  1152. void visitTyped(ICPackVisitor & visitor) override;
  1153. };
  1154. struct DLL_LINKAGE ShowWorldViewEx : public CPackForClient
  1155. {
  1156. PlayerColor player;
  1157. bool showTerrain; // TODO: send terrain state
  1158. std::vector<ObjectPosInfo> objectPositions;
  1159. template <typename Handler> void serialize(Handler & h)
  1160. {
  1161. h & player;
  1162. h & showTerrain;
  1163. h & objectPositions;
  1164. }
  1165. protected:
  1166. void visitTyped(ICPackVisitor & visitor) override;
  1167. };
  1168. struct DLL_LINKAGE PlayerMessageClient : public CPackForClient
  1169. {
  1170. PlayerMessageClient() = default;
  1171. PlayerMessageClient(const PlayerColor & Player, std::string Text)
  1172. : player(Player)
  1173. , text(std::move(Text))
  1174. {
  1175. }
  1176. void visitTyped(ICPackVisitor & visitor) override;
  1177. PlayerColor player;
  1178. std::string text;
  1179. template <typename Handler> void serialize(Handler & h)
  1180. {
  1181. h & player;
  1182. h & text;
  1183. }
  1184. };
  1185. struct DLL_LINKAGE CenterView : public CPackForClient
  1186. {
  1187. PlayerColor player;
  1188. int3 pos;
  1189. ui32 focusTime = 0; //ms
  1190. void visitTyped(ICPackVisitor & visitor) override;
  1191. template <typename Handler> void serialize(Handler & h)
  1192. {
  1193. h & pos;
  1194. h & player;
  1195. h & focusTime;
  1196. }
  1197. };
  1198. VCMI_LIB_NAMESPACE_END