NetPacks.h 40 KB

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