NetPacks.h 58 KB

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