NetPacks.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596
  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. #include "CCreatureSet.h"
  9. /*
  10. * NetPacks.h, part of VCMI engine
  11. *
  12. * Authors: listed in file AUTHORS in main folder
  13. *
  14. * License: GNU General Public License v2.0 or later
  15. * Full text of license available in license.txt file, in main folder
  16. *
  17. */
  18. class CClient;
  19. class CGameState;
  20. class CGameHandler;
  21. class CConnection;
  22. class CArtifact;
  23. struct CPack
  24. {
  25. ui16 type;
  26. CPack(){};
  27. virtual ~CPack(){};
  28. ui16 getType() const{return type;}
  29. template <typename Handler> void serialize(Handler &h, const int version)
  30. {
  31. tlog1 << "CPack serialized... this should not happen!\n";
  32. }
  33. DLL_EXPORT void applyGs(CGameState *gs)
  34. {};
  35. };
  36. struct CPackForClient : public CPack
  37. {
  38. CPackForClient(){type = 1;};
  39. CGameState* GS(CClient *cl);
  40. void applyFirstCl(CClient *cl)//called before applying to gs
  41. {};
  42. void applyCl(CClient *cl)//called after applying to gs
  43. {};
  44. };
  45. struct CPackForServer : public CPack
  46. {
  47. CConnection *c;
  48. CGameState* GS(CGameHandler *gh);
  49. CPackForServer()
  50. {
  51. type = 2;
  52. c = NULL;
  53. };
  54. bool applyGh(CGameHandler *gh);//called after applying to gs
  55. };
  56. struct Query : public CPackForClient
  57. {
  58. ui32 id;
  59. };
  60. struct MetaString : public CPack //2001 helper for object scrips
  61. {
  62. private:
  63. enum EMessage {TEXACT_STRING, TLOCAL_STRING, TNUMBER, TREPLACE_ESTRING, TREPLACE_LSTRING, TREPLACE_NUMBER};
  64. public:
  65. enum {GENERAL_TXT=1, XTRAINFO_TXT, OBJ_NAMES, RES_NAMES, ART_NAMES, ARRAY_TXT, CRE_PL_NAMES, CREGENS, MINE_NAMES,
  66. MINE_EVNTS, ADVOB_TXT, ART_EVNTS, SPELL_NAME, SEC_SKILL_NAME, CRE_SING_NAMES, CREGENS4, COLOR, ART_DESCR};
  67. std::vector<ui8> message; //vector of EMessage
  68. 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
  69. std::vector<std::string> exactStrings;
  70. std::vector<si32> numbers;
  71. template <typename Handler> void serialize(Handler &h, const int version)
  72. {
  73. h & exactStrings & localStrings & message & numbers;
  74. }
  75. void addTxt(ui8 type, ui32 serial)
  76. {
  77. message.push_back(TLOCAL_STRING);
  78. localStrings.push_back(std::pair<ui8,ui32>(type, serial));
  79. }
  80. MetaString& operator<<(const std::pair<ui8,ui32> &txt)
  81. {
  82. message.push_back(TLOCAL_STRING);
  83. localStrings.push_back(txt);
  84. return *this;
  85. }
  86. MetaString& operator<<(const std::string &txt)
  87. {
  88. message.push_back(TEXACT_STRING);
  89. exactStrings.push_back(txt);
  90. return *this;
  91. }
  92. MetaString& operator<<(int txt)
  93. {
  94. message.push_back(TNUMBER);
  95. numbers.push_back(txt);
  96. return *this;
  97. }
  98. void addReplacement(ui8 type, ui32 serial)
  99. {
  100. message.push_back(TREPLACE_LSTRING);
  101. localStrings.push_back(std::pair<ui8,ui32>(type, serial));
  102. }
  103. void addReplacement(const std::string &txt)
  104. {
  105. message.push_back(TREPLACE_ESTRING);
  106. exactStrings.push_back(txt);
  107. }
  108. void addReplacement(int txt)
  109. {
  110. message.push_back(TREPLACE_NUMBER);
  111. numbers.push_back(txt);
  112. }
  113. DLL_EXPORT void addReplacement(const CStackInstance &stack); //adds sing or plural name;
  114. DLL_EXPORT std::string buildList () const;
  115. void clear()
  116. {
  117. exactStrings.clear();
  118. localStrings.clear();
  119. message.clear();
  120. numbers.clear();
  121. }
  122. DLL_EXPORT void toString(std::string &dst) const;
  123. DLL_EXPORT std::string toString() const;
  124. void getLocalString(const std::pair<ui8,ui32> &txt, std::string &dst) const;
  125. MetaString()
  126. {
  127. type = 2001;
  128. }
  129. };
  130. /***********************************************************************************************************/
  131. struct PackageApplied : public CPackForClient //94
  132. {
  133. PackageApplied() {type = 94;}
  134. PackageApplied(ui8 Result) : result(Result) {type = 94;}
  135. void applyCl(CClient *cl);
  136. ui8 result; //0 - something went wrong, request hasn't been realized; 1 - OK
  137. ui32 packType; //type id of applied package
  138. template <typename Handler> void serialize(Handler &h, const int version)
  139. {
  140. h & result & packType;
  141. }
  142. };
  143. struct SystemMessage : public CPackForClient //95
  144. {
  145. SystemMessage(const std::string Text) : text(Text){type = 95;};
  146. SystemMessage(){type = 95;};
  147. void applyCl(CClient *cl);
  148. std::string text;
  149. template <typename Handler> void serialize(Handler &h, const int version)
  150. {
  151. h & text;
  152. }
  153. };
  154. struct PlayerBlocked : public CPackForClient //96
  155. {
  156. PlayerBlocked(){type = 96;};
  157. void applyCl(CClient *cl);
  158. enum EReason { UPCOMING_BATTLE };
  159. ui8 reason;
  160. ui8 player;
  161. template <typename Handler> void serialize(Handler &h, const int version)
  162. {
  163. h & reason & player;
  164. }
  165. };
  166. struct YourTurn : public CPackForClient //100
  167. {
  168. YourTurn(){type = 100;};
  169. void applyCl(CClient *cl);
  170. DLL_EXPORT void applyGs(CGameState *gs);
  171. ui8 player;
  172. template <typename Handler> void serialize(Handler &h, const int version)
  173. {
  174. h & player;
  175. }
  176. };
  177. struct SetResource : public CPackForClient //102
  178. {
  179. SetResource(){type = 102;};
  180. void applyCl(CClient *cl);
  181. DLL_EXPORT void applyGs(CGameState *gs);
  182. ui8 player, resid;
  183. si32 val;
  184. template <typename Handler> void serialize(Handler &h, const int version)
  185. {
  186. h & player & resid & val;
  187. }
  188. };
  189. struct SetResources : public CPackForClient //104
  190. {
  191. SetResources(){res.resize(RESOURCE_QUANTITY);type = 104;};
  192. void applyCl(CClient *cl);
  193. DLL_EXPORT void applyGs(CGameState *gs);
  194. ui8 player;
  195. std::vector<si32> res; //res[resid] => res amount
  196. template <typename Handler> void serialize(Handler &h, const int version)
  197. {
  198. h & player & res;
  199. }
  200. };
  201. struct SetPrimSkill : public CPackForClient //105
  202. {
  203. SetPrimSkill(){type = 105;};
  204. void applyCl(CClient *cl);
  205. DLL_EXPORT void applyGs(CGameState *gs);
  206. ui8 abs; //0 - changes by value; 1 - sets to value
  207. si32 id;
  208. ui16 which;
  209. si64 val;
  210. template <typename Handler> void serialize(Handler &h, const int version)
  211. {
  212. h & abs & id & which & val;
  213. }
  214. };
  215. struct SetSecSkill : public CPackForClient //106
  216. {
  217. SetSecSkill(){type = 106;};
  218. void applyCl(CClient *cl);
  219. DLL_EXPORT void applyGs(CGameState *gs);
  220. ui8 abs; //0 - changes by value; 1 - sets to value
  221. si32 id;
  222. ui16 which, val;
  223. template <typename Handler> void serialize(Handler &h, const int version)
  224. {
  225. h & abs & id & which & val;
  226. }
  227. };
  228. struct HeroVisitCastle : public CPackForClient //108
  229. {
  230. HeroVisitCastle(){flags=0;type = 108;};
  231. void applyCl(CClient *cl);
  232. DLL_EXPORT void applyGs(CGameState *gs);
  233. ui8 flags; //1 - start, 2 - garrison
  234. ui32 tid, hid;
  235. bool start() //if hero is entering castle (if false - leaving)
  236. {
  237. return flags & 1;
  238. }
  239. bool garrison() //if hero is entering/leaving garrison (if false - it's only visiting hero)
  240. {
  241. return flags & 2;
  242. }
  243. template <typename Handler> void serialize(Handler &h, const int version)
  244. {
  245. h & flags & tid & hid;
  246. }
  247. };
  248. struct ChangeSpells : public CPackForClient //109
  249. {
  250. ChangeSpells(){type = 109;};
  251. void applyCl(CClient *cl);
  252. DLL_EXPORT void applyGs(CGameState *gs);
  253. ui8 learn; //1 - gives spell, 0 - takes
  254. ui32 hid;
  255. std::set<ui32> spells;
  256. template <typename Handler> void serialize(Handler &h, const int version)
  257. {
  258. h & learn & hid & spells;
  259. }
  260. };
  261. struct SetMana : public CPackForClient //110
  262. {
  263. SetMana(){type = 110;};
  264. void applyCl(CClient *cl);
  265. DLL_EXPORT void applyGs(CGameState *gs);
  266. si32 hid, val;
  267. template <typename Handler> void serialize(Handler &h, const int version)
  268. {
  269. h & val & hid;
  270. }
  271. };
  272. struct SetMovePoints : public CPackForClient //111
  273. {
  274. SetMovePoints(){type = 111;};
  275. void applyCl(CClient *cl);
  276. DLL_EXPORT void applyGs(CGameState *gs);
  277. ui32 hid, val;
  278. template <typename Handler> void serialize(Handler &h, const int version)
  279. {
  280. h & val & hid;
  281. }
  282. };
  283. struct FoWChange : public CPackForClient //112
  284. {
  285. FoWChange(){type = 112;};
  286. void applyCl(CClient *cl);
  287. DLL_EXPORT void applyGs(CGameState *gs);
  288. std::set<int3> tiles;
  289. ui8 player, mode; //mode==0 - hide, mode==1 - reveal
  290. template <typename Handler> void serialize(Handler &h, const int version)
  291. {
  292. h & tiles & player & mode;
  293. }
  294. };
  295. struct SetAvailableHeroes : public CPackForClient //113
  296. {
  297. SetAvailableHeroes()
  298. {
  299. type = 113;
  300. for (int i = 0; i < AVAILABLE_HEROES_PER_PLAYER; i++)
  301. army[i] = NULL;
  302. }
  303. ~SetAvailableHeroes()
  304. {
  305. for (int i = 0; i < AVAILABLE_HEROES_PER_PLAYER; i++)
  306. delete army[i];
  307. }
  308. void applyCl(CClient *cl);
  309. DLL_EXPORT void applyGs(CGameState *gs);
  310. ui8 player;
  311. si32 hid[AVAILABLE_HEROES_PER_PLAYER]; //-1 if no hero
  312. CCreatureSet *army[AVAILABLE_HEROES_PER_PLAYER];
  313. template <typename Handler> void serialize(Handler &h, const int version)
  314. {
  315. h & player & hid & army;
  316. }
  317. };
  318. struct GiveBonus : public CPackForClient //115
  319. {
  320. GiveBonus(ui8 Who = 0)
  321. {
  322. who = Who;
  323. type = 115;
  324. }
  325. void applyCl(CClient *cl);
  326. DLL_EXPORT void applyGs(CGameState *gs);
  327. enum {HERO, PLAYER, TOWN};
  328. ui8 who; //who receives bonus, uses enum above
  329. ui32 id; //hero. town or player id - whoever receives it
  330. Bonus bonus;
  331. MetaString bdescr;
  332. template <typename Handler> void serialize(Handler &h, const int version)
  333. {
  334. h & bonus & id & bdescr & who;
  335. }
  336. };
  337. struct ChangeObjPos : public CPackForClient //116
  338. {
  339. ChangeObjPos()
  340. {
  341. type = 116;
  342. flags = 0;
  343. }
  344. void applyFirstCl(CClient *cl);
  345. void applyCl(CClient *cl);
  346. DLL_EXPORT void applyGs(CGameState *gs);
  347. ui32 objid;
  348. int3 nPos;
  349. ui8 flags; //bit flags: 1 - redraw
  350. template <typename Handler> void serialize(Handler &h, const int version)
  351. {
  352. h & objid & nPos & flags;
  353. }
  354. };
  355. struct PlayerEndsGame : public CPackForClient //117
  356. {
  357. PlayerEndsGame()
  358. {
  359. type = 117;
  360. }
  361. void applyCl(CClient *cl);
  362. DLL_EXPORT void applyGs(CGameState *gs);
  363. ui8 player;
  364. ui8 victory;
  365. template <typename Handler> void serialize(Handler &h, const int version)
  366. {
  367. h & player & victory;
  368. }
  369. };
  370. struct RemoveBonus : public CPackForClient //118
  371. {
  372. RemoveBonus(ui8 Who = 0)
  373. {
  374. who = Who;
  375. type = 118;
  376. }
  377. void applyCl(CClient *cl);
  378. DLL_EXPORT void applyGs(CGameState *gs);
  379. enum {HERO, PLAYER, TOWN};
  380. ui8 who; //who receives bonus, uses enum above
  381. ui32 whoID; //hero, town or player id - whoever loses bonus
  382. //vars to identify bonus: its source
  383. ui8 source;
  384. ui32 id; //source id
  385. //used locally: copy of removed bonus
  386. Bonus bonus;
  387. template <typename Handler> void serialize(Handler &h, const int version)
  388. {
  389. h & source & id & who & whoID;
  390. }
  391. };
  392. struct RemoveObject : public CPackForClient //500
  393. {
  394. RemoveObject(){type = 500;};
  395. RemoveObject(si32 ID){id = ID;type = 500;};
  396. void applyFirstCl(CClient *cl);
  397. void applyCl(CClient *cl);
  398. DLL_EXPORT void applyGs(CGameState *gs);
  399. si32 id;
  400. template <typename Handler> void serialize(Handler &h, const int version)
  401. {
  402. h & id;
  403. }
  404. };
  405. struct TryMoveHero : public CPackForClient //501
  406. {
  407. TryMoveHero(){type = 501;humanKnows=false; attackedFrom = int3(-1, -1, -1);};
  408. void applyFirstCl(CClient *cl);
  409. void applyCl(CClient *cl);
  410. void applyGs(CGameState *gs);
  411. enum EResult
  412. {
  413. FAILED, SUCCESS, TELEPORTATION, RESERVED___, BLOCKING_VISIT, EMBARK, DISEMBARK
  414. };
  415. ui32 id, movePoints;
  416. ui8 result; //uses EResult
  417. int3 start, end; //h3m format
  418. std::set<int3> fowRevealed; //revealed tiles
  419. int3 attackedFrom; // Set when stepping into endangered tile.
  420. bool humanKnows; //used locally during applying to client
  421. template <typename Handler> void serialize(Handler &h, const int version)
  422. {
  423. h & id & result & start & end & movePoints & fowRevealed & attackedFrom;
  424. }
  425. };
  426. struct SetGarrisons : public CPackForClient //502
  427. {
  428. SetGarrisons(){type = 502;};
  429. void applyCl(CClient *cl);
  430. DLL_EXPORT void applyGs(CGameState *gs);
  431. std::map<ui32,CCreatureSet> garrs;
  432. template <typename Handler> void serialize(Handler &h, const int version)
  433. {
  434. h & garrs;
  435. }
  436. };
  437. struct NewStructures : public CPackForClient //504
  438. {
  439. NewStructures(){type = 504;};
  440. void applyCl(CClient *cl);
  441. DLL_EXPORT virtual void applyGs(CGameState *gs);
  442. si32 tid;
  443. std::set<si32> bid;
  444. si16 builded;
  445. template <typename Handler> void serialize(Handler &h, const int version)
  446. {
  447. h & tid & bid & builded;
  448. }
  449. };
  450. struct RazeStructures : public CPackForClient //505
  451. {
  452. RazeStructures() {type = 505;};
  453. void applyCl (CClient *cl);
  454. DLL_EXPORT void applyGs(CGameState *gs);
  455. si32 tid;
  456. std::set<si32> bid;
  457. si16 destroyed;
  458. template <typename Handler> void serialize(Handler &h, const int version)
  459. {
  460. h & tid & bid & destroyed;
  461. }
  462. };
  463. struct SetAvailableCreatures : public CPackForClient //506
  464. {
  465. SetAvailableCreatures(){type = 506;};
  466. void applyCl(CClient *cl);
  467. DLL_EXPORT void applyGs(CGameState *gs);
  468. si32 tid;
  469. std::vector<std::pair<ui32, std::vector<ui32> > > creatures;
  470. template <typename Handler> void serialize(Handler &h, const int version)
  471. {
  472. h & tid & creatures;
  473. }
  474. };
  475. struct SetHeroesInTown : public CPackForClient //508
  476. {
  477. SetHeroesInTown(){type = 508;};
  478. void applyCl(CClient *cl);
  479. DLL_EXPORT void applyGs(CGameState *gs);
  480. si32 tid, visiting, garrison; //id of town, visiting hero, hero in garrison
  481. template <typename Handler> void serialize(Handler &h, const int version)
  482. {
  483. h & tid & visiting & garrison;
  484. }
  485. };
  486. struct SetHeroArtifacts : public CPackForClient //509
  487. {
  488. SetHeroArtifacts(){type = 509;};
  489. void applyCl(CClient *cl);
  490. DLL_EXPORT void applyGs(CGameState *gs);
  491. DLL_EXPORT void setArtAtPos(ui16 pos, int art);
  492. si32 hid;
  493. std::vector<ui32> artifacts; //hero's artifacts from bag
  494. 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
  495. template <typename Handler> void serialize(Handler &h, const int version)
  496. {
  497. h & hid & artifacts & artifWorn;
  498. }
  499. BonusList gained, lost; //used locally as hlp when applying
  500. };
  501. struct HeroRecruited : public CPackForClient //515
  502. {
  503. HeroRecruited(){type = 515;};
  504. void applyCl(CClient *cl);
  505. DLL_EXPORT void applyGs(CGameState *gs);
  506. si32 hid, tid; //subID of hero
  507. int3 tile;
  508. ui8 player;
  509. template <typename Handler> void serialize(Handler &h, const int version)
  510. {
  511. h & hid & tid & tile & player;
  512. }
  513. };
  514. struct GiveHero : public CPackForClient //516
  515. {
  516. GiveHero(){type = 516;};
  517. void applyFirstCl(CClient *cl);
  518. void applyCl(CClient *cl);
  519. DLL_EXPORT void applyGs(CGameState *gs);
  520. ui32 id; //object id
  521. ui8 player;
  522. template <typename Handler> void serialize(Handler &h, const int version)
  523. {
  524. h & id & player;
  525. }
  526. };
  527. struct OpenWindow : public CPackForClient //517
  528. {
  529. OpenWindow(){type = 517;};
  530. void applyCl(CClient *cl);
  531. enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL, SHIPYARD_WINDOW, THIEVES_GUILD, PUZZLE_MAP,
  532. MARKET_WINDOW, TAVERN_WINDOW};
  533. ui8 window;
  534. ui32 id1, id2;
  535. template <typename Handler> void serialize(Handler &h, const int version)
  536. {
  537. h & window & id1 & id2;
  538. }
  539. };
  540. struct NewObject : public CPackForClient //518
  541. {
  542. NewObject(){type = 518;};
  543. void applyCl(CClient *cl);
  544. DLL_EXPORT void applyGs(CGameState *gs);
  545. ui32 ID, subID;
  546. int3 pos;
  547. int id; //used internally
  548. template <typename Handler> void serialize(Handler &h, const int version)
  549. {
  550. h & ID & subID & pos;
  551. }
  552. };
  553. struct SetAvailableArtifacts : public CPackForClient //519
  554. {
  555. SetAvailableArtifacts(){type = 519;};
  556. void applyCl(CClient *cl);
  557. DLL_EXPORT void applyGs(CGameState *gs);
  558. si32 id; //two variants: id < 0: set artifact pool for Artifact Merchants in towns; id >= 0: set pool for adv. map Black Market (id is the id of Black Market instance then)
  559. std::vector<const CArtifact *> arts;
  560. template <typename Handler> void serialize(Handler &h, const int version)
  561. {
  562. h & id & arts;
  563. }
  564. };
  565. struct NewTurn : public CPackForClient //101
  566. {
  567. DLL_EXPORT void applyGs(CGameState *gs);
  568. struct Hero
  569. {
  570. ui32 id, move, mana; //id is a general serial id
  571. template <typename Handler> void serialize(Handler &h, const int version)
  572. {
  573. h & id & move & mana;
  574. }
  575. bool operator<(const Hero&h)const{return id < h.id;}
  576. };
  577. std::set<Hero> heroes; //updates movement and mana points
  578. //std::vector<SetResources> res;//resource list
  579. std::map<ui8, std::vector<si32> > res; //player ID => resource value[res_id]
  580. std::vector<SetAvailableCreatures> cres;//creatures to be placed in towns
  581. ui32 day;
  582. bool resetBuilded;
  583. NewTurn(){type = 101;};
  584. template <typename Handler> void serialize(Handler &h, const int version)
  585. {
  586. h & heroes & cres & res & day & resetBuilded;
  587. }
  588. };
  589. struct Component : public CPack //2002 helper for object scrips informations
  590. {
  591. enum EComponentType {PRIM_SKILL, SEC_SKILL, RESOURCE, CREATURE, ARTIFACT, EXPERIENCE, SPELL, MORALE=8, LUCK, BUILDING, HERO, FLAG};
  592. ui16 id, subtype; //id uses ^^^ enums, when id==EXPPERIENCE subtype==0 means exp points and subtype==1 levels)
  593. si32 val; // + give; - take
  594. si16 when; // 0 - now; +x - within x days; -x - per x days
  595. template <typename Handler> void serialize(Handler &h, const int version)
  596. {
  597. h & id & subtype & val & when;
  598. }
  599. Component()
  600. {
  601. type = 2002;
  602. }
  603. DLL_EXPORT explicit Component(const CStackInstance &stack);
  604. Component(ui16 Type, ui16 Subtype, si32 Val, si16 When)
  605. :id(Type),subtype(Subtype),val(Val),when(When)
  606. {
  607. type = 2002;
  608. }
  609. };
  610. struct InfoWindow : public CPackForClient //103 - displays simple info window
  611. {
  612. void applyCl(CClient *cl);
  613. MetaString text;
  614. std::vector<Component> components;
  615. ui8 player;
  616. ui16 soundID;
  617. template <typename Handler> void serialize(Handler &h, const int version)
  618. {
  619. h & text & components & player & soundID;
  620. }
  621. InfoWindow()
  622. {
  623. type = 103;
  624. soundID = 0;
  625. }
  626. };
  627. namespace ObjProperty
  628. {
  629. //TODO: move non general properties out to the appropriate objs classes
  630. enum {OWNER = 1, BLOCKVIS = 2, PRIMARY_STACK_COUNT = 3, VISITORS = 4, VISITED = 5, ID = 6};
  631. }
  632. struct SetObjectProperty : public CPackForClient//1001
  633. {
  634. DLL_EXPORT void applyGs(CGameState *gs);
  635. void applyCl(CClient *cl);
  636. ui32 id;
  637. ui8 what; //1 - owner; 2 - blockvis; 3 - first stack count; 4 - visitors; 5 - visited; 6 - ID (if 34 then also def is replaced)
  638. ui32 val;
  639. SetObjectProperty(){type = 1001;};
  640. SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
  641. template <typename Handler> void serialize(Handler &h, const int version)
  642. {
  643. h & id & what & val;
  644. }
  645. };
  646. struct SetHoverName : public CPackForClient//1002
  647. {
  648. DLL_EXPORT void applyGs(CGameState *gs);
  649. ui32 id;
  650. MetaString name;
  651. SetHoverName(){type = 1002;};
  652. SetHoverName(ui32 ID, MetaString& Name):id(ID),name(Name){type = 1002;};
  653. template <typename Handler> void serialize(Handler &h, const int version)
  654. {
  655. h & id & name;
  656. }
  657. };
  658. struct HeroLevelUp : public Query//2000
  659. {
  660. void applyCl(CClient *cl);
  661. DLL_EXPORT void applyGs(CGameState *gs);
  662. si32 heroid;
  663. ui8 primskill, level;
  664. std::vector<ui16> skills;
  665. HeroLevelUp(){type = 2000;};
  666. template <typename Handler> void serialize(Handler &h, const int version)
  667. {
  668. h & id & heroid & primskill & level & skills;
  669. }
  670. };
  671. struct TradeComponents : public CPackForClient, public CPackForServer
  672. {
  673. ///used to handle info about components available in shops
  674. void applyCl(CClient *cl);
  675. DLL_EXPORT void applyGs(CGameState *gs);
  676. si32 heroid;
  677. ui32 objectid;
  678. std::map<ui16, Component> available, chosen, bought;
  679. template <typename Handler> void serialize(Handler &h, const int version)
  680. {
  681. h & heroid & objectid & available & chosen & bought;
  682. }
  683. };
  684. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  685. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  686. //Until sending reply player won't be allowed to take any actions
  687. struct BlockingDialog : public Query//2003
  688. {
  689. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  690. void applyCl(CClient *cl);
  691. MetaString text;
  692. std::vector<Component> components;
  693. ui8 player;
  694. ui8 flags;
  695. ui16 soundID;
  696. bool cancel() const
  697. {
  698. return flags & ALLOW_CANCEL;
  699. }
  700. bool selection() const
  701. {
  702. return flags & SELECTION;
  703. }
  704. BlockingDialog(bool yesno, bool Selection)
  705. {
  706. type = 2003;
  707. flags = 0;
  708. soundID = 0;
  709. if(yesno) flags |= ALLOW_CANCEL;
  710. if(Selection) flags |= SELECTION;
  711. }
  712. BlockingDialog()
  713. {
  714. type = 2003;
  715. flags = 0;
  716. soundID = 0;
  717. };
  718. template <typename Handler> void serialize(Handler &h, const int version)
  719. {
  720. h & id & text & components & player & flags & soundID;
  721. }
  722. };
  723. struct GarrisonDialog : public Query//2004
  724. {
  725. GarrisonDialog(){type = 2004;}
  726. void applyCl(CClient *cl);
  727. si32 objid, hid;
  728. bool removableUnits;
  729. template <typename Handler> void serialize(Handler &h, const int version)
  730. {
  731. h & id & objid & hid & removableUnits;
  732. }
  733. };
  734. struct BattleInfo;
  735. struct BattleStart : public CPackForClient//3000
  736. {
  737. BattleStart(){type = 3000;};
  738. void applyCl(CClient *cl);
  739. DLL_EXPORT void applyGs(CGameState *gs);
  740. BattleInfo * info;
  741. template <typename Handler> void serialize(Handler &h, const int version)
  742. {
  743. h & info;
  744. }
  745. };
  746. struct BattleNextRound : public CPackForClient//3001
  747. {
  748. BattleNextRound(){type = 3001;};
  749. void applyFirstCl(CClient *cl);
  750. void applyCl(CClient *cl);
  751. DLL_EXPORT void applyGs( CGameState *gs );
  752. si32 round;
  753. template <typename Handler> void serialize(Handler &h, const int version)
  754. {
  755. h & round;
  756. }
  757. };
  758. struct BattleSetActiveStack : public CPackForClient//3002
  759. {
  760. BattleSetActiveStack(){type = 3002;};
  761. void applyCl(CClient *cl);
  762. DLL_EXPORT void applyGs(CGameState *gs);
  763. ui32 stack;
  764. template <typename Handler> void serialize(Handler &h, const int version)
  765. {
  766. h & stack;
  767. }
  768. };
  769. struct BattleResult : public CPackForClient//3003
  770. {
  771. BattleResult(){type = 3003;};
  772. void applyFirstCl(CClient *cl);
  773. void applyGs(CGameState *gs);
  774. ui8 result; //0 - normal victory; 1 - escape; 2 - surrender
  775. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  776. std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
  777. ui32 exp[2]; //exp for attacker and defender
  778. std::set<ui32> artifacts; //artifacts taken from loser to winner
  779. template <typename Handler> void serialize(Handler &h, const int version)
  780. {
  781. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  782. }
  783. };
  784. struct BattleStackMoved : public CPackForClient//3004
  785. {
  786. ui32 stack, tile;
  787. ui8 ending, distance, teleporting;
  788. BattleStackMoved(){type = 3004;};
  789. void applyFirstCl(CClient *cl);
  790. void applyGs(CGameState *gs);
  791. template <typename Handler> void serialize(Handler &h, const int version)
  792. {
  793. h & stack & tile & ending & distance;
  794. }
  795. };
  796. struct StacksHealedOrResurrected : public CPackForClient //3013
  797. {
  798. StacksHealedOrResurrected(){type = 3013;}
  799. DLL_EXPORT void applyGs(CGameState *gs);
  800. void applyCl(CClient *cl);
  801. struct HealInfo
  802. {
  803. ui32 stackID;
  804. ui32 healedHP;
  805. ui8 lowLevelResurrection; //in case this stack is resurrected by this heal, it will be marked as SUMMONED
  806. template <typename Handler> void serialize(Handler &h, const int version)
  807. {
  808. h & stackID & healedHP & lowLevelResurrection;
  809. }
  810. };
  811. std::vector<HealInfo> healedStacks;
  812. ui8 lifeDrain; //if true, this heal is an effect of life drain
  813. si32 drainedFrom; //if life drain - then stack life was drain from
  814. template <typename Handler> void serialize(Handler &h, const int version)
  815. {
  816. h & healedStacks & lifeDrain & drainedFrom;
  817. }
  818. };
  819. struct BattleStackAttacked : public CPackForClient//3005
  820. {
  821. BattleStackAttacked(){flags = 0; type = 3005;};
  822. void applyCl(CClient *cl);
  823. DLL_EXPORT void applyGs(CGameState *gs);
  824. ui32 stackAttacked, attackerID;
  825. ui32 newAmount, newHP, killedAmount, damageAmount;
  826. ui8 flags; //1 - is stack killed; 2 - is there special effect to be shown;
  827. ui32 effect; //set only if flag 2 is present
  828. std::vector<StacksHealedOrResurrected> healedStacks; //used when life drain
  829. bool killed() const//if target stack was killed
  830. {
  831. return flags & 1;
  832. }
  833. bool isEffect() const//if stack has been attacked by a spell
  834. {
  835. return flags & 2;
  836. }
  837. bool lifeDrain() const //if this attack involves life drain effect
  838. {
  839. return healedStacks.size() > 0;
  840. }
  841. template <typename Handler> void serialize(Handler &h, const int version)
  842. {
  843. h & stackAttacked & attackerID & newAmount & newHP & flags & killedAmount & damageAmount & effect
  844. & healedStacks;
  845. }
  846. bool operator<(const BattleStackAttacked &b) const
  847. {
  848. return stackAttacked < b.stackAttacked;
  849. }
  850. };
  851. struct BattleAttack : public CPackForClient//3006
  852. {
  853. BattleAttack(){flags = 0; type = 3006;};
  854. void applyFirstCl(CClient *cl);
  855. DLL_EXPORT void applyGs(CGameState *gs);
  856. void applyCl(CClient *cl);
  857. std::vector<BattleStackAttacked> bsa;
  858. ui32 stackAttacking;
  859. ui8 flags;
  860. bool shot()//distance attack - decrease number of shots
  861. {
  862. return flags & 1;
  863. }
  864. bool counter()//is it counterattack?
  865. {
  866. return flags & 2;
  867. }
  868. bool lucky()
  869. {
  870. return flags & 4;
  871. }
  872. bool unlucky()
  873. {
  874. //TODO: support?
  875. return flags & 8;
  876. }
  877. //bool killed() //if target stack was killed
  878. //{
  879. // return bsa.killed();
  880. //}
  881. template <typename Handler> void serialize(Handler &h, const int version)
  882. {
  883. h & bsa & stackAttacking & flags;
  884. }
  885. };
  886. struct StartAction : public CPackForClient//3007
  887. {
  888. StartAction(){type = 3007;};
  889. StartAction(const BattleAction &act){ba = act; type = 3007;};
  890. void applyFirstCl(CClient *cl);
  891. DLL_EXPORT void applyGs(CGameState *gs);
  892. BattleAction ba;
  893. template <typename Handler> void serialize(Handler &h, const int version)
  894. {
  895. h & ba;
  896. }
  897. };
  898. struct EndAction : public CPackForClient//3008
  899. {
  900. EndAction(){type = 3008;};
  901. void applyCl(CClient *cl);
  902. template <typename Handler> void serialize(Handler &h, const int version)
  903. {
  904. }
  905. };
  906. struct BattleSpellCast : public CPackForClient//3009
  907. {
  908. BattleSpellCast(){type = 3009;};
  909. DLL_EXPORT void applyGs(CGameState *gs);
  910. void applyCl(CClient *cl);
  911. si32 dmgToDisplay; //this amount will be displayed as amount of damage dealt by spell
  912. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  913. ui32 id; //id of spell
  914. ui8 skill; //caster's skill level
  915. ui16 tile; //destination tile (may not be set in some global/mass spells
  916. std::vector<ui32> resisted; //ids of creatures that resisted this spell
  917. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  918. ui8 castedByHero; //if true - spell has been casted by hero, otherwise by a creature
  919. template <typename Handler> void serialize(Handler &h, const int version)
  920. {
  921. h & dmgToDisplay & side & id & skill & tile & resisted & affectedCres & castedByHero;
  922. }
  923. };
  924. struct SetStackEffect : public CPackForClient //3010
  925. {
  926. SetStackEffect(){type = 3010;};
  927. DLL_EXPORT void applyGs(CGameState *gs);
  928. void applyCl(CClient *cl);
  929. std::vector<ui32> stacks; //affected stacks (IDs)
  930. CStack::StackEffect effect; //type of effect
  931. template <typename Handler> void serialize(Handler &h, const int version)
  932. {
  933. h & stacks & effect;
  934. }
  935. };
  936. struct StacksInjured : public CPackForClient //3011
  937. {
  938. StacksInjured(){type = 3011;}
  939. DLL_EXPORT void applyGs(CGameState *gs);
  940. void applyCl(CClient *cl);
  941. std::vector<BattleStackAttacked> stacks;
  942. template <typename Handler> void serialize(Handler &h, const int version)
  943. {
  944. h & stacks;
  945. }
  946. };
  947. struct BattleResultsApplied : public CPackForClient //3012
  948. {
  949. BattleResultsApplied(){type = 3012;}
  950. ui8 player1, player2;
  951. void applyCl(CClient *cl);
  952. template <typename Handler> void serialize(Handler &h, const int version)
  953. {
  954. h & player1 & player2;
  955. }
  956. };
  957. struct ObstaclesRemoved : public CPackForClient //3014
  958. {
  959. ObstaclesRemoved(){type = 3014;}
  960. DLL_EXPORT void applyGs(CGameState *gs);
  961. void applyCl(CClient *cl);
  962. std::set<si32> obstacles; //uniqueIDs of removed obstacles
  963. template <typename Handler> void serialize(Handler &h, const int version)
  964. {
  965. h & obstacles;
  966. }
  967. };
  968. struct CatapultAttack : public CPackForClient //3015
  969. {
  970. CatapultAttack(){type = 3015;}
  971. DLL_EXPORT void applyGs(CGameState *gs);
  972. void applyCl(CClient *cl);
  973. std::set< std::pair< std::pair< ui8, si16 >, ui8> > attackedParts; // < <attackedPartOfWall, attacked hex >, damageDealt>
  974. //attackedPartOfWall; //[0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate;
  975. //damageDealt;
  976. int attacker; //if -1, then a spell caused this
  977. template <typename Handler> void serialize(Handler &h, const int version)
  978. {
  979. h & attackedParts & attacker;
  980. }
  981. };
  982. struct BattleStacksRemoved : public CPackForClient //3016
  983. {
  984. BattleStacksRemoved(){type = 3016;}
  985. DLL_EXPORT void applyGs(CGameState *gs);
  986. void applyCl(CClient *cl);
  987. std::set<ui32> stackIDs; //IDs of removed stacks
  988. template <typename Handler> void serialize(Handler &h, const int version)
  989. {
  990. h & stackIDs;
  991. }
  992. };
  993. struct ShowInInfobox : public CPackForClient //107
  994. {
  995. ShowInInfobox(){type = 107;};
  996. ui8 player;
  997. Component c;
  998. MetaString text;
  999. void applyCl(CClient *cl);
  1000. template <typename Handler> void serialize(Handler &h, const int version)
  1001. {
  1002. h & player & c & text;
  1003. }
  1004. };
  1005. struct AdvmapSpellCast : public CPackForClient //108
  1006. {
  1007. AdvmapSpellCast(){type = 108;}
  1008. const CGHeroInstance * caster;
  1009. si32 spellID;
  1010. void applyCl(CClient *cl);
  1011. template <typename Handler> void serialize(Handler &h, const int version)
  1012. {
  1013. h & caster & spellID;
  1014. }
  1015. };
  1016. /***********************************************************************************************************/
  1017. struct CloseServer : public CPackForServer
  1018. {
  1019. bool applyGh(CGameHandler *gh);
  1020. template <typename Handler> void serialize(Handler &h, const int version)
  1021. {}
  1022. };
  1023. struct EndTurn : public CPackForServer
  1024. {
  1025. bool applyGh(CGameHandler *gh);
  1026. template <typename Handler> void serialize(Handler &h, const int version)
  1027. {}
  1028. };
  1029. struct DismissHero : public CPackForServer
  1030. {
  1031. DismissHero(){};
  1032. DismissHero(si32 HID) : hid(HID) {};
  1033. si32 hid;
  1034. bool applyGh(CGameHandler *gh);
  1035. template <typename Handler> void serialize(Handler &h, const int version)
  1036. {
  1037. h & hid;
  1038. }
  1039. };
  1040. struct MoveHero : public CPackForServer
  1041. {
  1042. MoveHero(){};
  1043. MoveHero(const int3 &Dest, si32 HID) : dest(Dest), hid(HID){};
  1044. int3 dest;
  1045. si32 hid;
  1046. bool applyGh(CGameHandler *gh);
  1047. template <typename Handler> void serialize(Handler &h, const int version)
  1048. {
  1049. h & dest & hid;
  1050. }
  1051. };
  1052. struct CastleTeleportHero : public CPackForServer
  1053. {
  1054. CastleTeleportHero(){};
  1055. CastleTeleportHero(const si32 HID, si32 Dest, ui8 Source ) : dest(Dest), hid(HID), source(Source){};
  1056. si32 dest;
  1057. si32 hid;
  1058. si8 source;//who give teleporting, 1=castle gate
  1059. bool applyGh(CGameHandler *gh);
  1060. template <typename Handler> void serialize(Handler &h, const int version)
  1061. {
  1062. h & dest & hid;
  1063. }
  1064. };
  1065. struct ArrangeStacks : public CPackForServer
  1066. {
  1067. ArrangeStacks(){};
  1068. ArrangeStacks(ui8 W, ui8 P1, ui8 P2, si32 ID1, si32 ID2, si32 VAL)
  1069. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  1070. ui8 what; //1 - swap; 2 - merge; 3 - split
  1071. ui8 p1, p2; //positions of first and second stack
  1072. si32 id1, id2; //ids of objects with garrison
  1073. si32 val;
  1074. bool applyGh(CGameHandler *gh);
  1075. template <typename Handler> void serialize(Handler &h, const int version)
  1076. {
  1077. h & what & p1 & p2 & id1 & id2 & val;
  1078. }
  1079. };
  1080. struct DisbandCreature : public CPackForServer
  1081. {
  1082. DisbandCreature(){};
  1083. DisbandCreature(ui8 Pos, si32 ID):pos(Pos),id(ID){};
  1084. ui8 pos; //stack pos
  1085. si32 id; //object id
  1086. bool applyGh(CGameHandler *gh);
  1087. template <typename Handler> void serialize(Handler &h, const int version)
  1088. {
  1089. h & pos & id;
  1090. }
  1091. };
  1092. struct BuildStructure : public CPackForServer
  1093. {
  1094. BuildStructure(){};
  1095. BuildStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  1096. si32 bid, tid; //structure and town ids
  1097. bool applyGh(CGameHandler *gh);
  1098. template <typename Handler> void serialize(Handler &h, const int version)
  1099. {
  1100. h & tid & bid;
  1101. }
  1102. };
  1103. struct RazeStructure : public BuildStructure
  1104. {
  1105. RazeStructure(){};
  1106. //RazeStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  1107. bool applyGh(CGameHandler *gh);
  1108. };
  1109. struct RecruitCreatures : public CPackForServer
  1110. {
  1111. RecruitCreatures(){};
  1112. RecruitCreatures(si32 TID, si32 CRID, si32 Amount, si32 Level):tid(TID),crid(CRID),amount(Amount),level(Level){};
  1113. si32 tid; //town id
  1114. ui32 crid, amount;//creature ID and amount
  1115. si32 level;//dwelling level to buy from, -1 if any
  1116. bool applyGh(CGameHandler *gh);
  1117. template <typename Handler> void serialize(Handler &h, const int version)
  1118. {
  1119. h & tid & crid & amount & level;
  1120. }
  1121. };
  1122. struct UpgradeCreature : public CPackForServer
  1123. {
  1124. UpgradeCreature(){};
  1125. UpgradeCreature(ui8 Pos, si32 ID, si32 CRID):pos(Pos),id(ID), cid(CRID){};
  1126. ui8 pos; //stack pos
  1127. si32 id; //object id
  1128. si32 cid; //id of type to which we want make upgrade
  1129. bool applyGh(CGameHandler *gh);
  1130. template <typename Handler> void serialize(Handler &h, const int version)
  1131. {
  1132. h & pos & id & cid;
  1133. }
  1134. };
  1135. struct GarrisonHeroSwap : public CPackForServer
  1136. {
  1137. GarrisonHeroSwap(){};
  1138. GarrisonHeroSwap(si32 TID):tid(TID){};
  1139. si32 tid;
  1140. bool applyGh(CGameHandler *gh);
  1141. template <typename Handler> void serialize(Handler &h, const int version)
  1142. {
  1143. h & tid;
  1144. }
  1145. };
  1146. struct ExchangeArtifacts : public CPackForServer
  1147. {
  1148. ExchangeArtifacts(){};
  1149. ExchangeArtifacts(si32 H1, si32 H2, ui16 S1, ui16 S2)
  1150. :hid1(H1),hid2(H2),slot1(S1),slot2(S2){};
  1151. si32 hid1, hid2;
  1152. ui16 slot1, slot2;
  1153. bool applyGh(CGameHandler *gh);
  1154. template <typename Handler> void serialize(Handler &h, const int version)
  1155. {
  1156. h & hid1 & hid2 & slot1 & slot2;
  1157. }
  1158. };
  1159. struct AssembleArtifacts : public CPackForServer
  1160. {
  1161. AssembleArtifacts(){};
  1162. AssembleArtifacts(si32 _heroID, ui16 _artifactSlot, bool _assemble, ui32 _assembleTo)
  1163. : heroID(_heroID), artifactSlot(_artifactSlot), assemble(_assemble), assembleTo(_assembleTo){};
  1164. si32 heroID;
  1165. ui16 artifactSlot;
  1166. bool assemble; // True to assemble artifact, false to disassemble.
  1167. ui32 assembleTo; // Artifact to assemble into.
  1168. bool applyGh(CGameHandler *gh);
  1169. template <typename Handler> void serialize(Handler &h, const int version)
  1170. {
  1171. h & heroID & artifactSlot & assemble & assembleTo;
  1172. }
  1173. };
  1174. struct BuyArtifact : public CPackForServer
  1175. {
  1176. BuyArtifact(){};
  1177. BuyArtifact(si32 HID, si32 AID):hid(HID),aid(AID){};
  1178. si32 hid, aid; //hero and artifact id
  1179. bool applyGh(CGameHandler *gh);
  1180. template <typename Handler> void serialize(Handler &h, const int version)
  1181. {
  1182. h & hid & aid;
  1183. }
  1184. };
  1185. struct TradeOnMarketplace : public CPackForServer
  1186. {
  1187. TradeOnMarketplace(){};
  1188. const CGObjectInstance *market;
  1189. const CGHeroInstance *hero; //needed when trading artifacts / creatures
  1190. ui8 mode;//0 - res<->res;
  1191. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res
  1192. ui32 val; //units of sold resource
  1193. bool applyGh(CGameHandler *gh);
  1194. template <typename Handler> void serialize(Handler &h, const int version)
  1195. {
  1196. h & market & hero & mode & r1 & r2 & val;
  1197. }
  1198. };
  1199. struct SetFormation : public CPackForServer
  1200. {
  1201. SetFormation(){};
  1202. SetFormation(si32 HID, ui8 Formation):hid(HID),formation(Formation){};
  1203. si32 hid;
  1204. ui8 formation;
  1205. bool applyGh(CGameHandler *gh);
  1206. template <typename Handler> void serialize(Handler &h, const int version)
  1207. {
  1208. h & hid & formation;
  1209. }
  1210. };
  1211. struct HireHero : public CPackForServer
  1212. {
  1213. HireHero(){};
  1214. HireHero(si32 HID, si32 TID):hid(HID),tid(TID){};
  1215. si32 hid, tid; //available hero serial and town (tavern) id
  1216. ui8 player;
  1217. bool applyGh(CGameHandler *gh);
  1218. template <typename Handler> void serialize(Handler &h, const int version)
  1219. {
  1220. h & hid & tid & player;
  1221. }
  1222. };
  1223. struct BuildBoat : public CPackForServer
  1224. {
  1225. BuildBoat(){};
  1226. si32 objid; //where player wants to buy a boat
  1227. bool applyGh(CGameHandler *gh);
  1228. template <typename Handler> void serialize(Handler &h, const int version)
  1229. {
  1230. h & objid;
  1231. }
  1232. };
  1233. struct QueryReply : public CPackForServer
  1234. {
  1235. QueryReply(){type = 6000;};
  1236. QueryReply(ui32 QID, ui32 Answer):qid(QID),answer(Answer){type = 6000;};
  1237. ui32 qid, answer; //hero and artifact id
  1238. bool applyGh(CGameHandler *gh);
  1239. template <typename Handler> void serialize(Handler &h, const int version)
  1240. {
  1241. h & qid & answer;
  1242. }
  1243. };
  1244. struct MakeAction : public CPackForServer
  1245. {
  1246. MakeAction(){};
  1247. MakeAction(const BattleAction &BA):ba(BA){};
  1248. BattleAction ba;
  1249. bool applyGh(CGameHandler *gh);
  1250. template <typename Handler> void serialize(Handler &h, const int version)
  1251. {
  1252. h & ba;
  1253. }
  1254. };
  1255. struct MakeCustomAction : public CPackForServer
  1256. {
  1257. MakeCustomAction(){};
  1258. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1259. BattleAction ba;
  1260. bool applyGh(CGameHandler *gh);
  1261. template <typename Handler> void serialize(Handler &h, const int version)
  1262. {
  1263. h & ba;
  1264. }
  1265. };
  1266. struct DigWithHero : public CPackForServer
  1267. {
  1268. DigWithHero(){}
  1269. si32 id; //digging hero id
  1270. bool applyGh(CGameHandler *gh);
  1271. template <typename Handler> void serialize(Handler &h, const int version)
  1272. {
  1273. h & id;
  1274. }
  1275. };
  1276. struct CastAdvSpell : public CPackForServer
  1277. {
  1278. CastAdvSpell(){}
  1279. si32 hid; //hero id
  1280. ui32 sid; //spell id
  1281. int3 pos; //selected tile (not always used)
  1282. bool applyGh(CGameHandler *gh);
  1283. template <typename Handler> void serialize(Handler &h, const int version)
  1284. {
  1285. h & hid & sid & pos;
  1286. }
  1287. };
  1288. /***********************************************************************************************************/
  1289. struct SaveGame : public CPackForClient, public CPackForServer
  1290. {
  1291. SaveGame(){};
  1292. SaveGame(const std::string &Fname) :fname(Fname){};
  1293. std::string fname;
  1294. void applyCl(CClient *cl);
  1295. void applyGs(CGameState *gs){};
  1296. bool applyGh(CGameHandler *gh);
  1297. template <typename Handler> void serialize(Handler &h, const int version)
  1298. {
  1299. h & fname;
  1300. }
  1301. };
  1302. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  1303. {
  1304. PlayerMessage(){CPackForClient::type = 513;};
  1305. PlayerMessage(ui8 Player, const std::string &Text)
  1306. :player(Player),text(Text)
  1307. {CPackForClient::type = 513;};
  1308. void applyCl(CClient *cl);
  1309. void applyGs(CGameState *gs){};
  1310. bool applyGh(CGameHandler *gh);
  1311. ui8 player;
  1312. std::string text;
  1313. template <typename Handler> void serialize(Handler &h, const int version)
  1314. {
  1315. h & text & player;
  1316. }
  1317. };
  1318. struct SetSelection : public CPackForClient, public CPackForServer //514
  1319. {
  1320. SetSelection(){CPackForClient::type = 514;};
  1321. DLL_EXPORT void applyGs(CGameState *gs);
  1322. bool applyGh(CGameHandler *gh);
  1323. void applyCl(CClient *cl);
  1324. ui8 player;
  1325. ui32 id;
  1326. template <typename Handler> void serialize(Handler &h, const int version)
  1327. {
  1328. h & id & player;
  1329. }
  1330. };
  1331. struct CenterView : public CPackForClient//515
  1332. {
  1333. CenterView(){CPackForClient::type = 515;};
  1334. void applyCl(CClient *cl);
  1335. ui8 player;
  1336. int3 pos;
  1337. ui32 focusTime; //ms
  1338. template <typename Handler> void serialize(Handler &h, const int version)
  1339. {
  1340. h & pos & player & focusTime;
  1341. }
  1342. };
  1343. #endif //__NETPACKS_H__