NetPacks.h 60 KB

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