NetPacks.h 48 KB

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