NetPacks.h 60 KB

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