NetPacks.h 34 KB

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