NetPacks.h 38 KB

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