NetPacks.h 48 KB

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