NetPacks.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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. si32 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 applyCl(CClient *cl);
  441. enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL};
  442. ui8 window;
  443. ui32 id1, id2;
  444. template <typename Handler> void serialize(Handler &h, const int version)
  445. {
  446. h & window & id1 & id2;
  447. }
  448. };
  449. struct NewTurn : public CPackForClient //101
  450. {
  451. DLL_EXPORT void applyGs(CGameState *gs);
  452. struct Hero
  453. {
  454. ui32 id, move, mana; //id is a general serial id
  455. template <typename Handler> void serialize(Handler &h, const int version)
  456. {
  457. h & id & move & mana;
  458. }
  459. bool operator<(const Hero&h)const{return id < h.id;}
  460. };
  461. std::set<Hero> heroes; //updates movement and mana points
  462. std::vector<SetResources> res;//resource list
  463. std::vector<SetAvailableCreatures> cres;//resource list
  464. ui32 day;
  465. bool resetBuilded;
  466. NewTurn(){type = 101;};
  467. template <typename Handler> void serialize(Handler &h, const int version)
  468. {
  469. h & heroes & cres & res & day & resetBuilded;
  470. }
  471. };
  472. struct Component : public CPack //2002 helper for object scrips informations
  473. {
  474. enum {PRIM_SKILL,SEC_SKILL,RESOURCE,CREATURE,ARTIFACT,EXPERIENCE,SPELL, MORALE=8, LUCK};
  475. ui16 id, subtype; //id uses ^^^ enums, when id==EXPPERIENCE subtype==0 means exp points and subtype==1 levels)
  476. si32 val; // + give; - take
  477. si16 when; // 0 - now; +x - within x days; -x - per x days
  478. template <typename Handler> void serialize(Handler &h, const int version)
  479. {
  480. h & id & subtype & val & when;
  481. }
  482. Component(){type = 2002;};
  483. Component(ui16 Type, ui16 Subtype, si32 Val, si16 When):id(Type),subtype(Subtype),val(Val),when(When){type = 2002;};
  484. };
  485. struct InfoWindow : public CPackForClient //103 - displays simple info window
  486. {
  487. void applyCl(CClient *cl);
  488. MetaString text;
  489. std::vector<Component> components;
  490. ui8 player;
  491. ui16 soundID;
  492. template <typename Handler> void serialize(Handler &h, const int version)
  493. {
  494. h & text & components & player & soundID;
  495. }
  496. InfoWindow() {
  497. type = 103;
  498. soundID = 0;
  499. };
  500. };
  501. struct SetObjectProperty : public CPackForClient//1001
  502. {
  503. DLL_EXPORT void applyGs(CGameState *gs);
  504. ui32 id;
  505. ui8 what; //1 - owner; 2 - blockvis; 3 - first stack count; 4 - visitors; 5 - visited; 6 - ID (if 34 then also def is replaced)
  506. ui32 val;
  507. SetObjectProperty(){type = 1001;};
  508. SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
  509. template <typename Handler> void serialize(Handler &h, const int version)
  510. {
  511. h & id & what & val;
  512. }
  513. };
  514. struct SetHoverName : public CPackForClient//1002
  515. {
  516. DLL_EXPORT void applyGs(CGameState *gs);
  517. ui32 id;
  518. MetaString name;
  519. SetHoverName(){type = 1002;};
  520. SetHoverName(ui32 ID, MetaString& Name):id(ID),name(Name){type = 1002;};
  521. template <typename Handler> void serialize(Handler &h, const int version)
  522. {
  523. h & id & name;
  524. }
  525. };
  526. struct HeroLevelUp : public Query//2000
  527. {
  528. void applyCl(CClient *cl);
  529. DLL_EXPORT void applyGs(CGameState *gs);
  530. si32 heroid;
  531. ui8 primskill, level;
  532. std::vector<ui16> skills;
  533. HeroLevelUp(){type = 2000;};
  534. template <typename Handler> void serialize(Handler &h, const int version)
  535. {
  536. h & id & heroid & primskill & level & skills;
  537. }
  538. };
  539. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  540. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  541. //Until sending reply player won't be allowed to take any actions
  542. struct BlockingDialog : public Query//2003
  543. {
  544. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  545. void applyCl(CClient *cl);
  546. MetaString text;
  547. std::vector<Component> components;
  548. ui8 player;
  549. ui8 flags;
  550. ui16 soundID;
  551. bool cancel() const
  552. {
  553. return flags & ALLOW_CANCEL;
  554. }
  555. bool selection() const
  556. {
  557. return flags & SELECTION;
  558. }
  559. BlockingDialog(bool yesno, bool Selection)
  560. {
  561. type = 2003;
  562. flags = 0;
  563. soundID = 0;
  564. if(yesno) flags |= ALLOW_CANCEL;
  565. if(Selection) flags |= SELECTION;
  566. }
  567. BlockingDialog()
  568. {
  569. type = 2003;
  570. flags = 0;
  571. soundID = 0;
  572. };
  573. template <typename Handler> void serialize(Handler &h, const int version)
  574. {
  575. h & id & text & components & player & flags & soundID;
  576. }
  577. };
  578. struct GarrisonDialog : public Query//2004
  579. {
  580. GarrisonDialog(){type = 2004;}
  581. void applyCl(CClient *cl);
  582. si32 objid, hid;
  583. template <typename Handler> void serialize(Handler &h, const int version)
  584. {
  585. h & id & objid & hid;
  586. }
  587. };
  588. struct BattleInfo;
  589. struct BattleStart : public CPackForClient//3000
  590. {
  591. BattleStart(){type = 3000;};
  592. void applyCl(CClient *cl);
  593. DLL_EXPORT void applyGs(CGameState *gs);
  594. BattleInfo * info;
  595. template <typename Handler> void serialize(Handler &h, const int version)
  596. {
  597. h & info;
  598. }
  599. };
  600. struct BattleNextRound : public CPackForClient//3001
  601. {
  602. BattleNextRound(){type = 3001;};
  603. void applyCl(CClient *cl);
  604. DLL_EXPORT void applyGs(CGameState *gs);
  605. si32 round;
  606. template <typename Handler> void serialize(Handler &h, const int version)
  607. {
  608. h & round;
  609. }
  610. };
  611. struct BattleSetActiveStack : public CPackForClient//3002
  612. {
  613. BattleSetActiveStack(){type = 3002;};
  614. void applyCl(CClient *cl);
  615. DLL_EXPORT void applyGs(CGameState *gs);
  616. ui32 stack;
  617. template <typename Handler> void serialize(Handler &h, const int version)
  618. {
  619. h & stack;
  620. }
  621. };
  622. struct BattleResult : public CPackForClient//3003
  623. {
  624. BattleResult(){type = 3003;};
  625. void applyFirstCl(CClient *cl);
  626. void applyGs(CGameState *gs);
  627. ui8 result; //0 - normal victory; 1 - escape; 2 - surrender
  628. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  629. std::set<std::pair<ui32,si32> > casualties[2]; //first => casualties of attackers - set of pairs crid<>number
  630. ui32 exp[2]; //exp for attacker and defender
  631. std::set<ui32> artifacts; //artifacts taken from loser to winner
  632. template <typename Handler> void serialize(Handler &h, const int version)
  633. {
  634. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  635. }
  636. };
  637. struct BattleStackMoved : public CPackForClient//3004
  638. {
  639. ui32 stack, tile;
  640. ui8 ending, distance;
  641. BattleStackMoved(){type = 3004;};
  642. void applyFirstCl(CClient *cl);
  643. void applyGs(CGameState *gs);
  644. template <typename Handler> void serialize(Handler &h, const int version)
  645. {
  646. h & stack & tile & ending & distance;
  647. }
  648. };
  649. struct BattleStackAttacked : public CPackForClient//3005
  650. {
  651. BattleStackAttacked(){flags = 0; type = 3005;};
  652. void applyCl(CClient *cl);
  653. DLL_EXPORT void applyGs(CGameState *gs);
  654. ui32 stackAttacked;
  655. ui32 newAmount, newHP, killedAmount, damageAmount;
  656. ui8 flags; //1 - is stack killed; 2 - is there special effect to be shown;
  657. ui32 effect; //set only if flag 2 is present
  658. bool killed() const//if target stack was killed
  659. {
  660. return flags & 1;
  661. }
  662. bool isEffect() const//if target stack was killed
  663. {
  664. return flags & 2;
  665. }
  666. template <typename Handler> void serialize(Handler &h, const int version)
  667. {
  668. h & stackAttacked & newAmount & newHP & flags & killedAmount & damageAmount & effect;
  669. }
  670. bool operator<(const BattleStackAttacked &b) const
  671. {
  672. return stackAttacked < b.stackAttacked;
  673. }
  674. };
  675. struct BattleAttack : public CPackForClient//3006
  676. {
  677. BattleAttack(){flags = 0; type = 3006;};
  678. void applyFirstCl(CClient *cl);
  679. DLL_EXPORT void applyGs(CGameState *gs);
  680. void applyCl(CClient *cl);
  681. std::set<BattleStackAttacked> bsa;
  682. ui32 stackAttacking;
  683. ui8 flags;
  684. bool shot()//distance attack - decrease number of shots
  685. {
  686. return flags & 1;
  687. }
  688. bool counter()//is it counterattack?
  689. {
  690. return flags & 2;
  691. }
  692. bool lucky()
  693. {
  694. return flags & 4;
  695. }
  696. bool unlucky()
  697. {
  698. //TODO: support?
  699. return flags & 8;
  700. }
  701. //bool killed() //if target stack was killed
  702. //{
  703. // return bsa.killed();
  704. //}
  705. template <typename Handler> void serialize(Handler &h, const int version)
  706. {
  707. h & bsa & stackAttacking & flags;
  708. }
  709. };
  710. struct StartAction : public CPackForClient//3007
  711. {
  712. StartAction(){type = 3007;};
  713. StartAction(const BattleAction &act){ba = act; type = 3007;};
  714. void applyFirstCl(CClient *cl);
  715. DLL_EXPORT void applyGs(CGameState *gs);
  716. BattleAction ba;
  717. template <typename Handler> void serialize(Handler &h, const int version)
  718. {
  719. h & ba;
  720. }
  721. };
  722. struct EndAction : public CPackForClient//3008
  723. {
  724. EndAction(){type = 3008;};
  725. void applyCl(CClient *cl);
  726. template <typename Handler> void serialize(Handler &h, const int version)
  727. {
  728. }
  729. };
  730. struct SpellCast : public CPackForClient//3009
  731. {
  732. SpellCast(){type = 3009;};
  733. DLL_EXPORT void applyGs(CGameState *gs);
  734. void applyCl(CClient *cl);
  735. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  736. ui32 id;
  737. ui8 skill;
  738. ui16 tile; //destination tile (may not be set in some global/mass spells
  739. template <typename Handler> void serialize(Handler &h, const int version)
  740. {
  741. h & side & id & skill & tile;
  742. }
  743. };
  744. struct SetStackEffect : public CPackForClient //3010
  745. {
  746. SetStackEffect(){type = 3010;};
  747. DLL_EXPORT void applyGs(CGameState *gs);
  748. void applyCl(CClient *cl);
  749. std::set<ui32> stacks;
  750. CStack::StackEffect effect;
  751. template <typename Handler> void serialize(Handler &h, const int version)
  752. {
  753. h & stacks & effect;
  754. }
  755. };
  756. struct StacksInjured : public CPackForClient //3011
  757. {
  758. StacksInjured(){type = 3011;}
  759. DLL_EXPORT void applyGs(CGameState *gs);
  760. void applyCl(CClient *cl);
  761. std::set<BattleStackAttacked> stacks;
  762. template <typename Handler> void serialize(Handler &h, const int version)
  763. {
  764. h & stacks;
  765. }
  766. };
  767. struct ShowInInfobox : public CPackForClient //107
  768. {
  769. ShowInInfobox(){type = 107;};
  770. ui8 player;
  771. Component c;
  772. MetaString text;
  773. void applyCl(CClient *cl);
  774. template <typename Handler> void serialize(Handler &h, const int version)
  775. {
  776. h & player & c & text;
  777. }
  778. };
  779. /***********************************************************************************************************/
  780. struct CloseServer : public CPackForServer
  781. {
  782. bool applyGh(CGameHandler *gh);
  783. template <typename Handler> void serialize(Handler &h, const int version)
  784. {}
  785. };
  786. struct EndTurn : public CPackForServer
  787. {
  788. bool applyGh(CGameHandler *gh);
  789. template <typename Handler> void serialize(Handler &h, const int version)
  790. {}
  791. };
  792. struct DismissHero : public CPackForServer
  793. {
  794. DismissHero(){};
  795. DismissHero(si32 HID) : hid(HID) {};
  796. si32 hid;
  797. bool applyGh(CGameHandler *gh);
  798. template <typename Handler> void serialize(Handler &h, const int version)
  799. {
  800. h & hid;
  801. }
  802. };
  803. struct MoveHero : public CPackForServer
  804. {
  805. MoveHero(){};
  806. MoveHero(const int3 &Dest, si32 HID) : dest(Dest), hid(HID){};
  807. int3 dest;
  808. si32 hid;
  809. bool applyGh(CGameHandler *gh);
  810. template <typename Handler> void serialize(Handler &h, const int version)
  811. {
  812. h & dest & hid;
  813. }
  814. };
  815. struct ArrangeStacks : public CPackForServer
  816. {
  817. ArrangeStacks(){};
  818. ArrangeStacks(ui8 W, ui8 P1, ui8 P2, si32 ID1, si32 ID2, si32 VAL)
  819. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  820. ui8 what; //1 - swap; 2 - merge; 3 - split
  821. ui8 p1, p2; //positions of first and second stack
  822. si32 id1, id2; //ids of objects with garrison
  823. si32 val;
  824. bool applyGh(CGameHandler *gh);
  825. template <typename Handler> void serialize(Handler &h, const int version)
  826. {
  827. h & what & p1 & p2 & id1 & id2 & val;
  828. }
  829. };
  830. struct DisbandCreature : public CPackForServer
  831. {
  832. DisbandCreature(){};
  833. DisbandCreature(ui8 Pos, si32 ID):pos(Pos),id(ID){};
  834. ui8 pos; //stack pos
  835. si32 id; //object id
  836. bool applyGh(CGameHandler *gh);
  837. template <typename Handler> void serialize(Handler &h, const int version)
  838. {
  839. h & pos & id;
  840. }
  841. };
  842. struct BuildStructure : public CPackForServer
  843. {
  844. BuildStructure(){};
  845. BuildStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  846. si32 bid, tid; //structure and town ids
  847. bool applyGh(CGameHandler *gh);
  848. template <typename Handler> void serialize(Handler &h, const int version)
  849. {
  850. h & tid & bid;
  851. }
  852. };
  853. struct RecruitCreatures : public CPackForServer
  854. {
  855. RecruitCreatures(){};
  856. RecruitCreatures(si32 TID, si32 CRID, si32 Amount):tid(TID),crid(CRID),amount(Amount){};
  857. si32 tid; //town id
  858. ui32 crid, amount;//creature ID and amount
  859. bool applyGh(CGameHandler *gh);
  860. template <typename Handler> void serialize(Handler &h, const int version)
  861. {
  862. h & tid & crid & amount;
  863. }
  864. };
  865. struct UpgradeCreature : public CPackForServer
  866. {
  867. UpgradeCreature(){};
  868. UpgradeCreature(ui8 Pos, si32 ID, si32 CRID):pos(Pos),id(ID), cid(CRID){};
  869. ui8 pos; //stack pos
  870. si32 id; //object id
  871. si32 cid; //id of type to which we want make upgrade
  872. bool applyGh(CGameHandler *gh);
  873. template <typename Handler> void serialize(Handler &h, const int version)
  874. {
  875. h & pos & id & cid;
  876. }
  877. };
  878. struct GarrisonHeroSwap : public CPackForServer
  879. {
  880. GarrisonHeroSwap(){};
  881. GarrisonHeroSwap(si32 TID):tid(TID){};
  882. si32 tid;
  883. bool applyGh(CGameHandler *gh);
  884. template <typename Handler> void serialize(Handler &h, const int version)
  885. {
  886. h & tid;
  887. }
  888. };
  889. struct ExchangeArtifacts : public CPackForServer
  890. {
  891. ExchangeArtifacts(){};
  892. ExchangeArtifacts(si32 H1, si32 H2, ui16 S1, ui16 S2)
  893. :hid1(H1),hid2(H2),slot1(S1),slot2(S2){};
  894. si32 hid1, hid2;
  895. ui16 slot1, slot2;
  896. bool applyGh(CGameHandler *gh);
  897. template <typename Handler> void serialize(Handler &h, const int version)
  898. {
  899. h & hid1 & hid2 & slot1 & slot2;
  900. }
  901. };
  902. struct BuyArtifact : public CPackForServer
  903. {
  904. BuyArtifact(){};
  905. BuyArtifact(si32 HID, si32 AID):hid(HID),aid(AID){};
  906. si32 hid, aid; //hero and artifact id
  907. bool applyGh(CGameHandler *gh);
  908. template <typename Handler> void serialize(Handler &h, const int version)
  909. {
  910. h & hid & aid;
  911. }
  912. };
  913. struct TradeOnMarketplace : public CPackForServer
  914. {
  915. TradeOnMarketplace(){};
  916. TradeOnMarketplace(ui8 Player, ui8 Mode, /*si32 ID, */ui32 R1, ui32 R2, ui32 Val)
  917. :player(Player),mode(Mode),/*id(ID),*/r1(R1),r2(R2),val(Val){};
  918. ui8 player;
  919. ui8 mode;//0 - res<->res;
  920. //si32 id; //object id
  921. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res
  922. ui32 val; //units of sold resource
  923. bool applyGh(CGameHandler *gh);
  924. template <typename Handler> void serialize(Handler &h, const int version)
  925. {
  926. h & player & mode & /*id & */r1 & r2 & val;
  927. }
  928. };
  929. struct SetFormation : public CPackForServer
  930. {
  931. SetFormation(){};
  932. SetFormation(si32 HID, ui8 Formation):hid(HID),formation(Formation){};
  933. si32 hid;
  934. ui8 formation;
  935. bool applyGh(CGameHandler *gh);
  936. template <typename Handler> void serialize(Handler &h, const int version)
  937. {
  938. h & hid & formation;
  939. }
  940. };
  941. struct HireHero : public CPackForServer
  942. {
  943. HireHero(){};
  944. HireHero(si32 HID, si32 TID):hid(HID),tid(TID){};
  945. si32 hid, tid; //available hero serial and town id
  946. bool applyGh(CGameHandler *gh);
  947. template <typename Handler> void serialize(Handler &h, const int version)
  948. {
  949. h & hid & tid;
  950. }
  951. };
  952. struct QueryReply : public CPackForServer
  953. {
  954. QueryReply(){};
  955. QueryReply(ui32 QID, ui32 Answer):qid(QID),answer(Answer){};
  956. ui32 qid, answer; //hero and artifact id
  957. bool applyGh(CGameHandler *gh);
  958. template <typename Handler> void serialize(Handler &h, const int version)
  959. {
  960. h & qid & answer;
  961. }
  962. };
  963. struct MakeAction : public CPackForServer
  964. {
  965. MakeAction(){};
  966. MakeAction(const BattleAction &BA):ba(BA){};
  967. BattleAction ba;
  968. bool applyGh(CGameHandler *gh);
  969. template <typename Handler> void serialize(Handler &h, const int version)
  970. {
  971. h & ba;
  972. }
  973. };
  974. struct MakeCustomAction : public CPackForServer
  975. {
  976. MakeCustomAction(){};
  977. MakeCustomAction(const BattleAction &BA):ba(BA){};
  978. BattleAction ba;
  979. bool applyGh(CGameHandler *gh);
  980. template <typename Handler> void serialize(Handler &h, const int version)
  981. {
  982. h & ba;
  983. }
  984. };
  985. /***********************************************************************************************************/
  986. struct SaveGame : public CPackForClient, public CPackForServer
  987. {
  988. SaveGame(){};
  989. SaveGame(const std::string &Fname) :fname(Fname){};
  990. std::string fname;
  991. void applyCl(CClient *cl);
  992. void applyGs(CGameState *gs){};
  993. bool applyGh(CGameHandler *gh);
  994. template <typename Handler> void serialize(Handler &h, const int version)
  995. {
  996. h & fname;
  997. }
  998. };
  999. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  1000. {
  1001. PlayerMessage(){CPackForClient::type = 513;};
  1002. PlayerMessage(ui8 Player, const std::string &Text)
  1003. :player(Player),text(Text)
  1004. {CPackForClient::type = 513;};
  1005. void applyCl(CClient *cl);
  1006. void applyGs(CGameState *gs){};
  1007. bool applyGh(CGameHandler *gh);
  1008. ui8 player;
  1009. std::string text;
  1010. template <typename Handler> void serialize(Handler &h, const int version)
  1011. {
  1012. h & text & player;
  1013. }
  1014. };
  1015. struct SetSelection : public CPackForClient, public CPackForServer //514
  1016. {
  1017. SetSelection(){CPackForClient::type = 514;};
  1018. DLL_EXPORT void applyGs(CGameState *gs);
  1019. bool applyGh(CGameHandler *gh);
  1020. ui8 player;
  1021. ui32 id;
  1022. template <typename Handler> void serialize(Handler &h, const int version)
  1023. {
  1024. h & id & player;
  1025. }
  1026. };
  1027. #endif //__NETPACKS_H__