NetPacks.h 53 KB

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