NetPacks.h 40 KB

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