NetPacks.h 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282
  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(){type = 3002;};
  1077. void applyCl(CClient *cl);
  1078. DLL_LINKAGE void applyGs(CGameState *gs);
  1079. ui32 stack;
  1080. template <typename Handler> void serialize(Handler &h, const int version)
  1081. {
  1082. h & stack;
  1083. }
  1084. };
  1085. struct BattleResult : public CPackForClient//3003
  1086. {
  1087. enum EResult {NORMAL = 0, ESCAPE = 1, SURRENDER = 2};
  1088. BattleResult(){type = 3003;};
  1089. void applyFirstCl(CClient *cl);
  1090. void applyGs(CGameState *gs);
  1091. ui8 result; //EResult values
  1092. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  1093. std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
  1094. expType exp[2]; //exp for attacker and defender
  1095. std::set<ui32> artifacts; //artifacts taken from loser to winner - currently unused
  1096. template <typename Handler> void serialize(Handler &h, const int version)
  1097. {
  1098. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  1099. }
  1100. };
  1101. struct BattleStackMoved : public CPackForClient//3004
  1102. {
  1103. ui32 stack;
  1104. std::vector<BattleHex> tilesToMove;
  1105. ui8 distance, teleporting;
  1106. BattleStackMoved(){type = 3004;};
  1107. void applyFirstCl(CClient *cl);
  1108. void applyGs(CGameState *gs);
  1109. template <typename Handler> void serialize(Handler &h, const int version)
  1110. {
  1111. h & stack & tilesToMove & distance;
  1112. }
  1113. };
  1114. struct StacksHealedOrResurrected : public CPackForClient //3013
  1115. {
  1116. StacksHealedOrResurrected(){type = 3013;}
  1117. DLL_LINKAGE void applyGs(CGameState *gs);
  1118. void applyCl(CClient *cl);
  1119. struct HealInfo
  1120. {
  1121. ui32 stackID;
  1122. ui32 healedHP;
  1123. ui8 lowLevelResurrection; //in case this stack is resurrected by this heal, it will be marked as SUMMONED //TODO: replace with separate counter
  1124. template <typename Handler> void serialize(Handler &h, const int version)
  1125. {
  1126. h & stackID & healedHP & lowLevelResurrection;
  1127. }
  1128. };
  1129. std::vector<HealInfo> healedStacks;
  1130. ui8 lifeDrain; //if true, this heal is an effect of life drain
  1131. ui8 tentHealing; //if true, than it's healing via First Aid Tent
  1132. si32 drainedFrom; //if life drain - then stack life was drain from, if tentHealing - stack that is a healer
  1133. template <typename Handler> void serialize(Handler &h, const int version)
  1134. {
  1135. h & healedStacks & lifeDrain & tentHealing & drainedFrom;
  1136. }
  1137. };
  1138. struct BattleStackAttacked : public CPackForClient//3005
  1139. {
  1140. BattleStackAttacked(){flags = 0; type = 3005;};
  1141. void applyFirstCl(CClient * cl);
  1142. //void applyCl(CClient *cl);
  1143. DLL_LINKAGE void applyGs(CGameState *gs);
  1144. ui32 stackAttacked, attackerID;
  1145. ui32 newAmount, newHP, killedAmount, damageAmount;
  1146. enum EFlags {KILLED = 1, EFFECT = 2, SECONDARY = 4, REBIRTH = 8, CLONE_KILLED = 16};
  1147. ui8 flags; //uses EFlags (above)
  1148. ui32 effect; //set only if flag EFFECT is set
  1149. std::vector<StacksHealedOrResurrected> healedStacks; //used when life drain
  1150. bool killed() const//if target stack was killed
  1151. {
  1152. return flags & KILLED || flags & CLONE_KILLED;
  1153. }
  1154. bool cloneKilled() const
  1155. {
  1156. return flags & CLONE_KILLED;
  1157. }
  1158. bool isEffect() const//if stack has been attacked by a spell
  1159. {
  1160. return flags & EFFECT;
  1161. }
  1162. bool isSecondary() const//if stack was not a primary target (receives no spell effects)
  1163. {
  1164. return flags & SECONDARY;
  1165. }
  1166. bool willRebirth() const//if stack was not a primary target (receives no spell effects)
  1167. {
  1168. return flags & REBIRTH;
  1169. }
  1170. bool lifeDrain() const //if this attack involves life drain effect
  1171. {
  1172. return healedStacks.size() > 0;
  1173. }
  1174. template <typename Handler> void serialize(Handler &h, const int version)
  1175. {
  1176. h & stackAttacked & attackerID & newAmount & newHP & flags & killedAmount & damageAmount & effect
  1177. & healedStacks;
  1178. }
  1179. bool operator<(const BattleStackAttacked &b) const
  1180. {
  1181. return stackAttacked < b.stackAttacked;
  1182. }
  1183. };
  1184. struct BattleAttack : public CPackForClient//3006
  1185. {
  1186. BattleAttack(){flags = 0; type = 3006;};
  1187. void applyFirstCl(CClient *cl);
  1188. DLL_LINKAGE void applyGs(CGameState *gs);
  1189. void applyCl(CClient *cl);
  1190. std::vector<BattleStackAttacked> bsa;
  1191. ui32 stackAttacking;
  1192. ui8 flags; //uses Eflags (below)
  1193. enum EFlags{SHOT = 1, COUNTER = 2, LUCKY = 4, UNLUCKY = 8, BALLISTA_DOUBLE_DMG = 16, DEATH_BLOW = 32};
  1194. bool shot() const//distance attack - decrease number of shots
  1195. {
  1196. return flags & SHOT;
  1197. }
  1198. bool counter() const//is it counterattack?
  1199. {
  1200. return flags & COUNTER;
  1201. }
  1202. bool lucky() const
  1203. {
  1204. return flags & LUCKY;
  1205. }
  1206. bool unlucky() const
  1207. {
  1208. //TODO: support?
  1209. return flags & UNLUCKY;
  1210. }
  1211. bool ballistaDoubleDmg() const //if it's ballista attack and does double dmg
  1212. {
  1213. return flags & BALLISTA_DOUBLE_DMG;
  1214. }
  1215. bool deathBlow() const
  1216. {
  1217. return flags & DEATH_BLOW;
  1218. }
  1219. //bool killed() //if target stack was killed
  1220. //{
  1221. // return bsa.killed();
  1222. //}
  1223. template <typename Handler> void serialize(Handler &h, const int version)
  1224. {
  1225. h & bsa & stackAttacking & flags;
  1226. }
  1227. };
  1228. struct StartAction : public CPackForClient//3007
  1229. {
  1230. StartAction(){type = 3007;};
  1231. StartAction(const BattleAction &act){ba = act; type = 3007;};
  1232. void applyFirstCl(CClient *cl);
  1233. DLL_LINKAGE void applyGs(CGameState *gs);
  1234. BattleAction ba;
  1235. template <typename Handler> void serialize(Handler &h, const int version)
  1236. {
  1237. h & ba;
  1238. }
  1239. };
  1240. struct EndAction : public CPackForClient//3008
  1241. {
  1242. EndAction(){type = 3008;};
  1243. void applyCl(CClient *cl);
  1244. template <typename Handler> void serialize(Handler &h, const int version)
  1245. {
  1246. }
  1247. };
  1248. struct BattleSpellCast : public CPackForClient//3009
  1249. {
  1250. BattleSpellCast(){type = 3009;};
  1251. DLL_LINKAGE void applyGs(CGameState *gs);
  1252. void applyCl(CClient *cl);
  1253. si32 dmgToDisplay; //this amount will be displayed as amount of damage dealt by spell
  1254. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  1255. ui32 id; //id of spell
  1256. ui8 skill; //caster's skill level
  1257. ui8 spellCost;
  1258. ui8 manaGained; //mana channeling ability
  1259. BattleHex tile; //destination tile (may not be set in some global/mass spells
  1260. std::vector<ui32> resisted; //ids of creatures that resisted this spell
  1261. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  1262. TCreature attackerType;//id of caster to generate console message; -1 if not set (eg. spell casted by artifact)
  1263. ui8 castedByHero; //if true - spell has been casted by hero, otherwise by a creature
  1264. template <typename Handler> void serialize(Handler &h, const int version)
  1265. {
  1266. h & dmgToDisplay & side & id & skill & spellCost & manaGained & tile & resisted & affectedCres & attackerType & castedByHero;
  1267. }
  1268. };
  1269. struct SetStackEffect : public CPackForClient //3010
  1270. {
  1271. SetStackEffect(){type = 3010;};
  1272. DLL_LINKAGE void applyGs(CGameState *gs);
  1273. void applyCl(CClient *cl);
  1274. std::vector<ui32> stacks; //affected stacks (IDs)
  1275. std::vector<Bonus> effect; //bonuses to apply
  1276. std::vector<std::pair<ui32, Bonus> > uniqueBonuses; //bonuses per single stack
  1277. template <typename Handler> void serialize(Handler &h, const int version)
  1278. {
  1279. h & stacks & effect & uniqueBonuses;
  1280. }
  1281. };
  1282. struct StacksInjured : public CPackForClient //3011
  1283. {
  1284. StacksInjured(){type = 3011;}
  1285. DLL_LINKAGE void applyGs(CGameState *gs);
  1286. void applyCl(CClient *cl);
  1287. std::vector<BattleStackAttacked> stacks;
  1288. template <typename Handler> void serialize(Handler &h, const int version)
  1289. {
  1290. h & stacks;
  1291. }
  1292. };
  1293. struct BattleResultsApplied : public CPackForClient //3012
  1294. {
  1295. BattleResultsApplied(){type = 3012;}
  1296. ui8 player1, player2;
  1297. void applyCl(CClient *cl);
  1298. template <typename Handler> void serialize(Handler &h, const int version)
  1299. {
  1300. h & player1 & player2;
  1301. }
  1302. };
  1303. struct ObstaclesRemoved : public CPackForClient //3014
  1304. {
  1305. ObstaclesRemoved(){type = 3014;}
  1306. DLL_LINKAGE void applyGs(CGameState *gs);
  1307. void applyCl(CClient *cl);
  1308. std::set<si32> obstacles; //uniqueIDs of removed obstacles
  1309. template <typename Handler> void serialize(Handler &h, const int version)
  1310. {
  1311. h & obstacles;
  1312. }
  1313. };
  1314. struct CatapultAttack : public CPackForClient //3015
  1315. {
  1316. CatapultAttack(){type = 3015;}
  1317. DLL_LINKAGE void applyGs(CGameState *gs);
  1318. void applyCl(CClient *cl);
  1319. std::set< std::pair< std::pair< ui8, si16 >, ui8> > attackedParts; // < <attackedPartOfWall, attacked hex >, damageDealt>
  1320. //attackedPartOfWall; //[0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate;
  1321. //damageDealt;
  1322. int attacker; //if -1, then a spell caused this
  1323. template <typename Handler> void serialize(Handler &h, const int version)
  1324. {
  1325. h & attackedParts & attacker;
  1326. }
  1327. };
  1328. struct BattleStacksRemoved : public CPackForClient //3016
  1329. {
  1330. BattleStacksRemoved(){type = 3016;}
  1331. DLL_LINKAGE void applyGs(CGameState *gs);
  1332. void applyCl(CClient *cl);
  1333. std::set<ui32> stackIDs; //IDs of removed stacks
  1334. template <typename Handler> void serialize(Handler &h, const int version)
  1335. {
  1336. h & stackIDs;
  1337. }
  1338. };
  1339. struct BattleStackAdded : public CPackForClient //3017
  1340. {
  1341. BattleStackAdded(){type = 3017;};
  1342. DLL_LINKAGE void applyGs(CGameState *gs);
  1343. void applyCl(CClient *cl);
  1344. int attacker; // if true, stack belongs to attacker
  1345. int creID;
  1346. int amount;
  1347. int pos;
  1348. int summoned; //if true, remove it afterwards
  1349. template <typename Handler> void serialize(Handler &h, const int version)
  1350. {
  1351. h & attacker & creID & amount & pos & summoned;
  1352. }
  1353. };
  1354. struct BattleSetStackProperty : public CPackForClient //3018
  1355. {
  1356. BattleSetStackProperty(){type = 3018;};
  1357. enum BattleStackProperty {CASTS, ENCHANTER_COUNTER, UNBIND, CLONED};
  1358. DLL_LINKAGE void applyGs(CGameState *gs);
  1359. //void applyCl(CClient *cl){};
  1360. int stackID;
  1361. int which; //using enum values
  1362. int val;
  1363. int absolute;
  1364. template <typename Handler> void serialize(Handler &h, const int version)
  1365. {
  1366. h & stackID & which & val & absolute;
  1367. }
  1368. };
  1369. struct BattleTriggerEffect : public CPackForClient //3019
  1370. { //activated at the beginning of turn
  1371. BattleTriggerEffect(){type = 3019;};
  1372. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1373. void applyCl(CClient *cl); //play animations & stuff
  1374. //enum BattleEffect {REGENERATION, MANA_DRAIN, FEAR, MANA_CHANNELING, ENCHANTER, UNBIND, POISON, ENCHANTED, SUMMONER};
  1375. int stackID;
  1376. int effect; //use enumBattleEffect or corresponding Bonus type for sanity?
  1377. int val;
  1378. int additionalInfo;
  1379. template <typename Handler> void serialize(Handler &h, const int version)
  1380. {
  1381. h & stackID & effect & val & additionalInfo;
  1382. }
  1383. };
  1384. struct BattleObstaclePlaced : public CPackForClient //3020
  1385. { //activated at the beginning of turn
  1386. BattleObstaclePlaced(){type = 3020;};
  1387. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1388. void applyCl(CClient *cl); //play animations & stuff
  1389. shared_ptr<CObstacleInstance> obstacle;
  1390. template <typename Handler> void serialize(Handler &h, const int version)
  1391. {
  1392. h & obstacle;
  1393. }
  1394. };
  1395. struct ShowInInfobox : public CPackForClient //107
  1396. {
  1397. ShowInInfobox(){type = 107;};
  1398. ui8 player;
  1399. Component c;
  1400. MetaString text;
  1401. void applyCl(CClient *cl);
  1402. template <typename Handler> void serialize(Handler &h, const int version)
  1403. {
  1404. h & player & c & text;
  1405. }
  1406. };
  1407. struct AdvmapSpellCast : public CPackForClient //108
  1408. {
  1409. AdvmapSpellCast(){type = 108;}
  1410. const CGHeroInstance * caster;
  1411. si32 spellID;
  1412. void applyCl(CClient *cl);
  1413. template <typename Handler> void serialize(Handler &h, const int version)
  1414. {
  1415. h & caster & spellID;
  1416. }
  1417. };
  1418. /***********************************************************************************************************/
  1419. struct CommitPackage : public CPackForServer
  1420. {
  1421. bool freePack; //for local usage, DO NOT serialize
  1422. bool applyGh(CGameHandler *gh);
  1423. CPackForClient *packToCommit;
  1424. CommitPackage()
  1425. {
  1426. freePack = true;
  1427. }
  1428. ~CommitPackage()
  1429. {
  1430. if(freePack)
  1431. delete packToCommit;
  1432. }
  1433. template <typename Handler> void serialize(Handler &h, const int version)
  1434. {
  1435. h & packToCommit;
  1436. }
  1437. };
  1438. struct CloseServer : public CPackForServer
  1439. {
  1440. bool applyGh(CGameHandler *gh);
  1441. template <typename Handler> void serialize(Handler &h, const int version)
  1442. {}
  1443. };
  1444. struct EndTurn : public CPackForServer
  1445. {
  1446. bool applyGh(CGameHandler *gh);
  1447. template <typename Handler> void serialize(Handler &h, const int version)
  1448. {}
  1449. };
  1450. struct DismissHero : public CPackForServer
  1451. {
  1452. DismissHero(){};
  1453. DismissHero(si32 HID) : hid(HID) {};
  1454. si32 hid;
  1455. bool applyGh(CGameHandler *gh);
  1456. template <typename Handler> void serialize(Handler &h, const int version)
  1457. {
  1458. h & hid;
  1459. }
  1460. };
  1461. struct MoveHero : public CPackForServer
  1462. {
  1463. MoveHero(){};
  1464. MoveHero(const int3 &Dest, si32 HID) : dest(Dest), hid(HID){};
  1465. int3 dest;
  1466. si32 hid;
  1467. bool applyGh(CGameHandler *gh);
  1468. template <typename Handler> void serialize(Handler &h, const int version)
  1469. {
  1470. h & dest & hid;
  1471. }
  1472. };
  1473. struct CastleTeleportHero : public CPackForServer
  1474. {
  1475. CastleTeleportHero(){};
  1476. CastleTeleportHero(const si32 HID, si32 Dest, ui8 Source ) : dest(Dest), hid(HID), source(Source){};
  1477. si32 dest;
  1478. si32 hid;
  1479. si8 source;//who give teleporting, 1=castle gate
  1480. bool applyGh(CGameHandler *gh);
  1481. template <typename Handler> void serialize(Handler &h, const int version)
  1482. {
  1483. h & dest & hid;
  1484. }
  1485. };
  1486. struct ArrangeStacks : public CPackForServer
  1487. {
  1488. ArrangeStacks(){};
  1489. ArrangeStacks(ui8 W, ui8 P1, ui8 P2, si32 ID1, si32 ID2, si32 VAL)
  1490. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  1491. ui8 what; //1 - swap; 2 - merge; 3 - split
  1492. ui8 p1, p2; //positions of first and second stack
  1493. si32 id1, id2; //ids of objects with garrison
  1494. si32 val;
  1495. bool applyGh(CGameHandler *gh);
  1496. template <typename Handler> void serialize(Handler &h, const int version)
  1497. {
  1498. h & what & p1 & p2 & id1 & id2 & val;
  1499. }
  1500. };
  1501. struct DisbandCreature : public CPackForServer
  1502. {
  1503. DisbandCreature(){};
  1504. DisbandCreature(ui8 Pos, si32 ID):pos(Pos),id(ID){};
  1505. ui8 pos; //stack pos
  1506. si32 id; //object id
  1507. bool applyGh(CGameHandler *gh);
  1508. template <typename Handler> void serialize(Handler &h, const int version)
  1509. {
  1510. h & pos & id;
  1511. }
  1512. };
  1513. struct BuildStructure : public CPackForServer
  1514. {
  1515. BuildStructure(){};
  1516. BuildStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  1517. si32 bid, tid; //structure and town ids
  1518. bool applyGh(CGameHandler *gh);
  1519. template <typename Handler> void serialize(Handler &h, const int version)
  1520. {
  1521. h & tid & bid;
  1522. }
  1523. };
  1524. struct RazeStructure : public BuildStructure
  1525. {
  1526. RazeStructure(){};
  1527. //RazeStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  1528. bool applyGh(CGameHandler *gh);
  1529. };
  1530. struct RecruitCreatures : public CPackForServer
  1531. {
  1532. RecruitCreatures(){};
  1533. RecruitCreatures(si32 TID, si32 CRID, si32 Amount, si32 Level):tid(TID),crid(CRID),amount(Amount),level(Level){};
  1534. si32 tid; //town id
  1535. ui32 crid, amount;//creature ID and amount
  1536. si32 level;//dwelling level to buy from, -1 if any
  1537. bool applyGh(CGameHandler *gh);
  1538. template <typename Handler> void serialize(Handler &h, const int version)
  1539. {
  1540. h & tid & crid & amount & level;
  1541. }
  1542. };
  1543. struct UpgradeCreature : public CPackForServer
  1544. {
  1545. UpgradeCreature(){};
  1546. UpgradeCreature(ui8 Pos, si32 ID, si32 CRID):pos(Pos),id(ID), cid(CRID){};
  1547. ui8 pos; //stack pos
  1548. si32 id; //object id
  1549. si32 cid; //id of type to which we want make upgrade
  1550. bool applyGh(CGameHandler *gh);
  1551. template <typename Handler> void serialize(Handler &h, const int version)
  1552. {
  1553. h & pos & id & cid;
  1554. }
  1555. };
  1556. struct GarrisonHeroSwap : public CPackForServer
  1557. {
  1558. GarrisonHeroSwap(){};
  1559. GarrisonHeroSwap(si32 TID):tid(TID){};
  1560. si32 tid;
  1561. bool applyGh(CGameHandler *gh);
  1562. template <typename Handler> void serialize(Handler &h, const int version)
  1563. {
  1564. h & tid;
  1565. }
  1566. };
  1567. struct ExchangeArtifacts : public CPackForServer
  1568. //TODO: allow exchange between heroes, stacks and commanders
  1569. {
  1570. ArtifactLocation src, dst;
  1571. ExchangeArtifacts(){};
  1572. bool applyGh(CGameHandler *gh);
  1573. template <typename Handler> void serialize(Handler &h, const int version)
  1574. {
  1575. h & src & dst;
  1576. }
  1577. };
  1578. struct AssembleArtifacts : public CPackForServer
  1579. {
  1580. AssembleArtifacts(){};
  1581. AssembleArtifacts(si32 _heroID, ui16 _artifactSlot, bool _assemble, ui32 _assembleTo)
  1582. : heroID(_heroID), artifactSlot(_artifactSlot), assemble(_assemble), assembleTo(_assembleTo){};
  1583. si32 heroID;
  1584. ui16 artifactSlot;
  1585. bool assemble; // True to assemble artifact, false to disassemble.
  1586. ui32 assembleTo; // Artifact to assemble into.
  1587. bool applyGh(CGameHandler *gh);
  1588. template <typename Handler> void serialize(Handler &h, const int version)
  1589. {
  1590. h & heroID & artifactSlot & assemble & assembleTo;
  1591. }
  1592. };
  1593. struct BuyArtifact : public CPackForServer
  1594. {
  1595. BuyArtifact(){};
  1596. BuyArtifact(si32 HID, si32 AID):hid(HID),aid(AID){};
  1597. si32 hid, aid; //hero and artifact id
  1598. bool applyGh(CGameHandler *gh);
  1599. template <typename Handler> void serialize(Handler &h, const int version)
  1600. {
  1601. h & hid & aid;
  1602. }
  1603. };
  1604. struct TradeOnMarketplace : public CPackForServer
  1605. {
  1606. TradeOnMarketplace(){};
  1607. const CGObjectInstance *market;
  1608. const CGHeroInstance *hero; //needed when trading artifacts / creatures
  1609. ui8 mode;//enum EEMarketMode
  1610. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res (exception: when sacrificing art r1 is art id [todo: make r2 preferred slot?]
  1611. ui32 val; //units of sold resource
  1612. bool applyGh(CGameHandler *gh);
  1613. template <typename Handler> void serialize(Handler &h, const int version)
  1614. {
  1615. h & market & hero & mode & r1 & r2 & val;
  1616. }
  1617. };
  1618. struct SetFormation : public CPackForServer
  1619. {
  1620. SetFormation(){};
  1621. SetFormation(si32 HID, ui8 Formation):hid(HID),formation(Formation){};
  1622. si32 hid;
  1623. ui8 formation;
  1624. bool applyGh(CGameHandler *gh);
  1625. template <typename Handler> void serialize(Handler &h, const int version)
  1626. {
  1627. h & hid & formation;
  1628. }
  1629. };
  1630. struct HireHero : public CPackForServer
  1631. {
  1632. HireHero(){};
  1633. HireHero(si32 HID, si32 TID):hid(HID),tid(TID){};
  1634. si32 hid, tid; //available hero serial and town (tavern) id
  1635. ui8 player;
  1636. bool applyGh(CGameHandler *gh);
  1637. template <typename Handler> void serialize(Handler &h, const int version)
  1638. {
  1639. h & hid & tid & player;
  1640. }
  1641. };
  1642. struct BuildBoat : public CPackForServer
  1643. {
  1644. BuildBoat(){};
  1645. si32 objid; //where player wants to buy a boat
  1646. bool applyGh(CGameHandler *gh);
  1647. template <typename Handler> void serialize(Handler &h, const int version)
  1648. {
  1649. h & objid;
  1650. }
  1651. };
  1652. struct QueryReply : public CPackForServer
  1653. {
  1654. QueryReply(){type = 6000;};
  1655. QueryReply(ui32 QID, ui32 Answer):qid(QID),answer(Answer){type = 6000;};
  1656. ui32 qid, answer; //hero and artifact id
  1657. ui8 player;
  1658. bool applyGh(CGameHandler *gh);
  1659. template <typename Handler> void serialize(Handler &h, const int version)
  1660. {
  1661. h & qid & answer & player;
  1662. }
  1663. };
  1664. struct MakeAction : public CPackForServer
  1665. {
  1666. MakeAction(){};
  1667. MakeAction(const BattleAction &BA):ba(BA){};
  1668. BattleAction ba;
  1669. bool applyGh(CGameHandler *gh);
  1670. template <typename Handler> void serialize(Handler &h, const int version)
  1671. {
  1672. h & ba;
  1673. }
  1674. };
  1675. struct MakeCustomAction : public CPackForServer
  1676. {
  1677. MakeCustomAction(){};
  1678. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1679. BattleAction ba;
  1680. bool applyGh(CGameHandler *gh);
  1681. template <typename Handler> void serialize(Handler &h, const int version)
  1682. {
  1683. h & ba;
  1684. }
  1685. };
  1686. struct DigWithHero : public CPackForServer
  1687. {
  1688. DigWithHero(){}
  1689. si32 id; //digging hero id
  1690. bool applyGh(CGameHandler *gh);
  1691. template <typename Handler> void serialize(Handler &h, const int version)
  1692. {
  1693. h & id;
  1694. }
  1695. };
  1696. struct CastAdvSpell : public CPackForServer
  1697. {
  1698. CastAdvSpell(){}
  1699. si32 hid; //hero id
  1700. ui32 sid; //spell id
  1701. int3 pos; //selected tile (not always used)
  1702. bool applyGh(CGameHandler *gh);
  1703. template <typename Handler> void serialize(Handler &h, const int version)
  1704. {
  1705. h & hid & sid & pos;
  1706. }
  1707. };
  1708. /***********************************************************************************************************/
  1709. struct SaveGame : public CPackForClient, public CPackForServer
  1710. {
  1711. SaveGame(){};
  1712. SaveGame(const std::string &Fname) :fname(Fname){};
  1713. std::string fname;
  1714. void applyCl(CClient *cl);
  1715. void applyGs(CGameState *gs){};
  1716. bool applyGh(CGameHandler *gh);
  1717. template <typename Handler> void serialize(Handler &h, const int version)
  1718. {
  1719. h & fname;
  1720. }
  1721. };
  1722. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  1723. {
  1724. PlayerMessage(){CPackForClient::type = 513;};
  1725. PlayerMessage(ui8 Player, const std::string &Text)
  1726. :player(Player),text(Text)
  1727. {CPackForClient::type = 513;};
  1728. void applyCl(CClient *cl);
  1729. void applyGs(CGameState *gs){};
  1730. bool applyGh(CGameHandler *gh);
  1731. ui8 player;
  1732. std::string text;
  1733. template <typename Handler> void serialize(Handler &h, const int version)
  1734. {
  1735. h & text & player;
  1736. }
  1737. };
  1738. struct SetSelection : public CPackForClient, public CPackForServer //514
  1739. {
  1740. SetSelection(){CPackForClient::type = 514;};
  1741. DLL_LINKAGE void applyGs(CGameState *gs);
  1742. bool applyGh(CGameHandler *gh);
  1743. void applyCl(CClient *cl);
  1744. ui8 player;
  1745. ui32 id;
  1746. template <typename Handler> void serialize(Handler &h, const int version)
  1747. {
  1748. h & id & player;
  1749. }
  1750. };
  1751. struct CenterView : public CPackForClient//515
  1752. {
  1753. CenterView(){CPackForClient::type = 515;};
  1754. void applyCl(CClient *cl);
  1755. ui8 player;
  1756. int3 pos;
  1757. ui32 focusTime; //ms
  1758. template <typename Handler> void serialize(Handler &h, const int version)
  1759. {
  1760. h & pos & player & focusTime;
  1761. }
  1762. };
  1763. /***********************************************************************************************************/
  1764. struct CPackForSelectionScreen : public CPack
  1765. {
  1766. void apply(CSelectionScreen *selScreen){}; //that functions are implemented in CPreGame.cpp
  1767. };
  1768. class CPregamePackToPropagate : public CPackForSelectionScreen
  1769. {};
  1770. class CPregamePackToHost : public CPackForSelectionScreen
  1771. {};
  1772. struct ChatMessage : public CPregamePackToPropagate
  1773. {
  1774. std::string playerName, message;
  1775. void apply(CSelectionScreen *selScreen);
  1776. template <typename Handler> void serialize(Handler &h, const int version)
  1777. {
  1778. h & playerName & message;
  1779. }
  1780. };
  1781. struct QuitMenuWithoutStarting : public CPregamePackToPropagate
  1782. {
  1783. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1784. template <typename Handler> void serialize(Handler &h, const int version)
  1785. {}
  1786. };
  1787. struct PlayerJoined : public CPregamePackToHost
  1788. {
  1789. std::string playerName;
  1790. ui8 connectionID;
  1791. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1792. template <typename Handler> void serialize(Handler &h, const int version)
  1793. {
  1794. h & playerName & connectionID;
  1795. }
  1796. };
  1797. struct SelectMap : public CPregamePackToPropagate
  1798. {
  1799. const CMapInfo *mapInfo;
  1800. bool free;
  1801. SelectMap(const CMapInfo &src)
  1802. {
  1803. mapInfo = &src;
  1804. free = false;
  1805. }
  1806. SelectMap()
  1807. {
  1808. mapInfo = NULL;
  1809. free = true;
  1810. }
  1811. ~SelectMap()
  1812. {
  1813. if(free)
  1814. delete mapInfo;
  1815. }
  1816. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1817. template <typename Handler> void serialize(Handler &h, const int version)
  1818. {
  1819. h & mapInfo;
  1820. }
  1821. };
  1822. struct UpdateStartOptions : public CPregamePackToPropagate
  1823. {
  1824. StartInfo *options;
  1825. bool free;
  1826. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1827. UpdateStartOptions(StartInfo &src)
  1828. {
  1829. options = &src;
  1830. free = false;
  1831. }
  1832. UpdateStartOptions()
  1833. {
  1834. options = NULL;
  1835. free = true;
  1836. }
  1837. ~UpdateStartOptions()
  1838. {
  1839. if(free)
  1840. delete options;
  1841. }
  1842. template <typename Handler> void serialize(Handler &h, const int version)
  1843. {
  1844. h & options;
  1845. }
  1846. };
  1847. struct PregameGuiAction : public CPregamePackToPropagate
  1848. {
  1849. enum {NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST};
  1850. ui8 action;
  1851. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1852. template <typename Handler> void serialize(Handler &h, const int version)
  1853. {
  1854. h & action;
  1855. }
  1856. };
  1857. struct RequestOptionsChange : public CPregamePackToHost
  1858. {
  1859. enum {TOWN, HERO, BONUS};
  1860. ui8 what;
  1861. si8 direction; //-1 or +1
  1862. ui8 playerID;
  1863. RequestOptionsChange(ui8 What, si8 Dir, ui8 Player)
  1864. :what(What), direction(Dir), playerID(Player)
  1865. {}
  1866. RequestOptionsChange(){}
  1867. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1868. template <typename Handler> void serialize(Handler &h, const int version)
  1869. {
  1870. h & what & direction & playerID;
  1871. }
  1872. };
  1873. struct PlayerLeft : public CPregamePackToPropagate
  1874. {
  1875. ui8 playerID;
  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 & playerID;
  1880. }
  1881. };
  1882. struct PlayersNames : public CPregamePackToPropagate
  1883. {
  1884. public:
  1885. std::map<ui32, std::string> playerNames;
  1886. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1887. template <typename Handler> void serialize(Handler &h, const int version)
  1888. {
  1889. h & playerNames;
  1890. }
  1891. };
  1892. struct StartWithCurrentSettings : public CPregamePackToPropagate
  1893. {
  1894. public:
  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. };