NetPacks.h 30 KB

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