NetPacks.h 57 KB

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