PacksForServer.h 14 KB

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