NetPacks.h 33 KB

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