NetPacks.h 49 KB

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