NetPacks.h 39 KB

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