NetPacks.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  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 virtual 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 RazeStructures : public CPackForClient //505
  388. {
  389. RazeStructures() {type = 505;};
  390. void applyCl (CClient *cl);
  391. DLL_EXPORT void applyGs(CGameState *gs);
  392. si32 tid;
  393. std::set<si32> bid;
  394. si16 destroyed;
  395. template <typename Handler> void serialize(Handler &h, const int version)
  396. {
  397. h & tid & bid & destroyed;
  398. }
  399. };
  400. struct SetAvailableCreatures : public CPackForClient //506
  401. {
  402. SetAvailableCreatures(){type = 506;};
  403. void applyCl(CClient *cl);
  404. DLL_EXPORT void applyGs(CGameState *gs);
  405. si32 tid;
  406. std::vector<std::pair<ui32, std::vector<ui32> > > creatures;
  407. template <typename Handler> void serialize(Handler &h, const int version)
  408. {
  409. h & tid & creatures;
  410. }
  411. };
  412. struct SetHeroesInTown : public CPackForClient //508
  413. {
  414. SetHeroesInTown(){type = 508;};
  415. void applyCl(CClient *cl);
  416. DLL_EXPORT void applyGs(CGameState *gs);
  417. si32 tid, visiting, garrison; //id of town, visiting hero, hero in garrison
  418. template <typename Handler> void serialize(Handler &h, const int version)
  419. {
  420. h & tid & visiting & garrison;
  421. }
  422. };
  423. struct SetHeroArtifacts : public CPackForClient //509
  424. {
  425. SetHeroArtifacts(){type = 509;};
  426. void applyCl(CClient *cl);
  427. DLL_EXPORT void applyGs(CGameState *gs);
  428. DLL_EXPORT void setArtAtPos(ui16 pos, int art);
  429. si32 hid;
  430. std::vector<ui32> artifacts; //hero's artifacts from bag
  431. 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
  432. template <typename Handler> void serialize(Handler &h, const int version)
  433. {
  434. h & hid & artifacts & artifWorn;
  435. }
  436. std::vector<HeroBonus*> gained, lost; //used locally as hlp when applying
  437. };
  438. struct HeroRecruited : public CPackForClient //515
  439. {
  440. HeroRecruited(){type = 515;};
  441. void applyCl(CClient *cl);
  442. DLL_EXPORT void applyGs(CGameState *gs);
  443. si32 hid, tid; //subID of hero
  444. int3 tile;
  445. ui8 player;
  446. template <typename Handler> void serialize(Handler &h, const int version)
  447. {
  448. h & hid & tid & tile & player;
  449. }
  450. };
  451. struct GiveHero : public CPackForClient //516
  452. {
  453. GiveHero(){type = 516;};
  454. void applyFirstCl(CClient *cl);
  455. void applyCl(CClient *cl);
  456. DLL_EXPORT void applyGs(CGameState *gs);
  457. ui32 id; //object id
  458. ui8 player;
  459. template <typename Handler> void serialize(Handler &h, const int version)
  460. {
  461. h & id & player;
  462. }
  463. };
  464. struct OpenWindow : public CPackForClient //517
  465. {
  466. OpenWindow(){type = 517;};
  467. void applyCl(CClient *cl);
  468. enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL, SHIPYARD_WINDOW};
  469. ui8 window;
  470. ui32 id1, id2;
  471. template <typename Handler> void serialize(Handler &h, const int version)
  472. {
  473. h & window & id1 & id2;
  474. }
  475. };
  476. struct NewObject : public CPackForClient //518
  477. {
  478. NewObject(){type = 518;};
  479. void applyCl(CClient *cl);
  480. DLL_EXPORT void applyGs(CGameState *gs);
  481. ui32 ID, subID;
  482. int3 pos;
  483. int id; //used internally
  484. template <typename Handler> void serialize(Handler &h, const int version)
  485. {
  486. h & ID & subID & pos;
  487. }
  488. };
  489. struct NewTurn : public CPackForClient //101
  490. {
  491. DLL_EXPORT void applyGs(CGameState *gs);
  492. struct Hero
  493. {
  494. ui32 id, move, mana; //id is a general serial id
  495. template <typename Handler> void serialize(Handler &h, const int version)
  496. {
  497. h & id & move & mana;
  498. }
  499. bool operator<(const Hero&h)const{return id < h.id;}
  500. };
  501. std::set<Hero> heroes; //updates movement and mana points
  502. std::vector<SetResources> res;//resource list
  503. std::vector<SetAvailableCreatures> cres;//resource list
  504. ui32 day;
  505. bool resetBuilded;
  506. NewTurn(){type = 101;};
  507. template <typename Handler> void serialize(Handler &h, const int version)
  508. {
  509. h & heroes & cres & res & day & resetBuilded;
  510. }
  511. };
  512. struct Component : public CPack //2002 helper for object scrips informations
  513. {
  514. enum {PRIM_SKILL, SEC_SKILL, RESOURCE, CREATURE, ARTIFACT, EXPERIENCE, SPELL, MORALE=8, LUCK, HERO};
  515. ui16 id, subtype; //id uses ^^^ enums, when id==EXPPERIENCE subtype==0 means exp points and subtype==1 levels)
  516. si32 val; // + give; - take
  517. si16 when; // 0 - now; +x - within x days; -x - per x days
  518. template <typename Handler> void serialize(Handler &h, const int version)
  519. {
  520. h & id & subtype & val & when;
  521. }
  522. Component(){type = 2002;};
  523. Component(ui16 Type, ui16 Subtype, si32 Val, si16 When):id(Type),subtype(Subtype),val(Val),when(When){type = 2002;};
  524. };
  525. struct InfoWindow : public CPackForClient //103 - displays simple info window
  526. {
  527. void applyCl(CClient *cl);
  528. MetaString text;
  529. std::vector<Component> components;
  530. ui8 player;
  531. ui16 soundID;
  532. template <typename Handler> void serialize(Handler &h, const int version)
  533. {
  534. h & text & components & player & soundID;
  535. }
  536. InfoWindow() {
  537. type = 103;
  538. soundID = 0;
  539. };
  540. };
  541. struct SetObjectProperty : public CPackForClient//1001
  542. {
  543. DLL_EXPORT void applyGs(CGameState *gs);
  544. void applyCl(CClient *cl);
  545. ui32 id;
  546. ui8 what; //1 - owner; 2 - blockvis; 3 - first stack count; 4 - visitors; 5 - visited; 6 - ID (if 34 then also def is replaced)
  547. ui32 val;
  548. SetObjectProperty(){type = 1001;};
  549. SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
  550. template <typename Handler> void serialize(Handler &h, const int version)
  551. {
  552. h & id & what & val;
  553. }
  554. };
  555. struct SetHoverName : public CPackForClient//1002
  556. {
  557. DLL_EXPORT void applyGs(CGameState *gs);
  558. ui32 id;
  559. MetaString name;
  560. SetHoverName(){type = 1002;};
  561. SetHoverName(ui32 ID, MetaString& Name):id(ID),name(Name){type = 1002;};
  562. template <typename Handler> void serialize(Handler &h, const int version)
  563. {
  564. h & id & name;
  565. }
  566. };
  567. struct HeroLevelUp : public Query//2000
  568. {
  569. void applyCl(CClient *cl);
  570. DLL_EXPORT void applyGs(CGameState *gs);
  571. si32 heroid;
  572. ui8 primskill, level;
  573. std::vector<ui16> skills;
  574. HeroLevelUp(){type = 2000;};
  575. template <typename Handler> void serialize(Handler &h, const int version)
  576. {
  577. h & id & heroid & primskill & level & skills;
  578. }
  579. };
  580. struct TradeComponents : public CPackForClient, public CPackForServer
  581. {
  582. ///used to handle info about components available in shops
  583. void applyCl(CClient *cl);
  584. DLL_EXPORT void applyGs(CGameState *gs);
  585. si32 heroid;
  586. ui32 objectid;
  587. std::map<ui16, Component> available, chosen, bought;
  588. template <typename Handler> void serialize(Handler &h, const int version)
  589. {
  590. h & heroid & objectid & available & chosen & bought;
  591. }
  592. };
  593. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  594. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  595. //Until sending reply player won't be allowed to take any actions
  596. struct BlockingDialog : public Query//2003
  597. {
  598. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  599. void applyCl(CClient *cl);
  600. MetaString text;
  601. std::vector<Component> components;
  602. ui8 player;
  603. ui8 flags;
  604. ui16 soundID;
  605. bool cancel() const
  606. {
  607. return flags & ALLOW_CANCEL;
  608. }
  609. bool selection() const
  610. {
  611. return flags & SELECTION;
  612. }
  613. BlockingDialog(bool yesno, bool Selection)
  614. {
  615. type = 2003;
  616. flags = 0;
  617. soundID = 0;
  618. if(yesno) flags |= ALLOW_CANCEL;
  619. if(Selection) flags |= SELECTION;
  620. }
  621. BlockingDialog()
  622. {
  623. type = 2003;
  624. flags = 0;
  625. soundID = 0;
  626. };
  627. template <typename Handler> void serialize(Handler &h, const int version)
  628. {
  629. h & id & text & components & player & flags & soundID;
  630. }
  631. };
  632. struct GarrisonDialog : public Query//2004
  633. {
  634. GarrisonDialog(){type = 2004;}
  635. void applyCl(CClient *cl);
  636. si32 objid, hid;
  637. bool removableUnits;
  638. template <typename Handler> void serialize(Handler &h, const int version)
  639. {
  640. h & id & objid & hid & removableUnits;
  641. }
  642. };
  643. struct BattleInfo;
  644. struct BattleStart : public CPackForClient//3000
  645. {
  646. BattleStart(){type = 3000;};
  647. void applyCl(CClient *cl);
  648. DLL_EXPORT void applyGs(CGameState *gs);
  649. BattleInfo * info;
  650. template <typename Handler> void serialize(Handler &h, const int version)
  651. {
  652. h & info;
  653. }
  654. };
  655. struct BattleNextRound : public CPackForClient//3001
  656. {
  657. BattleNextRound(){type = 3001;};
  658. void applyCl(CClient *cl);
  659. DLL_EXPORT void applyGs(CGameState *gs);
  660. si32 round;
  661. template <typename Handler> void serialize(Handler &h, const int version)
  662. {
  663. h & round;
  664. }
  665. };
  666. struct BattleSetActiveStack : public CPackForClient//3002
  667. {
  668. BattleSetActiveStack(){type = 3002;};
  669. void applyCl(CClient *cl);
  670. DLL_EXPORT void applyGs(CGameState *gs);
  671. ui32 stack;
  672. template <typename Handler> void serialize(Handler &h, const int version)
  673. {
  674. h & stack;
  675. }
  676. };
  677. struct BattleResult : public CPackForClient//3003
  678. {
  679. BattleResult(){type = 3003;};
  680. void applyFirstCl(CClient *cl);
  681. void applyGs(CGameState *gs);
  682. ui8 result; //0 - normal victory; 1 - escape; 2 - surrender
  683. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  684. std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
  685. ui32 exp[2]; //exp for attacker and defender
  686. std::set<ui32> artifacts; //artifacts taken from loser to winner
  687. template <typename Handler> void serialize(Handler &h, const int version)
  688. {
  689. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  690. }
  691. };
  692. struct BattleStackMoved : public CPackForClient//3004
  693. {
  694. ui32 stack, tile;
  695. ui8 ending, distance;
  696. BattleStackMoved(){type = 3004;};
  697. void applyFirstCl(CClient *cl);
  698. void applyGs(CGameState *gs);
  699. template <typename Handler> void serialize(Handler &h, const int version)
  700. {
  701. h & stack & tile & ending & distance;
  702. }
  703. };
  704. struct BattleStackAttacked : public CPackForClient//3005
  705. {
  706. BattleStackAttacked(){flags = 0; type = 3005;};
  707. void applyCl(CClient *cl);
  708. DLL_EXPORT void applyGs(CGameState *gs);
  709. ui32 stackAttacked, attackerID;
  710. ui32 newAmount, newHP, killedAmount, damageAmount;
  711. ui8 flags; //1 - is stack killed; 2 - is there special effect to be shown;
  712. ui32 effect; //set only if flag 2 is present
  713. bool killed() const//if target stack was killed
  714. {
  715. return flags & 1;
  716. }
  717. bool isEffect() const//if target stack was killed
  718. {
  719. return flags & 2;
  720. }
  721. template <typename Handler> void serialize(Handler &h, const int version)
  722. {
  723. h & stackAttacked & attackerID & newAmount & newHP & flags & killedAmount & damageAmount & effect;
  724. }
  725. bool operator<(const BattleStackAttacked &b) const
  726. {
  727. return stackAttacked < b.stackAttacked;
  728. }
  729. };
  730. struct BattleAttack : public CPackForClient//3006
  731. {
  732. BattleAttack(){flags = 0; type = 3006;};
  733. void applyFirstCl(CClient *cl);
  734. DLL_EXPORT void applyGs(CGameState *gs);
  735. void applyCl(CClient *cl);
  736. std::set<BattleStackAttacked> bsa;
  737. ui32 stackAttacking;
  738. ui8 flags;
  739. bool shot()//distance attack - decrease number of shots
  740. {
  741. return flags & 1;
  742. }
  743. bool counter()//is it counterattack?
  744. {
  745. return flags & 2;
  746. }
  747. bool lucky()
  748. {
  749. return flags & 4;
  750. }
  751. bool unlucky()
  752. {
  753. //TODO: support?
  754. return flags & 8;
  755. }
  756. //bool killed() //if target stack was killed
  757. //{
  758. // return bsa.killed();
  759. //}
  760. template <typename Handler> void serialize(Handler &h, const int version)
  761. {
  762. h & bsa & stackAttacking & flags;
  763. }
  764. };
  765. struct StartAction : public CPackForClient//3007
  766. {
  767. StartAction(){type = 3007;};
  768. StartAction(const BattleAction &act){ba = act; type = 3007;};
  769. void applyFirstCl(CClient *cl);
  770. DLL_EXPORT void applyGs(CGameState *gs);
  771. BattleAction ba;
  772. template <typename Handler> void serialize(Handler &h, const int version)
  773. {
  774. h & ba;
  775. }
  776. };
  777. struct EndAction : public CPackForClient//3008
  778. {
  779. EndAction(){type = 3008;};
  780. void applyCl(CClient *cl);
  781. template <typename Handler> void serialize(Handler &h, const int version)
  782. {
  783. }
  784. };
  785. struct SpellCast : public CPackForClient//3009
  786. {
  787. SpellCast(){type = 3009;};
  788. DLL_EXPORT void applyGs(CGameState *gs);
  789. void applyCl(CClient *cl);
  790. si32 dmgToDisplay; //this amount will be displayed as amount of damage dealt by spell
  791. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  792. ui32 id; //id of spell
  793. ui8 skill; //caster's skill level
  794. ui16 tile; //destination tile (may not be set in some global/mass spells
  795. std::vector<ui32> resisted; //ids of creatures that resisted this spell
  796. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  797. template <typename Handler> void serialize(Handler &h, const int version)
  798. {
  799. h & dmgToDisplay & side & id & skill & tile & resisted & affectedCres;
  800. }
  801. };
  802. struct SetStackEffect : public CPackForClient //3010
  803. {
  804. SetStackEffect(){type = 3010;};
  805. DLL_EXPORT void applyGs(CGameState *gs);
  806. void applyCl(CClient *cl);
  807. std::set<ui32> stacks; //affected stacks (IDs)
  808. CStack::StackEffect effect; //type of effect
  809. template <typename Handler> void serialize(Handler &h, const int version)
  810. {
  811. h & stacks & effect;
  812. }
  813. };
  814. struct StacksInjured : public CPackForClient //3011
  815. {
  816. StacksInjured(){type = 3011;}
  817. DLL_EXPORT void applyGs(CGameState *gs);
  818. void applyCl(CClient *cl);
  819. std::set<BattleStackAttacked> stacks;
  820. template <typename Handler> void serialize(Handler &h, const int version)
  821. {
  822. h & stacks;
  823. }
  824. };
  825. struct BattleResultsApplied : public CPackForClient //3012
  826. {
  827. BattleResultsApplied(){type = 3012;}
  828. ui8 player1, player2;
  829. void applyCl(CClient *cl);
  830. template <typename Handler> void serialize(Handler &h, const int version)
  831. {
  832. h & player1 & player2;
  833. }
  834. };
  835. struct StacksHealedOrResurrected : public CPackForClient //3013
  836. {
  837. StacksHealedOrResurrected(){type = 3013;}
  838. DLL_EXPORT void applyGs(CGameState *gs);
  839. void applyCl(CClient *cl);
  840. struct HealInfo
  841. {
  842. ui32 stackID;
  843. ui32 healedHP;
  844. template <typename Handler> void serialize(Handler &h, const int version)
  845. {
  846. h & stackID & healedHP;
  847. }
  848. };
  849. std::vector<HealInfo> healedStacks;
  850. template <typename Handler> void serialize(Handler &h, const int version)
  851. {
  852. h & healedStacks;
  853. }
  854. };
  855. struct ObstaclesRemoved : public CPackForClient //3014
  856. {
  857. ObstaclesRemoved(){type = 3014;}
  858. DLL_EXPORT void applyGs(CGameState *gs);
  859. void applyCl(CClient *cl);
  860. std::set<si32> obstacles; //uniqueIDs of removed obstacles
  861. template <typename Handler> void serialize(Handler &h, const int version)
  862. {
  863. h & obstacles;
  864. }
  865. };
  866. struct CatapultAttack : public CPackForClient //3015
  867. {
  868. CatapultAttack(){type = 3015;}
  869. DLL_EXPORT void applyGs(CGameState *gs);
  870. void applyCl(CClient *cl);
  871. std::set< std::pair< std::pair< ui8, si16 >, ui8> > attackedParts; // < <attackedPartOfWall, attacked hex >, damageDealt>
  872. //attackedPartOfWall; //[0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate;
  873. //damageDealt;
  874. int attacker; //if -1, then a spell caused this
  875. template <typename Handler> void serialize(Handler &h, const int version)
  876. {
  877. h & attackedParts & attacker;
  878. }
  879. };
  880. struct BattleStacksRemoved : public CPackForClient //3016
  881. {
  882. BattleStacksRemoved(){type = 3016;}
  883. DLL_EXPORT void applyGs(CGameState *gs);
  884. void applyCl(CClient *cl);
  885. std::set<ui32> stackIDs; //IDs of removed stacks
  886. template <typename Handler> void serialize(Handler &h, const int version)
  887. {
  888. h & stackIDs;
  889. }
  890. };
  891. struct ShowInInfobox : public CPackForClient //107
  892. {
  893. ShowInInfobox(){type = 107;};
  894. ui8 player;
  895. Component c;
  896. MetaString text;
  897. void applyCl(CClient *cl);
  898. template <typename Handler> void serialize(Handler &h, const int version)
  899. {
  900. h & player & c & text;
  901. }
  902. };
  903. /***********************************************************************************************************/
  904. struct CloseServer : public CPackForServer
  905. {
  906. bool applyGh(CGameHandler *gh);
  907. template <typename Handler> void serialize(Handler &h, const int version)
  908. {}
  909. };
  910. struct EndTurn : public CPackForServer
  911. {
  912. bool applyGh(CGameHandler *gh);
  913. template <typename Handler> void serialize(Handler &h, const int version)
  914. {}
  915. };
  916. struct DismissHero : public CPackForServer
  917. {
  918. DismissHero(){};
  919. DismissHero(si32 HID) : hid(HID) {};
  920. si32 hid;
  921. bool applyGh(CGameHandler *gh);
  922. template <typename Handler> void serialize(Handler &h, const int version)
  923. {
  924. h & hid;
  925. }
  926. };
  927. struct MoveHero : public CPackForServer
  928. {
  929. MoveHero(){};
  930. MoveHero(const int3 &Dest, si32 HID) : dest(Dest), hid(HID){};
  931. int3 dest;
  932. si32 hid;
  933. bool applyGh(CGameHandler *gh);
  934. template <typename Handler> void serialize(Handler &h, const int version)
  935. {
  936. h & dest & hid;
  937. }
  938. };
  939. struct ArrangeStacks : public CPackForServer
  940. {
  941. ArrangeStacks(){};
  942. ArrangeStacks(ui8 W, ui8 P1, ui8 P2, si32 ID1, si32 ID2, si32 VAL)
  943. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  944. ui8 what; //1 - swap; 2 - merge; 3 - split
  945. ui8 p1, p2; //positions of first and second stack
  946. si32 id1, id2; //ids of objects with garrison
  947. si32 val;
  948. bool applyGh(CGameHandler *gh);
  949. template <typename Handler> void serialize(Handler &h, const int version)
  950. {
  951. h & what & p1 & p2 & id1 & id2 & val;
  952. }
  953. };
  954. struct DisbandCreature : public CPackForServer
  955. {
  956. DisbandCreature(){};
  957. DisbandCreature(ui8 Pos, si32 ID):pos(Pos),id(ID){};
  958. ui8 pos; //stack pos
  959. si32 id; //object id
  960. bool applyGh(CGameHandler *gh);
  961. template <typename Handler> void serialize(Handler &h, const int version)
  962. {
  963. h & pos & id;
  964. }
  965. };
  966. struct BuildStructure : public CPackForServer
  967. {
  968. BuildStructure(){};
  969. BuildStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  970. si32 bid, tid; //structure and town ids
  971. bool applyGh(CGameHandler *gh);
  972. template <typename Handler> void serialize(Handler &h, const int version)
  973. {
  974. h & tid & bid;
  975. }
  976. };
  977. struct RazeStructure : public BuildStructure
  978. {
  979. RazeStructure(){};
  980. //RazeStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  981. bool applyGh(CGameHandler *gh);
  982. };
  983. struct RecruitCreatures : public CPackForServer
  984. {
  985. RecruitCreatures(){};
  986. RecruitCreatures(si32 TID, si32 CRID, si32 Amount):tid(TID),crid(CRID),amount(Amount){};
  987. si32 tid; //town id
  988. ui32 crid, amount;//creature ID and amount
  989. bool applyGh(CGameHandler *gh);
  990. template <typename Handler> void serialize(Handler &h, const int version)
  991. {
  992. h & tid & crid & amount;
  993. }
  994. };
  995. struct UpgradeCreature : public CPackForServer
  996. {
  997. UpgradeCreature(){};
  998. UpgradeCreature(ui8 Pos, si32 ID, si32 CRID):pos(Pos),id(ID), cid(CRID){};
  999. ui8 pos; //stack pos
  1000. si32 id; //object id
  1001. si32 cid; //id of type to which we want make upgrade
  1002. bool applyGh(CGameHandler *gh);
  1003. template <typename Handler> void serialize(Handler &h, const int version)
  1004. {
  1005. h & pos & id & cid;
  1006. }
  1007. };
  1008. struct GarrisonHeroSwap : public CPackForServer
  1009. {
  1010. GarrisonHeroSwap(){};
  1011. GarrisonHeroSwap(si32 TID):tid(TID){};
  1012. si32 tid;
  1013. bool applyGh(CGameHandler *gh);
  1014. template <typename Handler> void serialize(Handler &h, const int version)
  1015. {
  1016. h & tid;
  1017. }
  1018. };
  1019. struct ExchangeArtifacts : public CPackForServer
  1020. {
  1021. ExchangeArtifacts(){};
  1022. ExchangeArtifacts(si32 H1, si32 H2, ui16 S1, ui16 S2)
  1023. :hid1(H1),hid2(H2),slot1(S1),slot2(S2){};
  1024. si32 hid1, hid2;
  1025. ui16 slot1, slot2;
  1026. bool applyGh(CGameHandler *gh);
  1027. template <typename Handler> void serialize(Handler &h, const int version)
  1028. {
  1029. h & hid1 & hid2 & slot1 & slot2;
  1030. }
  1031. };
  1032. struct BuyArtifact : public CPackForServer
  1033. {
  1034. BuyArtifact(){};
  1035. BuyArtifact(si32 HID, si32 AID):hid(HID),aid(AID){};
  1036. si32 hid, aid; //hero and artifact id
  1037. bool applyGh(CGameHandler *gh);
  1038. template <typename Handler> void serialize(Handler &h, const int version)
  1039. {
  1040. h & hid & aid;
  1041. }
  1042. };
  1043. struct TradeOnMarketplace : public CPackForServer
  1044. {
  1045. TradeOnMarketplace(){};
  1046. TradeOnMarketplace(ui8 Player, ui8 Mode, /*si32 ID, */ui32 R1, ui32 R2, ui32 Val)
  1047. :player(Player),mode(Mode),/*id(ID),*/r1(R1),r2(R2),val(Val){};
  1048. ui8 player;
  1049. ui8 mode;//0 - res<->res;
  1050. //si32 id; //object id
  1051. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res
  1052. ui32 val; //units of sold resource
  1053. bool applyGh(CGameHandler *gh);
  1054. template <typename Handler> void serialize(Handler &h, const int version)
  1055. {
  1056. h & player & mode & /*id & */r1 & r2 & val;
  1057. }
  1058. };
  1059. struct SetFormation : public CPackForServer
  1060. {
  1061. SetFormation(){};
  1062. SetFormation(si32 HID, ui8 Formation):hid(HID),formation(Formation){};
  1063. si32 hid;
  1064. ui8 formation;
  1065. bool applyGh(CGameHandler *gh);
  1066. template <typename Handler> void serialize(Handler &h, const int version)
  1067. {
  1068. h & hid & formation;
  1069. }
  1070. };
  1071. struct HireHero : public CPackForServer
  1072. {
  1073. HireHero(){};
  1074. HireHero(si32 HID, si32 TID):hid(HID),tid(TID){};
  1075. si32 hid, tid; //available hero serial and town id
  1076. bool applyGh(CGameHandler *gh);
  1077. template <typename Handler> void serialize(Handler &h, const int version)
  1078. {
  1079. h & hid & tid;
  1080. }
  1081. };
  1082. struct BuildBoat : public CPackForServer
  1083. {
  1084. BuildBoat(){};
  1085. si32 objid; //where player wants to buy a boat
  1086. bool applyGh(CGameHandler *gh);
  1087. template <typename Handler> void serialize(Handler &h, const int version)
  1088. {
  1089. h & objid;
  1090. }
  1091. };
  1092. struct QueryReply : public CPackForServer
  1093. {
  1094. QueryReply(){type = 6000;};
  1095. QueryReply(ui32 QID, ui32 Answer):qid(QID),answer(Answer){type = 6000;};
  1096. ui32 qid, answer; //hero and artifact id
  1097. bool applyGh(CGameHandler *gh);
  1098. template <typename Handler> void serialize(Handler &h, const int version)
  1099. {
  1100. h & qid & answer;
  1101. }
  1102. };
  1103. struct MakeAction : public CPackForServer
  1104. {
  1105. MakeAction(){};
  1106. MakeAction(const BattleAction &BA):ba(BA){};
  1107. BattleAction ba;
  1108. bool applyGh(CGameHandler *gh);
  1109. template <typename Handler> void serialize(Handler &h, const int version)
  1110. {
  1111. h & ba;
  1112. }
  1113. };
  1114. struct MakeCustomAction : public CPackForServer
  1115. {
  1116. MakeCustomAction(){};
  1117. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1118. BattleAction ba;
  1119. bool applyGh(CGameHandler *gh);
  1120. template <typename Handler> void serialize(Handler &h, const int version)
  1121. {
  1122. h & ba;
  1123. }
  1124. };
  1125. /***********************************************************************************************************/
  1126. struct SaveGame : public CPackForClient, public CPackForServer
  1127. {
  1128. SaveGame(){};
  1129. SaveGame(const std::string &Fname) :fname(Fname){};
  1130. std::string fname;
  1131. void applyCl(CClient *cl);
  1132. void applyGs(CGameState *gs){};
  1133. bool applyGh(CGameHandler *gh);
  1134. template <typename Handler> void serialize(Handler &h, const int version)
  1135. {
  1136. h & fname;
  1137. }
  1138. };
  1139. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  1140. {
  1141. PlayerMessage(){CPackForClient::type = 513;};
  1142. PlayerMessage(ui8 Player, const std::string &Text)
  1143. :player(Player),text(Text)
  1144. {CPackForClient::type = 513;};
  1145. void applyCl(CClient *cl);
  1146. void applyGs(CGameState *gs){};
  1147. bool applyGh(CGameHandler *gh);
  1148. ui8 player;
  1149. std::string text;
  1150. template <typename Handler> void serialize(Handler &h, const int version)
  1151. {
  1152. h & text & player;
  1153. }
  1154. };
  1155. struct SetSelection : public CPackForClient, public CPackForServer //514
  1156. {
  1157. SetSelection(){CPackForClient::type = 514;};
  1158. DLL_EXPORT void applyGs(CGameState *gs);
  1159. bool applyGh(CGameHandler *gh);
  1160. void applyCl(CClient *cl);
  1161. ui8 player;
  1162. ui32 id;
  1163. template <typename Handler> void serialize(Handler &h, const int version)
  1164. {
  1165. h & id & player;
  1166. }
  1167. };
  1168. struct CenterView : public CPackForClient//515
  1169. {
  1170. CenterView(){CPackForClient::type = 515;};
  1171. void applyCl(CClient *cl);
  1172. ui8 player;
  1173. int3 pos;
  1174. ui32 focusTime; //ms
  1175. template <typename Handler> void serialize(Handler &h, const int version)
  1176. {
  1177. h & pos & player & focusTime;
  1178. }
  1179. };
  1180. #endif //__NETPACKS_H__