NetPacks.h 28 KB

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