NetPacks.h 29 KB

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