NetPacks.h 29 KB

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