NetPacks.h 30 KB

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