NetPacks.h 55 KB

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