NetPacks.h 57 KB

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