NetPacks.h 41 KB

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