NetPacks.h 28 KB

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