NetPacks.h 57 KB

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