NetPacks.h 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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};
  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. void clear()
  112. {
  113. exactStrings.clear();
  114. localStrings.clear();
  115. message.clear();
  116. numbers.clear();
  117. }
  118. DLL_EXPORT void toString(std::string &dst) const;
  119. void getLocalString(const std::pair<ui8,ui32> &txt, std::string &dst) const;
  120. MetaString()
  121. {
  122. type = 2001;
  123. }
  124. };
  125. /***********************************************************************************************************/
  126. struct PackageApplied : public CPackForClient //94
  127. {
  128. PackageApplied() {type = 94;}
  129. PackageApplied(ui8 Result) : result(Result) {type = 94;}
  130. void applyCl(CClient *cl);
  131. ui8 result; //0 - something went wrong, request hasn't been realized; 1 - OK
  132. ui32 packType; //type id of applied package
  133. template <typename Handler> void serialize(Handler &h, const int version)
  134. {
  135. h & result & packType;
  136. }
  137. };
  138. struct SystemMessage : public CPackForClient //95
  139. {
  140. SystemMessage(const std::string Text) : text(Text){type = 95;};
  141. SystemMessage(){type = 95;};
  142. void applyCl(CClient *cl);
  143. std::string text;
  144. template <typename Handler> void serialize(Handler &h, const int version)
  145. {
  146. h & text;
  147. }
  148. };
  149. struct PlayerBlocked : public CPackForClient //96
  150. {
  151. PlayerBlocked(){type = 96;};
  152. void applyCl(CClient *cl);
  153. enum EReason { UPCOMING_BATTLE };
  154. ui8 reason;
  155. ui8 player;
  156. template <typename Handler> void serialize(Handler &h, const int version)
  157. {
  158. h & reason & player;
  159. }
  160. };
  161. struct YourTurn : public CPackForClient //100
  162. {
  163. YourTurn(){type = 100;};
  164. void applyCl(CClient *cl);
  165. DLL_EXPORT void applyGs(CGameState *gs);
  166. ui8 player;
  167. template <typename Handler> void serialize(Handler &h, const int version)
  168. {
  169. h & player;
  170. }
  171. };
  172. struct SetResource : public CPackForClient //102
  173. {
  174. SetResource(){type = 102;};
  175. void applyCl(CClient *cl);
  176. DLL_EXPORT void applyGs(CGameState *gs);
  177. ui8 player, resid;
  178. si32 val;
  179. template <typename Handler> void serialize(Handler &h, const int version)
  180. {
  181. h & player & resid & val;
  182. }
  183. };
  184. struct SetResources : public CPackForClient //104
  185. {
  186. SetResources(){res.resize(RESOURCE_QUANTITY);type = 104;};
  187. void applyCl(CClient *cl);
  188. DLL_EXPORT void applyGs(CGameState *gs);
  189. ui8 player;
  190. std::vector<si32> res; //res[resid] => res amount
  191. template <typename Handler> void serialize(Handler &h, const int version)
  192. {
  193. h & player & res;
  194. }
  195. };
  196. struct SetPrimSkill : public CPackForClient //105
  197. {
  198. SetPrimSkill(){type = 105;};
  199. void applyCl(CClient *cl);
  200. DLL_EXPORT void applyGs(CGameState *gs);
  201. ui8 abs; //0 - changes by value; 1 - sets to value
  202. si32 id;
  203. ui16 which, val;
  204. template <typename Handler> void serialize(Handler &h, const int version)
  205. {
  206. h & abs & id & which & val;
  207. }
  208. };
  209. struct SetSecSkill : public CPackForClient //106
  210. {
  211. SetSecSkill(){type = 106;};
  212. void applyCl(CClient *cl);
  213. DLL_EXPORT void applyGs(CGameState *gs);
  214. ui8 abs; //0 - changes by value; 1 - sets to value
  215. si32 id;
  216. ui16 which, val;
  217. template <typename Handler> void serialize(Handler &h, const int version)
  218. {
  219. h & abs & id & which & val;
  220. }
  221. };
  222. struct HeroVisitCastle : public CPackForClient //108
  223. {
  224. HeroVisitCastle(){flags=0;type = 108;};
  225. void applyCl(CClient *cl);
  226. DLL_EXPORT void applyGs(CGameState *gs);
  227. ui8 flags; //1 - start, 2 - garrison
  228. ui32 tid, hid;
  229. bool start() //if hero is entering castle (if false - leaving)
  230. {
  231. return flags & 1;
  232. }
  233. bool garrison() //if hero is entering/leaving garrison (if false - it's only visiting hero)
  234. {
  235. return flags & 2;
  236. }
  237. template <typename Handler> void serialize(Handler &h, const int version)
  238. {
  239. h & flags & tid & hid;
  240. }
  241. };
  242. struct ChangeSpells : public CPackForClient //109
  243. {
  244. ChangeSpells(){type = 109;};
  245. void applyCl(CClient *cl);
  246. DLL_EXPORT void applyGs(CGameState *gs);
  247. ui8 learn; //1 - gives spell, 0 - takes
  248. ui32 hid;
  249. std::set<ui32> spells;
  250. template <typename Handler> void serialize(Handler &h, const int version)
  251. {
  252. h & learn & hid & spells;
  253. }
  254. };
  255. struct SetMana : public CPackForClient //110
  256. {
  257. SetMana(){type = 110;};
  258. void applyCl(CClient *cl);
  259. DLL_EXPORT void applyGs(CGameState *gs);
  260. si32 hid, val;
  261. template <typename Handler> void serialize(Handler &h, const int version)
  262. {
  263. h & val & hid;
  264. }
  265. };
  266. struct SetMovePoints : public CPackForClient //111
  267. {
  268. SetMovePoints(){type = 111;};
  269. void applyCl(CClient *cl);
  270. DLL_EXPORT void applyGs(CGameState *gs);
  271. ui32 hid, val;
  272. template <typename Handler> void serialize(Handler &h, const int version)
  273. {
  274. h & val & hid;
  275. }
  276. };
  277. struct FoWChange : public CPackForClient //112
  278. {
  279. FoWChange(){type = 112;};
  280. void applyCl(CClient *cl);
  281. DLL_EXPORT void applyGs(CGameState *gs);
  282. std::set<int3> tiles;
  283. ui8 player, mode; //mode==0 - hide, mode==1 - reveal
  284. template <typename Handler> void serialize(Handler &h, const int version)
  285. {
  286. h & tiles & player & mode;
  287. }
  288. };
  289. struct SetAvailableHeroes : public CPackForClient //113
  290. {
  291. SetAvailableHeroes(){type = 113;flags=0;};
  292. void applyCl(CClient *cl);
  293. DLL_EXPORT void applyGs(CGameState *gs);
  294. ui8 player;
  295. si32 hid1, hid2;
  296. ui8 flags; //1 - reset army of hero1; 2 - reset army of hero 2
  297. template <typename Handler> void serialize(Handler &h, const int version)
  298. {
  299. h & player & hid1 & hid2 & flags;
  300. }
  301. };
  302. struct GiveBonus : public CPackForClient //115
  303. {
  304. GiveBonus(){type = 115;};
  305. void applyCl(CClient *cl);
  306. DLL_EXPORT void applyGs(CGameState *gs);
  307. ui32 hid;
  308. HeroBonus bonus;
  309. MetaString bdescr;
  310. template <typename Handler> void serialize(Handler &h, const int version)
  311. {
  312. h & bonus & hid & bdescr;
  313. }
  314. };
  315. struct ChangeObjPos : public CPackForClient //116
  316. {
  317. ChangeObjPos(){type = 116;};
  318. void applyFirstCl(CClient *cl);
  319. void applyCl(CClient *cl);
  320. DLL_EXPORT void applyGs(CGameState *gs);
  321. ui32 objid;
  322. int3 nPos;
  323. ui8 flags; //bit flags: 1 - redraw
  324. template <typename Handler> void serialize(Handler &h, const int version)
  325. {
  326. h & objid & nPos & flags;
  327. }
  328. };
  329. struct RemoveObject : public CPackForClient //500
  330. {
  331. RemoveObject(){type = 500;};
  332. RemoveObject(si32 ID){id = ID;type = 500;};
  333. void applyFirstCl(CClient *cl);
  334. void applyCl(CClient *cl);
  335. DLL_EXPORT void applyGs(CGameState *gs);
  336. si32 id;
  337. template <typename Handler> void serialize(Handler &h, const int version)
  338. {
  339. h & id;
  340. }
  341. };
  342. struct TryMoveHero : public CPackForClient //501
  343. {
  344. TryMoveHero(){type = 501;};
  345. void applyFirstCl(CClient *cl);
  346. void applyCl(CClient *cl);
  347. void applyGs(CGameState *gs);
  348. enum EResult
  349. {
  350. FAILED, SUCCESS, TELEPORTATION, RESERVED___, BLOCKING_VISIT, EMBARK, DISEMBARK
  351. };
  352. ui32 id, movePoints;
  353. ui8 result; //uses EResult
  354. int3 start, end;
  355. std::set<int3> fowRevealed; //revealed tiles
  356. template <typename Handler> void serialize(Handler &h, const int version)
  357. {
  358. h & id & result & start & end & movePoints & fowRevealed;
  359. }
  360. };
  361. struct SetGarrisons : public CPackForClient //502
  362. {
  363. SetGarrisons(){type = 502;};
  364. void applyCl(CClient *cl);
  365. DLL_EXPORT void applyGs(CGameState *gs);
  366. std::map<ui32,CCreatureSet> garrs;
  367. template <typename Handler> void serialize(Handler &h, const int version)
  368. {
  369. h & garrs;
  370. }
  371. };
  372. struct NewStructures : public CPackForClient //504
  373. {
  374. NewStructures(){type = 504;};
  375. void applyCl(CClient *cl);
  376. DLL_EXPORT void applyGs(CGameState *gs);
  377. si32 tid;
  378. std::set<si32> bid;
  379. si16 builded;
  380. template <typename Handler> void serialize(Handler &h, const int version)
  381. {
  382. h & tid & bid & builded;
  383. }
  384. };
  385. struct SetAvailableCreatures : public CPackForClient //506
  386. {
  387. SetAvailableCreatures(){type = 506;};
  388. void applyCl(CClient *cl);
  389. DLL_EXPORT void applyGs(CGameState *gs);
  390. si32 tid;
  391. std::vector<std::pair<ui32, std::vector<ui32> > > creatures;
  392. template <typename Handler> void serialize(Handler &h, const int version)
  393. {
  394. h & tid & creatures;
  395. }
  396. };
  397. struct SetHeroesInTown : public CPackForClient //508
  398. {
  399. SetHeroesInTown(){type = 508;};
  400. void applyCl(CClient *cl);
  401. DLL_EXPORT void applyGs(CGameState *gs);
  402. si32 tid, visiting, garrison; //id of town, visiting hero, hero in garrison
  403. template <typename Handler> void serialize(Handler &h, const int version)
  404. {
  405. h & tid & visiting & garrison;
  406. }
  407. };
  408. struct SetHeroArtifacts : public CPackForClient //509
  409. {
  410. SetHeroArtifacts(){type = 509;};
  411. void applyCl(CClient *cl);
  412. DLL_EXPORT void applyGs(CGameState *gs);
  413. DLL_EXPORT void setArtAtPos(ui16 pos, int art);
  414. si32 hid;
  415. std::vector<ui32> artifacts; //hero's artifacts from bag
  416. 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
  417. template <typename Handler> void serialize(Handler &h, const int version)
  418. {
  419. h & hid & artifacts & artifWorn;
  420. }
  421. std::vector<HeroBonus*> gained, lost; //used locally as hlp when applying
  422. };
  423. struct HeroRecruited : public CPackForClient //515
  424. {
  425. HeroRecruited(){type = 515;};
  426. void applyCl(CClient *cl);
  427. DLL_EXPORT void applyGs(CGameState *gs);
  428. si32 hid, tid; //subID of hero
  429. int3 tile;
  430. ui8 player;
  431. template <typename Handler> void serialize(Handler &h, const int version)
  432. {
  433. h & hid & tid & tile & player;
  434. }
  435. };
  436. struct GiveHero : public CPackForClient //516
  437. {
  438. GiveHero(){type = 516;};
  439. void applyFirstCl(CClient *cl);
  440. void applyCl(CClient *cl);
  441. DLL_EXPORT void applyGs(CGameState *gs);
  442. ui32 id; //object id
  443. ui8 player;
  444. template <typename Handler> void serialize(Handler &h, const int version)
  445. {
  446. h & id & player;
  447. }
  448. };
  449. struct OpenWindow : public CPackForClient //517
  450. {
  451. OpenWindow(){type = 517;};
  452. void applyCl(CClient *cl);
  453. enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL, SHIPYARD_WINDOW};
  454. ui8 window;
  455. ui32 id1, id2;
  456. template <typename Handler> void serialize(Handler &h, const int version)
  457. {
  458. h & window & id1 & id2;
  459. }
  460. };
  461. struct NewObject : public CPackForClient //518
  462. {
  463. NewObject(){type = 518;};
  464. void applyCl(CClient *cl);
  465. DLL_EXPORT void applyGs(CGameState *gs);
  466. ui32 ID, subID;
  467. int3 pos;
  468. int id; //used internally
  469. template <typename Handler> void serialize(Handler &h, const int version)
  470. {
  471. h & ID & subID & pos;
  472. }
  473. };
  474. struct NewTurn : public CPackForClient //101
  475. {
  476. DLL_EXPORT void applyGs(CGameState *gs);
  477. struct Hero
  478. {
  479. ui32 id, move, mana; //id is a general serial id
  480. template <typename Handler> void serialize(Handler &h, const int version)
  481. {
  482. h & id & move & mana;
  483. }
  484. bool operator<(const Hero&h)const{return id < h.id;}
  485. };
  486. std::set<Hero> heroes; //updates movement and mana points
  487. std::vector<SetResources> res;//resource list
  488. std::vector<SetAvailableCreatures> cres;//resource list
  489. ui32 day;
  490. bool resetBuilded;
  491. NewTurn(){type = 101;};
  492. template <typename Handler> void serialize(Handler &h, const int version)
  493. {
  494. h & heroes & cres & res & day & resetBuilded;
  495. }
  496. };
  497. struct Component : public CPack //2002 helper for object scrips informations
  498. {
  499. enum {PRIM_SKILL,SEC_SKILL,RESOURCE,CREATURE,ARTIFACT,EXPERIENCE,SPELL, MORALE=8, LUCK};
  500. ui16 id, subtype; //id uses ^^^ enums, when id==EXPPERIENCE subtype==0 means exp points and subtype==1 levels)
  501. si32 val; // + give; - take
  502. si16 when; // 0 - now; +x - within x days; -x - per x days
  503. template <typename Handler> void serialize(Handler &h, const int version)
  504. {
  505. h & id & subtype & val & when;
  506. }
  507. Component(){type = 2002;};
  508. Component(ui16 Type, ui16 Subtype, si32 Val, si16 When):id(Type),subtype(Subtype),val(Val),when(When){type = 2002;};
  509. };
  510. struct InfoWindow : public CPackForClient //103 - displays simple info window
  511. {
  512. void applyCl(CClient *cl);
  513. MetaString text;
  514. std::vector<Component> components;
  515. ui8 player;
  516. ui16 soundID;
  517. template <typename Handler> void serialize(Handler &h, const int version)
  518. {
  519. h & text & components & player & soundID;
  520. }
  521. InfoWindow() {
  522. type = 103;
  523. soundID = 0;
  524. };
  525. };
  526. struct SetObjectProperty : public CPackForClient//1001
  527. {
  528. DLL_EXPORT void applyGs(CGameState *gs);
  529. void applyCl(CClient *cl);
  530. ui32 id;
  531. ui8 what; //1 - owner; 2 - blockvis; 3 - first stack count; 4 - visitors; 5 - visited; 6 - ID (if 34 then also def is replaced)
  532. ui32 val;
  533. SetObjectProperty(){type = 1001;};
  534. SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
  535. template <typename Handler> void serialize(Handler &h, const int version)
  536. {
  537. h & id & what & val;
  538. }
  539. };
  540. struct SetHoverName : public CPackForClient//1002
  541. {
  542. DLL_EXPORT void applyGs(CGameState *gs);
  543. ui32 id;
  544. MetaString name;
  545. SetHoverName(){type = 1002;};
  546. SetHoverName(ui32 ID, MetaString& Name):id(ID),name(Name){type = 1002;};
  547. template <typename Handler> void serialize(Handler &h, const int version)
  548. {
  549. h & id & name;
  550. }
  551. };
  552. struct HeroLevelUp : public Query//2000
  553. {
  554. void applyCl(CClient *cl);
  555. DLL_EXPORT void applyGs(CGameState *gs);
  556. si32 heroid;
  557. ui8 primskill, level;
  558. std::vector<ui16> skills;
  559. HeroLevelUp(){type = 2000;};
  560. template <typename Handler> void serialize(Handler &h, const int version)
  561. {
  562. h & id & heroid & primskill & level & skills;
  563. }
  564. };
  565. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  566. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  567. //Until sending reply player won't be allowed to take any actions
  568. struct BlockingDialog : public Query//2003
  569. {
  570. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  571. void applyCl(CClient *cl);
  572. MetaString text;
  573. std::vector<Component> components;
  574. ui8 player;
  575. ui8 flags;
  576. ui16 soundID;
  577. bool cancel() const
  578. {
  579. return flags & ALLOW_CANCEL;
  580. }
  581. bool selection() const
  582. {
  583. return flags & SELECTION;
  584. }
  585. BlockingDialog(bool yesno, bool Selection)
  586. {
  587. type = 2003;
  588. flags = 0;
  589. soundID = 0;
  590. if(yesno) flags |= ALLOW_CANCEL;
  591. if(Selection) flags |= SELECTION;
  592. }
  593. BlockingDialog()
  594. {
  595. type = 2003;
  596. flags = 0;
  597. soundID = 0;
  598. };
  599. template <typename Handler> void serialize(Handler &h, const int version)
  600. {
  601. h & id & text & components & player & flags & soundID;
  602. }
  603. };
  604. struct GarrisonDialog : public Query//2004
  605. {
  606. GarrisonDialog(){type = 2004;}
  607. void applyCl(CClient *cl);
  608. si32 objid, hid;
  609. template <typename Handler> void serialize(Handler &h, const int version)
  610. {
  611. h & id & objid & hid;
  612. }
  613. };
  614. struct BattleInfo;
  615. struct BattleStart : public CPackForClient//3000
  616. {
  617. BattleStart(){type = 3000;};
  618. void applyCl(CClient *cl);
  619. DLL_EXPORT void applyGs(CGameState *gs);
  620. BattleInfo * info;
  621. template <typename Handler> void serialize(Handler &h, const int version)
  622. {
  623. h & info;
  624. }
  625. };
  626. struct BattleNextRound : public CPackForClient//3001
  627. {
  628. BattleNextRound(){type = 3001;};
  629. void applyCl(CClient *cl);
  630. DLL_EXPORT void applyGs(CGameState *gs);
  631. si32 round;
  632. template <typename Handler> void serialize(Handler &h, const int version)
  633. {
  634. h & round;
  635. }
  636. };
  637. struct BattleSetActiveStack : public CPackForClient//3002
  638. {
  639. BattleSetActiveStack(){type = 3002;};
  640. void applyCl(CClient *cl);
  641. DLL_EXPORT void applyGs(CGameState *gs);
  642. ui32 stack;
  643. template <typename Handler> void serialize(Handler &h, const int version)
  644. {
  645. h & stack;
  646. }
  647. };
  648. struct BattleResult : public CPackForClient//3003
  649. {
  650. BattleResult(){type = 3003;};
  651. void applyFirstCl(CClient *cl);
  652. void applyGs(CGameState *gs);
  653. ui8 result; //0 - normal victory; 1 - escape; 2 - surrender
  654. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  655. std::set<std::pair<ui32,si32> > casualties[2]; //first => casualties of attackers - set of pairs crid<>number
  656. ui32 exp[2]; //exp for attacker and defender
  657. std::set<ui32> artifacts; //artifacts taken from loser to winner
  658. template <typename Handler> void serialize(Handler &h, const int version)
  659. {
  660. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  661. }
  662. };
  663. struct BattleStackMoved : public CPackForClient//3004
  664. {
  665. ui32 stack, tile;
  666. ui8 ending, distance;
  667. BattleStackMoved(){type = 3004;};
  668. void applyFirstCl(CClient *cl);
  669. void applyGs(CGameState *gs);
  670. template <typename Handler> void serialize(Handler &h, const int version)
  671. {
  672. h & stack & tile & ending & distance;
  673. }
  674. };
  675. struct BattleStackAttacked : public CPackForClient//3005
  676. {
  677. BattleStackAttacked(){flags = 0; type = 3005;};
  678. void applyCl(CClient *cl);
  679. DLL_EXPORT void applyGs(CGameState *gs);
  680. ui32 stackAttacked;
  681. ui32 newAmount, newHP, killedAmount, damageAmount;
  682. ui8 flags; //1 - is stack killed; 2 - is there special effect to be shown;
  683. ui32 effect; //set only if flag 2 is present
  684. bool killed() const//if target stack was killed
  685. {
  686. return flags & 1;
  687. }
  688. bool isEffect() const//if target stack was killed
  689. {
  690. return flags & 2;
  691. }
  692. template <typename Handler> void serialize(Handler &h, const int version)
  693. {
  694. h & stackAttacked & newAmount & newHP & flags & killedAmount & damageAmount & effect;
  695. }
  696. bool operator<(const BattleStackAttacked &b) const
  697. {
  698. return stackAttacked < b.stackAttacked;
  699. }
  700. };
  701. struct BattleAttack : public CPackForClient//3006
  702. {
  703. BattleAttack(){flags = 0; type = 3006;};
  704. void applyFirstCl(CClient *cl);
  705. DLL_EXPORT void applyGs(CGameState *gs);
  706. void applyCl(CClient *cl);
  707. std::set<BattleStackAttacked> bsa;
  708. ui32 stackAttacking;
  709. ui8 flags;
  710. bool shot()//distance attack - decrease number of shots
  711. {
  712. return flags & 1;
  713. }
  714. bool counter()//is it counterattack?
  715. {
  716. return flags & 2;
  717. }
  718. bool lucky()
  719. {
  720. return flags & 4;
  721. }
  722. bool unlucky()
  723. {
  724. //TODO: support?
  725. return flags & 8;
  726. }
  727. //bool killed() //if target stack was killed
  728. //{
  729. // return bsa.killed();
  730. //}
  731. template <typename Handler> void serialize(Handler &h, const int version)
  732. {
  733. h & bsa & stackAttacking & flags;
  734. }
  735. };
  736. struct StartAction : public CPackForClient//3007
  737. {
  738. StartAction(){type = 3007;};
  739. StartAction(const BattleAction &act){ba = act; type = 3007;};
  740. void applyFirstCl(CClient *cl);
  741. DLL_EXPORT void applyGs(CGameState *gs);
  742. BattleAction ba;
  743. template <typename Handler> void serialize(Handler &h, const int version)
  744. {
  745. h & ba;
  746. }
  747. };
  748. struct EndAction : public CPackForClient//3008
  749. {
  750. EndAction(){type = 3008;};
  751. void applyCl(CClient *cl);
  752. template <typename Handler> void serialize(Handler &h, const int version)
  753. {
  754. }
  755. };
  756. struct SpellCast : public CPackForClient//3009
  757. {
  758. SpellCast(){type = 3009;};
  759. DLL_EXPORT void applyGs(CGameState *gs);
  760. void applyCl(CClient *cl);
  761. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  762. ui32 id; //id of spell
  763. ui8 skill; //caster's skill level
  764. ui16 tile; //destination tile (may not be set in some global/mass spells
  765. std::vector<ui32> resisted; //ids of creatures that resisted this spell
  766. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  767. template <typename Handler> void serialize(Handler &h, const int version)
  768. {
  769. h & side & id & skill & tile & resisted & affectedCres;
  770. }
  771. };
  772. struct SetStackEffect : public CPackForClient //3010
  773. {
  774. SetStackEffect(){type = 3010;};
  775. DLL_EXPORT void applyGs(CGameState *gs);
  776. void applyCl(CClient *cl);
  777. std::set<ui32> stacks; //affected stacks (IDs)
  778. CStack::StackEffect effect; //type of effect
  779. template <typename Handler> void serialize(Handler &h, const int version)
  780. {
  781. h & stacks & effect;
  782. }
  783. };
  784. struct StacksInjured : public CPackForClient //3011
  785. {
  786. StacksInjured(){type = 3011;}
  787. DLL_EXPORT void applyGs(CGameState *gs);
  788. void applyCl(CClient *cl);
  789. std::set<BattleStackAttacked> stacks;
  790. template <typename Handler> void serialize(Handler &h, const int version)
  791. {
  792. h & stacks;
  793. }
  794. };
  795. struct BattleResultsApplied : public CPackForClient //3012
  796. {
  797. BattleResultsApplied(){type = 3012;}
  798. ui8 player1, player2;
  799. void applyCl(CClient *cl);
  800. template <typename Handler> void serialize(Handler &h, const int version)
  801. {
  802. h & player1 & player2;
  803. }
  804. };
  805. struct StacksHealedOrResurrected : public CPackForClient //3013
  806. {
  807. StacksHealedOrResurrected(){type = 3013;}
  808. DLL_EXPORT void applyGs(CGameState *gs);
  809. void applyCl(CClient *cl);
  810. struct HealInfo
  811. {
  812. ui32 stackID;
  813. ui32 healedHP;
  814. template <typename Handler> void serialize(Handler &h, const int version)
  815. {
  816. h & stackID & healedHP;
  817. }
  818. };
  819. std::vector<HealInfo> healedStacks;
  820. template <typename Handler> void serialize(Handler &h, const int version)
  821. {
  822. h & healedStacks;
  823. }
  824. };
  825. struct ShowInInfobox : public CPackForClient //107
  826. {
  827. ShowInInfobox(){type = 107;};
  828. ui8 player;
  829. Component c;
  830. MetaString text;
  831. void applyCl(CClient *cl);
  832. template <typename Handler> void serialize(Handler &h, const int version)
  833. {
  834. h & player & c & text;
  835. }
  836. };
  837. /***********************************************************************************************************/
  838. struct CloseServer : public CPackForServer
  839. {
  840. bool applyGh(CGameHandler *gh);
  841. template <typename Handler> void serialize(Handler &h, const int version)
  842. {}
  843. };
  844. struct EndTurn : public CPackForServer
  845. {
  846. bool applyGh(CGameHandler *gh);
  847. template <typename Handler> void serialize(Handler &h, const int version)
  848. {}
  849. };
  850. struct DismissHero : public CPackForServer
  851. {
  852. DismissHero(){};
  853. DismissHero(si32 HID) : hid(HID) {};
  854. si32 hid;
  855. bool applyGh(CGameHandler *gh);
  856. template <typename Handler> void serialize(Handler &h, const int version)
  857. {
  858. h & hid;
  859. }
  860. };
  861. struct MoveHero : public CPackForServer
  862. {
  863. MoveHero(){};
  864. MoveHero(const int3 &Dest, si32 HID) : dest(Dest), hid(HID){};
  865. int3 dest;
  866. si32 hid;
  867. bool applyGh(CGameHandler *gh);
  868. template <typename Handler> void serialize(Handler &h, const int version)
  869. {
  870. h & dest & hid;
  871. }
  872. };
  873. struct ArrangeStacks : public CPackForServer
  874. {
  875. ArrangeStacks(){};
  876. ArrangeStacks(ui8 W, ui8 P1, ui8 P2, si32 ID1, si32 ID2, si32 VAL)
  877. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  878. ui8 what; //1 - swap; 2 - merge; 3 - split
  879. ui8 p1, p2; //positions of first and second stack
  880. si32 id1, id2; //ids of objects with garrison
  881. si32 val;
  882. bool applyGh(CGameHandler *gh);
  883. template <typename Handler> void serialize(Handler &h, const int version)
  884. {
  885. h & what & p1 & p2 & id1 & id2 & val;
  886. }
  887. };
  888. struct DisbandCreature : public CPackForServer
  889. {
  890. DisbandCreature(){};
  891. DisbandCreature(ui8 Pos, si32 ID):pos(Pos),id(ID){};
  892. ui8 pos; //stack pos
  893. si32 id; //object id
  894. bool applyGh(CGameHandler *gh);
  895. template <typename Handler> void serialize(Handler &h, const int version)
  896. {
  897. h & pos & id;
  898. }
  899. };
  900. struct BuildStructure : public CPackForServer
  901. {
  902. BuildStructure(){};
  903. BuildStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  904. si32 bid, tid; //structure and town ids
  905. bool applyGh(CGameHandler *gh);
  906. template <typename Handler> void serialize(Handler &h, const int version)
  907. {
  908. h & tid & bid;
  909. }
  910. };
  911. struct RecruitCreatures : public CPackForServer
  912. {
  913. RecruitCreatures(){};
  914. RecruitCreatures(si32 TID, si32 CRID, si32 Amount):tid(TID),crid(CRID),amount(Amount){};
  915. si32 tid; //town id
  916. ui32 crid, amount;//creature ID and amount
  917. bool applyGh(CGameHandler *gh);
  918. template <typename Handler> void serialize(Handler &h, const int version)
  919. {
  920. h & tid & crid & amount;
  921. }
  922. };
  923. struct UpgradeCreature : public CPackForServer
  924. {
  925. UpgradeCreature(){};
  926. UpgradeCreature(ui8 Pos, si32 ID, si32 CRID):pos(Pos),id(ID), cid(CRID){};
  927. ui8 pos; //stack pos
  928. si32 id; //object id
  929. si32 cid; //id of type to which we want make upgrade
  930. bool applyGh(CGameHandler *gh);
  931. template <typename Handler> void serialize(Handler &h, const int version)
  932. {
  933. h & pos & id & cid;
  934. }
  935. };
  936. struct GarrisonHeroSwap : public CPackForServer
  937. {
  938. GarrisonHeroSwap(){};
  939. GarrisonHeroSwap(si32 TID):tid(TID){};
  940. si32 tid;
  941. bool applyGh(CGameHandler *gh);
  942. template <typename Handler> void serialize(Handler &h, const int version)
  943. {
  944. h & tid;
  945. }
  946. };
  947. struct ExchangeArtifacts : public CPackForServer
  948. {
  949. ExchangeArtifacts(){};
  950. ExchangeArtifacts(si32 H1, si32 H2, ui16 S1, ui16 S2)
  951. :hid1(H1),hid2(H2),slot1(S1),slot2(S2){};
  952. si32 hid1, hid2;
  953. ui16 slot1, slot2;
  954. bool applyGh(CGameHandler *gh);
  955. template <typename Handler> void serialize(Handler &h, const int version)
  956. {
  957. h & hid1 & hid2 & slot1 & slot2;
  958. }
  959. };
  960. struct BuyArtifact : public CPackForServer
  961. {
  962. BuyArtifact(){};
  963. BuyArtifact(si32 HID, si32 AID):hid(HID),aid(AID){};
  964. si32 hid, aid; //hero and artifact id
  965. bool applyGh(CGameHandler *gh);
  966. template <typename Handler> void serialize(Handler &h, const int version)
  967. {
  968. h & hid & aid;
  969. }
  970. };
  971. struct TradeOnMarketplace : public CPackForServer
  972. {
  973. TradeOnMarketplace(){};
  974. TradeOnMarketplace(ui8 Player, ui8 Mode, /*si32 ID, */ui32 R1, ui32 R2, ui32 Val)
  975. :player(Player),mode(Mode),/*id(ID),*/r1(R1),r2(R2),val(Val){};
  976. ui8 player;
  977. ui8 mode;//0 - res<->res;
  978. //si32 id; //object id
  979. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res
  980. ui32 val; //units of sold resource
  981. bool applyGh(CGameHandler *gh);
  982. template <typename Handler> void serialize(Handler &h, const int version)
  983. {
  984. h & player & mode & /*id & */r1 & r2 & val;
  985. }
  986. };
  987. struct SetFormation : public CPackForServer
  988. {
  989. SetFormation(){};
  990. SetFormation(si32 HID, ui8 Formation):hid(HID),formation(Formation){};
  991. si32 hid;
  992. ui8 formation;
  993. bool applyGh(CGameHandler *gh);
  994. template <typename Handler> void serialize(Handler &h, const int version)
  995. {
  996. h & hid & formation;
  997. }
  998. };
  999. struct HireHero : public CPackForServer
  1000. {
  1001. HireHero(){};
  1002. HireHero(si32 HID, si32 TID):hid(HID),tid(TID){};
  1003. si32 hid, tid; //available hero serial and town id
  1004. bool applyGh(CGameHandler *gh);
  1005. template <typename Handler> void serialize(Handler &h, const int version)
  1006. {
  1007. h & hid & tid;
  1008. }
  1009. };
  1010. struct BuildBoat : public CPackForServer
  1011. {
  1012. BuildBoat(){};
  1013. si32 objid; //where player wants to buy a boat
  1014. bool applyGh(CGameHandler *gh);
  1015. template <typename Handler> void serialize(Handler &h, const int version)
  1016. {
  1017. h & objid;
  1018. }
  1019. };
  1020. struct QueryReply : public CPackForServer
  1021. {
  1022. QueryReply(){type = 6000;};
  1023. QueryReply(ui32 QID, ui32 Answer):qid(QID),answer(Answer){type = 6000;};
  1024. ui32 qid, answer; //hero and artifact id
  1025. bool applyGh(CGameHandler *gh);
  1026. template <typename Handler> void serialize(Handler &h, const int version)
  1027. {
  1028. h & qid & answer;
  1029. }
  1030. };
  1031. struct MakeAction : public CPackForServer
  1032. {
  1033. MakeAction(){};
  1034. MakeAction(const BattleAction &BA):ba(BA){};
  1035. BattleAction ba;
  1036. bool applyGh(CGameHandler *gh);
  1037. template <typename Handler> void serialize(Handler &h, const int version)
  1038. {
  1039. h & ba;
  1040. }
  1041. };
  1042. struct MakeCustomAction : public CPackForServer
  1043. {
  1044. MakeCustomAction(){};
  1045. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1046. BattleAction ba;
  1047. bool applyGh(CGameHandler *gh);
  1048. template <typename Handler> void serialize(Handler &h, const int version)
  1049. {
  1050. h & ba;
  1051. }
  1052. };
  1053. /***********************************************************************************************************/
  1054. struct SaveGame : public CPackForClient, public CPackForServer
  1055. {
  1056. SaveGame(){};
  1057. SaveGame(const std::string &Fname) :fname(Fname){};
  1058. std::string fname;
  1059. void applyCl(CClient *cl);
  1060. void applyGs(CGameState *gs){};
  1061. bool applyGh(CGameHandler *gh);
  1062. template <typename Handler> void serialize(Handler &h, const int version)
  1063. {
  1064. h & fname;
  1065. }
  1066. };
  1067. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  1068. {
  1069. PlayerMessage(){CPackForClient::type = 513;};
  1070. PlayerMessage(ui8 Player, const std::string &Text)
  1071. :player(Player),text(Text)
  1072. {CPackForClient::type = 513;};
  1073. void applyCl(CClient *cl);
  1074. void applyGs(CGameState *gs){};
  1075. bool applyGh(CGameHandler *gh);
  1076. ui8 player;
  1077. std::string text;
  1078. template <typename Handler> void serialize(Handler &h, const int version)
  1079. {
  1080. h & text & player;
  1081. }
  1082. };
  1083. struct SetSelection : public CPackForClient, public CPackForServer //514
  1084. {
  1085. SetSelection(){CPackForClient::type = 514;};
  1086. DLL_EXPORT void applyGs(CGameState *gs);
  1087. bool applyGh(CGameHandler *gh);
  1088. ui8 player;
  1089. ui32 id;
  1090. template <typename Handler> void serialize(Handler &h, const int version)
  1091. {
  1092. h & id & player;
  1093. }
  1094. };
  1095. struct CenterView : public CPackForClient//515
  1096. {
  1097. CenterView(){CPackForClient::type = 515;};
  1098. void applyCl(CClient *cl);
  1099. ui8 player;
  1100. int3 pos;
  1101. ui32 focusTime; //ms
  1102. template <typename Handler> void serialize(Handler &h, const int version)
  1103. {
  1104. h & pos & player & focusTime;
  1105. }
  1106. };
  1107. #endif //__NETPACKS_H__