NetPacks.h 58 KB

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