NetPacks.h 59 KB

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