NetPacks.h 54 KB

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