NetPacks.h 29 KB

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