NetPacks.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  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. class CClient;
  9. class CGameState;
  10. class CGameHandler;
  11. class CConnection;
  12. struct CPack
  13. {
  14. ui16 type;
  15. CPack(){};
  16. virtual ~CPack(){};
  17. ui16 getType() const{return type;}
  18. template <typename Handler> void serialize(Handler &h, const int version)
  19. {
  20. tlog1 << "CPack serialized... this should not happen!\n";
  21. }
  22. DLL_EXPORT void applyGs(CGameState *gs)
  23. {};
  24. };
  25. struct CPackForClient : public CPack
  26. {
  27. CPackForClient(){type = 1;};
  28. CGameState* GS(CClient *cl);
  29. void applyFirstCl(CClient *cl)//called before applying to gs
  30. {};
  31. void applyCl(CClient *cl)//called after applying to gs
  32. {};
  33. };
  34. struct CPackForServer : public CPack
  35. {
  36. CConnection *c;
  37. CGameState* GS(CGameHandler *gh);
  38. CPackForServer()
  39. {
  40. type = 2;
  41. c = NULL;
  42. };
  43. void applyGh(CGameHandler *gh)//called after applying to gs
  44. {};
  45. };
  46. struct Query : public CPackForClient
  47. {
  48. ui32 id;
  49. };
  50. struct MetaString : public CPack //2001 helper for object scrips
  51. {
  52. enum {GENERAL_TXT=1, XTRAINFO_TXT, OBJ_NAMES, RES_NAMES, ART_NAMES, ARRAY_TXT, CRE_PL_NAMES, CREGENS, MINE_NAMES,
  53. MINE_EVNTS, ADVOB_TXT, ART_EVNTS, SPELL_NAME};
  54. std::vector<std::string> strings;
  55. std::vector<std::pair<ui8,ui32> > texts; //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
  56. std::vector<si32> message;
  57. std::vector<std::string> replacements;
  58. template <typename Handler> void serialize(Handler &h, const int version)
  59. {
  60. h & strings & texts & message & replacements;
  61. }
  62. void addTxt(ui8 type, ui32 serial)
  63. {
  64. *this << std::make_pair(type,serial);
  65. }
  66. MetaString& operator<<(const std::pair<ui8,ui32> &txt)
  67. {
  68. message.push_back(-((si32)texts.size())-1);
  69. texts.push_back(txt);
  70. return *this;
  71. }
  72. MetaString& operator<<(const std::string &txt)
  73. {
  74. message.push_back(strings.size()+1);
  75. strings.push_back(txt);
  76. return *this;
  77. }
  78. void clear()
  79. {
  80. strings.clear();
  81. texts.clear();
  82. message.clear();
  83. }
  84. MetaString(){type = 2001;};
  85. };
  86. /***********************************************************************************************************/
  87. struct SystemMessage : public CPackForClient //95
  88. {
  89. SystemMessage(const std::string Text) : text(Text){type = 95;};
  90. SystemMessage(){type = 95;};
  91. void applyCl(CClient *cl);
  92. std::string text;
  93. template <typename Handler> void serialize(Handler &h, const int version)
  94. {
  95. h & text;
  96. }
  97. };
  98. struct YourTurn : public CPackForClient //100
  99. {
  100. YourTurn(){type = 100;};
  101. void applyCl(CClient *cl);
  102. DLL_EXPORT void applyGs(CGameState *gs);
  103. ui8 player;
  104. template <typename Handler> void serialize(Handler &h, const int version)
  105. {
  106. h & player;
  107. }
  108. };
  109. struct SetResource : public CPackForClient //102
  110. {
  111. SetResource(){type = 102;};
  112. void applyCl(CClient *cl);
  113. DLL_EXPORT void applyGs(CGameState *gs);
  114. ui8 player, resid;
  115. si32 val;
  116. template <typename Handler> void serialize(Handler &h, const int version)
  117. {
  118. h & player & resid & val;
  119. }
  120. };
  121. struct SetResources : public CPackForClient //104
  122. {
  123. SetResources(){res.resize(RESOURCE_QUANTITY);type = 104;};
  124. void applyCl(CClient *cl);
  125. DLL_EXPORT void applyGs(CGameState *gs);
  126. ui8 player;
  127. std::vector<si32> res; //res[resid] => res amount
  128. template <typename Handler> void serialize(Handler &h, const int version)
  129. {
  130. h & player & res;
  131. }
  132. };
  133. struct SetPrimSkill : public CPackForClient //105
  134. {
  135. SetPrimSkill(){type = 105;};
  136. void applyCl(CClient *cl);
  137. DLL_EXPORT void applyGs(CGameState *gs);
  138. ui8 abs; //0 - changes by value; 1 - sets to value
  139. si32 id;
  140. ui16 which, val;
  141. template <typename Handler> void serialize(Handler &h, const int version)
  142. {
  143. h & abs & id & which & val;
  144. }
  145. };
  146. struct SetSecSkill : public CPackForClient //106
  147. {
  148. SetSecSkill(){type = 106;};
  149. void applyCl(CClient *cl);
  150. DLL_EXPORT void applyGs(CGameState *gs);
  151. ui8 abs; //0 - changes by value; 1 - sets to value
  152. si32 id;
  153. ui16 which, val;
  154. template <typename Handler> void serialize(Handler &h, const int version)
  155. {
  156. h & abs & id & which & val;
  157. }
  158. };
  159. struct HeroVisitCastle : public CPackForClient //108
  160. {
  161. HeroVisitCastle(){flags=0;type = 108;};
  162. void applyCl(CClient *cl);
  163. DLL_EXPORT void applyGs(CGameState *gs);
  164. ui8 flags; //1 - start, 2 - garrison
  165. ui32 tid, hid;
  166. bool start() //if hero is entering castle (if false - leaving)
  167. {
  168. return flags & 1;
  169. }
  170. bool garrison() //if hero is entering/leaving garrison (if false - it's only visiting hero)
  171. {
  172. return flags & 2;
  173. }
  174. template <typename Handler> void serialize(Handler &h, const int version)
  175. {
  176. h & flags & tid & hid;
  177. }
  178. };
  179. struct ChangeSpells : public CPackForClient //109
  180. {
  181. ChangeSpells(){type = 109;};
  182. void applyCl(CClient *cl);
  183. DLL_EXPORT void applyGs(CGameState *gs);
  184. ui8 learn; //1 - gives spell, 0 - takes
  185. ui32 hid;
  186. std::set<ui32> spells;
  187. template <typename Handler> void serialize(Handler &h, const int version)
  188. {
  189. h & learn & hid & spells;
  190. }
  191. };
  192. struct SetMana : public CPackForClient //110
  193. {
  194. SetMana(){type = 110;};
  195. void applyCl(CClient *cl);
  196. DLL_EXPORT void applyGs(CGameState *gs);
  197. ui32 hid, val;
  198. template <typename Handler> void serialize(Handler &h, const int version)
  199. {
  200. h & val & hid;
  201. }
  202. };
  203. struct SetMovePoints : public CPackForClient //111
  204. {
  205. SetMovePoints(){type = 111;};
  206. void applyCl(CClient *cl);
  207. DLL_EXPORT void applyGs(CGameState *gs);
  208. ui32 hid, val;
  209. template <typename Handler> void serialize(Handler &h, const int version)
  210. {
  211. h & val & hid;
  212. }
  213. };
  214. struct FoWChange : public CPackForClient //112
  215. {
  216. FoWChange(){type = 112;};
  217. void applyCl(CClient *cl);
  218. DLL_EXPORT void applyGs(CGameState *gs);
  219. std::set<int3> tiles;
  220. ui8 player, mode; //mode==0 - hide, mode==1 - reveal
  221. template <typename Handler> void serialize(Handler &h, const int version)
  222. {
  223. h & tiles & player;
  224. }
  225. };
  226. struct SetAvailableHeroes : public CPackForClient //113
  227. {
  228. SetAvailableHeroes(){type = 113;flags=0;};
  229. void applyCl(CClient *cl);
  230. DLL_EXPORT void applyGs(CGameState *gs);
  231. ui8 player;
  232. si32 hid1, hid2;
  233. ui8 flags; //1 - reset army of hero1; 2 - reset army of hero 2
  234. template <typename Handler> void serialize(Handler &h, const int version)
  235. {
  236. h & player & hid1 & hid2 & flags;
  237. }
  238. };
  239. struct GiveBonus : public CPackForClient //115
  240. {
  241. GiveBonus(){type = 115;};
  242. void applyCl(CClient *cl);
  243. DLL_EXPORT void applyGs(CGameState *gs);
  244. ui32 hid;
  245. HeroBonus bonus;
  246. MetaString bdescr;
  247. template <typename Handler> void serialize(Handler &h, const int version)
  248. {
  249. h & bonus & hid & bdescr;
  250. }
  251. };
  252. struct ChangeObjPos : public CPackForClient //116
  253. {
  254. ChangeObjPos(){type = 116;};
  255. void applyFirstCl(CClient *cl);
  256. void applyCl(CClient *cl);
  257. DLL_EXPORT void applyGs(CGameState *gs);
  258. ui32 objid;
  259. int3 nPos;
  260. ui8 flags; //bit flags: 1 - redraw
  261. template <typename Handler> void serialize(Handler &h, const int version)
  262. {
  263. h & objid & nPos & flags;
  264. }
  265. };
  266. struct RemoveObject : public CPackForClient //500
  267. {
  268. RemoveObject(){type = 500;};
  269. RemoveObject(si32 ID){id = ID;type = 500;};
  270. void applyFirstCl(CClient *cl);
  271. void applyCl(CClient *cl);
  272. DLL_EXPORT void applyGs(CGameState *gs);
  273. si32 id;
  274. template <typename Handler> void serialize(Handler &h, const int version)
  275. {
  276. h & id;
  277. }
  278. };
  279. struct TryMoveHero : public CPackForClient //501
  280. {
  281. TryMoveHero(){type = 501;};
  282. void applyFirstCl(CClient *cl);
  283. void applyCl(CClient *cl);
  284. void applyGs(CGameState *gs);
  285. ui32 id, movePoints;
  286. ui8 result; //0 - failed; 1- succes -normal move; 2 - teleportation, 3 - instant jump
  287. int3 start, end;
  288. std::set<int3> fowRevealed; //revealed tiles
  289. template <typename Handler> void serialize(Handler &h, const int version)
  290. {
  291. h & id & result & start & end & movePoints & fowRevealed;
  292. }
  293. };
  294. struct SetGarrisons : public CPackForClient //502
  295. {
  296. SetGarrisons(){type = 502;};
  297. void applyCl(CClient *cl);
  298. DLL_EXPORT void applyGs(CGameState *gs);
  299. std::map<ui32,CCreatureSet> garrs;
  300. template <typename Handler> void serialize(Handler &h, const int version)
  301. {
  302. h & garrs;
  303. }
  304. };
  305. struct NewStructures : public CPackForClient //504
  306. {
  307. NewStructures(){type = 504;};
  308. void applyCl(CClient *cl);
  309. DLL_EXPORT void applyGs(CGameState *gs);
  310. si32 tid;
  311. std::set<si32> bid;
  312. si16 builded;
  313. template <typename Handler> void serialize(Handler &h, const int version)
  314. {
  315. h & tid & bid & builded;
  316. }
  317. };
  318. struct SetAvailableCreatures : public CPackForClient //506
  319. {
  320. SetAvailableCreatures(){type = 506;};
  321. void applyCl(CClient *cl);
  322. DLL_EXPORT void applyGs(CGameState *gs);
  323. si32 tid;
  324. std::map<si32,ui32> creatures;
  325. template <typename Handler> void serialize(Handler &h, const int version)
  326. {
  327. h & tid & creatures;
  328. }
  329. };
  330. struct SetHeroesInTown : public CPackForClient //508
  331. {
  332. SetHeroesInTown(){type = 508;};
  333. void applyCl(CClient *cl);
  334. DLL_EXPORT void applyGs(CGameState *gs);
  335. si32 tid, visiting, garrison; //id of town, visiting hero, hero in garrison
  336. template <typename Handler> void serialize(Handler &h, const int version)
  337. {
  338. h & tid & visiting & garrison;
  339. }
  340. };
  341. struct SetHeroArtifacts : public CPackForClient //509
  342. {
  343. SetHeroArtifacts(){type = 509;};
  344. void applyCl(CClient *cl);
  345. DLL_EXPORT void applyGs(CGameState *gs);
  346. si32 hid;
  347. std::vector<ui32> artifacts; //hero's artifacts from bag
  348. 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
  349. template <typename Handler> void serialize(Handler &h, const int version)
  350. {
  351. h & hid & artifacts & artifWorn;
  352. }
  353. };
  354. struct HeroRecruited : public CPackForClient //515
  355. {
  356. HeroRecruited(){type = 515;};
  357. void applyCl(CClient *cl);
  358. DLL_EXPORT void applyGs(CGameState *gs);
  359. si32 hid, tid; //subID of hero
  360. int3 tile;
  361. ui8 player;
  362. template <typename Handler> void serialize(Handler &h, const int version)
  363. {
  364. h & hid & tid & tile & player;
  365. }
  366. };
  367. struct GiveHero : public CPackForClient //516
  368. {
  369. GiveHero(){type = 516;};
  370. void applyFirstCl(CClient *cl);
  371. void applyCl(CClient *cl);
  372. DLL_EXPORT void applyGs(CGameState *gs);
  373. ui32 id; //object id
  374. ui8 player;
  375. template <typename Handler> void serialize(Handler &h, const int version)
  376. {
  377. h & id & player;
  378. }
  379. };
  380. struct NewTurn : public CPackForClient //101
  381. {
  382. DLL_EXPORT void applyGs(CGameState *gs);
  383. struct Hero
  384. {
  385. ui32 id, move, mana; //id is a general serial id
  386. template <typename Handler> void serialize(Handler &h, const int version)
  387. {
  388. h & id & move & mana;
  389. }
  390. bool operator<(const Hero&h)const{return id < h.id;}
  391. };
  392. std::set<Hero> heroes; //updates movement and mana points
  393. std::vector<SetResources> res;//resource list
  394. std::vector<SetAvailableCreatures> cres;//resource list
  395. ui32 day;
  396. bool resetBuilded;
  397. NewTurn(){type = 101;};
  398. template <typename Handler> void serialize(Handler &h, const int version)
  399. {
  400. h & heroes & cres & res & day & resetBuilded;
  401. }
  402. };
  403. struct Component : public CPack //2002 helper for object scrips informations
  404. {
  405. enum {PRIM_SKILL,SEC_SKILL,RESOURCE,CREATURE,ARTIFACT,EXPERIENCE,SPELL};
  406. ui16 id, subtype; //id uses ^^^ enums, when id==EXPPERIENCE subtype==0 means exp points and subtype==1 levels)
  407. si32 val; // + give; - take
  408. si16 when; // 0 - now; +x - within x days; -x - per x days
  409. template <typename Handler> void serialize(Handler &h, const int version)
  410. {
  411. h & id & subtype & val & when;
  412. }
  413. Component(){type = 2002;};
  414. Component(ui16 Type, ui16 Subtype, si32 Val, si16 When):id(Type),subtype(Subtype),val(Val),when(When){type = 2002;};
  415. };
  416. struct InfoWindow : public CPackForClient //103 - displays simple info window
  417. {
  418. void applyCl(CClient *cl);
  419. MetaString text;
  420. std::vector<Component> components;
  421. ui8 player;
  422. template <typename Handler> void serialize(Handler &h, const int version)
  423. {
  424. h & text & components & player;
  425. }
  426. InfoWindow(){type = 103;};
  427. };
  428. struct SetObjectProperty : public CPackForClient//1001
  429. {
  430. DLL_EXPORT void applyGs(CGameState *gs);
  431. ui32 id;
  432. ui8 what; //1 - owner; 2 - blockvis; 3 - first stack count; 4 - visitors; 5 - visited; 6 - ID (if 34 then also def is replaced)
  433. ui32 val;
  434. SetObjectProperty(){type = 1001;};
  435. SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
  436. template <typename Handler> void serialize(Handler &h, const int version)
  437. {
  438. h & id & what & val;
  439. }
  440. };
  441. struct SetHoverName : public CPackForClient//1002
  442. {
  443. DLL_EXPORT void applyGs(CGameState *gs);
  444. ui32 id;
  445. MetaString name;
  446. SetHoverName(){type = 1002;};
  447. SetHoverName(ui32 ID, MetaString& Name):id(ID),name(Name){type = 1002;};
  448. template <typename Handler> void serialize(Handler &h, const int version)
  449. {
  450. h & id & name;
  451. }
  452. };
  453. struct HeroLevelUp : public Query//2000
  454. {
  455. void applyCl(CClient *cl);
  456. DLL_EXPORT void applyGs(CGameState *gs);
  457. si32 heroid;
  458. ui8 primskill, level;
  459. std::vector<ui16> skills;
  460. HeroLevelUp(){type = 2000;};
  461. template <typename Handler> void serialize(Handler &h, const int version)
  462. {
  463. h & id & heroid & primskill & level & skills;
  464. }
  465. };
  466. struct SelectionDialog : public Query//2001
  467. {
  468. void applyCl(CClient *cl);
  469. MetaString text;
  470. std::vector<Component> components;
  471. ui8 player;
  472. SelectionDialog(){type = 2001;};
  473. template <typename Handler> void serialize(Handler &h, const int version)
  474. {
  475. h & id & text & components & player;
  476. }
  477. };
  478. struct YesNoDialog : public Query//2002
  479. {
  480. void applyCl(CClient *cl);
  481. MetaString text;
  482. std::vector<Component> components;
  483. ui8 player;
  484. YesNoDialog(){type = 2002;};
  485. template <typename Handler> void serialize(Handler &h, const int version)
  486. {
  487. h & id & text & components & player;
  488. }
  489. };
  490. struct BattleInfo;
  491. struct BattleStart : public CPackForClient//3000
  492. {
  493. BattleStart(){type = 3000;};
  494. void applyCl(CClient *cl);
  495. DLL_EXPORT void applyGs(CGameState *gs);
  496. BattleInfo * info;
  497. template <typename Handler> void serialize(Handler &h, const int version)
  498. {
  499. h & info;
  500. }
  501. };
  502. struct BattleNextRound : public CPackForClient//3001
  503. {
  504. BattleNextRound(){type = 3001;};
  505. void applyCl(CClient *cl);
  506. DLL_EXPORT void applyGs(CGameState *gs);
  507. si32 round;
  508. template <typename Handler> void serialize(Handler &h, const int version)
  509. {
  510. h & round;
  511. }
  512. };
  513. struct BattleSetActiveStack : public CPackForClient//3002
  514. {
  515. BattleSetActiveStack(){type = 3002;};
  516. void applyCl(CClient *cl);
  517. DLL_EXPORT void applyGs(CGameState *gs);
  518. ui32 stack;
  519. template <typename Handler> void serialize(Handler &h, const int version)
  520. {
  521. h & stack;
  522. }
  523. };
  524. struct BattleResult : public CPackForClient//3003
  525. {
  526. BattleResult(){type = 3003;};
  527. void applyFirstCl(CClient *cl);
  528. void applyGs(CGameState *gs);
  529. ui8 result; //0 - normal victory; 1 - escape; 2 - surrender
  530. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  531. std::set<std::pair<ui32,si32> > casualties[2]; //first => casualties of attackers - set of pairs crid<>number
  532. ui32 exp[2]; //exp for attacker and defender
  533. std::set<ui32> artifacts; //artifacts taken from loser to winner
  534. template <typename Handler> void serialize(Handler &h, const int version)
  535. {
  536. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  537. }
  538. };
  539. struct BattleStackMoved : public CPackForClient//3004
  540. {
  541. ui32 stack, tile, distance;
  542. BattleStackMoved(){type = 3004;};
  543. void applyFirstCl(CClient *cl);
  544. void applyGs(CGameState *gs);
  545. template <typename Handler> void serialize(Handler &h, const int version)
  546. {
  547. h & stack & tile & distance;
  548. }
  549. };
  550. struct BattleStackAttacked : public CPackForClient//3005
  551. {
  552. BattleStackAttacked(){flags = 0; type = 3005;};
  553. void applyCl(CClient *cl);
  554. DLL_EXPORT void applyGs(CGameState *gs);
  555. ui32 stackAttacked;
  556. ui32 newAmount, newHP, killedAmount, damageAmount;
  557. ui8 flags; //1 - is stack killed; 2 - is there special effect to be shown;
  558. ui32 effect; //set only if flag 2 is present
  559. bool killed() const//if target stack was killed
  560. {
  561. return flags & 1;
  562. }
  563. bool isEffect() const//if target stack was killed
  564. {
  565. return flags & 2;
  566. }
  567. template <typename Handler> void serialize(Handler &h, const int version)
  568. {
  569. h & stackAttacked & newAmount & newHP & flags & killedAmount & damageAmount & effect;
  570. }
  571. bool operator<(const BattleStackAttacked &b) const
  572. {
  573. return stackAttacked < b.stackAttacked;
  574. }
  575. };
  576. struct BattleAttack : public CPackForClient//3006
  577. {
  578. BattleAttack(){flags = 0; type = 3006;};
  579. void applyFirstCl(CClient *cl);
  580. DLL_EXPORT void applyGs(CGameState *gs);
  581. void applyCl(CClient *cl);
  582. std::set<BattleStackAttacked> bsa;
  583. ui32 stackAttacking;
  584. ui8 flags;
  585. bool shot()//distance attack - decrease number of shots
  586. {
  587. return flags & 1;
  588. }
  589. bool counter()//is it counterattack?
  590. {
  591. return flags & 2;
  592. }
  593. bool lucky()
  594. {
  595. return flags & 4;
  596. }
  597. bool unlucky()
  598. {
  599. //TODO: support?
  600. return flags & 8;
  601. }
  602. //bool killed() //if target stack was killed
  603. //{
  604. // return bsa.killed();
  605. //}
  606. template <typename Handler> void serialize(Handler &h, const int version)
  607. {
  608. h & bsa & stackAttacking & flags;
  609. }
  610. };
  611. struct StartAction : public CPackForClient//3007
  612. {
  613. StartAction(){type = 3007;};
  614. StartAction(const BattleAction &act){ba = act; type = 3007;};
  615. void applyFirstCl(CClient *cl);
  616. DLL_EXPORT void applyGs(CGameState *gs);
  617. BattleAction ba;
  618. template <typename Handler> void serialize(Handler &h, const int version)
  619. {
  620. h & ba;
  621. }
  622. };
  623. struct EndAction : public CPackForClient//3008
  624. {
  625. EndAction(){type = 3008;};
  626. void applyCl(CClient *cl);
  627. template <typename Handler> void serialize(Handler &h, const int version)
  628. {
  629. }
  630. };
  631. struct SpellCasted : public CPackForClient//3009
  632. {
  633. SpellCasted(){type = 3009;};
  634. DLL_EXPORT void applyGs(CGameState *gs);
  635. void applyCl(CClient *cl);
  636. ui8 side; //which hero casted spell: 0 - attacker, 1 - defender
  637. ui32 id;
  638. ui8 skill;
  639. ui16 tile; //destination tile (may not be set in some global/mass spells
  640. template <typename Handler> void serialize(Handler &h, const int version)
  641. {
  642. h & side & id & skill & tile;
  643. }
  644. };
  645. struct SetStackEffect : public CPackForClient //3010
  646. {
  647. SetStackEffect(){type = 3010;};
  648. DLL_EXPORT void applyGs(CGameState *gs);
  649. void applyCl(CClient *cl);
  650. std::set<ui32> stacks;
  651. CStack::StackEffect effect;
  652. template <typename Handler> void serialize(Handler &h, const int version)
  653. {
  654. h & stacks & effect;
  655. }
  656. };
  657. struct ShowInInfobox : public CPackForClient //107
  658. {
  659. ShowInInfobox(){type = 107;};
  660. ui8 player;
  661. Component c;
  662. MetaString text;
  663. void applyCl(CClient *cl);
  664. template <typename Handler> void serialize(Handler &h, const int version)
  665. {
  666. h & player & c & text;
  667. }
  668. };
  669. /***********************************************************************************************************/
  670. struct SaveGame : public CPackForServer
  671. {
  672. SaveGame(){};
  673. SaveGame(const std::string &Fname) :fname(Fname){};
  674. std::string fname;
  675. void applyGh(CGameHandler *gh);
  676. template <typename Handler> void serialize(Handler &h, const int version)
  677. {
  678. h & fname;
  679. }
  680. };
  681. struct CloseServer : public CPackForServer
  682. {
  683. void applyGh(CGameHandler *gh);
  684. template <typename Handler> void serialize(Handler &h, const int version)
  685. {}
  686. };
  687. struct EndTurn : public CPackForServer
  688. {
  689. void applyGh(CGameHandler *gh);
  690. template <typename Handler> void serialize(Handler &h, const int version)
  691. {}
  692. };
  693. struct DismissHero : public CPackForServer
  694. {
  695. DismissHero(){};
  696. DismissHero(si32 HID) : hid(HID) {};
  697. si32 hid;
  698. void applyGh(CGameHandler *gh);
  699. template <typename Handler> void serialize(Handler &h, const int version)
  700. {
  701. h & hid;
  702. }
  703. };
  704. struct MoveHero : public CPackForServer
  705. {
  706. MoveHero(){};
  707. MoveHero(const int3 &Dest, si32 HID) : dest(Dest), hid(HID){};
  708. int3 dest;
  709. si32 hid;
  710. void applyGh(CGameHandler *gh);
  711. template <typename Handler> void serialize(Handler &h, const int version)
  712. {
  713. h & dest & hid;
  714. }
  715. };
  716. struct ArrangeStacks : public CPackForServer
  717. {
  718. ArrangeStacks(){};
  719. ArrangeStacks(ui8 W, ui8 P1, ui8 P2, si32 ID1, si32 ID2, si32 VAL)
  720. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  721. ui8 what; //1 - swap; 2 - merge; 3 - split
  722. ui8 p1, p2; //positions of first and second stack
  723. si32 id1, id2; //ids of objects with garrison
  724. si32 val;
  725. void applyGh(CGameHandler *gh);
  726. template <typename Handler> void serialize(Handler &h, const int version)
  727. {
  728. h & what & p1 & p2 & id1 & id2 & val;
  729. }
  730. };
  731. struct DisbandCreature : public CPackForServer
  732. {
  733. DisbandCreature(){};
  734. DisbandCreature(ui8 Pos, si32 ID):pos(Pos),id(ID){};
  735. ui8 pos; //stack pos
  736. si32 id; //object id
  737. void applyGh(CGameHandler *gh);
  738. template <typename Handler> void serialize(Handler &h, const int version)
  739. {
  740. h & pos & id;
  741. }
  742. };
  743. struct BuildStructure : public CPackForServer
  744. {
  745. BuildStructure(){};
  746. BuildStructure(si32 TID, si32 BID):tid(TID),bid(BID){};
  747. si32 bid, tid; //structure and town ids
  748. void applyGh(CGameHandler *gh);
  749. template <typename Handler> void serialize(Handler &h, const int version)
  750. {
  751. h & tid & bid;
  752. }
  753. };
  754. struct RecruitCreatures : public CPackForServer
  755. {
  756. RecruitCreatures(){};
  757. RecruitCreatures(si32 TID, si32 CRID, si32 Amount):tid(TID),crid(CRID),amount(Amount){};
  758. si32 tid; //town id
  759. ui32 crid, amount;//creature ID and amount
  760. void applyGh(CGameHandler *gh);
  761. template <typename Handler> void serialize(Handler &h, const int version)
  762. {
  763. h & tid & crid & amount;
  764. }
  765. };
  766. struct UpgradeCreature : public CPackForServer
  767. {
  768. UpgradeCreature(){};
  769. UpgradeCreature(ui8 Pos, si32 ID, si32 CRID):pos(Pos),id(ID), cid(CRID){};
  770. ui8 pos; //stack pos
  771. si32 id; //object id
  772. si32 cid; //id of type to which we want make upgrade
  773. void applyGh(CGameHandler *gh);
  774. template <typename Handler> void serialize(Handler &h, const int version)
  775. {
  776. h & pos & id & cid;
  777. }
  778. };
  779. struct GarrisonHeroSwap : public CPackForServer
  780. {
  781. GarrisonHeroSwap(){};
  782. GarrisonHeroSwap(si32 TID):tid(TID){};
  783. si32 tid;
  784. void applyGh(CGameHandler *gh);
  785. template <typename Handler> void serialize(Handler &h, const int version)
  786. {
  787. h & tid;
  788. }
  789. };
  790. struct ExchangeArtifacts : public CPackForServer
  791. {
  792. ExchangeArtifacts(){};
  793. ExchangeArtifacts(si32 H1, si32 H2, ui16 S1, ui16 S2)
  794. :hid1(H1),hid2(H2),slot1(S1),slot2(S2){};
  795. si32 hid1, hid2;
  796. ui16 slot1, slot2;
  797. void applyGh(CGameHandler *gh);
  798. template <typename Handler> void serialize(Handler &h, const int version)
  799. {
  800. h & hid1 & hid2 & slot1 & slot2;
  801. }
  802. };
  803. struct BuyArtifact : public CPackForServer
  804. {
  805. BuyArtifact(){};
  806. BuyArtifact(si32 HID, si32 AID):hid(HID),aid(AID){};
  807. si32 hid, aid; //hero and artifact id
  808. void applyGh(CGameHandler *gh);
  809. template <typename Handler> void serialize(Handler &h, const int version)
  810. {
  811. h & hid & aid;
  812. }
  813. };
  814. struct TradeOnMarketplace : public CPackForServer
  815. {
  816. TradeOnMarketplace(){};
  817. TradeOnMarketplace(ui8 Player, ui8 Mode, /*si32 ID, */ui32 R1, ui32 R2, ui32 Val)
  818. :player(Player),mode(Mode),/*id(ID),*/r1(R1),r2(R2),val(Val){};
  819. ui8 player;
  820. ui8 mode;//0 - res<->res;
  821. //si32 id; //object id
  822. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res
  823. ui32 val; //units of sold resource
  824. void applyGh(CGameHandler *gh);
  825. template <typename Handler> void serialize(Handler &h, const int version)
  826. {
  827. h & player & mode & /*id & */r1 & r2 & val;
  828. }
  829. };
  830. struct SetFormation : public CPackForServer
  831. {
  832. SetFormation(){};
  833. SetFormation(si32 HID, ui8 Formation):hid(HID),formation(Formation){};
  834. si32 hid;
  835. ui8 formation;
  836. void applyGh(CGameHandler *gh);
  837. template <typename Handler> void serialize(Handler &h, const int version)
  838. {
  839. h & hid & formation;
  840. }
  841. };
  842. struct HireHero : public CPackForServer
  843. {
  844. HireHero(){};
  845. HireHero(si32 HID, si32 TID):hid(HID),tid(TID){};
  846. si32 hid, tid; //available hero serial and town id
  847. void applyGh(CGameHandler *gh);
  848. template <typename Handler> void serialize(Handler &h, const int version)
  849. {
  850. h & hid & tid;
  851. }
  852. };
  853. struct QueryReply : public CPackForServer
  854. {
  855. QueryReply(){};
  856. QueryReply(ui32 QID, ui32 Answer):qid(QID),answer(Answer){};
  857. ui32 qid, answer; //hero and artifact id
  858. void applyGh(CGameHandler *gh);
  859. template <typename Handler> void serialize(Handler &h, const int version)
  860. {
  861. h & qid & answer;
  862. }
  863. };
  864. struct MakeAction : public CPackForServer
  865. {
  866. MakeAction(){};
  867. MakeAction(const BattleAction &BA):ba(BA){};
  868. BattleAction ba;
  869. void applyGh(CGameHandler *gh);
  870. template <typename Handler> void serialize(Handler &h, const int version)
  871. {
  872. h & ba;
  873. }
  874. };
  875. struct MakeCustomAction : public CPackForServer
  876. {
  877. MakeCustomAction(){};
  878. MakeCustomAction(const BattleAction &BA):ba(BA){};
  879. BattleAction ba;
  880. void applyGh(CGameHandler *gh);
  881. template <typename Handler> void serialize(Handler &h, const int version)
  882. {
  883. h & ba;
  884. }
  885. };
  886. /***********************************************************************************************************/
  887. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  888. {
  889. PlayerMessage(){CPackForClient::type = 513;};
  890. PlayerMessage(ui8 Player, const std::string &Text)
  891. :player(Player),text(Text)
  892. {CPackForClient::type = 513;};
  893. void applyCl(CClient *cl);
  894. void applyGs(CGameState *gs){};
  895. void applyGh(CGameHandler *gh);
  896. ui8 player;
  897. std::string text;
  898. template <typename Handler> void serialize(Handler &h, const int version)
  899. {
  900. h & text & player;
  901. }
  902. };
  903. struct SetSelection : public CPackForClient, public CPackForServer //514
  904. {
  905. SetSelection(){CPackForClient::type = 514;};
  906. DLL_EXPORT void applyGs(CGameState *gs);
  907. void applyGh(CGameHandler *gh);
  908. ui8 player;
  909. ui32 id;
  910. template <typename Handler> void serialize(Handler &h, const int version)
  911. {
  912. h & id & player;
  913. }
  914. };
  915. #endif //__NETPACKS_H__