NetPacks.h 57 KB

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