NetPacks.h 59 KB

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