NetPacks.h 53 KB

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