NetPacks.h 50 KB

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