NetPacks.h 44 KB

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