NetPacks.h 56 KB

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