NetPacks.h 53 KB

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