NetPacks.h 56 KB

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