NetPacks.h 55 KB

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