NetPacks.h 56 KB

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