NetPacks.h 33 KB

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