NetPacks.h 55 KB

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