NetPacks.h 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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;
  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 YourTurn : public CPackForClient //100
  150. {
  151. YourTurn(){type = 100;};
  152. void applyCl(CClient *cl);
  153. DLL_EXPORT void applyGs(CGameState *gs);
  154. ui8 player;
  155. template <typename Handler> void serialize(Handler &h, const int version)
  156. {
  157. h & player;
  158. }
  159. };
  160. struct SetResource : public CPackForClient //102
  161. {
  162. SetResource(){type = 102;};
  163. void applyCl(CClient *cl);
  164. DLL_EXPORT void applyGs(CGameState *gs);
  165. ui8 player, resid;
  166. si32 val;
  167. template <typename Handler> void serialize(Handler &h, const int version)
  168. {
  169. h & player & resid & val;
  170. }
  171. };
  172. struct SetResources : public CPackForClient //104
  173. {
  174. SetResources(){res.resize(RESOURCE_QUANTITY);type = 104;};
  175. void applyCl(CClient *cl);
  176. DLL_EXPORT void applyGs(CGameState *gs);
  177. ui8 player;
  178. std::vector<si32> res; //res[resid] => res amount
  179. template <typename Handler> void serialize(Handler &h, const int version)
  180. {
  181. h & player & res;
  182. }
  183. };
  184. struct SetPrimSkill : public CPackForClient //105
  185. {
  186. SetPrimSkill(){type = 105;};
  187. void applyCl(CClient *cl);
  188. DLL_EXPORT void applyGs(CGameState *gs);
  189. ui8 abs; //0 - changes by value; 1 - sets to value
  190. si32 id;
  191. ui16 which, val;
  192. template <typename Handler> void serialize(Handler &h, const int version)
  193. {
  194. h & abs & id & which & val;
  195. }
  196. };
  197. struct SetSecSkill : public CPackForClient //106
  198. {
  199. SetSecSkill(){type = 106;};
  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, val;
  205. template <typename Handler> void serialize(Handler &h, const int version)
  206. {
  207. h & abs & id & which & val;
  208. }
  209. };
  210. struct HeroVisitCastle : public CPackForClient //108
  211. {
  212. HeroVisitCastle(){flags=0;type = 108;};
  213. void applyCl(CClient *cl);
  214. DLL_EXPORT void applyGs(CGameState *gs);
  215. ui8 flags; //1 - start, 2 - garrison
  216. ui32 tid, hid;
  217. bool start() //if hero is entering castle (if false - leaving)
  218. {
  219. return flags & 1;
  220. }
  221. bool garrison() //if hero is entering/leaving garrison (if false - it's only visiting hero)
  222. {
  223. return flags & 2;
  224. }
  225. template <typename Handler> void serialize(Handler &h, const int version)
  226. {
  227. h & flags & tid & hid;
  228. }
  229. };
  230. struct ChangeSpells : public CPackForClient //109
  231. {
  232. ChangeSpells(){type = 109;};
  233. void applyCl(CClient *cl);
  234. DLL_EXPORT void applyGs(CGameState *gs);
  235. ui8 learn; //1 - gives spell, 0 - takes
  236. ui32 hid;
  237. std::set<ui32> spells;
  238. template <typename Handler> void serialize(Handler &h, const int version)
  239. {
  240. h & learn & hid & spells;
  241. }
  242. };
  243. struct SetMana : public CPackForClient //110
  244. {
  245. SetMana(){type = 110;};
  246. void applyCl(CClient *cl);
  247. DLL_EXPORT void applyGs(CGameState *gs);
  248. si32 hid, val;
  249. template <typename Handler> void serialize(Handler &h, const int version)
  250. {
  251. h & val & hid;
  252. }
  253. };
  254. struct SetMovePoints : public CPackForClient //111
  255. {
  256. SetMovePoints(){type = 111;};
  257. void applyCl(CClient *cl);
  258. DLL_EXPORT void applyGs(CGameState *gs);
  259. ui32 hid, val;
  260. template <typename Handler> void serialize(Handler &h, const int version)
  261. {
  262. h & val & hid;
  263. }
  264. };
  265. struct FoWChange : public CPackForClient //112
  266. {
  267. FoWChange(){type = 112;};
  268. void applyCl(CClient *cl);
  269. DLL_EXPORT void applyGs(CGameState *gs);
  270. std::set<int3> tiles;
  271. ui8 player, mode; //mode==0 - hide, mode==1 - reveal
  272. template <typename Handler> void serialize(Handler &h, const int version)
  273. {
  274. h & tiles & player & mode;
  275. }
  276. };
  277. struct SetAvailableHeroes : public CPackForClient //113
  278. {
  279. SetAvailableHeroes(){type = 113;flags=0;};
  280. void applyCl(CClient *cl);
  281. DLL_EXPORT void applyGs(CGameState *gs);
  282. ui8 player;
  283. si32 hid1, hid2;
  284. ui8 flags; //1 - reset army of hero1; 2 - reset army of hero 2
  285. template <typename Handler> void serialize(Handler &h, const int version)
  286. {
  287. h & player & hid1 & hid2 & flags;
  288. }
  289. };
  290. struct GiveBonus : public CPackForClient //115
  291. {
  292. GiveBonus(){type = 115;};
  293. void applyCl(CClient *cl);
  294. DLL_EXPORT void applyGs(CGameState *gs);
  295. ui32 hid;
  296. HeroBonus bonus;
  297. MetaString bdescr;
  298. template <typename Handler> void serialize(Handler &h, const int version)
  299. {
  300. h & bonus & hid & bdescr;
  301. }
  302. };
  303. struct ChangeObjPos : public CPackForClient //116
  304. {
  305. ChangeObjPos(){type = 116;};
  306. void applyFirstCl(CClient *cl);
  307. void applyCl(CClient *cl);
  308. DLL_EXPORT void applyGs(CGameState *gs);
  309. ui32 objid;
  310. int3 nPos;
  311. ui8 flags; //bit flags: 1 - redraw
  312. template <typename Handler> void serialize(Handler &h, const int version)
  313. {
  314. h & objid & nPos & flags;
  315. }
  316. };
  317. struct RemoveObject : public CPackForClient //500
  318. {
  319. RemoveObject(){type = 500;};
  320. RemoveObject(si32 ID){id = ID;type = 500;};
  321. void applyFirstCl(CClient *cl);
  322. void applyCl(CClient *cl);
  323. DLL_EXPORT void applyGs(CGameState *gs);
  324. si32 id;
  325. template <typename Handler> void serialize(Handler &h, const int version)
  326. {
  327. h & id;
  328. }
  329. };
  330. struct TryMoveHero : public CPackForClient //501
  331. {
  332. TryMoveHero(){type = 501;};
  333. void applyFirstCl(CClient *cl);
  334. void applyCl(CClient *cl);
  335. void applyGs(CGameState *gs);
  336. enum EResult
  337. {
  338. FAILED, SUCCESS, TELEPORTATION, RESERVED___, BLOCKING_VISIT, EMBARK, DISEMBARK
  339. };
  340. ui32 id, movePoints;
  341. ui8 result; //uses EResult
  342. int3 start, end;
  343. std::set<int3> fowRevealed; //revealed tiles
  344. template <typename Handler> void serialize(Handler &h, const int version)
  345. {
  346. h & id & result & start & end & movePoints & fowRevealed;
  347. }
  348. };
  349. struct SetGarrisons : public CPackForClient //502
  350. {
  351. SetGarrisons(){type = 502;};
  352. void applyCl(CClient *cl);
  353. DLL_EXPORT void applyGs(CGameState *gs);
  354. std::map<ui32,CCreatureSet> garrs;
  355. template <typename Handler> void serialize(Handler &h, const int version)
  356. {
  357. h & garrs;
  358. }
  359. };
  360. struct NewStructures : public CPackForClient //504
  361. {
  362. NewStructures(){type = 504;};
  363. void applyCl(CClient *cl);
  364. DLL_EXPORT void applyGs(CGameState *gs);
  365. si32 tid;
  366. std::set<si32> bid;
  367. si16 builded;
  368. template <typename Handler> void serialize(Handler &h, const int version)
  369. {
  370. h & tid & bid & builded;
  371. }
  372. };
  373. struct SetAvailableCreatures : public CPackForClient //506
  374. {
  375. SetAvailableCreatures(){type = 506;};
  376. void applyCl(CClient *cl);
  377. DLL_EXPORT void applyGs(CGameState *gs);
  378. si32 tid;
  379. std::vector<std::pair<ui32, std::vector<ui32> > > creatures;
  380. template <typename Handler> void serialize(Handler &h, const int version)
  381. {
  382. h & tid & creatures;
  383. }
  384. };
  385. struct SetHeroesInTown : public CPackForClient //508
  386. {
  387. SetHeroesInTown(){type = 508;};
  388. void applyCl(CClient *cl);
  389. DLL_EXPORT void applyGs(CGameState *gs);
  390. si32 tid, visiting, garrison; //id of town, visiting hero, hero in garrison
  391. template <typename Handler> void serialize(Handler &h, const int version)
  392. {
  393. h & tid & visiting & garrison;
  394. }
  395. };
  396. struct SetHeroArtifacts : public CPackForClient //509
  397. {
  398. SetHeroArtifacts(){type = 509;};
  399. void applyCl(CClient *cl);
  400. DLL_EXPORT void applyGs(CGameState *gs);
  401. DLL_EXPORT void setArtAtPos(ui16 pos, int art);
  402. si32 hid;
  403. std::vector<ui32> artifacts; //hero's artifacts from bag
  404. 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
  405. template <typename Handler> void serialize(Handler &h, const int version)
  406. {
  407. h & hid & artifacts & artifWorn;
  408. }
  409. std::vector<HeroBonus*> gained, lost; //used locally as hlp when applying
  410. };
  411. struct HeroRecruited : public CPackForClient //515
  412. {
  413. HeroRecruited(){type = 515;};
  414. void applyCl(CClient *cl);
  415. DLL_EXPORT void applyGs(CGameState *gs);
  416. si32 hid, tid; //subID of hero
  417. int3 tile;
  418. ui8 player;
  419. template <typename Handler> void serialize(Handler &h, const int version)
  420. {
  421. h & hid & tid & tile & player;
  422. }
  423. };
  424. struct GiveHero : public CPackForClient //516
  425. {
  426. GiveHero(){type = 516;};
  427. void applyFirstCl(CClient *cl);
  428. void applyCl(CClient *cl);
  429. DLL_EXPORT void applyGs(CGameState *gs);
  430. ui32 id; //object id
  431. ui8 player;
  432. template <typename Handler> void serialize(Handler &h, const int version)
  433. {
  434. h & id & player;
  435. }
  436. };
  437. struct OpenWindow : public CPackForClient //517
  438. {
  439. OpenWindow(){type = 517;};
  440. void applyCl(CClient *cl);
  441. enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL, SHIPYARD_WINDOW};
  442. ui8 window;
  443. ui32 id1, id2;
  444. template <typename Handler> void serialize(Handler &h, const int version)
  445. {
  446. h & window & id1 & id2;
  447. }
  448. };
  449. struct NewObject : public CPackForClient //518
  450. {
  451. NewObject(){type = 518;};
  452. void applyCl(CClient *cl);
  453. DLL_EXPORT void applyGs(CGameState *gs);
  454. ui32 ID, subID;
  455. int3 pos;
  456. int id; //used internally
  457. template <typename Handler> void serialize(Handler &h, const int version)
  458. {
  459. h & ID & subID & pos;
  460. }
  461. };
  462. struct NewTurn : public CPackForClient //101
  463. {
  464. DLL_EXPORT void applyGs(CGameState *gs);
  465. struct Hero
  466. {
  467. ui32 id, move, mana; //id is a general serial id
  468. template <typename Handler> void serialize(Handler &h, const int version)
  469. {
  470. h & id & move & mana;
  471. }
  472. bool operator<(const Hero&h)const{return id < h.id;}
  473. };
  474. std::set<Hero> heroes; //updates movement and mana points
  475. std::vector<SetResources> res;//resource list
  476. std::vector<SetAvailableCreatures> cres;//resource list
  477. ui32 day;
  478. bool resetBuilded;
  479. NewTurn(){type = 101;};
  480. template <typename Handler> void serialize(Handler &h, const int version)
  481. {
  482. h & heroes & cres & res & day & resetBuilded;
  483. }
  484. };
  485. struct Component : public CPack //2002 helper for object scrips informations
  486. {
  487. enum {PRIM_SKILL,SEC_SKILL,RESOURCE,CREATURE,ARTIFACT,EXPERIENCE,SPELL, MORALE=8, LUCK};
  488. ui16 id, subtype; //id uses ^^^ enums, when id==EXPPERIENCE subtype==0 means exp points and subtype==1 levels)
  489. si32 val; // + give; - take
  490. si16 when; // 0 - now; +x - within x days; -x - per x days
  491. template <typename Handler> void serialize(Handler &h, const int version)
  492. {
  493. h & id & subtype & val & when;
  494. }
  495. Component(){type = 2002;};
  496. Component(ui16 Type, ui16 Subtype, si32 Val, si16 When):id(Type),subtype(Subtype),val(Val),when(When){type = 2002;};
  497. };
  498. struct InfoWindow : public CPackForClient //103 - displays simple info window
  499. {
  500. void applyCl(CClient *cl);
  501. MetaString text;
  502. std::vector<Component> components;
  503. ui8 player;
  504. ui16 soundID;
  505. template <typename Handler> void serialize(Handler &h, const int version)
  506. {
  507. h & text & components & player & soundID;
  508. }
  509. InfoWindow() {
  510. type = 103;
  511. soundID = 0;
  512. };
  513. };
  514. struct SetObjectProperty : public CPackForClient//1001
  515. {
  516. DLL_EXPORT void applyGs(CGameState *gs);
  517. void applyCl(CClient *cl);
  518. ui32 id;
  519. ui8 what; //1 - owner; 2 - blockvis; 3 - first stack count; 4 - visitors; 5 - visited; 6 - ID (if 34 then also def is replaced)
  520. ui32 val;
  521. SetObjectProperty(){type = 1001;};
  522. SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
  523. template <typename Handler> void serialize(Handler &h, const int version)
  524. {
  525. h & id & what & val;
  526. }
  527. };
  528. struct SetHoverName : public CPackForClient//1002
  529. {
  530. DLL_EXPORT void applyGs(CGameState *gs);
  531. ui32 id;
  532. MetaString name;
  533. SetHoverName(){type = 1002;};
  534. SetHoverName(ui32 ID, MetaString& Name):id(ID),name(Name){type = 1002;};
  535. template <typename Handler> void serialize(Handler &h, const int version)
  536. {
  537. h & id & name;
  538. }
  539. };
  540. struct HeroLevelUp : public Query//2000
  541. {
  542. void applyCl(CClient *cl);
  543. DLL_EXPORT void applyGs(CGameState *gs);
  544. si32 heroid;
  545. ui8 primskill, level;
  546. std::vector<ui16> skills;
  547. HeroLevelUp(){type = 2000;};
  548. template <typename Handler> void serialize(Handler &h, const int version)
  549. {
  550. h & id & heroid & primskill & level & skills;
  551. }
  552. };
  553. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  554. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  555. //Until sending reply player won't be allowed to take any actions
  556. struct BlockingDialog : public Query//2003
  557. {
  558. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  559. void applyCl(CClient *cl);
  560. MetaString text;
  561. std::vector<Component> components;
  562. ui8 player;
  563. ui8 flags;
  564. ui16 soundID;
  565. bool cancel() const
  566. {
  567. return flags & ALLOW_CANCEL;
  568. }
  569. bool selection() const
  570. {
  571. return flags & SELECTION;
  572. }
  573. BlockingDialog(bool yesno, bool Selection)
  574. {
  575. type = 2003;
  576. flags = 0;
  577. soundID = 0;
  578. if(yesno) flags |= ALLOW_CANCEL;
  579. if(Selection) flags |= SELECTION;
  580. }
  581. BlockingDialog()
  582. {
  583. type = 2003;
  584. flags = 0;
  585. soundID = 0;
  586. };
  587. template <typename Handler> void serialize(Handler &h, const int version)
  588. {
  589. h & id & text & components & player & flags & soundID;
  590. }
  591. };
  592. struct GarrisonDialog : public Query//2004
  593. {
  594. GarrisonDialog(){type = 2004;}
  595. void applyCl(CClient *cl);
  596. si32 objid, hid;
  597. template <typename Handler> void serialize(Handler &h, const int version)
  598. {
  599. h & id & objid & hid;
  600. }
  601. };
  602. struct BattleInfo;
  603. struct BattleStart : public CPackForClient//3000
  604. {
  605. BattleStart(){type = 3000;};
  606. void applyCl(CClient *cl);
  607. DLL_EXPORT void applyGs(CGameState *gs);
  608. BattleInfo * info;
  609. template <typename Handler> void serialize(Handler &h, const int version)
  610. {
  611. h & info;
  612. }
  613. };
  614. struct BattleNextRound : public CPackForClient//3001
  615. {
  616. BattleNextRound(){type = 3001;};
  617. void applyCl(CClient *cl);
  618. DLL_EXPORT void applyGs(CGameState *gs);
  619. si32 round;
  620. template <typename Handler> void serialize(Handler &h, const int version)
  621. {
  622. h & round;
  623. }
  624. };
  625. struct BattleSetActiveStack : public CPackForClient//3002
  626. {
  627. BattleSetActiveStack(){type = 3002;};
  628. void applyCl(CClient *cl);
  629. DLL_EXPORT void applyGs(CGameState *gs);
  630. ui32 stack;
  631. template <typename Handler> void serialize(Handler &h, const int version)
  632. {
  633. h & stack;
  634. }
  635. };
  636. struct BattleResult : public CPackForClient//3003
  637. {
  638. BattleResult(){type = 3003;};
  639. void applyFirstCl(CClient *cl);
  640. void applyGs(CGameState *gs);
  641. ui8 result; //0 - normal victory; 1 - escape; 2 - surrender
  642. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  643. std::set<std::pair<ui32,si32> > casualties[2]; //first => casualties of attackers - set of pairs crid<>number
  644. ui32 exp[2]; //exp for attacker and defender
  645. std::set<ui32> artifacts; //artifacts taken from loser to winner
  646. template <typename Handler> void serialize(Handler &h, const int version)
  647. {
  648. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  649. }
  650. };
  651. struct BattleStackMoved : public CPackForClient//3004
  652. {
  653. ui32 stack, tile;
  654. ui8 ending, distance;
  655. BattleStackMoved(){type = 3004;};
  656. void applyFirstCl(CClient *cl);
  657. void applyGs(CGameState *gs);
  658. template <typename Handler> void serialize(Handler &h, const int version)
  659. {
  660. h & stack & tile & ending & distance;
  661. }
  662. };
  663. struct BattleStackAttacked : public CPackForClient//3005
  664. {
  665. BattleStackAttacked(){flags = 0; type = 3005;};
  666. void applyCl(CClient *cl);
  667. DLL_EXPORT void applyGs(CGameState *gs);
  668. ui32 stackAttacked;
  669. ui32 newAmount, newHP, killedAmount, damageAmount;
  670. ui8 flags; //1 - is stack killed; 2 - is there special effect to be shown;
  671. ui32 effect; //set only if flag 2 is present
  672. bool killed() const//if target stack was killed
  673. {
  674. return flags & 1;
  675. }
  676. bool isEffect() const//if target stack was killed
  677. {
  678. return flags & 2;
  679. }
  680. template <typename Handler> void serialize(Handler &h, const int version)
  681. {
  682. h & stackAttacked & newAmount & newHP & flags & killedAmount & damageAmount & effect;
  683. }
  684. bool operator<(const BattleStackAttacked &b) const
  685. {
  686. return stackAttacked < b.stackAttacked;
  687. }
  688. };
  689. struct BattleAttack : public CPackForClient//3006
  690. {
  691. BattleAttack(){flags = 0; type = 3006;};
  692. void applyFirstCl(CClient *cl);
  693. DLL_EXPORT void applyGs(CGameState *gs);
  694. void applyCl(CClient *cl);
  695. std::set<BattleStackAttacked> bsa;
  696. ui32 stackAttacking;
  697. ui8 flags;
  698. bool shot()//distance attack - decrease number of shots
  699. {
  700. return flags & 1;
  701. }
  702. bool counter()//is it counterattack?
  703. {
  704. return flags & 2;
  705. }
  706. bool lucky()
  707. {
  708. return flags & 4;
  709. }
  710. bool unlucky()
  711. {
  712. //TODO: support?
  713. return flags & 8;
  714. }
  715. //bool killed() //if target stack was killed
  716. //{
  717. // return bsa.killed();
  718. //}
  719. template <typename Handler> void serialize(Handler &h, const int version)
  720. {
  721. h & bsa & stackAttacking & flags;
  722. }
  723. };
  724. struct StartAction : public CPackForClient//3007
  725. {
  726. StartAction(){type = 3007;};
  727. StartAction(const BattleAction &act){ba = act; type = 3007;};
  728. void applyFirstCl(CClient *cl);
  729. DLL_EXPORT void applyGs(CGameState *gs);
  730. BattleAction ba;
  731. template <typename Handler> void serialize(Handler &h, const int version)
  732. {
  733. h & ba;
  734. }
  735. };
  736. struct EndAction : public CPackForClient//3008
  737. {
  738. EndAction(){type = 3008;};
  739. void applyCl(CClient *cl);
  740. template <typename Handler> void serialize(Handler &h, const int version)
  741. {
  742. }
  743. };
  744. struct SpellCast : public CPackForClient//3009
  745. {
  746. SpellCast(){type = 3009;};
  747. DLL_EXPORT void applyGs(CGameState *gs);
  748. void applyCl(CClient *cl);
  749. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  750. ui32 id;
  751. ui8 skill;
  752. ui16 tile; //destination tile (may not be set in some global/mass spells
  753. std::vector<ui32> resisted; //ids of creatures that resisted this spell
  754. template <typename Handler> void serialize(Handler &h, const int version)
  755. {
  756. h & side & id & skill & tile & resisted;
  757. }
  758. };
  759. struct SetStackEffect : public CPackForClient //3010
  760. {
  761. SetStackEffect(){type = 3010;};
  762. DLL_EXPORT void applyGs(CGameState *gs);
  763. void applyCl(CClient *cl);
  764. std::set<ui32> stacks;
  765. CStack::StackEffect effect;
  766. template <typename Handler> void serialize(Handler &h, const int version)
  767. {
  768. h & stacks & effect;
  769. }
  770. };
  771. struct StacksInjured : public CPackForClient //3011
  772. {
  773. StacksInjured(){type = 3011;}
  774. DLL_EXPORT void applyGs(CGameState *gs);
  775. void applyCl(CClient *cl);
  776. std::set<BattleStackAttacked> stacks;
  777. template <typename Handler> void serialize(Handler &h, const int version)
  778. {
  779. h & stacks;
  780. }
  781. };
  782. struct ShowInInfobox : public CPackForClient //107
  783. {
  784. ShowInInfobox(){type = 107;};
  785. ui8 player;
  786. Component c;
  787. MetaString text;
  788. void applyCl(CClient *cl);
  789. template <typename Handler> void serialize(Handler &h, const int version)
  790. {
  791. h & player & c & text;
  792. }
  793. };
  794. /***********************************************************************************************************/
  795. struct CloseServer : public CPackForServer
  796. {
  797. bool applyGh(CGameHandler *gh);
  798. template <typename Handler> void serialize(Handler &h, const int version)
  799. {}
  800. };
  801. struct EndTurn : public CPackForServer
  802. {
  803. bool applyGh(CGameHandler *gh);
  804. template <typename Handler> void serialize(Handler &h, const int version)
  805. {}
  806. };
  807. struct DismissHero : public CPackForServer
  808. {
  809. DismissHero(){};
  810. DismissHero(si32 HID) : hid(HID) {};
  811. si32 hid;
  812. bool applyGh(CGameHandler *gh);
  813. template <typename Handler> void serialize(Handler &h, const int version)
  814. {
  815. h & hid;
  816. }
  817. };
  818. struct MoveHero : public CPackForServer
  819. {
  820. MoveHero(){};
  821. MoveHero(const int3 &Dest, si32 HID) : dest(Dest), hid(HID){};
  822. int3 dest;
  823. si32 hid;
  824. bool applyGh(CGameHandler *gh);
  825. template <typename Handler> void serialize(Handler &h, const int version)
  826. {
  827. h & dest & hid;
  828. }
  829. };
  830. struct ArrangeStacks : public CPackForServer
  831. {
  832. ArrangeStacks(){};
  833. ArrangeStacks(ui8 W, ui8 P1, ui8 P2, si32 ID1, si32 ID2, si32 VAL)
  834. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  835. ui8 what; //1 - swap; 2 - merge; 3 - split
  836. ui8 p1, p2; //positions of first and second stack
  837. si32 id1, id2; //ids of objects with garrison
  838. si32 val;
  839. bool applyGh(CGameHandler *gh);
  840. template <typename Handler> void serialize(Handler &h, const int version)
  841. {
  842. h & what & p1 & p2 & id1 & id2 & val;
  843. }
  844. };
  845. struct DisbandCreature : public CPackForServer
  846. {
  847. DisbandCreature(){};
  848. DisbandCreature(ui8 Pos, si32 ID):pos(Pos),id(ID){};
  849. ui8 pos; //stack pos
  850. si32 id; //object id
  851. bool applyGh(CGameHandler *gh);
  852. template <typename Handler> void serialize(Handler &h, const int version)
  853. {
  854. h & pos & id;
  855. }
  856. };
  857. struct BuildStructure : public CPackForServer
  858. {
  859. BuildStructure(){};
  860. BuildStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  861. si32 bid, tid; //structure and town ids
  862. bool applyGh(CGameHandler *gh);
  863. template <typename Handler> void serialize(Handler &h, const int version)
  864. {
  865. h & tid & bid;
  866. }
  867. };
  868. struct RecruitCreatures : public CPackForServer
  869. {
  870. RecruitCreatures(){};
  871. RecruitCreatures(si32 TID, si32 CRID, si32 Amount):tid(TID),crid(CRID),amount(Amount){};
  872. si32 tid; //town id
  873. ui32 crid, amount;//creature ID and amount
  874. bool applyGh(CGameHandler *gh);
  875. template <typename Handler> void serialize(Handler &h, const int version)
  876. {
  877. h & tid & crid & amount;
  878. }
  879. };
  880. struct UpgradeCreature : public CPackForServer
  881. {
  882. UpgradeCreature(){};
  883. UpgradeCreature(ui8 Pos, si32 ID, si32 CRID):pos(Pos),id(ID), cid(CRID){};
  884. ui8 pos; //stack pos
  885. si32 id; //object id
  886. si32 cid; //id of type to which we want make upgrade
  887. bool applyGh(CGameHandler *gh);
  888. template <typename Handler> void serialize(Handler &h, const int version)
  889. {
  890. h & pos & id & cid;
  891. }
  892. };
  893. struct GarrisonHeroSwap : public CPackForServer
  894. {
  895. GarrisonHeroSwap(){};
  896. GarrisonHeroSwap(si32 TID):tid(TID){};
  897. si32 tid;
  898. bool applyGh(CGameHandler *gh);
  899. template <typename Handler> void serialize(Handler &h, const int version)
  900. {
  901. h & tid;
  902. }
  903. };
  904. struct ExchangeArtifacts : public CPackForServer
  905. {
  906. ExchangeArtifacts(){};
  907. ExchangeArtifacts(si32 H1, si32 H2, ui16 S1, ui16 S2)
  908. :hid1(H1),hid2(H2),slot1(S1),slot2(S2){};
  909. si32 hid1, hid2;
  910. ui16 slot1, slot2;
  911. bool applyGh(CGameHandler *gh);
  912. template <typename Handler> void serialize(Handler &h, const int version)
  913. {
  914. h & hid1 & hid2 & slot1 & slot2;
  915. }
  916. };
  917. struct BuyArtifact : public CPackForServer
  918. {
  919. BuyArtifact(){};
  920. BuyArtifact(si32 HID, si32 AID):hid(HID),aid(AID){};
  921. si32 hid, aid; //hero and artifact id
  922. bool applyGh(CGameHandler *gh);
  923. template <typename Handler> void serialize(Handler &h, const int version)
  924. {
  925. h & hid & aid;
  926. }
  927. };
  928. struct TradeOnMarketplace : public CPackForServer
  929. {
  930. TradeOnMarketplace(){};
  931. TradeOnMarketplace(ui8 Player, ui8 Mode, /*si32 ID, */ui32 R1, ui32 R2, ui32 Val)
  932. :player(Player),mode(Mode),/*id(ID),*/r1(R1),r2(R2),val(Val){};
  933. ui8 player;
  934. ui8 mode;//0 - res<->res;
  935. //si32 id; //object id
  936. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res
  937. ui32 val; //units of sold resource
  938. bool applyGh(CGameHandler *gh);
  939. template <typename Handler> void serialize(Handler &h, const int version)
  940. {
  941. h & player & mode & /*id & */r1 & r2 & val;
  942. }
  943. };
  944. struct SetFormation : public CPackForServer
  945. {
  946. SetFormation(){};
  947. SetFormation(si32 HID, ui8 Formation):hid(HID),formation(Formation){};
  948. si32 hid;
  949. ui8 formation;
  950. bool applyGh(CGameHandler *gh);
  951. template <typename Handler> void serialize(Handler &h, const int version)
  952. {
  953. h & hid & formation;
  954. }
  955. };
  956. struct HireHero : public CPackForServer
  957. {
  958. HireHero(){};
  959. HireHero(si32 HID, si32 TID):hid(HID),tid(TID){};
  960. si32 hid, tid; //available hero serial and town id
  961. bool applyGh(CGameHandler *gh);
  962. template <typename Handler> void serialize(Handler &h, const int version)
  963. {
  964. h & hid & tid;
  965. }
  966. };
  967. struct BuildBoat : public CPackForServer
  968. {
  969. BuildBoat(){};
  970. si32 objid; //where player wants to buy a boat
  971. bool applyGh(CGameHandler *gh);
  972. template <typename Handler> void serialize(Handler &h, const int version)
  973. {
  974. h & objid;
  975. }
  976. };
  977. struct QueryReply : public CPackForServer
  978. {
  979. QueryReply(){};
  980. QueryReply(ui32 QID, ui32 Answer):qid(QID),answer(Answer){};
  981. ui32 qid, answer; //hero and artifact id
  982. bool applyGh(CGameHandler *gh);
  983. template <typename Handler> void serialize(Handler &h, const int version)
  984. {
  985. h & qid & answer;
  986. }
  987. };
  988. struct MakeAction : public CPackForServer
  989. {
  990. MakeAction(){};
  991. MakeAction(const BattleAction &BA):ba(BA){};
  992. BattleAction ba;
  993. bool applyGh(CGameHandler *gh);
  994. template <typename Handler> void serialize(Handler &h, const int version)
  995. {
  996. h & ba;
  997. }
  998. };
  999. struct MakeCustomAction : public CPackForServer
  1000. {
  1001. MakeCustomAction(){};
  1002. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1003. BattleAction ba;
  1004. bool applyGh(CGameHandler *gh);
  1005. template <typename Handler> void serialize(Handler &h, const int version)
  1006. {
  1007. h & ba;
  1008. }
  1009. };
  1010. /***********************************************************************************************************/
  1011. struct SaveGame : public CPackForClient, public CPackForServer
  1012. {
  1013. SaveGame(){};
  1014. SaveGame(const std::string &Fname) :fname(Fname){};
  1015. std::string fname;
  1016. void applyCl(CClient *cl);
  1017. void applyGs(CGameState *gs){};
  1018. bool applyGh(CGameHandler *gh);
  1019. template <typename Handler> void serialize(Handler &h, const int version)
  1020. {
  1021. h & fname;
  1022. }
  1023. };
  1024. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  1025. {
  1026. PlayerMessage(){CPackForClient::type = 513;};
  1027. PlayerMessage(ui8 Player, const std::string &Text)
  1028. :player(Player),text(Text)
  1029. {CPackForClient::type = 513;};
  1030. void applyCl(CClient *cl);
  1031. void applyGs(CGameState *gs){};
  1032. bool applyGh(CGameHandler *gh);
  1033. ui8 player;
  1034. std::string text;
  1035. template <typename Handler> void serialize(Handler &h, const int version)
  1036. {
  1037. h & text & player;
  1038. }
  1039. };
  1040. struct SetSelection : public CPackForClient, public CPackForServer //514
  1041. {
  1042. SetSelection(){CPackForClient::type = 514;};
  1043. DLL_EXPORT void applyGs(CGameState *gs);
  1044. bool applyGh(CGameHandler *gh);
  1045. ui8 player;
  1046. ui32 id;
  1047. template <typename Handler> void serialize(Handler &h, const int version)
  1048. {
  1049. h & id & player;
  1050. }
  1051. };
  1052. #endif //__NETPACKS_H__