NetPacks.h 56 KB

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