NetPacks.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. #ifndef __NETPACKS_H__
  2. #define __NETPACKS_H__
  3. #include "../global.h"
  4. #include "CGameState.h"
  5. #include "BattleAction.h"
  6. #include "HeroBonus.h"
  7. #include <set>
  8. #include "CCreatureSet.h"
  9. /*
  10. * NetPacks.h, part of VCMI engine
  11. *
  12. * Authors: listed in file AUTHORS in main folder
  13. *
  14. * License: GNU General Public License v2.0 or later
  15. * Full text of license available in license.txt file, in main folder
  16. *
  17. */
  18. class CClient;
  19. class CGameState;
  20. class CGameHandler;
  21. class CConnection;
  22. class CCampaignState;
  23. class CArtifact;
  24. struct CPack
  25. {
  26. ui16 type;
  27. CPack(){};
  28. virtual ~CPack(){};
  29. ui16 getType() const{return type;}
  30. template <typename Handler> void serialize(Handler &h, const int version)
  31. {
  32. tlog1 << "CPack serialized... this should not happen!\n";
  33. }
  34. DLL_EXPORT void applyGs(CGameState *gs)
  35. {};
  36. };
  37. struct CPackForClient : public CPack
  38. {
  39. CPackForClient(){type = 1;};
  40. CGameState* GS(CClient *cl);
  41. void applyFirstCl(CClient *cl)//called before applying to gs
  42. {};
  43. void applyCl(CClient *cl)//called after applying to gs
  44. {};
  45. };
  46. struct CPackForServer : public CPack
  47. {
  48. CConnection *c;
  49. CGameState* GS(CGameHandler *gh);
  50. CPackForServer()
  51. {
  52. type = 2;
  53. c = NULL;
  54. };
  55. bool applyGh(CGameHandler *gh);//called after applying to gs
  56. };
  57. struct Query : public CPackForClient
  58. {
  59. ui32 id;
  60. };
  61. struct MetaString : public CPack //2001 helper for object scrips
  62. {
  63. private:
  64. enum EMessage {TEXACT_STRING, TLOCAL_STRING, TNUMBER, TREPLACE_ESTRING, TREPLACE_LSTRING, TREPLACE_NUMBER};
  65. public:
  66. enum {GENERAL_TXT=1, XTRAINFO_TXT, OBJ_NAMES, RES_NAMES, ART_NAMES, ARRAY_TXT, CRE_PL_NAMES, CREGENS, MINE_NAMES,
  67. MINE_EVNTS, ADVOB_TXT, ART_EVNTS, SPELL_NAME, SEC_SKILL_NAME, CRE_SING_NAMES, CREGENS4, COLOR, ART_DESCR};
  68. std::vector<ui8> message; //vector of EMessage
  69. std::vector<std::pair<ui8,ui32> > localStrings; //pairs<text handler type, text number>; types: 1 - generaltexthandler->all; 2 - objh->xtrainfo; 3 - objh->names; 4 - objh->restypes; 5 - arth->artifacts[id].name; 6 - generaltexth->arraytxt; 7 - creh->creatures[os->subID].namePl; 8 - objh->creGens; 9 - objh->mines[ID]->first; 10 - objh->mines[ID]->second; 11 - objh->advobtxt
  70. std::vector<std::string> exactStrings;
  71. std::vector<si32> numbers;
  72. template <typename Handler> void serialize(Handler &h, const int version)
  73. {
  74. h & exactStrings & localStrings & message & numbers;
  75. }
  76. void addTxt(ui8 type, ui32 serial)
  77. {
  78. message.push_back(TLOCAL_STRING);
  79. localStrings.push_back(std::pair<ui8,ui32>(type, serial));
  80. }
  81. MetaString& operator<<(const std::pair<ui8,ui32> &txt)
  82. {
  83. message.push_back(TLOCAL_STRING);
  84. localStrings.push_back(txt);
  85. return *this;
  86. }
  87. MetaString& operator<<(const std::string &txt)
  88. {
  89. message.push_back(TEXACT_STRING);
  90. exactStrings.push_back(txt);
  91. return *this;
  92. }
  93. MetaString& operator<<(int txt)
  94. {
  95. message.push_back(TNUMBER);
  96. numbers.push_back(txt);
  97. return *this;
  98. }
  99. void addReplacement(ui8 type, ui32 serial)
  100. {
  101. message.push_back(TREPLACE_LSTRING);
  102. localStrings.push_back(std::pair<ui8,ui32>(type, serial));
  103. }
  104. void addReplacement(const std::string &txt)
  105. {
  106. message.push_back(TREPLACE_ESTRING);
  107. exactStrings.push_back(txt);
  108. }
  109. void addReplacement(int txt)
  110. {
  111. message.push_back(TREPLACE_NUMBER);
  112. numbers.push_back(txt);
  113. }
  114. DLL_EXPORT void addReplacement(const CStackInstance &stack); //adds sing or plural name;
  115. DLL_EXPORT std::string buildList () const;
  116. void clear()
  117. {
  118. exactStrings.clear();
  119. localStrings.clear();
  120. message.clear();
  121. numbers.clear();
  122. }
  123. DLL_EXPORT void toString(std::string &dst) const;
  124. DLL_EXPORT std::string toString() const;
  125. void getLocalString(const std::pair<ui8,ui32> &txt, std::string &dst) const;
  126. MetaString()
  127. {
  128. type = 2001;
  129. }
  130. };
  131. /***********************************************************************************************************/
  132. struct PackageApplied : public CPackForClient //94
  133. {
  134. PackageApplied() {type = 94;}
  135. PackageApplied(ui8 Result) : result(Result) {type = 94;}
  136. void applyCl(CClient *cl);
  137. ui8 result; //0 - something went wrong, request hasn't been realized; 1 - OK
  138. ui32 packType; //type id of applied package
  139. template <typename Handler> void serialize(Handler &h, const int version)
  140. {
  141. h & result & packType;
  142. }
  143. };
  144. struct SystemMessage : public CPackForClient //95
  145. {
  146. SystemMessage(const std::string Text) : text(Text){type = 95;};
  147. SystemMessage(){type = 95;};
  148. void applyCl(CClient *cl);
  149. std::string text;
  150. template <typename Handler> void serialize(Handler &h, const int version)
  151. {
  152. h & text;
  153. }
  154. };
  155. struct PlayerBlocked : public CPackForClient //96
  156. {
  157. PlayerBlocked(){type = 96;};
  158. void applyCl(CClient *cl);
  159. enum EReason { UPCOMING_BATTLE };
  160. ui8 reason;
  161. ui8 player;
  162. template <typename Handler> void serialize(Handler &h, const int version)
  163. {
  164. h & reason & player;
  165. }
  166. };
  167. struct YourTurn : public CPackForClient //100
  168. {
  169. YourTurn(){type = 100;};
  170. void applyCl(CClient *cl);
  171. DLL_EXPORT void applyGs(CGameState *gs);
  172. ui8 player;
  173. template <typename Handler> void serialize(Handler &h, const int version)
  174. {
  175. h & player;
  176. }
  177. };
  178. struct SetResource : public CPackForClient //102
  179. {
  180. SetResource(){type = 102;};
  181. void applyCl(CClient *cl);
  182. DLL_EXPORT void applyGs(CGameState *gs);
  183. ui8 player, resid;
  184. si32 val;
  185. template <typename Handler> void serialize(Handler &h, const int version)
  186. {
  187. h & player & resid & val;
  188. }
  189. };
  190. struct SetResources : public CPackForClient //104
  191. {
  192. SetResources(){res.resize(RESOURCE_QUANTITY);type = 104;};
  193. void applyCl(CClient *cl);
  194. DLL_EXPORT void applyGs(CGameState *gs);
  195. ui8 player;
  196. std::vector<si32> res; //res[resid] => res amount
  197. template <typename Handler> void serialize(Handler &h, const int version)
  198. {
  199. h & player & res;
  200. }
  201. };
  202. struct SetPrimSkill : public CPackForClient //105
  203. {
  204. SetPrimSkill(){type = 105;};
  205. void applyCl(CClient *cl);
  206. DLL_EXPORT void applyGs(CGameState *gs);
  207. ui8 abs; //0 - changes by value; 1 - sets to value
  208. si32 id;
  209. ui16 which;
  210. si64 val;
  211. template <typename Handler> void serialize(Handler &h, const int version)
  212. {
  213. h & abs & id & which & val;
  214. }
  215. };
  216. struct SetSecSkill : public CPackForClient //106
  217. {
  218. SetSecSkill(){type = 106;};
  219. void applyCl(CClient *cl);
  220. DLL_EXPORT void applyGs(CGameState *gs);
  221. ui8 abs; //0 - changes by value; 1 - sets to value
  222. si32 id;
  223. ui16 which, val;
  224. template <typename Handler> void serialize(Handler &h, const int version)
  225. {
  226. h & abs & id & which & val;
  227. }
  228. };
  229. struct HeroVisitCastle : public CPackForClient //108
  230. {
  231. HeroVisitCastle(){flags=0;type = 108;};
  232. void applyCl(CClient *cl);
  233. DLL_EXPORT void applyGs(CGameState *gs);
  234. ui8 flags; //1 - start, 2 - garrison
  235. ui32 tid, hid;
  236. bool start() //if hero is entering castle (if false - leaving)
  237. {
  238. return flags & 1;
  239. }
  240. bool garrison() //if hero is entering/leaving garrison (if false - it's only visiting hero)
  241. {
  242. return flags & 2;
  243. }
  244. template <typename Handler> void serialize(Handler &h, const int version)
  245. {
  246. h & flags & tid & hid;
  247. }
  248. };
  249. struct ChangeSpells : public CPackForClient //109
  250. {
  251. ChangeSpells(){type = 109;};
  252. void applyCl(CClient *cl);
  253. DLL_EXPORT void applyGs(CGameState *gs);
  254. ui8 learn; //1 - gives spell, 0 - takes
  255. ui32 hid;
  256. std::set<ui32> spells;
  257. template <typename Handler> void serialize(Handler &h, const int version)
  258. {
  259. h & learn & hid & spells;
  260. }
  261. };
  262. struct SetMana : public CPackForClient //110
  263. {
  264. SetMana(){type = 110;};
  265. void applyCl(CClient *cl);
  266. DLL_EXPORT void applyGs(CGameState *gs);
  267. si32 hid, val;
  268. template <typename Handler> void serialize(Handler &h, const int version)
  269. {
  270. h & val & hid;
  271. }
  272. };
  273. struct SetMovePoints : public CPackForClient //111
  274. {
  275. SetMovePoints(){type = 111;};
  276. void applyCl(CClient *cl);
  277. DLL_EXPORT void applyGs(CGameState *gs);
  278. ui32 hid, val;
  279. template <typename Handler> void serialize(Handler &h, const int version)
  280. {
  281. h & val & hid;
  282. }
  283. };
  284. struct FoWChange : public CPackForClient //112
  285. {
  286. FoWChange(){type = 112;};
  287. void applyCl(CClient *cl);
  288. DLL_EXPORT void applyGs(CGameState *gs);
  289. std::set<int3> tiles;
  290. ui8 player, mode; //mode==0 - hide, mode==1 - reveal
  291. template <typename Handler> void serialize(Handler &h, const int version)
  292. {
  293. h & tiles & player & mode;
  294. }
  295. };
  296. struct SetAvailableHeroes : public CPackForClient //113
  297. {
  298. SetAvailableHeroes()
  299. {
  300. type = 113;
  301. for (int i = 0; i < AVAILABLE_HEROES_PER_PLAYER; i++)
  302. army[i] = NULL;
  303. }
  304. ~SetAvailableHeroes()
  305. {
  306. for (int i = 0; i < AVAILABLE_HEROES_PER_PLAYER; i++)
  307. delete army[i];
  308. }
  309. void applyCl(CClient *cl);
  310. DLL_EXPORT void applyGs(CGameState *gs);
  311. ui8 player;
  312. si32 hid[AVAILABLE_HEROES_PER_PLAYER]; //-1 if no hero
  313. CCreatureSet *army[AVAILABLE_HEROES_PER_PLAYER];
  314. template <typename Handler> void serialize(Handler &h, const int version)
  315. {
  316. h & player & hid & army;
  317. }
  318. };
  319. struct GiveBonus : public CPackForClient //115
  320. {
  321. GiveBonus(ui8 Who = 0)
  322. {
  323. who = Who;
  324. type = 115;
  325. }
  326. void applyCl(CClient *cl);
  327. DLL_EXPORT void applyGs(CGameState *gs);
  328. enum {HERO, PLAYER, TOWN};
  329. ui8 who; //who receives bonus, uses enum above
  330. ui32 id; //hero. town or player id - whoever receives it
  331. Bonus bonus;
  332. MetaString bdescr;
  333. template <typename Handler> void serialize(Handler &h, const int version)
  334. {
  335. h & bonus & id & bdescr & who;
  336. }
  337. };
  338. struct ChangeObjPos : public CPackForClient //116
  339. {
  340. ChangeObjPos()
  341. {
  342. type = 116;
  343. flags = 0;
  344. }
  345. void applyFirstCl(CClient *cl);
  346. void applyCl(CClient *cl);
  347. DLL_EXPORT void applyGs(CGameState *gs);
  348. ui32 objid;
  349. int3 nPos;
  350. ui8 flags; //bit flags: 1 - redraw
  351. template <typename Handler> void serialize(Handler &h, const int version)
  352. {
  353. h & objid & nPos & flags;
  354. }
  355. };
  356. struct PlayerEndsGame : public CPackForClient //117
  357. {
  358. PlayerEndsGame()
  359. {
  360. type = 117;
  361. }
  362. void applyCl(CClient *cl);
  363. DLL_EXPORT void applyGs(CGameState *gs);
  364. ui8 player;
  365. ui8 victory;
  366. template <typename Handler> void serialize(Handler &h, const int version)
  367. {
  368. h & player & victory;
  369. }
  370. };
  371. struct RemoveBonus : public CPackForClient //118
  372. {
  373. RemoveBonus(ui8 Who = 0)
  374. {
  375. who = Who;
  376. type = 118;
  377. }
  378. void applyCl(CClient *cl);
  379. DLL_EXPORT void applyGs(CGameState *gs);
  380. enum {HERO, PLAYER, TOWN};
  381. ui8 who; //who receives bonus, uses enum above
  382. ui32 whoID; //hero, town or player id - whoever loses bonus
  383. //vars to identify bonus: its source
  384. ui8 source;
  385. ui32 id; //source id
  386. //used locally: copy of removed bonus
  387. Bonus bonus;
  388. template <typename Handler> void serialize(Handler &h, const int version)
  389. {
  390. h & source & id & who & whoID;
  391. }
  392. };
  393. struct UpdateCampaignState : public CPackForClient //119
  394. {
  395. UpdateCampaignState()
  396. {
  397. type = 119;
  398. }
  399. CCampaignState *camp;
  400. void applyCl(CClient *cl);
  401. template <typename Handler> void serialize(Handler &h, const int version)
  402. {
  403. h & camp;
  404. }
  405. };
  406. struct RemoveObject : public CPackForClient //500
  407. {
  408. RemoveObject(){type = 500;};
  409. RemoveObject(si32 ID){id = ID;type = 500;};
  410. void applyFirstCl(CClient *cl);
  411. void applyCl(CClient *cl);
  412. DLL_EXPORT void applyGs(CGameState *gs);
  413. si32 id;
  414. template <typename Handler> void serialize(Handler &h, const int version)
  415. {
  416. h & id;
  417. }
  418. };
  419. struct TryMoveHero : public CPackForClient //501
  420. {
  421. TryMoveHero(){type = 501;humanKnows=false; attackedFrom = int3(-1, -1, -1);};
  422. void applyFirstCl(CClient *cl);
  423. void applyCl(CClient *cl);
  424. void applyGs(CGameState *gs);
  425. enum EResult
  426. {
  427. FAILED, SUCCESS, TELEPORTATION, RESERVED___, BLOCKING_VISIT, EMBARK, DISEMBARK
  428. };
  429. ui32 id, movePoints;
  430. ui8 result; //uses EResult
  431. int3 start, end; //h3m format
  432. std::set<int3> fowRevealed; //revealed tiles
  433. int3 attackedFrom; // Set when stepping into endangered tile.
  434. bool humanKnows; //used locally during applying to client
  435. template <typename Handler> void serialize(Handler &h, const int version)
  436. {
  437. h & id & result & start & end & movePoints & fowRevealed & attackedFrom;
  438. }
  439. };
  440. struct SetGarrisons : public CPackForClient //502
  441. {
  442. SetGarrisons(){type = 502;};
  443. void applyCl(CClient *cl);
  444. DLL_EXPORT void applyGs(CGameState *gs);
  445. std::map<ui32,CCreatureSet> garrs;
  446. template <typename Handler> void serialize(Handler &h, const int version)
  447. {
  448. h & garrs;
  449. }
  450. };
  451. struct NewStructures : public CPackForClient //504
  452. {
  453. NewStructures(){type = 504;};
  454. void applyCl(CClient *cl);
  455. DLL_EXPORT virtual void applyGs(CGameState *gs);
  456. si32 tid;
  457. std::set<si32> bid;
  458. si16 builded;
  459. template <typename Handler> void serialize(Handler &h, const int version)
  460. {
  461. h & tid & bid & builded;
  462. }
  463. };
  464. struct RazeStructures : public CPackForClient //505
  465. {
  466. RazeStructures() {type = 505;};
  467. void applyCl (CClient *cl);
  468. DLL_EXPORT void applyGs(CGameState *gs);
  469. si32 tid;
  470. std::set<si32> bid;
  471. si16 destroyed;
  472. template <typename Handler> void serialize(Handler &h, const int version)
  473. {
  474. h & tid & bid & destroyed;
  475. }
  476. };
  477. struct SetAvailableCreatures : public CPackForClient //506
  478. {
  479. SetAvailableCreatures(){type = 506;};
  480. void applyCl(CClient *cl);
  481. DLL_EXPORT void applyGs(CGameState *gs);
  482. si32 tid;
  483. std::vector<std::pair<ui32, std::vector<ui32> > > creatures;
  484. template <typename Handler> void serialize(Handler &h, const int version)
  485. {
  486. h & tid & creatures;
  487. }
  488. };
  489. struct SetHeroesInTown : public CPackForClient //508
  490. {
  491. SetHeroesInTown(){type = 508;};
  492. void applyCl(CClient *cl);
  493. DLL_EXPORT void applyGs(CGameState *gs);
  494. si32 tid, visiting, garrison; //id of town, visiting hero, hero in garrison
  495. template <typename Handler> void serialize(Handler &h, const int version)
  496. {
  497. h & tid & visiting & garrison;
  498. }
  499. };
  500. struct SetHeroArtifacts : public CPackForClient //509
  501. {
  502. SetHeroArtifacts(){type = 509;};
  503. void applyCl(CClient *cl);
  504. DLL_EXPORT void applyGs(CGameState *gs);
  505. DLL_EXPORT void setArtAtPos(ui16 pos, int art);
  506. si32 hid;
  507. std::vector<ui32> artifacts; //hero's artifacts from bag
  508. std::map<ui16,ui32> artifWorn; //map<position,artifact_id>; positions: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
  509. template <typename Handler> void serialize(Handler &h, const int version)
  510. {
  511. h & hid & artifacts & artifWorn;
  512. }
  513. std::vector<ui32> equiped, unequiped; //used locally
  514. BonusList gained, lost; //used locally as hlp when applying
  515. };
  516. struct HeroRecruited : public CPackForClient //515
  517. {
  518. HeroRecruited(){type = 515;};
  519. void applyCl(CClient *cl);
  520. DLL_EXPORT void applyGs(CGameState *gs);
  521. si32 hid, tid; //subID of hero
  522. int3 tile;
  523. ui8 player;
  524. template <typename Handler> void serialize(Handler &h, const int version)
  525. {
  526. h & hid & tid & tile & player;
  527. }
  528. };
  529. struct GiveHero : public CPackForClient //516
  530. {
  531. GiveHero(){type = 516;};
  532. void applyFirstCl(CClient *cl);
  533. void applyCl(CClient *cl);
  534. DLL_EXPORT void applyGs(CGameState *gs);
  535. ui32 id; //object id
  536. ui8 player;
  537. template <typename Handler> void serialize(Handler &h, const int version)
  538. {
  539. h & id & player;
  540. }
  541. };
  542. struct OpenWindow : public CPackForClient //517
  543. {
  544. OpenWindow(){type = 517;};
  545. void applyCl(CClient *cl);
  546. enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL, SHIPYARD_WINDOW, THIEVES_GUILD,
  547. UNIVERSITY_WINDOW, HILL_FORT_WINDOW, MARKET_WINDOW, PUZZLE_MAP, TAVERN_WINDOW};
  548. ui8 window;
  549. ui32 id1, id2;
  550. template <typename Handler> void serialize(Handler &h, const int version)
  551. {
  552. h & window & id1 & id2;
  553. }
  554. };
  555. struct NewObject : public CPackForClient //518
  556. {
  557. NewObject(){type = 518;};
  558. void applyCl(CClient *cl);
  559. DLL_EXPORT void applyGs(CGameState *gs);
  560. ui32 ID, subID;
  561. int3 pos;
  562. int id; //used internally
  563. template <typename Handler> void serialize(Handler &h, const int version)
  564. {
  565. h & ID & subID & pos;
  566. }
  567. };
  568. struct SetAvailableArtifacts : public CPackForClient //519
  569. {
  570. SetAvailableArtifacts(){type = 519;};
  571. void applyCl(CClient *cl);
  572. DLL_EXPORT void applyGs(CGameState *gs);
  573. si32 id; //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)
  574. std::vector<const CArtifact *> arts;
  575. template <typename Handler> void serialize(Handler &h, const int version)
  576. {
  577. h & id & arts;
  578. }
  579. };
  580. struct NewTurn : public CPackForClient //101
  581. {
  582. enum weekType {NORMAL, DOUBLE_GROWTH, BONUS_GROWTH, PLAGUE, CUSTOM, NO_ACTION, NONE};
  583. DLL_EXPORT void applyGs(CGameState *gs);
  584. struct Hero
  585. {
  586. ui32 id, move, mana; //id is a general serial id
  587. template <typename Handler> void serialize(Handler &h, const int version)
  588. {
  589. h & id & move & mana;
  590. }
  591. bool operator<(const Hero&h)const{return id < h.id;}
  592. };
  593. std::set<Hero> heroes; //updates movement and mana points
  594. //std::vector<SetResources> res;//resource list
  595. std::map<ui8, std::vector<si32> > res; //player ID => resource value[res_id]
  596. std::vector<SetAvailableCreatures> cres;//creatures to be placed in towns
  597. ui32 day;
  598. bool resetBuilded;
  599. weekType specialWeek;
  600. TQuantity creatureid; //for creature weeks
  601. NewTurn(){type = 101;};
  602. template <typename Handler> void serialize(Handler &h, const int version)
  603. {
  604. h & heroes & cres & res & day & resetBuilded;
  605. }
  606. };
  607. struct Component : public CPack //2002 helper for object scrips informations
  608. {
  609. enum EComponentType {PRIM_SKILL, SEC_SKILL, RESOURCE, CREATURE, ARTIFACT, EXPERIENCE, SPELL, MORALE=8, LUCK, BUILDING, HERO, FLAG};
  610. ui16 id, subtype; //id uses ^^^ enums, when id==EXPPERIENCE subtype==0 means exp points and subtype==1 levels)
  611. si32 val; // + give; - take
  612. si16 when; // 0 - now; +x - within x days; -x - per x days
  613. template <typename Handler> void serialize(Handler &h, const int version)
  614. {
  615. h & id & subtype & val & when;
  616. }
  617. Component()
  618. {
  619. type = 2002;
  620. }
  621. DLL_EXPORT explicit Component(const CStackInstance &stack);
  622. Component(ui16 Type, ui16 Subtype, si32 Val, si16 When)
  623. :id(Type),subtype(Subtype),val(Val),when(When)
  624. {
  625. type = 2002;
  626. }
  627. };
  628. struct InfoWindow : public CPackForClient //103 - displays simple info window
  629. {
  630. void applyCl(CClient *cl);
  631. MetaString text;
  632. std::vector<Component> components;
  633. ui8 player;
  634. ui16 soundID;
  635. template <typename Handler> void serialize(Handler &h, const int version)
  636. {
  637. h & text & components & player & soundID;
  638. }
  639. InfoWindow()
  640. {
  641. type = 103;
  642. soundID = 0;
  643. }
  644. };
  645. namespace ObjProperty
  646. {
  647. //TODO: move non general properties out to the appropriate objs classes
  648. enum {OWNER = 1, BLOCKVIS = 2, PRIMARY_STACK_COUNT = 3, VISITORS = 4, VISITED = 5, ID = 6, AVAILABLE_CREATURE = 7, SUBID = 8};
  649. }
  650. struct SetObjectProperty : public CPackForClient//1001
  651. {
  652. DLL_EXPORT void applyGs(CGameState *gs);
  653. void applyCl(CClient *cl);
  654. ui32 id;
  655. ui8 what; //1 - owner; 2 - blockvis; 3 - first stack count; 4 - visitors; 5 - visited; 6 - ID (if 34 then also def is replaced)
  656. ui32 val;
  657. SetObjectProperty(){type = 1001;};
  658. SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
  659. template <typename Handler> void serialize(Handler &h, const int version)
  660. {
  661. h & id & what & val;
  662. }
  663. };
  664. struct SetHoverName : public CPackForClient//1002
  665. {
  666. DLL_EXPORT void applyGs(CGameState *gs);
  667. ui32 id;
  668. MetaString name;
  669. SetHoverName(){type = 1002;};
  670. SetHoverName(ui32 ID, MetaString& Name):id(ID),name(Name){type = 1002;};
  671. template <typename Handler> void serialize(Handler &h, const int version)
  672. {
  673. h & id & name;
  674. }
  675. };
  676. struct HeroLevelUp : public Query//2000
  677. {
  678. void applyCl(CClient *cl);
  679. DLL_EXPORT void applyGs(CGameState *gs);
  680. si32 heroid;
  681. ui8 primskill, level;
  682. std::vector<ui16> skills;
  683. HeroLevelUp(){type = 2000;};
  684. template <typename Handler> void serialize(Handler &h, const int version)
  685. {
  686. h & id & heroid & primskill & level & skills;
  687. }
  688. };
  689. struct TradeComponents : public CPackForClient, public CPackForServer
  690. {
  691. ///used to handle info about components available in shops
  692. void applyCl(CClient *cl);
  693. DLL_EXPORT void applyGs(CGameState *gs);
  694. si32 heroid;
  695. ui32 objectid;
  696. std::map<ui16, Component> available, chosen, bought;
  697. template <typename Handler> void serialize(Handler &h, const int version)
  698. {
  699. h & heroid & objectid & available & chosen & bought;
  700. }
  701. };
  702. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  703. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  704. //Until sending reply player won't be allowed to take any actions
  705. struct BlockingDialog : public Query//2003
  706. {
  707. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  708. void applyCl(CClient *cl);
  709. MetaString text;
  710. std::vector<Component> components;
  711. ui8 player;
  712. ui8 flags;
  713. ui16 soundID;
  714. bool cancel() const
  715. {
  716. return flags & ALLOW_CANCEL;
  717. }
  718. bool selection() const
  719. {
  720. return flags & SELECTION;
  721. }
  722. BlockingDialog(bool yesno, bool Selection)
  723. {
  724. type = 2003;
  725. flags = 0;
  726. soundID = 0;
  727. if(yesno) flags |= ALLOW_CANCEL;
  728. if(Selection) flags |= SELECTION;
  729. }
  730. BlockingDialog()
  731. {
  732. type = 2003;
  733. flags = 0;
  734. soundID = 0;
  735. };
  736. template <typename Handler> void serialize(Handler &h, const int version)
  737. {
  738. h & id & text & components & player & flags & soundID;
  739. }
  740. };
  741. struct GarrisonDialog : public Query//2004
  742. {
  743. GarrisonDialog(){type = 2004;}
  744. void applyCl(CClient *cl);
  745. si32 objid, hid;
  746. bool removableUnits;
  747. template <typename Handler> void serialize(Handler &h, const int version)
  748. {
  749. h & id & objid & hid & removableUnits;
  750. }
  751. };
  752. struct BattleInfo;
  753. struct BattleStart : public CPackForClient//3000
  754. {
  755. BattleStart(){type = 3000;};
  756. void applyCl(CClient *cl);
  757. DLL_EXPORT void applyGs(CGameState *gs);
  758. BattleInfo * info;
  759. template <typename Handler> void serialize(Handler &h, const int version)
  760. {
  761. h & info;
  762. }
  763. };
  764. struct BattleNextRound : public CPackForClient//3001
  765. {
  766. BattleNextRound(){type = 3001;};
  767. void applyFirstCl(CClient *cl);
  768. void applyCl(CClient *cl);
  769. DLL_EXPORT void applyGs( CGameState *gs );
  770. si32 round;
  771. template <typename Handler> void serialize(Handler &h, const int version)
  772. {
  773. h & round;
  774. }
  775. };
  776. struct BattleSetActiveStack : public CPackForClient//3002
  777. {
  778. BattleSetActiveStack(){type = 3002;};
  779. void applyCl(CClient *cl);
  780. DLL_EXPORT void applyGs(CGameState *gs);
  781. ui32 stack;
  782. template <typename Handler> void serialize(Handler &h, const int version)
  783. {
  784. h & stack;
  785. }
  786. };
  787. struct BattleResult : public CPackForClient//3003
  788. {
  789. BattleResult(){type = 3003;};
  790. void applyFirstCl(CClient *cl);
  791. void applyGs(CGameState *gs);
  792. ui8 result; //0 - normal victory; 1 - escape; 2 - surrender
  793. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  794. std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
  795. expType exp[2]; //exp for attacker and defender
  796. std::set<ui32> artifacts; //artifacts taken from loser to winner
  797. template <typename Handler> void serialize(Handler &h, const int version)
  798. {
  799. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  800. }
  801. };
  802. struct BattleStackMoved : public CPackForClient//3004
  803. {
  804. ui32 stack, tile;
  805. ui8 ending, distance, teleporting;
  806. BattleStackMoved(){type = 3004;};
  807. void applyFirstCl(CClient *cl);
  808. void applyGs(CGameState *gs);
  809. template <typename Handler> void serialize(Handler &h, const int version)
  810. {
  811. h & stack & tile & ending & distance;
  812. }
  813. };
  814. struct StacksHealedOrResurrected : public CPackForClient //3013
  815. {
  816. StacksHealedOrResurrected(){type = 3013;}
  817. DLL_EXPORT void applyGs(CGameState *gs);
  818. void applyCl(CClient *cl);
  819. struct HealInfo
  820. {
  821. ui32 stackID;
  822. ui32 healedHP;
  823. ui8 lowLevelResurrection; //in case this stack is resurrected by this heal, it will be marked as SUMMONED
  824. template <typename Handler> void serialize(Handler &h, const int version)
  825. {
  826. h & stackID & healedHP & lowLevelResurrection;
  827. }
  828. };
  829. std::vector<HealInfo> healedStacks;
  830. ui8 lifeDrain; //if true, this heal is an effect of life drain
  831. si32 drainedFrom; //if life drain - then stack life was drain from
  832. template <typename Handler> void serialize(Handler &h, const int version)
  833. {
  834. h & healedStacks & lifeDrain & drainedFrom;
  835. }
  836. };
  837. struct BattleStackAttacked : public CPackForClient//3005
  838. {
  839. BattleStackAttacked(){flags = 0; type = 3005;};
  840. void applyCl(CClient *cl);
  841. DLL_EXPORT void applyGs(CGameState *gs);
  842. ui32 stackAttacked, attackerID;
  843. ui32 newAmount, newHP, killedAmount, damageAmount;
  844. ui8 flags; //1 - is stack killed; 2 - is there special effect to be shown;
  845. ui32 effect; //set only if flag 2 is present
  846. std::vector<StacksHealedOrResurrected> healedStacks; //used when life drain
  847. bool killed() const//if target stack was killed
  848. {
  849. return flags & 1;
  850. }
  851. bool isEffect() const//if stack has been attacked by a spell
  852. {
  853. return flags & 2;
  854. }
  855. bool lifeDrain() const //if this attack involves life drain effect
  856. {
  857. return healedStacks.size() > 0;
  858. }
  859. template <typename Handler> void serialize(Handler &h, const int version)
  860. {
  861. h & stackAttacked & attackerID & newAmount & newHP & flags & killedAmount & damageAmount & effect
  862. & healedStacks;
  863. }
  864. bool operator<(const BattleStackAttacked &b) const
  865. {
  866. return stackAttacked < b.stackAttacked;
  867. }
  868. };
  869. struct BattleAttack : public CPackForClient//3006
  870. {
  871. BattleAttack(){flags = 0; type = 3006;};
  872. void applyFirstCl(CClient *cl);
  873. DLL_EXPORT void applyGs(CGameState *gs);
  874. void applyCl(CClient *cl);
  875. std::vector<BattleStackAttacked> bsa;
  876. ui32 stackAttacking;
  877. ui8 flags;
  878. bool shot()//distance attack - decrease number of shots
  879. {
  880. return flags & 1;
  881. }
  882. bool counter()//is it counterattack?
  883. {
  884. return flags & 2;
  885. }
  886. bool lucky()
  887. {
  888. return flags & 4;
  889. }
  890. bool unlucky()
  891. {
  892. //TODO: support?
  893. return flags & 8;
  894. }
  895. //bool killed() //if target stack was killed
  896. //{
  897. // return bsa.killed();
  898. //}
  899. template <typename Handler> void serialize(Handler &h, const int version)
  900. {
  901. h & bsa & stackAttacking & flags;
  902. }
  903. };
  904. struct StartAction : public CPackForClient//3007
  905. {
  906. StartAction(){type = 3007;};
  907. StartAction(const BattleAction &act){ba = act; type = 3007;};
  908. void applyFirstCl(CClient *cl);
  909. DLL_EXPORT void applyGs(CGameState *gs);
  910. BattleAction ba;
  911. template <typename Handler> void serialize(Handler &h, const int version)
  912. {
  913. h & ba;
  914. }
  915. };
  916. struct EndAction : public CPackForClient//3008
  917. {
  918. EndAction(){type = 3008;};
  919. void applyCl(CClient *cl);
  920. template <typename Handler> void serialize(Handler &h, const int version)
  921. {
  922. }
  923. };
  924. struct BattleSpellCast : public CPackForClient//3009
  925. {
  926. BattleSpellCast(){type = 3009;};
  927. DLL_EXPORT void applyGs(CGameState *gs);
  928. void applyCl(CClient *cl);
  929. si32 dmgToDisplay; //this amount will be displayed as amount of damage dealt by spell
  930. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  931. ui32 id; //id of spell
  932. ui8 skill; //caster's skill level
  933. ui16 tile; //destination tile (may not be set in some global/mass spells
  934. std::vector<ui32> resisted; //ids of creatures that resisted this spell
  935. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  936. ui8 castedByHero; //if true - spell has been casted by hero, otherwise by a creature
  937. template <typename Handler> void serialize(Handler &h, const int version)
  938. {
  939. h & dmgToDisplay & side & id & skill & tile & resisted & affectedCres & castedByHero;
  940. }
  941. };
  942. struct SetStackEffect : public CPackForClient //3010
  943. {
  944. SetStackEffect(){type = 3010;};
  945. DLL_EXPORT void applyGs(CGameState *gs);
  946. void applyCl(CClient *cl);
  947. std::vector<ui32> stacks; //affected stacks (IDs)
  948. CStack::StackEffect effect; //type of effect
  949. template <typename Handler> void serialize(Handler &h, const int version)
  950. {
  951. h & stacks & effect;
  952. }
  953. };
  954. struct StacksInjured : public CPackForClient //3011
  955. {
  956. StacksInjured(){type = 3011;}
  957. DLL_EXPORT void applyGs(CGameState *gs);
  958. void applyCl(CClient *cl);
  959. std::vector<BattleStackAttacked> stacks;
  960. template <typename Handler> void serialize(Handler &h, const int version)
  961. {
  962. h & stacks;
  963. }
  964. };
  965. struct BattleResultsApplied : public CPackForClient //3012
  966. {
  967. BattleResultsApplied(){type = 3012;}
  968. ui8 player1, player2;
  969. void applyCl(CClient *cl);
  970. template <typename Handler> void serialize(Handler &h, const int version)
  971. {
  972. h & player1 & player2;
  973. }
  974. };
  975. struct ObstaclesRemoved : public CPackForClient //3014
  976. {
  977. ObstaclesRemoved(){type = 3014;}
  978. DLL_EXPORT void applyGs(CGameState *gs);
  979. void applyCl(CClient *cl);
  980. std::set<si32> obstacles; //uniqueIDs of removed obstacles
  981. template <typename Handler> void serialize(Handler &h, const int version)
  982. {
  983. h & obstacles;
  984. }
  985. };
  986. struct CatapultAttack : public CPackForClient //3015
  987. {
  988. CatapultAttack(){type = 3015;}
  989. DLL_EXPORT void applyGs(CGameState *gs);
  990. void applyCl(CClient *cl);
  991. std::set< std::pair< std::pair< ui8, si16 >, ui8> > attackedParts; // < <attackedPartOfWall, attacked hex >, damageDealt>
  992. //attackedPartOfWall; //[0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate;
  993. //damageDealt;
  994. int attacker; //if -1, then a spell caused this
  995. template <typename Handler> void serialize(Handler &h, const int version)
  996. {
  997. h & attackedParts & attacker;
  998. }
  999. };
  1000. struct BattleStacksRemoved : public CPackForClient //3016
  1001. {
  1002. BattleStacksRemoved(){type = 3016;}
  1003. DLL_EXPORT void applyGs(CGameState *gs);
  1004. void applyCl(CClient *cl);
  1005. std::set<ui32> stackIDs; //IDs of removed stacks
  1006. template <typename Handler> void serialize(Handler &h, const int version)
  1007. {
  1008. h & stackIDs;
  1009. }
  1010. };
  1011. struct ShowInInfobox : public CPackForClient //107
  1012. {
  1013. ShowInInfobox(){type = 107;};
  1014. ui8 player;
  1015. Component c;
  1016. MetaString text;
  1017. void applyCl(CClient *cl);
  1018. template <typename Handler> void serialize(Handler &h, const int version)
  1019. {
  1020. h & player & c & text;
  1021. }
  1022. };
  1023. struct AdvmapSpellCast : public CPackForClient //108
  1024. {
  1025. AdvmapSpellCast(){type = 108;}
  1026. const CGHeroInstance * caster;
  1027. si32 spellID;
  1028. void applyCl(CClient *cl);
  1029. template <typename Handler> void serialize(Handler &h, const int version)
  1030. {
  1031. h & caster & spellID;
  1032. }
  1033. };
  1034. /***********************************************************************************************************/
  1035. struct CloseServer : public CPackForServer
  1036. {
  1037. bool applyGh(CGameHandler *gh);
  1038. template <typename Handler> void serialize(Handler &h, const int version)
  1039. {}
  1040. };
  1041. struct EndTurn : public CPackForServer
  1042. {
  1043. bool applyGh(CGameHandler *gh);
  1044. template <typename Handler> void serialize(Handler &h, const int version)
  1045. {}
  1046. };
  1047. struct DismissHero : public CPackForServer
  1048. {
  1049. DismissHero(){};
  1050. DismissHero(si32 HID) : hid(HID) {};
  1051. si32 hid;
  1052. bool applyGh(CGameHandler *gh);
  1053. template <typename Handler> void serialize(Handler &h, const int version)
  1054. {
  1055. h & hid;
  1056. }
  1057. };
  1058. struct MoveHero : public CPackForServer
  1059. {
  1060. MoveHero(){};
  1061. MoveHero(const int3 &Dest, si32 HID) : dest(Dest), hid(HID){};
  1062. int3 dest;
  1063. si32 hid;
  1064. bool applyGh(CGameHandler *gh);
  1065. template <typename Handler> void serialize(Handler &h, const int version)
  1066. {
  1067. h & dest & hid;
  1068. }
  1069. };
  1070. struct CastleTeleportHero : public CPackForServer
  1071. {
  1072. CastleTeleportHero(){};
  1073. CastleTeleportHero(const si32 HID, si32 Dest, ui8 Source ) : dest(Dest), hid(HID), source(Source){};
  1074. si32 dest;
  1075. si32 hid;
  1076. si8 source;//who give teleporting, 1=castle gate
  1077. bool applyGh(CGameHandler *gh);
  1078. template <typename Handler> void serialize(Handler &h, const int version)
  1079. {
  1080. h & dest & hid;
  1081. }
  1082. };
  1083. struct ArrangeStacks : public CPackForServer
  1084. {
  1085. ArrangeStacks(){};
  1086. ArrangeStacks(ui8 W, ui8 P1, ui8 P2, si32 ID1, si32 ID2, si32 VAL)
  1087. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  1088. ui8 what; //1 - swap; 2 - merge; 3 - split
  1089. ui8 p1, p2; //positions of first and second stack
  1090. si32 id1, id2; //ids of objects with garrison
  1091. si32 val;
  1092. bool applyGh(CGameHandler *gh);
  1093. template <typename Handler> void serialize(Handler &h, const int version)
  1094. {
  1095. h & what & p1 & p2 & id1 & id2 & val;
  1096. }
  1097. };
  1098. struct DisbandCreature : public CPackForServer
  1099. {
  1100. DisbandCreature(){};
  1101. DisbandCreature(ui8 Pos, si32 ID):pos(Pos),id(ID){};
  1102. ui8 pos; //stack pos
  1103. si32 id; //object id
  1104. bool applyGh(CGameHandler *gh);
  1105. template <typename Handler> void serialize(Handler &h, const int version)
  1106. {
  1107. h & pos & id;
  1108. }
  1109. };
  1110. struct BuildStructure : public CPackForServer
  1111. {
  1112. BuildStructure(){};
  1113. BuildStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  1114. si32 bid, tid; //structure and town ids
  1115. bool applyGh(CGameHandler *gh);
  1116. template <typename Handler> void serialize(Handler &h, const int version)
  1117. {
  1118. h & tid & bid;
  1119. }
  1120. };
  1121. struct RazeStructure : public BuildStructure
  1122. {
  1123. RazeStructure(){};
  1124. //RazeStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  1125. bool applyGh(CGameHandler *gh);
  1126. };
  1127. struct RecruitCreatures : public CPackForServer
  1128. {
  1129. RecruitCreatures(){};
  1130. RecruitCreatures(si32 TID, si32 CRID, si32 Amount, si32 Level):tid(TID),crid(CRID),amount(Amount),level(Level){};
  1131. si32 tid; //town id
  1132. ui32 crid, amount;//creature ID and amount
  1133. si32 level;//dwelling level to buy from, -1 if any
  1134. bool applyGh(CGameHandler *gh);
  1135. template <typename Handler> void serialize(Handler &h, const int version)
  1136. {
  1137. h & tid & crid & amount & level;
  1138. }
  1139. };
  1140. struct UpgradeCreature : public CPackForServer
  1141. {
  1142. UpgradeCreature(){};
  1143. UpgradeCreature(ui8 Pos, si32 ID, si32 CRID):pos(Pos),id(ID), cid(CRID){};
  1144. ui8 pos; //stack pos
  1145. si32 id; //object id
  1146. si32 cid; //id of type to which we want make upgrade
  1147. bool applyGh(CGameHandler *gh);
  1148. template <typename Handler> void serialize(Handler &h, const int version)
  1149. {
  1150. h & pos & id & cid;
  1151. }
  1152. };
  1153. struct GarrisonHeroSwap : public CPackForServer
  1154. {
  1155. GarrisonHeroSwap(){};
  1156. GarrisonHeroSwap(si32 TID):tid(TID){};
  1157. si32 tid;
  1158. bool applyGh(CGameHandler *gh);
  1159. template <typename Handler> void serialize(Handler &h, const int version)
  1160. {
  1161. h & tid;
  1162. }
  1163. };
  1164. struct ExchangeArtifacts : public CPackForServer
  1165. {
  1166. ExchangeArtifacts(){};
  1167. ExchangeArtifacts(si32 H1, si32 H2, ui16 S1, ui16 S2)
  1168. :hid1(H1),hid2(H2),slot1(S1),slot2(S2){};
  1169. si32 hid1, hid2;
  1170. ui16 slot1, slot2;
  1171. bool applyGh(CGameHandler *gh);
  1172. template <typename Handler> void serialize(Handler &h, const int version)
  1173. {
  1174. h & hid1 & hid2 & slot1 & slot2;
  1175. }
  1176. };
  1177. struct AssembleArtifacts : public CPackForServer
  1178. {
  1179. AssembleArtifacts(){};
  1180. AssembleArtifacts(si32 _heroID, ui16 _artifactSlot, bool _assemble, ui32 _assembleTo)
  1181. : heroID(_heroID), artifactSlot(_artifactSlot), assemble(_assemble), assembleTo(_assembleTo){};
  1182. si32 heroID;
  1183. ui16 artifactSlot;
  1184. bool assemble; // True to assemble artifact, false to disassemble.
  1185. ui32 assembleTo; // Artifact to assemble into.
  1186. bool applyGh(CGameHandler *gh);
  1187. template <typename Handler> void serialize(Handler &h, const int version)
  1188. {
  1189. h & heroID & artifactSlot & assemble & assembleTo;
  1190. }
  1191. };
  1192. struct BuyArtifact : public CPackForServer
  1193. {
  1194. BuyArtifact(){};
  1195. BuyArtifact(si32 HID, si32 AID):hid(HID),aid(AID){};
  1196. si32 hid, aid; //hero and artifact id
  1197. bool applyGh(CGameHandler *gh);
  1198. template <typename Handler> void serialize(Handler &h, const int version)
  1199. {
  1200. h & hid & aid;
  1201. }
  1202. };
  1203. struct TradeOnMarketplace : public CPackForServer
  1204. {
  1205. TradeOnMarketplace(){};
  1206. const CGObjectInstance *market;
  1207. const CGHeroInstance *hero; //needed when trading artifacts / creatures
  1208. ui8 mode;//enum EMarketMode
  1209. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res (exception: when sacrificing art r1 is art id [todo: make r2 preferred slot?]
  1210. ui32 val; //units of sold resource
  1211. bool applyGh(CGameHandler *gh);
  1212. template <typename Handler> void serialize(Handler &h, const int version)
  1213. {
  1214. h & market & hero & mode & r1 & r2 & val;
  1215. }
  1216. };
  1217. struct SetFormation : public CPackForServer
  1218. {
  1219. SetFormation(){};
  1220. SetFormation(si32 HID, ui8 Formation):hid(HID),formation(Formation){};
  1221. si32 hid;
  1222. ui8 formation;
  1223. bool applyGh(CGameHandler *gh);
  1224. template <typename Handler> void serialize(Handler &h, const int version)
  1225. {
  1226. h & hid & formation;
  1227. }
  1228. };
  1229. struct HireHero : public CPackForServer
  1230. {
  1231. HireHero(){};
  1232. HireHero(si32 HID, si32 TID):hid(HID),tid(TID){};
  1233. si32 hid, tid; //available hero serial and town (tavern) id
  1234. ui8 player;
  1235. bool applyGh(CGameHandler *gh);
  1236. template <typename Handler> void serialize(Handler &h, const int version)
  1237. {
  1238. h & hid & tid & player;
  1239. }
  1240. };
  1241. struct BuildBoat : public CPackForServer
  1242. {
  1243. BuildBoat(){};
  1244. si32 objid; //where player wants to buy a boat
  1245. bool applyGh(CGameHandler *gh);
  1246. template <typename Handler> void serialize(Handler &h, const int version)
  1247. {
  1248. h & objid;
  1249. }
  1250. };
  1251. struct QueryReply : public CPackForServer
  1252. {
  1253. QueryReply(){type = 6000;};
  1254. QueryReply(ui32 QID, ui32 Answer):qid(QID),answer(Answer){type = 6000;};
  1255. ui32 qid, answer; //hero and artifact id
  1256. bool applyGh(CGameHandler *gh);
  1257. template <typename Handler> void serialize(Handler &h, const int version)
  1258. {
  1259. h & qid & answer;
  1260. }
  1261. };
  1262. struct MakeAction : public CPackForServer
  1263. {
  1264. MakeAction(){};
  1265. MakeAction(const BattleAction &BA):ba(BA){};
  1266. BattleAction ba;
  1267. bool applyGh(CGameHandler *gh);
  1268. template <typename Handler> void serialize(Handler &h, const int version)
  1269. {
  1270. h & ba;
  1271. }
  1272. };
  1273. struct MakeCustomAction : public CPackForServer
  1274. {
  1275. MakeCustomAction(){};
  1276. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1277. BattleAction ba;
  1278. bool applyGh(CGameHandler *gh);
  1279. template <typename Handler> void serialize(Handler &h, const int version)
  1280. {
  1281. h & ba;
  1282. }
  1283. };
  1284. struct DigWithHero : public CPackForServer
  1285. {
  1286. DigWithHero(){}
  1287. si32 id; //digging hero id
  1288. bool applyGh(CGameHandler *gh);
  1289. template <typename Handler> void serialize(Handler &h, const int version)
  1290. {
  1291. h & id;
  1292. }
  1293. };
  1294. struct CastAdvSpell : public CPackForServer
  1295. {
  1296. CastAdvSpell(){}
  1297. si32 hid; //hero id
  1298. ui32 sid; //spell id
  1299. int3 pos; //selected tile (not always used)
  1300. bool applyGh(CGameHandler *gh);
  1301. template <typename Handler> void serialize(Handler &h, const int version)
  1302. {
  1303. h & hid & sid & pos;
  1304. }
  1305. };
  1306. /***********************************************************************************************************/
  1307. struct SaveGame : public CPackForClient, public CPackForServer
  1308. {
  1309. SaveGame(){};
  1310. SaveGame(const std::string &Fname) :fname(Fname){};
  1311. std::string fname;
  1312. void applyCl(CClient *cl);
  1313. void applyGs(CGameState *gs){};
  1314. bool applyGh(CGameHandler *gh);
  1315. template <typename Handler> void serialize(Handler &h, const int version)
  1316. {
  1317. h & fname;
  1318. }
  1319. };
  1320. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  1321. {
  1322. PlayerMessage(){CPackForClient::type = 513;};
  1323. PlayerMessage(ui8 Player, const std::string &Text)
  1324. :player(Player),text(Text)
  1325. {CPackForClient::type = 513;};
  1326. void applyCl(CClient *cl);
  1327. void applyGs(CGameState *gs){};
  1328. bool applyGh(CGameHandler *gh);
  1329. ui8 player;
  1330. std::string text;
  1331. template <typename Handler> void serialize(Handler &h, const int version)
  1332. {
  1333. h & text & player;
  1334. }
  1335. };
  1336. struct SetSelection : public CPackForClient, public CPackForServer //514
  1337. {
  1338. SetSelection(){CPackForClient::type = 514;};
  1339. DLL_EXPORT void applyGs(CGameState *gs);
  1340. bool applyGh(CGameHandler *gh);
  1341. void applyCl(CClient *cl);
  1342. ui8 player;
  1343. ui32 id;
  1344. template <typename Handler> void serialize(Handler &h, const int version)
  1345. {
  1346. h & id & player;
  1347. }
  1348. };
  1349. struct CenterView : public CPackForClient//515
  1350. {
  1351. CenterView(){CPackForClient::type = 515;};
  1352. void applyCl(CClient *cl);
  1353. ui8 player;
  1354. int3 pos;
  1355. ui32 focusTime; //ms
  1356. template <typename Handler> void serialize(Handler &h, const int version)
  1357. {
  1358. h & pos & player & focusTime;
  1359. }
  1360. };
  1361. #endif //__NETPACKS_H__