NetPacks.h 61 KB

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