NetPacks.h 56 KB

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