NetPacks.h 57 KB

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