NetPacks.h 53 KB

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