NetPacks.h 40 KB

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