NetPacks.h 47 KB

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