2
0

NetPacks.h 26 KB

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