NetPacks.h 55 KB

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