PacksForServer.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. * NetPacks.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "NetPacksBase.h"
  12. #include "../int3.h"
  13. #include "../battle/BattleAction.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. struct DLL_LINKAGE GamePause : public CPackForServer
  16. {
  17. void visitTyped(ICPackVisitor & visitor) override;
  18. template <typename Handler> void serialize(Handler & h, const int version)
  19. {
  20. h & static_cast<CPackForServer &>(*this);
  21. }
  22. };
  23. struct DLL_LINKAGE EndTurn : public CPackForServer
  24. {
  25. void visitTyped(ICPackVisitor & visitor) override;
  26. template <typename Handler> void serialize(Handler & h, const int version)
  27. {
  28. h & static_cast<CPackForServer &>(*this);
  29. }
  30. };
  31. struct DLL_LINKAGE DismissHero : public CPackForServer
  32. {
  33. DismissHero() = default;
  34. DismissHero(const ObjectInstanceID & HID)
  35. : hid(HID)
  36. {
  37. }
  38. ObjectInstanceID hid;
  39. void visitTyped(ICPackVisitor & visitor) override;
  40. template <typename Handler> void serialize(Handler & h, const int version)
  41. {
  42. h & static_cast<CPackForServer &>(*this);
  43. h & hid;
  44. }
  45. };
  46. struct DLL_LINKAGE MoveHero : public CPackForServer
  47. {
  48. MoveHero() = default;
  49. MoveHero(const int3 & Dest, const ObjectInstanceID & HID, bool Transit)
  50. : dest(Dest)
  51. , hid(HID)
  52. , transit(Transit)
  53. {
  54. }
  55. int3 dest;
  56. ObjectInstanceID hid;
  57. bool transit = false;
  58. void visitTyped(ICPackVisitor & visitor) override;
  59. template <typename Handler> void serialize(Handler & h, const int version)
  60. {
  61. h & static_cast<CPackForServer &>(*this);
  62. h & dest;
  63. h & hid;
  64. h & transit;
  65. }
  66. };
  67. struct DLL_LINKAGE CastleTeleportHero : public CPackForServer
  68. {
  69. CastleTeleportHero() = default;
  70. CastleTeleportHero(const ObjectInstanceID & HID, const ObjectInstanceID & Dest, ui8 Source)
  71. : dest(Dest)
  72. , hid(HID)
  73. , source(Source)
  74. {
  75. }
  76. ObjectInstanceID dest;
  77. ObjectInstanceID hid;
  78. si8 source = 0; //who give teleporting, 1=castle gate
  79. void visitTyped(ICPackVisitor & visitor) override;
  80. template <typename Handler> void serialize(Handler & h, const int version)
  81. {
  82. h & static_cast<CPackForServer &>(*this);
  83. h & dest;
  84. h & hid;
  85. }
  86. };
  87. struct DLL_LINKAGE ArrangeStacks : public CPackForServer
  88. {
  89. ArrangeStacks() = default;
  90. ArrangeStacks(ui8 W, const SlotID & P1, const SlotID & P2, const ObjectInstanceID & ID1, const ObjectInstanceID & ID2, si32 VAL)
  91. : what(W)
  92. , p1(P1)
  93. , p2(P2)
  94. , id1(ID1)
  95. , id2(ID2)
  96. , val(VAL)
  97. {
  98. }
  99. ui8 what = 0; //1 - swap; 2 - merge; 3 - split
  100. SlotID p1, p2; //positions of first and second stack
  101. ObjectInstanceID id1, id2; //ids of objects with garrison
  102. si32 val = 0;
  103. void visitTyped(ICPackVisitor & visitor) override;
  104. template <typename Handler> void serialize(Handler & h, const int version)
  105. {
  106. h & static_cast<CPackForServer &>(*this);
  107. h & what;
  108. h & p1;
  109. h & p2;
  110. h & id1;
  111. h & id2;
  112. h & val;
  113. }
  114. };
  115. struct DLL_LINKAGE BulkMoveArmy : public CPackForServer
  116. {
  117. SlotID srcSlot;
  118. ObjectInstanceID srcArmy;
  119. ObjectInstanceID destArmy;
  120. BulkMoveArmy() = default;
  121. BulkMoveArmy(const ObjectInstanceID & srcArmy, const ObjectInstanceID & destArmy, const SlotID & srcSlot)
  122. : srcArmy(srcArmy)
  123. , destArmy(destArmy)
  124. , srcSlot(srcSlot)
  125. {
  126. }
  127. void visitTyped(ICPackVisitor & visitor) override;
  128. template <typename Handler>
  129. void serialize(Handler & h, const int version)
  130. {
  131. h & static_cast<CPackForServer &>(*this);
  132. h & srcSlot;
  133. h & srcArmy;
  134. h & destArmy;
  135. }
  136. };
  137. struct DLL_LINKAGE BulkSplitStack : public CPackForServer
  138. {
  139. SlotID src;
  140. ObjectInstanceID srcOwner;
  141. si32 amount = 0;
  142. BulkSplitStack() = default;
  143. BulkSplitStack(const ObjectInstanceID & srcOwner, const SlotID & src, si32 howMany)
  144. : src(src)
  145. , srcOwner(srcOwner)
  146. , amount(howMany)
  147. {
  148. }
  149. void visitTyped(ICPackVisitor & visitor) override;
  150. template <typename Handler>
  151. void serialize(Handler & h, const int version)
  152. {
  153. h & static_cast<CPackForServer &>(*this);
  154. h & src;
  155. h & srcOwner;
  156. h & amount;
  157. }
  158. };
  159. struct DLL_LINKAGE BulkMergeStacks : public CPackForServer
  160. {
  161. SlotID src;
  162. ObjectInstanceID srcOwner;
  163. BulkMergeStacks() = default;
  164. BulkMergeStacks(const ObjectInstanceID & srcOwner, const SlotID & src)
  165. : src(src)
  166. , srcOwner(srcOwner)
  167. {
  168. }
  169. void visitTyped(ICPackVisitor & visitor) override;
  170. template <typename Handler>
  171. void serialize(Handler & h, const int version)
  172. {
  173. h & static_cast<CPackForServer &>(*this);
  174. h & src;
  175. h & srcOwner;
  176. }
  177. };
  178. struct DLL_LINKAGE BulkSmartSplitStack : public CPackForServer
  179. {
  180. SlotID src;
  181. ObjectInstanceID srcOwner;
  182. BulkSmartSplitStack() = default;
  183. BulkSmartSplitStack(const ObjectInstanceID & srcOwner, const SlotID & src)
  184. : src(src)
  185. , srcOwner(srcOwner)
  186. {
  187. }
  188. void visitTyped(ICPackVisitor & visitor) override;
  189. template <typename Handler>
  190. void serialize(Handler & h, const int version)
  191. {
  192. h & static_cast<CPackForServer &>(*this);
  193. h & src;
  194. h & srcOwner;
  195. }
  196. };
  197. struct DLL_LINKAGE DisbandCreature : public CPackForServer
  198. {
  199. DisbandCreature() = default;
  200. DisbandCreature(const SlotID & Pos, const ObjectInstanceID & ID)
  201. : pos(Pos)
  202. , id(ID)
  203. {
  204. }
  205. SlotID pos; //stack pos
  206. ObjectInstanceID id; //object id
  207. void visitTyped(ICPackVisitor & visitor) override;
  208. template <typename Handler> void serialize(Handler & h, const int version)
  209. {
  210. h & static_cast<CPackForServer &>(*this);
  211. h & pos;
  212. h & id;
  213. }
  214. };
  215. struct DLL_LINKAGE BuildStructure : public CPackForServer
  216. {
  217. BuildStructure() = default;
  218. BuildStructure(const ObjectInstanceID & TID, const BuildingID & BID)
  219. : tid(TID)
  220. , bid(BID)
  221. {
  222. }
  223. ObjectInstanceID tid; //town id
  224. BuildingID bid; //structure id
  225. void visitTyped(ICPackVisitor & visitor) override;
  226. template <typename Handler> void serialize(Handler & h, const int version)
  227. {
  228. h & static_cast<CPackForServer &>(*this);
  229. h & tid;
  230. h & bid;
  231. }
  232. };
  233. struct DLL_LINKAGE RazeStructure : public BuildStructure
  234. {
  235. void visitTyped(ICPackVisitor & visitor) override;
  236. };
  237. struct DLL_LINKAGE RecruitCreatures : public CPackForServer
  238. {
  239. RecruitCreatures() = default;
  240. RecruitCreatures(const ObjectInstanceID & TID, const ObjectInstanceID & DST, const CreatureID & CRID, si32 Amount, si32 Level)
  241. : tid(TID)
  242. , dst(DST)
  243. , crid(CRID)
  244. , amount(Amount)
  245. , level(Level)
  246. {
  247. }
  248. ObjectInstanceID tid; //dwelling id, or town
  249. ObjectInstanceID dst; //destination ID, e.g. hero
  250. CreatureID crid;
  251. ui32 amount = 0; //creature amount
  252. si32 level = 0; //dwelling level to buy from, -1 if any
  253. void visitTyped(ICPackVisitor & visitor) override;
  254. template <typename Handler> void serialize(Handler & h, const int version)
  255. {
  256. h & static_cast<CPackForServer &>(*this);
  257. h & tid;
  258. h & dst;
  259. h & crid;
  260. h & amount;
  261. h & level;
  262. }
  263. };
  264. struct DLL_LINKAGE UpgradeCreature : public CPackForServer
  265. {
  266. UpgradeCreature() = default;
  267. UpgradeCreature(const SlotID & Pos, const ObjectInstanceID & ID, const CreatureID & CRID)
  268. : pos(Pos)
  269. , id(ID)
  270. , cid(CRID)
  271. {
  272. }
  273. SlotID pos; //stack pos
  274. ObjectInstanceID id; //object id
  275. CreatureID cid; //id of type to which we want make upgrade
  276. void visitTyped(ICPackVisitor & visitor) override;
  277. template <typename Handler> void serialize(Handler & h, const int version)
  278. {
  279. h & static_cast<CPackForServer &>(*this);
  280. h & pos;
  281. h & id;
  282. h & cid;
  283. }
  284. };
  285. struct DLL_LINKAGE GarrisonHeroSwap : public CPackForServer
  286. {
  287. GarrisonHeroSwap() = default;
  288. GarrisonHeroSwap(const ObjectInstanceID & TID)
  289. : tid(TID)
  290. {
  291. }
  292. ObjectInstanceID tid;
  293. void visitTyped(ICPackVisitor & visitor) override;
  294. template <typename Handler> void serialize(Handler & h, const int version)
  295. {
  296. h & static_cast<CPackForServer &>(*this);
  297. h & tid;
  298. }
  299. };
  300. struct DLL_LINKAGE ExchangeArtifacts : public CPackForServer
  301. {
  302. ArtifactLocation src, dst;
  303. void visitTyped(ICPackVisitor & visitor) override;
  304. template <typename Handler> void serialize(Handler & h, const int version)
  305. {
  306. h & static_cast<CPackForServer &>(*this);
  307. h & src;
  308. h & dst;
  309. }
  310. };
  311. struct DLL_LINKAGE BulkExchangeArtifacts : public CPackForServer
  312. {
  313. ObjectInstanceID srcHero;
  314. ObjectInstanceID dstHero;
  315. bool swap = false;
  316. bool equipped = true;
  317. bool backpack = true;
  318. BulkExchangeArtifacts() = default;
  319. BulkExchangeArtifacts(const ObjectInstanceID & srcHero, const ObjectInstanceID & dstHero, bool swap, bool equipped, bool backpack)
  320. : srcHero(srcHero)
  321. , dstHero(dstHero)
  322. , swap(swap)
  323. , equipped(equipped)
  324. , backpack(backpack)
  325. {
  326. }
  327. void visitTyped(ICPackVisitor & visitor) override;
  328. template <typename Handler> void serialize(Handler & h, const int version)
  329. {
  330. h & static_cast<CPackForServer &>(*this);
  331. h & srcHero;
  332. h & dstHero;
  333. h & swap;
  334. h & equipped;
  335. h & backpack;
  336. }
  337. };
  338. struct DLL_LINKAGE AssembleArtifacts : public CPackForServer
  339. {
  340. AssembleArtifacts() = default;
  341. AssembleArtifacts(const ObjectInstanceID & _heroID, const ArtifactPosition & _artifactSlot, bool _assemble, const ArtifactID & _assembleTo)
  342. : heroID(_heroID)
  343. , artifactSlot(_artifactSlot)
  344. , assemble(_assemble)
  345. , assembleTo(_assembleTo)
  346. {
  347. }
  348. ObjectInstanceID heroID;
  349. ArtifactPosition artifactSlot;
  350. bool assemble = false; // True to assemble artifact, false to disassemble.
  351. ArtifactID assembleTo; // Artifact to assemble into.
  352. void visitTyped(ICPackVisitor & visitor) override;
  353. template <typename Handler> void serialize(Handler & h, const int version)
  354. {
  355. h & static_cast<CPackForServer &>(*this);
  356. h & heroID;
  357. h & artifactSlot;
  358. h & assemble;
  359. h & assembleTo;
  360. }
  361. };
  362. struct DLL_LINKAGE EraseArtifactByClient : public CPackForServer
  363. {
  364. EraseArtifactByClient() = default;
  365. EraseArtifactByClient(const ArtifactLocation & al)
  366. : al(al)
  367. {
  368. }
  369. ArtifactLocation al;
  370. void visitTyped(ICPackVisitor & visitor) override;
  371. template <typename Handler> void serialize(Handler & h, const int version)
  372. {
  373. h & static_cast<CPackForServer&>(*this);
  374. h & al;
  375. }
  376. };
  377. struct DLL_LINKAGE BuyArtifact : public CPackForServer
  378. {
  379. BuyArtifact() = default;
  380. BuyArtifact(const ObjectInstanceID & HID, const ArtifactID & AID)
  381. : hid(HID)
  382. , aid(AID)
  383. {
  384. }
  385. ObjectInstanceID hid;
  386. ArtifactID aid;
  387. void visitTyped(ICPackVisitor & visitor) override;
  388. template <typename Handler> void serialize(Handler & h, const int version)
  389. {
  390. h & static_cast<CPackForServer &>(*this);
  391. h & hid;
  392. h & aid;
  393. }
  394. };
  395. struct DLL_LINKAGE TradeOnMarketplace : public CPackForServer
  396. {
  397. ObjectInstanceID marketId;
  398. ObjectInstanceID heroId;
  399. EMarketMode mode = EMarketMode::RESOURCE_RESOURCE;
  400. std::vector<ui32> r1, r2; //mode 0: r1 - sold resource, r2 - bought res (exception: when sacrificing art r1 is art id [todo: make r2 preferred slot?]
  401. std::vector<ui32> val; //units of sold resource
  402. void visitTyped(ICPackVisitor & visitor) override;
  403. template <typename Handler> void serialize(Handler & h, const int version)
  404. {
  405. h & static_cast<CPackForServer &>(*this);
  406. h & marketId;
  407. h & heroId;
  408. h & mode;
  409. h & r1;
  410. h & r2;
  411. h & val;
  412. }
  413. };
  414. struct DLL_LINKAGE SetFormation : public CPackForServer
  415. {
  416. SetFormation() = default;
  417. ;
  418. SetFormation(const ObjectInstanceID & HID, ui8 Formation)
  419. : hid(HID)
  420. , formation(Formation)
  421. {
  422. }
  423. ObjectInstanceID hid;
  424. ui8 formation = 0;
  425. void visitTyped(ICPackVisitor & visitor) override;
  426. template <typename Handler> void serialize(Handler & h, const int version)
  427. {
  428. h & static_cast<CPackForServer &>(*this);
  429. h & hid;
  430. h & formation;
  431. }
  432. };
  433. struct DLL_LINKAGE HireHero : public CPackForServer
  434. {
  435. HireHero() = default;
  436. HireHero(HeroTypeID HID, const ObjectInstanceID & TID)
  437. : hid(HID)
  438. , tid(TID)
  439. {
  440. }
  441. HeroTypeID hid; //available hero serial
  442. ObjectInstanceID tid; //town (tavern) id
  443. PlayerColor player;
  444. void visitTyped(ICPackVisitor & visitor) override;
  445. template <typename Handler> void serialize(Handler & h, const int version)
  446. {
  447. h & static_cast<CPackForServer &>(*this);
  448. h & hid;
  449. h & tid;
  450. h & player;
  451. }
  452. };
  453. struct DLL_LINKAGE BuildBoat : public CPackForServer
  454. {
  455. ObjectInstanceID objid; //where player wants to buy a boat
  456. void visitTyped(ICPackVisitor & visitor) override;
  457. template <typename Handler> void serialize(Handler & h, const int version)
  458. {
  459. h & static_cast<CPackForServer &>(*this);
  460. h & objid;
  461. }
  462. };
  463. struct DLL_LINKAGE QueryReply : public CPackForServer
  464. {
  465. QueryReply() = default;
  466. QueryReply(const QueryID & QID, std::optional<int32_t> Reply)
  467. : qid(QID)
  468. , reply(Reply)
  469. {
  470. }
  471. QueryID qid;
  472. PlayerColor player;
  473. std::optional<int32_t> reply;
  474. void visitTyped(ICPackVisitor & visitor) override;
  475. template <typename Handler> void serialize(Handler & h, const int version)
  476. {
  477. h & static_cast<CPackForServer &>(*this);
  478. h & qid;
  479. h & player;
  480. h & reply;
  481. }
  482. };
  483. struct DLL_LINKAGE MakeAction : public CPackForServer
  484. {
  485. MakeAction() = default;
  486. MakeAction(BattleAction BA)
  487. : ba(std::move(BA))
  488. {
  489. }
  490. BattleAction ba;
  491. BattleID battleID;
  492. void visitTyped(ICPackVisitor & visitor) override;
  493. template <typename Handler> void serialize(Handler & h, const int version)
  494. {
  495. h & static_cast<CPackForServer &>(*this);
  496. h & ba;
  497. h & battleID;
  498. }
  499. };
  500. struct DLL_LINKAGE DigWithHero : public CPackForServer
  501. {
  502. ObjectInstanceID id; //digging hero id
  503. void visitTyped(ICPackVisitor & visitor) override;
  504. template <typename Handler> void serialize(Handler & h, const int version)
  505. {
  506. h & static_cast<CPackForServer &>(*this);
  507. h & id;
  508. }
  509. };
  510. struct DLL_LINKAGE CastAdvSpell : public CPackForServer
  511. {
  512. ObjectInstanceID hid; //hero id
  513. SpellID sid; //spell id
  514. int3 pos; //selected tile (not always used)
  515. void visitTyped(ICPackVisitor & visitor) override;
  516. template <typename Handler> void serialize(Handler & h, const int version)
  517. {
  518. h & static_cast<CPackForServer &>(*this);
  519. h & hid;
  520. h & sid;
  521. h & pos;
  522. }
  523. };
  524. /***********************************************************************************************************/
  525. struct DLL_LINKAGE SaveGame : public CPackForServer
  526. {
  527. SaveGame() = default;
  528. SaveGame(std::string Fname)
  529. : fname(std::move(Fname))
  530. {
  531. }
  532. std::string fname;
  533. void applyGs(CGameState * gs) {};
  534. void visitTyped(ICPackVisitor & visitor) override;
  535. template <typename Handler> void serialize(Handler & h, const int version)
  536. {
  537. h & static_cast<CPackForServer &>(*this);
  538. h & fname;
  539. }
  540. };
  541. struct DLL_LINKAGE PlayerMessage : public CPackForServer
  542. {
  543. PlayerMessage() = default;
  544. PlayerMessage(std::string Text, const ObjectInstanceID & obj)
  545. : text(std::move(Text))
  546. , currObj(obj)
  547. {
  548. }
  549. void applyGs(CGameState * gs) {};
  550. void visitTyped(ICPackVisitor & visitor) override;
  551. std::string text;
  552. ObjectInstanceID currObj; // optional parameter that specifies current object. For cheats :)
  553. template <typename Handler> void serialize(Handler & h, const int version)
  554. {
  555. h & static_cast<CPackForServer &>(*this);
  556. h & text;
  557. h & currObj;
  558. }
  559. };
  560. VCMI_LIB_NAMESPACE_END