NetPacks.h 27 KB

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