NetPacks.h 32 KB

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