NetPacks.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  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, COLOR};
  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(ui8 Who = 0)
  307. {
  308. who = Who;
  309. type = 115;
  310. }
  311. void applyCl(CClient *cl);
  312. DLL_EXPORT void applyGs(CGameState *gs);
  313. enum {HERO, PLAYER};
  314. ui8 who; //who receives bonus, uses enum above
  315. ui32 id; //hero or player id
  316. HeroBonus bonus;
  317. MetaString bdescr;
  318. template <typename Handler> void serialize(Handler &h, const int version)
  319. {
  320. h & bonus & id & bdescr & who;
  321. }
  322. };
  323. struct ChangeObjPos : public CPackForClient //116
  324. {
  325. ChangeObjPos(){type = 116;};
  326. void applyFirstCl(CClient *cl);
  327. void applyCl(CClient *cl);
  328. DLL_EXPORT void applyGs(CGameState *gs);
  329. ui32 objid;
  330. int3 nPos;
  331. ui8 flags; //bit flags: 1 - redraw
  332. template <typename Handler> void serialize(Handler &h, const int version)
  333. {
  334. h & objid & nPos & flags;
  335. }
  336. };
  337. struct PlayerEndsGame : public CPackForClient //117
  338. {
  339. PlayerEndsGame()
  340. {
  341. type = 117;
  342. }
  343. void applyCl(CClient *cl);
  344. DLL_EXPORT void applyGs(CGameState *gs);
  345. ui8 player;
  346. ui8 victory;
  347. template <typename Handler> void serialize(Handler &h, const int version)
  348. {
  349. h & player & victory;
  350. }
  351. };
  352. struct RemoveBonus : public CPackForClient //118
  353. {
  354. RemoveBonus(ui8 Who = 0)
  355. {
  356. who = Who;
  357. type = 118;
  358. }
  359. void applyCl(CClient *cl);
  360. DLL_EXPORT void applyGs(CGameState *gs);
  361. enum {HERO, PLAYER};
  362. ui8 who; //who receives bonus, uses enum above
  363. ui32 whoID; //hero or player id
  364. //vars to identify bonus: its source
  365. ui8 source;
  366. ui32 id; //source id
  367. //used locally: copy of removed bonus
  368. HeroBonus bonus;
  369. template <typename Handler> void serialize(Handler &h, const int version)
  370. {
  371. h & source & id & who & whoID;
  372. }
  373. };
  374. struct RemoveObject : public CPackForClient //500
  375. {
  376. RemoveObject(){type = 500;};
  377. RemoveObject(si32 ID){id = ID;type = 500;};
  378. void applyFirstCl(CClient *cl);
  379. void applyCl(CClient *cl);
  380. DLL_EXPORT void applyGs(CGameState *gs);
  381. si32 id;
  382. template <typename Handler> void serialize(Handler &h, const int version)
  383. {
  384. h & id;
  385. }
  386. };
  387. struct TryMoveHero : public CPackForClient //501
  388. {
  389. TryMoveHero(){type = 501;humanKnows=false;};
  390. void applyFirstCl(CClient *cl);
  391. void applyCl(CClient *cl);
  392. void applyGs(CGameState *gs);
  393. enum EResult
  394. {
  395. FAILED, SUCCESS, TELEPORTATION, RESERVED___, BLOCKING_VISIT, EMBARK, DISEMBARK
  396. };
  397. ui32 id, movePoints;
  398. ui8 result; //uses EResult
  399. int3 start, end;
  400. std::set<int3> fowRevealed; //revealed tiles
  401. bool humanKnows; //used locally during applying to client
  402. template <typename Handler> void serialize(Handler &h, const int version)
  403. {
  404. h & id & result & start & end & movePoints & fowRevealed;
  405. }
  406. };
  407. struct SetGarrisons : public CPackForClient //502
  408. {
  409. SetGarrisons(){type = 502;};
  410. void applyCl(CClient *cl);
  411. DLL_EXPORT void applyGs(CGameState *gs);
  412. std::map<ui32,CCreatureSet> garrs;
  413. template <typename Handler> void serialize(Handler &h, const int version)
  414. {
  415. h & garrs;
  416. }
  417. };
  418. struct NewStructures : public CPackForClient //504
  419. {
  420. NewStructures(){type = 504;};
  421. void applyCl(CClient *cl);
  422. DLL_EXPORT virtual void applyGs(CGameState *gs);
  423. si32 tid;
  424. std::set<si32> bid;
  425. si16 builded;
  426. template <typename Handler> void serialize(Handler &h, const int version)
  427. {
  428. h & tid & bid & builded;
  429. }
  430. };
  431. struct RazeStructures : public CPackForClient //505
  432. {
  433. RazeStructures() {type = 505;};
  434. void applyCl (CClient *cl);
  435. DLL_EXPORT void applyGs(CGameState *gs);
  436. si32 tid;
  437. std::set<si32> bid;
  438. si16 destroyed;
  439. template <typename Handler> void serialize(Handler &h, const int version)
  440. {
  441. h & tid & bid & destroyed;
  442. }
  443. };
  444. struct SetAvailableCreatures : public CPackForClient //506
  445. {
  446. SetAvailableCreatures(){type = 506;};
  447. void applyCl(CClient *cl);
  448. DLL_EXPORT void applyGs(CGameState *gs);
  449. si32 tid;
  450. std::vector<std::pair<ui32, std::vector<ui32> > > creatures;
  451. template <typename Handler> void serialize(Handler &h, const int version)
  452. {
  453. h & tid & creatures;
  454. }
  455. };
  456. struct SetHeroesInTown : public CPackForClient //508
  457. {
  458. SetHeroesInTown(){type = 508;};
  459. void applyCl(CClient *cl);
  460. DLL_EXPORT void applyGs(CGameState *gs);
  461. si32 tid, visiting, garrison; //id of town, visiting hero, hero in garrison
  462. template <typename Handler> void serialize(Handler &h, const int version)
  463. {
  464. h & tid & visiting & garrison;
  465. }
  466. };
  467. struct SetHeroArtifacts : public CPackForClient //509
  468. {
  469. SetHeroArtifacts(){type = 509;};
  470. void applyCl(CClient *cl);
  471. DLL_EXPORT void applyGs(CGameState *gs);
  472. DLL_EXPORT void setArtAtPos(ui16 pos, int art);
  473. si32 hid;
  474. std::vector<ui32> artifacts; //hero's artifacts from bag
  475. 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
  476. template <typename Handler> void serialize(Handler &h, const int version)
  477. {
  478. h & hid & artifacts & artifWorn;
  479. }
  480. std::vector<HeroBonus*> gained, lost; //used locally as hlp when applying
  481. };
  482. struct HeroRecruited : public CPackForClient //515
  483. {
  484. HeroRecruited(){type = 515;};
  485. void applyCl(CClient *cl);
  486. DLL_EXPORT void applyGs(CGameState *gs);
  487. si32 hid, tid; //subID of hero
  488. int3 tile;
  489. ui8 player;
  490. template <typename Handler> void serialize(Handler &h, const int version)
  491. {
  492. h & hid & tid & tile & player;
  493. }
  494. };
  495. struct GiveHero : public CPackForClient //516
  496. {
  497. GiveHero(){type = 516;};
  498. void applyFirstCl(CClient *cl);
  499. void applyCl(CClient *cl);
  500. DLL_EXPORT void applyGs(CGameState *gs);
  501. ui32 id; //object id
  502. ui8 player;
  503. template <typename Handler> void serialize(Handler &h, const int version)
  504. {
  505. h & id & player;
  506. }
  507. };
  508. struct OpenWindow : public CPackForClient //517
  509. {
  510. OpenWindow(){type = 517;};
  511. void applyCl(CClient *cl);
  512. enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL, SHIPYARD_WINDOW, THIEVES_GUILD, PUZZLE_MAP};
  513. ui8 window;
  514. ui32 id1, id2;
  515. template <typename Handler> void serialize(Handler &h, const int version)
  516. {
  517. h & window & id1 & id2;
  518. }
  519. };
  520. struct NewObject : public CPackForClient //518
  521. {
  522. NewObject(){type = 518;};
  523. void applyCl(CClient *cl);
  524. DLL_EXPORT void applyGs(CGameState *gs);
  525. ui32 ID, subID;
  526. int3 pos;
  527. int id; //used internally
  528. template <typename Handler> void serialize(Handler &h, const int version)
  529. {
  530. h & ID & subID & pos;
  531. }
  532. };
  533. struct NewTurn : public CPackForClient //101
  534. {
  535. DLL_EXPORT void applyGs(CGameState *gs);
  536. struct Hero
  537. {
  538. ui32 id, move, mana; //id is a general serial id
  539. template <typename Handler> void serialize(Handler &h, const int version)
  540. {
  541. h & id & move & mana;
  542. }
  543. bool operator<(const Hero&h)const{return id < h.id;}
  544. };
  545. std::set<Hero> heroes; //updates movement and mana points
  546. //std::vector<SetResources> res;//resource list
  547. std::map<ui8, std::vector<si32> > res; //player ID => resource value[res_id]
  548. std::vector<SetAvailableCreatures> cres;//creatures to be placed in towns
  549. ui32 day;
  550. bool resetBuilded;
  551. NewTurn(){type = 101;};
  552. template <typename Handler> void serialize(Handler &h, const int version)
  553. {
  554. h & heroes & cres & res & day & resetBuilded;
  555. }
  556. };
  557. struct Component : public CPack //2002 helper for object scrips informations
  558. {
  559. enum {PRIM_SKILL, SEC_SKILL, RESOURCE, CREATURE, ARTIFACT, EXPERIENCE, SPELL, MORALE=8, LUCK, BUILDING, HERO, FLAG};
  560. ui16 id, subtype; //id uses ^^^ enums, when id==EXPPERIENCE subtype==0 means exp points and subtype==1 levels)
  561. si32 val; // + give; - take
  562. si16 when; // 0 - now; +x - within x days; -x - per x days
  563. template <typename Handler> void serialize(Handler &h, const int version)
  564. {
  565. h & id & subtype & val & when;
  566. }
  567. Component(){type = 2002;};
  568. Component(ui16 Type, ui16 Subtype, si32 Val, si16 When):id(Type),subtype(Subtype),val(Val),when(When){type = 2002;};
  569. };
  570. struct InfoWindow : public CPackForClient //103 - displays simple info window
  571. {
  572. void applyCl(CClient *cl);
  573. MetaString text;
  574. std::vector<Component> components;
  575. ui8 player;
  576. ui16 soundID;
  577. template <typename Handler> void serialize(Handler &h, const int version)
  578. {
  579. h & text & components & player & soundID;
  580. }
  581. InfoWindow() {
  582. type = 103;
  583. soundID = 0;
  584. };
  585. };
  586. struct SetObjectProperty : public CPackForClient//1001
  587. {
  588. DLL_EXPORT void applyGs(CGameState *gs);
  589. void applyCl(CClient *cl);
  590. ui32 id;
  591. ui8 what; //1 - owner; 2 - blockvis; 3 - first stack count; 4 - visitors; 5 - visited; 6 - ID (if 34 then also def is replaced)
  592. ui32 val;
  593. SetObjectProperty(){type = 1001;};
  594. SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
  595. template <typename Handler> void serialize(Handler &h, const int version)
  596. {
  597. h & id & what & val;
  598. }
  599. };
  600. struct SetHoverName : public CPackForClient//1002
  601. {
  602. DLL_EXPORT void applyGs(CGameState *gs);
  603. ui32 id;
  604. MetaString name;
  605. SetHoverName(){type = 1002;};
  606. SetHoverName(ui32 ID, MetaString& Name):id(ID),name(Name){type = 1002;};
  607. template <typename Handler> void serialize(Handler &h, const int version)
  608. {
  609. h & id & name;
  610. }
  611. };
  612. struct HeroLevelUp : public Query//2000
  613. {
  614. void applyCl(CClient *cl);
  615. DLL_EXPORT void applyGs(CGameState *gs);
  616. si32 heroid;
  617. ui8 primskill, level;
  618. std::vector<ui16> skills;
  619. HeroLevelUp(){type = 2000;};
  620. template <typename Handler> void serialize(Handler &h, const int version)
  621. {
  622. h & id & heroid & primskill & level & skills;
  623. }
  624. };
  625. struct TradeComponents : public CPackForClient, public CPackForServer
  626. {
  627. ///used to handle info about components available in shops
  628. void applyCl(CClient *cl);
  629. DLL_EXPORT void applyGs(CGameState *gs);
  630. si32 heroid;
  631. ui32 objectid;
  632. std::map<ui16, Component> available, chosen, bought;
  633. template <typename Handler> void serialize(Handler &h, const int version)
  634. {
  635. h & heroid & objectid & available & chosen & bought;
  636. }
  637. };
  638. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  639. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  640. //Until sending reply player won't be allowed to take any actions
  641. struct BlockingDialog : public Query//2003
  642. {
  643. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  644. void applyCl(CClient *cl);
  645. MetaString text;
  646. std::vector<Component> components;
  647. ui8 player;
  648. ui8 flags;
  649. ui16 soundID;
  650. bool cancel() const
  651. {
  652. return flags & ALLOW_CANCEL;
  653. }
  654. bool selection() const
  655. {
  656. return flags & SELECTION;
  657. }
  658. BlockingDialog(bool yesno, bool Selection)
  659. {
  660. type = 2003;
  661. flags = 0;
  662. soundID = 0;
  663. if(yesno) flags |= ALLOW_CANCEL;
  664. if(Selection) flags |= SELECTION;
  665. }
  666. BlockingDialog()
  667. {
  668. type = 2003;
  669. flags = 0;
  670. soundID = 0;
  671. };
  672. template <typename Handler> void serialize(Handler &h, const int version)
  673. {
  674. h & id & text & components & player & flags & soundID;
  675. }
  676. };
  677. struct GarrisonDialog : public Query//2004
  678. {
  679. GarrisonDialog(){type = 2004;}
  680. void applyCl(CClient *cl);
  681. si32 objid, hid;
  682. bool removableUnits;
  683. template <typename Handler> void serialize(Handler &h, const int version)
  684. {
  685. h & id & objid & hid & removableUnits;
  686. }
  687. };
  688. struct BattleInfo;
  689. struct BattleStart : public CPackForClient//3000
  690. {
  691. BattleStart(){type = 3000;};
  692. void applyCl(CClient *cl);
  693. DLL_EXPORT void applyGs(CGameState *gs);
  694. BattleInfo * info;
  695. template <typename Handler> void serialize(Handler &h, const int version)
  696. {
  697. h & info;
  698. }
  699. };
  700. struct BattleNextRound : public CPackForClient//3001
  701. {
  702. BattleNextRound(){type = 3001;};
  703. void applyCl(CClient *cl);
  704. DLL_EXPORT void applyGs(CGameState *gs);
  705. si32 round;
  706. template <typename Handler> void serialize(Handler &h, const int version)
  707. {
  708. h & round;
  709. }
  710. };
  711. struct BattleSetActiveStack : public CPackForClient//3002
  712. {
  713. BattleSetActiveStack(){type = 3002;};
  714. void applyCl(CClient *cl);
  715. DLL_EXPORT void applyGs(CGameState *gs);
  716. ui32 stack;
  717. template <typename Handler> void serialize(Handler &h, const int version)
  718. {
  719. h & stack;
  720. }
  721. };
  722. struct BattleResult : public CPackForClient//3003
  723. {
  724. BattleResult(){type = 3003;};
  725. void applyFirstCl(CClient *cl);
  726. void applyGs(CGameState *gs);
  727. ui8 result; //0 - normal victory; 1 - escape; 2 - surrender
  728. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  729. std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
  730. ui32 exp[2]; //exp for attacker and defender
  731. std::set<ui32> artifacts; //artifacts taken from loser to winner
  732. template <typename Handler> void serialize(Handler &h, const int version)
  733. {
  734. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  735. }
  736. };
  737. struct BattleStackMoved : public CPackForClient//3004
  738. {
  739. ui32 stack, tile;
  740. ui8 ending, distance;
  741. BattleStackMoved(){type = 3004;};
  742. void applyFirstCl(CClient *cl);
  743. void applyGs(CGameState *gs);
  744. template <typename Handler> void serialize(Handler &h, const int version)
  745. {
  746. h & stack & tile & ending & distance;
  747. }
  748. };
  749. struct BattleStackAttacked : public CPackForClient//3005
  750. {
  751. BattleStackAttacked(){flags = 0; type = 3005;};
  752. void applyCl(CClient *cl);
  753. DLL_EXPORT void applyGs(CGameState *gs);
  754. ui32 stackAttacked, attackerID;
  755. ui32 newAmount, newHP, killedAmount, damageAmount;
  756. ui8 flags; //1 - is stack killed; 2 - is there special effect to be shown;
  757. ui32 effect; //set only if flag 2 is present
  758. bool killed() const//if target stack was killed
  759. {
  760. return flags & 1;
  761. }
  762. bool isEffect() const//if target stack was killed
  763. {
  764. return flags & 2;
  765. }
  766. template <typename Handler> void serialize(Handler &h, const int version)
  767. {
  768. h & stackAttacked & attackerID & newAmount & newHP & flags & killedAmount & damageAmount & effect;
  769. }
  770. bool operator<(const BattleStackAttacked &b) const
  771. {
  772. return stackAttacked < b.stackAttacked;
  773. }
  774. };
  775. struct BattleAttack : public CPackForClient//3006
  776. {
  777. BattleAttack(){flags = 0; type = 3006;};
  778. void applyFirstCl(CClient *cl);
  779. DLL_EXPORT void applyGs(CGameState *gs);
  780. void applyCl(CClient *cl);
  781. std::vector<BattleStackAttacked> bsa;
  782. ui32 stackAttacking;
  783. ui8 flags;
  784. bool shot()//distance attack - decrease number of shots
  785. {
  786. return flags & 1;
  787. }
  788. bool counter()//is it counterattack?
  789. {
  790. return flags & 2;
  791. }
  792. bool lucky()
  793. {
  794. return flags & 4;
  795. }
  796. bool unlucky()
  797. {
  798. //TODO: support?
  799. return flags & 8;
  800. }
  801. //bool killed() //if target stack was killed
  802. //{
  803. // return bsa.killed();
  804. //}
  805. template <typename Handler> void serialize(Handler &h, const int version)
  806. {
  807. h & bsa & stackAttacking & flags;
  808. }
  809. };
  810. struct StartAction : public CPackForClient//3007
  811. {
  812. StartAction(){type = 3007;};
  813. StartAction(const BattleAction &act){ba = act; type = 3007;};
  814. void applyFirstCl(CClient *cl);
  815. DLL_EXPORT void applyGs(CGameState *gs);
  816. BattleAction ba;
  817. template <typename Handler> void serialize(Handler &h, const int version)
  818. {
  819. h & ba;
  820. }
  821. };
  822. struct EndAction : public CPackForClient//3008
  823. {
  824. EndAction(){type = 3008;};
  825. void applyCl(CClient *cl);
  826. template <typename Handler> void serialize(Handler &h, const int version)
  827. {
  828. }
  829. };
  830. struct SpellCast : public CPackForClient//3009
  831. {
  832. SpellCast(){type = 3009;};
  833. DLL_EXPORT void applyGs(CGameState *gs);
  834. void applyCl(CClient *cl);
  835. si32 dmgToDisplay; //this amount will be displayed as amount of damage dealt by spell
  836. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  837. ui32 id; //id of spell
  838. ui8 skill; //caster's skill level
  839. ui16 tile; //destination tile (may not be set in some global/mass spells
  840. std::vector<ui32> resisted; //ids of creatures that resisted this spell
  841. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  842. ui8 castedByHero; //if true - spell has been casted by hero, otherwise by a creature
  843. template <typename Handler> void serialize(Handler &h, const int version)
  844. {
  845. h & dmgToDisplay & side & id & skill & tile & resisted & affectedCres & castedByHero;
  846. }
  847. };
  848. struct SetStackEffect : public CPackForClient //3010
  849. {
  850. SetStackEffect(){type = 3010;};
  851. DLL_EXPORT void applyGs(CGameState *gs);
  852. void applyCl(CClient *cl);
  853. std::vector<ui32> stacks; //affected stacks (IDs)
  854. CStack::StackEffect effect; //type of effect
  855. template <typename Handler> void serialize(Handler &h, const int version)
  856. {
  857. h & stacks & effect;
  858. }
  859. };
  860. struct StacksInjured : public CPackForClient //3011
  861. {
  862. StacksInjured(){type = 3011;}
  863. DLL_EXPORT void applyGs(CGameState *gs);
  864. void applyCl(CClient *cl);
  865. std::vector<BattleStackAttacked> stacks;
  866. template <typename Handler> void serialize(Handler &h, const int version)
  867. {
  868. h & stacks;
  869. }
  870. };
  871. struct BattleResultsApplied : public CPackForClient //3012
  872. {
  873. BattleResultsApplied(){type = 3012;}
  874. ui8 player1, player2;
  875. void applyCl(CClient *cl);
  876. template <typename Handler> void serialize(Handler &h, const int version)
  877. {
  878. h & player1 & player2;
  879. }
  880. };
  881. struct StacksHealedOrResurrected : public CPackForClient //3013
  882. {
  883. StacksHealedOrResurrected(){type = 3013;}
  884. DLL_EXPORT void applyGs(CGameState *gs);
  885. void applyCl(CClient *cl);
  886. struct HealInfo
  887. {
  888. ui32 stackID;
  889. ui32 healedHP;
  890. ui8 lowLevelResurrection; //in case this stack is resurrected by this heal, it will be marked as SUMMONED
  891. template <typename Handler> void serialize(Handler &h, const int version)
  892. {
  893. h & stackID & healedHP & lowLevelResurrection;
  894. }
  895. };
  896. std::vector<HealInfo> healedStacks;
  897. template <typename Handler> void serialize(Handler &h, const int version)
  898. {
  899. h & healedStacks;
  900. }
  901. };
  902. struct ObstaclesRemoved : public CPackForClient //3014
  903. {
  904. ObstaclesRemoved(){type = 3014;}
  905. DLL_EXPORT void applyGs(CGameState *gs);
  906. void applyCl(CClient *cl);
  907. std::set<si32> obstacles; //uniqueIDs of removed obstacles
  908. template <typename Handler> void serialize(Handler &h, const int version)
  909. {
  910. h & obstacles;
  911. }
  912. };
  913. struct CatapultAttack : public CPackForClient //3015
  914. {
  915. CatapultAttack(){type = 3015;}
  916. DLL_EXPORT void applyGs(CGameState *gs);
  917. void applyCl(CClient *cl);
  918. std::set< std::pair< std::pair< ui8, si16 >, ui8> > attackedParts; // < <attackedPartOfWall, attacked hex >, damageDealt>
  919. //attackedPartOfWall; //[0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate;
  920. //damageDealt;
  921. int attacker; //if -1, then a spell caused this
  922. template <typename Handler> void serialize(Handler &h, const int version)
  923. {
  924. h & attackedParts & attacker;
  925. }
  926. };
  927. struct BattleStacksRemoved : public CPackForClient //3016
  928. {
  929. BattleStacksRemoved(){type = 3016;}
  930. DLL_EXPORT void applyGs(CGameState *gs);
  931. void applyCl(CClient *cl);
  932. std::set<ui32> stackIDs; //IDs of removed stacks
  933. template <typename Handler> void serialize(Handler &h, const int version)
  934. {
  935. h & stackIDs;
  936. }
  937. };
  938. struct ShowInInfobox : public CPackForClient //107
  939. {
  940. ShowInInfobox(){type = 107;};
  941. ui8 player;
  942. Component c;
  943. MetaString text;
  944. void applyCl(CClient *cl);
  945. template <typename Handler> void serialize(Handler &h, const int version)
  946. {
  947. h & player & c & text;
  948. }
  949. };
  950. /***********************************************************************************************************/
  951. struct CloseServer : public CPackForServer
  952. {
  953. bool applyGh(CGameHandler *gh);
  954. template <typename Handler> void serialize(Handler &h, const int version)
  955. {}
  956. };
  957. struct EndTurn : public CPackForServer
  958. {
  959. bool applyGh(CGameHandler *gh);
  960. template <typename Handler> void serialize(Handler &h, const int version)
  961. {}
  962. };
  963. struct DismissHero : public CPackForServer
  964. {
  965. DismissHero(){};
  966. DismissHero(si32 HID) : hid(HID) {};
  967. si32 hid;
  968. bool applyGh(CGameHandler *gh);
  969. template <typename Handler> void serialize(Handler &h, const int version)
  970. {
  971. h & hid;
  972. }
  973. };
  974. struct MoveHero : public CPackForServer
  975. {
  976. MoveHero(){};
  977. MoveHero(const int3 &Dest, si32 HID) : dest(Dest), hid(HID){};
  978. int3 dest;
  979. si32 hid;
  980. bool applyGh(CGameHandler *gh);
  981. template <typename Handler> void serialize(Handler &h, const int version)
  982. {
  983. h & dest & hid;
  984. }
  985. };
  986. struct ArrangeStacks : public CPackForServer
  987. {
  988. ArrangeStacks(){};
  989. ArrangeStacks(ui8 W, ui8 P1, ui8 P2, si32 ID1, si32 ID2, si32 VAL)
  990. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  991. ui8 what; //1 - swap; 2 - merge; 3 - split
  992. ui8 p1, p2; //positions of first and second stack
  993. si32 id1, id2; //ids of objects with garrison
  994. si32 val;
  995. bool applyGh(CGameHandler *gh);
  996. template <typename Handler> void serialize(Handler &h, const int version)
  997. {
  998. h & what & p1 & p2 & id1 & id2 & val;
  999. }
  1000. };
  1001. struct DisbandCreature : public CPackForServer
  1002. {
  1003. DisbandCreature(){};
  1004. DisbandCreature(ui8 Pos, si32 ID):pos(Pos),id(ID){};
  1005. ui8 pos; //stack pos
  1006. si32 id; //object id
  1007. bool applyGh(CGameHandler *gh);
  1008. template <typename Handler> void serialize(Handler &h, const int version)
  1009. {
  1010. h & pos & id;
  1011. }
  1012. };
  1013. struct BuildStructure : public CPackForServer
  1014. {
  1015. BuildStructure(){};
  1016. BuildStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  1017. si32 bid, tid; //structure and town ids
  1018. bool applyGh(CGameHandler *gh);
  1019. template <typename Handler> void serialize(Handler &h, const int version)
  1020. {
  1021. h & tid & bid;
  1022. }
  1023. };
  1024. struct RazeStructure : public BuildStructure
  1025. {
  1026. RazeStructure(){};
  1027. //RazeStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  1028. bool applyGh(CGameHandler *gh);
  1029. };
  1030. struct RecruitCreatures : public CPackForServer
  1031. {
  1032. RecruitCreatures(){};
  1033. RecruitCreatures(si32 TID, si32 CRID, si32 Amount):tid(TID),crid(CRID),amount(Amount){};
  1034. si32 tid; //town id
  1035. ui32 crid, amount;//creature ID and amount
  1036. bool applyGh(CGameHandler *gh);
  1037. template <typename Handler> void serialize(Handler &h, const int version)
  1038. {
  1039. h & tid & crid & amount;
  1040. }
  1041. };
  1042. struct UpgradeCreature : public CPackForServer
  1043. {
  1044. UpgradeCreature(){};
  1045. UpgradeCreature(ui8 Pos, si32 ID, si32 CRID):pos(Pos),id(ID), cid(CRID){};
  1046. ui8 pos; //stack pos
  1047. si32 id; //object id
  1048. si32 cid; //id of type to which we want make upgrade
  1049. bool applyGh(CGameHandler *gh);
  1050. template <typename Handler> void serialize(Handler &h, const int version)
  1051. {
  1052. h & pos & id & cid;
  1053. }
  1054. };
  1055. struct GarrisonHeroSwap : public CPackForServer
  1056. {
  1057. GarrisonHeroSwap(){};
  1058. GarrisonHeroSwap(si32 TID):tid(TID){};
  1059. si32 tid;
  1060. bool applyGh(CGameHandler *gh);
  1061. template <typename Handler> void serialize(Handler &h, const int version)
  1062. {
  1063. h & tid;
  1064. }
  1065. };
  1066. struct ExchangeArtifacts : public CPackForServer
  1067. {
  1068. ExchangeArtifacts(){};
  1069. ExchangeArtifacts(si32 H1, si32 H2, ui16 S1, ui16 S2)
  1070. :hid1(H1),hid2(H2),slot1(S1),slot2(S2){};
  1071. si32 hid1, hid2;
  1072. ui16 slot1, slot2;
  1073. bool applyGh(CGameHandler *gh);
  1074. template <typename Handler> void serialize(Handler &h, const int version)
  1075. {
  1076. h & hid1 & hid2 & slot1 & slot2;
  1077. }
  1078. };
  1079. struct AssembleArtifacts : public CPackForServer
  1080. {
  1081. AssembleArtifacts(){};
  1082. AssembleArtifacts(si32 _heroID, ui16 _artifactSlot, bool _assemble, ui32 _assembleTo)
  1083. : heroID(_heroID), artifactSlot(_artifactSlot), assemble(_assemble), assembleTo(_assembleTo){};
  1084. si32 heroID;
  1085. ui16 artifactSlot;
  1086. bool assemble; // True to assemble artifact, false to disassemble.
  1087. ui32 assembleTo; // Artifact to assemble into.
  1088. bool applyGh(CGameHandler *gh);
  1089. template <typename Handler> void serialize(Handler &h, const int version)
  1090. {
  1091. h & heroID & artifactSlot & assemble & assembleTo;
  1092. }
  1093. };
  1094. struct BuyArtifact : public CPackForServer
  1095. {
  1096. BuyArtifact(){};
  1097. BuyArtifact(si32 HID, si32 AID):hid(HID),aid(AID){};
  1098. si32 hid, aid; //hero and artifact id
  1099. bool applyGh(CGameHandler *gh);
  1100. template <typename Handler> void serialize(Handler &h, const int version)
  1101. {
  1102. h & hid & aid;
  1103. }
  1104. };
  1105. struct TradeOnMarketplace : public CPackForServer
  1106. {
  1107. TradeOnMarketplace(){};
  1108. TradeOnMarketplace(ui8 Player, ui8 Mode, /*si32 ID, */ui32 R1, ui32 R2, ui32 Val)
  1109. :player(Player),mode(Mode),/*id(ID),*/r1(R1),r2(R2),val(Val){};
  1110. ui8 player;
  1111. ui8 mode;//0 - res<->res;
  1112. //si32 id; //object id
  1113. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res
  1114. ui32 val; //units of sold resource
  1115. bool applyGh(CGameHandler *gh);
  1116. template <typename Handler> void serialize(Handler &h, const int version)
  1117. {
  1118. h & player & mode & /*id & */r1 & r2 & val;
  1119. }
  1120. };
  1121. struct SetFormation : public CPackForServer
  1122. {
  1123. SetFormation(){};
  1124. SetFormation(si32 HID, ui8 Formation):hid(HID),formation(Formation){};
  1125. si32 hid;
  1126. ui8 formation;
  1127. bool applyGh(CGameHandler *gh);
  1128. template <typename Handler> void serialize(Handler &h, const int version)
  1129. {
  1130. h & hid & formation;
  1131. }
  1132. };
  1133. struct HireHero : public CPackForServer
  1134. {
  1135. HireHero(){};
  1136. HireHero(si32 HID, si32 TID):hid(HID),tid(TID){};
  1137. si32 hid, tid; //available hero serial and town id
  1138. bool applyGh(CGameHandler *gh);
  1139. template <typename Handler> void serialize(Handler &h, const int version)
  1140. {
  1141. h & hid & tid;
  1142. }
  1143. };
  1144. struct BuildBoat : public CPackForServer
  1145. {
  1146. BuildBoat(){};
  1147. si32 objid; //where player wants to buy a boat
  1148. bool applyGh(CGameHandler *gh);
  1149. template <typename Handler> void serialize(Handler &h, const int version)
  1150. {
  1151. h & objid;
  1152. }
  1153. };
  1154. struct QueryReply : public CPackForServer
  1155. {
  1156. QueryReply(){type = 6000;};
  1157. QueryReply(ui32 QID, ui32 Answer):qid(QID),answer(Answer){type = 6000;};
  1158. ui32 qid, answer; //hero and artifact id
  1159. bool applyGh(CGameHandler *gh);
  1160. template <typename Handler> void serialize(Handler &h, const int version)
  1161. {
  1162. h & qid & answer;
  1163. }
  1164. };
  1165. struct MakeAction : public CPackForServer
  1166. {
  1167. MakeAction(){};
  1168. MakeAction(const BattleAction &BA):ba(BA){};
  1169. BattleAction ba;
  1170. bool applyGh(CGameHandler *gh);
  1171. template <typename Handler> void serialize(Handler &h, const int version)
  1172. {
  1173. h & ba;
  1174. }
  1175. };
  1176. struct MakeCustomAction : public CPackForServer
  1177. {
  1178. MakeCustomAction(){};
  1179. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1180. BattleAction ba;
  1181. bool applyGh(CGameHandler *gh);
  1182. template <typename Handler> void serialize(Handler &h, const int version)
  1183. {
  1184. h & ba;
  1185. }
  1186. };
  1187. struct DigWithHero : public CPackForServer
  1188. {
  1189. DigWithHero(){}
  1190. si32 id; //digging hero id
  1191. bool applyGh(CGameHandler *gh);
  1192. template <typename Handler> void serialize(Handler &h, const int version)
  1193. {
  1194. h & id;
  1195. }
  1196. };
  1197. /***********************************************************************************************************/
  1198. struct SaveGame : public CPackForClient, public CPackForServer
  1199. {
  1200. SaveGame(){};
  1201. SaveGame(const std::string &Fname) :fname(Fname){};
  1202. std::string fname;
  1203. void applyCl(CClient *cl);
  1204. void applyGs(CGameState *gs){};
  1205. bool applyGh(CGameHandler *gh);
  1206. template <typename Handler> void serialize(Handler &h, const int version)
  1207. {
  1208. h & fname;
  1209. }
  1210. };
  1211. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  1212. {
  1213. PlayerMessage(){CPackForClient::type = 513;};
  1214. PlayerMessage(ui8 Player, const std::string &Text)
  1215. :player(Player),text(Text)
  1216. {CPackForClient::type = 513;};
  1217. void applyCl(CClient *cl);
  1218. void applyGs(CGameState *gs){};
  1219. bool applyGh(CGameHandler *gh);
  1220. ui8 player;
  1221. std::string text;
  1222. template <typename Handler> void serialize(Handler &h, const int version)
  1223. {
  1224. h & text & player;
  1225. }
  1226. };
  1227. struct SetSelection : public CPackForClient, public CPackForServer //514
  1228. {
  1229. SetSelection(){CPackForClient::type = 514;};
  1230. DLL_EXPORT void applyGs(CGameState *gs);
  1231. bool applyGh(CGameHandler *gh);
  1232. void applyCl(CClient *cl);
  1233. ui8 player;
  1234. ui32 id;
  1235. template <typename Handler> void serialize(Handler &h, const int version)
  1236. {
  1237. h & id & player;
  1238. }
  1239. };
  1240. struct CenterView : public CPackForClient//515
  1241. {
  1242. CenterView(){CPackForClient::type = 515;};
  1243. void applyCl(CClient *cl);
  1244. ui8 player;
  1245. int3 pos;
  1246. ui32 focusTime; //ms
  1247. template <typename Handler> void serialize(Handler &h, const int version)
  1248. {
  1249. h & pos & player & focusTime;
  1250. }
  1251. };
  1252. #endif //__NETPACKS_H__