NetPacks.h 49 KB

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