NetPacks.h 37 KB

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