NetPacks.h 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265
  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 "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_RESET, BANK_CLEAR,
  838. //object with reward
  839. REWARD_RESET, REWARD_SELECT
  840. };
  841. }
  842. struct SetObjectProperty : public CPackForClient//1001
  843. {
  844. DLL_LINKAGE void applyGs(CGameState *gs);
  845. void applyCl(CClient *cl);
  846. ObjectInstanceID id;
  847. ui8 what; // see ObjProperty enum
  848. ui32 val;
  849. SetObjectProperty(){type = 1001;};
  850. SetObjectProperty(ObjectInstanceID ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
  851. template <typename Handler> void serialize(Handler &h, const int version)
  852. {
  853. h & id & what & val;
  854. }
  855. };
  856. struct SetHoverName : public CPackForClient//1002
  857. {
  858. DLL_LINKAGE void applyGs(CGameState *gs);
  859. ObjectInstanceID id;
  860. MetaString name;
  861. SetHoverName(){type = 1002;}
  862. SetHoverName(ObjectInstanceID ID, MetaString& Name):id(ID),name(Name){type = 1002;}
  863. template <typename Handler> void serialize(Handler &h, const int version)
  864. {
  865. h & id & name;
  866. }
  867. };
  868. struct ChangeObjectVisitors : public CPackForClient // 1003
  869. {
  870. enum VisitMode
  871. {
  872. VISITOR_ADD, // mark hero as one that have visited this object
  873. VISITOR_REMOVE, // unmark visitor, reversed to ADD
  874. VISITOR_CLEAR // clear all visitors from this object (object reset)
  875. };
  876. ui32 mode; // uses VisitMode enum
  877. ObjectInstanceID object;
  878. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  879. DLL_LINKAGE void applyGs(CGameState *gs);
  880. ChangeObjectVisitors()
  881. { type = 1003; }
  882. ChangeObjectVisitors(ui32 mode, ObjectInstanceID object, ObjectInstanceID heroID = ObjectInstanceID(-1)):
  883. mode(mode),
  884. object(object),
  885. hero(heroID)
  886. { type = 1003; }
  887. template <typename Handler> void serialize(Handler &h, const int version)
  888. {
  889. h & object & hero & mode;
  890. }
  891. };
  892. struct HeroLevelUp : public Query//2000
  893. {
  894. void applyCl(CClient *cl);
  895. DLL_LINKAGE void applyGs(CGameState *gs);
  896. const CGHeroInstance *hero;
  897. PrimarySkill::PrimarySkill primskill;
  898. std::vector<SecondarySkill> skills;
  899. HeroLevelUp(){type = 2000;};
  900. template <typename Handler> void serialize(Handler &h, const int version)
  901. {
  902. h & queryID & hero & primskill & skills;
  903. }
  904. };
  905. struct CommanderLevelUp : public Query
  906. {
  907. void applyCl(CClient *cl);
  908. DLL_LINKAGE void applyGs(CGameState *gs);
  909. const CGHeroInstance *hero;
  910. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  911. CommanderLevelUp(){type = 2005;};
  912. template <typename Handler> void serialize(Handler &h, const int version)
  913. {
  914. h & queryID & hero & skills;
  915. }
  916. };
  917. struct TradeComponents : public CPackForClient, public CPackForServer
  918. {
  919. ///used to handle info about components available in shops
  920. void applyCl(CClient *cl);
  921. DLL_LINKAGE void applyGs(CGameState *gs);
  922. si32 heroid;
  923. ui32 objectid;
  924. std::map<ui16, Component> available, chosen, bought;
  925. template <typename Handler> void serialize(Handler &h, const int version)
  926. {
  927. h & heroid & objectid & available & chosen & bought;
  928. }
  929. };
  930. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  931. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  932. //Until sending reply player won't be allowed to take any actions
  933. struct BlockingDialog : public Query//2003
  934. {
  935. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  936. void applyCl(CClient *cl);
  937. MetaString text;
  938. std::vector<Component> components;
  939. PlayerColor player;
  940. ui8 flags;
  941. ui16 soundID;
  942. bool cancel() const
  943. {
  944. return flags & ALLOW_CANCEL;
  945. }
  946. bool selection() const
  947. {
  948. return flags & SELECTION;
  949. }
  950. BlockingDialog(bool yesno, bool Selection)
  951. {
  952. type = 2003;
  953. flags = 0;
  954. soundID = 0;
  955. if(yesno) flags |= ALLOW_CANCEL;
  956. if(Selection) flags |= SELECTION;
  957. }
  958. BlockingDialog()
  959. {
  960. type = 2003;
  961. flags = 0;
  962. soundID = 0;
  963. };
  964. void addResourceComponents(TResources resources)
  965. {
  966. for(TResources::nziterator i(resources); i.valid(); i++)
  967. components.push_back(Component(Component::RESOURCE, i->resType, i->resVal, 0));
  968. }
  969. template <typename Handler> void serialize(Handler &h, const int version)
  970. {
  971. h & queryID & text & components & player & flags & soundID;
  972. }
  973. };
  974. struct GarrisonDialog : public Query//2004
  975. {
  976. GarrisonDialog(){type = 2004;}
  977. void applyCl(CClient *cl);
  978. ObjectInstanceID objid, hid;
  979. bool removableUnits;
  980. template <typename Handler> void serialize(Handler &h, const int version)
  981. {
  982. h & queryID & objid & hid & removableUnits;
  983. }
  984. };
  985. struct ExchangeDialog : public Query//2005
  986. {
  987. ExchangeDialog(){type = 2005;}
  988. void applyCl(CClient *cl);
  989. std::array<const CGHeroInstance*, 2> heroes;
  990. template <typename Handler> void serialize(Handler &h, const int version)
  991. {
  992. h & queryID & heroes;
  993. }
  994. };
  995. struct BattleInfo;
  996. struct BattleStart : public CPackForClient//3000
  997. {
  998. BattleStart(){type = 3000;};
  999. void applyFirstCl(CClient *cl);
  1000. void applyCl(CClient *cl);
  1001. DLL_LINKAGE void applyGs(CGameState *gs);
  1002. BattleInfo * info;
  1003. template <typename Handler> void serialize(Handler &h, const int version)
  1004. {
  1005. h & info;
  1006. }
  1007. };
  1008. struct BattleNextRound : public CPackForClient//3001
  1009. {
  1010. BattleNextRound(){type = 3001;};
  1011. void applyFirstCl(CClient *cl);
  1012. void applyCl(CClient *cl);
  1013. DLL_LINKAGE void applyGs( CGameState *gs );
  1014. si32 round;
  1015. template <typename Handler> void serialize(Handler &h, const int version)
  1016. {
  1017. h & round;
  1018. }
  1019. };
  1020. struct BattleSetActiveStack : public CPackForClient//3002
  1021. {
  1022. BattleSetActiveStack()
  1023. {
  1024. type = 3002;
  1025. askPlayerInterface = true;
  1026. }
  1027. void applyCl(CClient *cl);
  1028. DLL_LINKAGE void applyGs(CGameState *gs);
  1029. ui32 stack;
  1030. ui8 askPlayerInterface;
  1031. template <typename Handler> void serialize(Handler &h, const int version)
  1032. {
  1033. h & stack & askPlayerInterface;
  1034. }
  1035. };
  1036. struct BattleResult : public CPackForClient//3003
  1037. {
  1038. enum EResult {NORMAL = 0, ESCAPE = 1, SURRENDER = 2};
  1039. BattleResult(){type = 3003;};
  1040. void applyFirstCl(CClient *cl);
  1041. void applyGs(CGameState *gs);
  1042. EResult result;
  1043. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  1044. std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
  1045. TExpType exp[2]; //exp for attacker and defender
  1046. std::set<ArtifactInstanceID> artifacts; //artifacts taken from loser to winner - currently unused
  1047. template <typename Handler> void serialize(Handler &h, const int version)
  1048. {
  1049. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  1050. }
  1051. };
  1052. struct BattleStackMoved : public CPackForClient//3004
  1053. {
  1054. ui32 stack;
  1055. std::vector<BattleHex> tilesToMove;
  1056. ui8 distance, teleporting;
  1057. BattleStackMoved(){type = 3004;};
  1058. void applyFirstCl(CClient *cl);
  1059. void applyGs(CGameState *gs);
  1060. template <typename Handler> void serialize(Handler &h, const int version)
  1061. {
  1062. h & stack & tilesToMove & distance;
  1063. }
  1064. };
  1065. struct StacksHealedOrResurrected : public CPackForClient //3013
  1066. {
  1067. StacksHealedOrResurrected(){type = 3013;}
  1068. DLL_LINKAGE void applyGs(CGameState *gs);
  1069. void applyCl(CClient *cl);
  1070. struct HealInfo
  1071. {
  1072. ui32 stackID;
  1073. ui32 healedHP;
  1074. ui8 lowLevelResurrection; //in case this stack is resurrected by this heal, it will be marked as SUMMONED //TODO: replace with separate counter
  1075. template <typename Handler> void serialize(Handler &h, const int version)
  1076. {
  1077. h & stackID & healedHP & lowLevelResurrection;
  1078. }
  1079. };
  1080. std::vector<HealInfo> healedStacks;
  1081. bool lifeDrain; //if true, this heal is an effect of life drain
  1082. bool tentHealing; //if true, than it's healing via First Aid Tent
  1083. si32 drainedFrom; //if life drain - then stack life was drain from, if tentHealing - stack that is a healer
  1084. template <typename Handler> void serialize(Handler &h, const int version)
  1085. {
  1086. h & healedStacks & lifeDrain & tentHealing & drainedFrom;
  1087. }
  1088. };
  1089. struct BattleStackAttacked : public CPackForClient//3005
  1090. {
  1091. BattleStackAttacked(){flags = 0; type = 3005;};
  1092. void applyFirstCl(CClient * cl);
  1093. //void applyCl(CClient *cl);
  1094. DLL_LINKAGE void applyGs(CGameState *gs);
  1095. ui32 stackAttacked, attackerID;
  1096. ui32 newAmount, newHP, killedAmount, damageAmount;
  1097. enum EFlags {KILLED = 1, EFFECT = 2, SECONDARY = 4, REBIRTH = 8, CLONE_KILLED = 16};
  1098. ui8 flags; //uses EFlags (above)
  1099. ui32 effect; //set only if flag EFFECT is set
  1100. std::vector<StacksHealedOrResurrected> healedStacks; //used when life drain
  1101. bool killed() const//if target stack was killed
  1102. {
  1103. return flags & KILLED || flags & CLONE_KILLED;
  1104. }
  1105. bool cloneKilled() const
  1106. {
  1107. return flags & CLONE_KILLED;
  1108. }
  1109. bool isEffect() const//if stack has been attacked by a spell
  1110. {
  1111. return flags & EFFECT;
  1112. }
  1113. bool isSecondary() const//if stack was not a primary target (receives no spell effects)
  1114. {
  1115. return flags & SECONDARY;
  1116. }
  1117. bool willRebirth() const//resurrection, e.g. Phoenix
  1118. {
  1119. return flags & REBIRTH;
  1120. }
  1121. bool lifeDrain() const //if this attack involves life drain effect
  1122. {
  1123. return healedStacks.size() > 0;
  1124. }
  1125. template <typename Handler> void serialize(Handler &h, const int version)
  1126. {
  1127. h & stackAttacked & attackerID & newAmount & newHP & flags & killedAmount & damageAmount & effect
  1128. & healedStacks;
  1129. }
  1130. bool operator<(const BattleStackAttacked &b) const
  1131. {
  1132. return stackAttacked < b.stackAttacked;
  1133. }
  1134. };
  1135. struct BattleAttack : public CPackForClient//3006
  1136. {
  1137. BattleAttack(){flags = 0; type = 3006;};
  1138. void applyFirstCl(CClient *cl);
  1139. DLL_LINKAGE void applyGs(CGameState *gs);
  1140. void applyCl(CClient *cl);
  1141. std::vector<BattleStackAttacked> bsa;
  1142. ui32 stackAttacking;
  1143. ui8 flags; //uses Eflags (below)
  1144. enum EFlags{SHOT = 1, COUNTER = 2, LUCKY = 4, UNLUCKY = 8, BALLISTA_DOUBLE_DMG = 16, DEATH_BLOW = 32};
  1145. bool shot() const//distance attack - decrease number of shots
  1146. {
  1147. return flags & SHOT;
  1148. }
  1149. bool counter() const//is it counterattack?
  1150. {
  1151. return flags & COUNTER;
  1152. }
  1153. bool lucky() const
  1154. {
  1155. return flags & LUCKY;
  1156. }
  1157. bool unlucky() const
  1158. {
  1159. return flags & UNLUCKY;
  1160. }
  1161. bool ballistaDoubleDmg() const //if it's ballista attack and does double dmg
  1162. {
  1163. return flags & BALLISTA_DOUBLE_DMG;
  1164. }
  1165. bool deathBlow() const
  1166. {
  1167. return flags & DEATH_BLOW;
  1168. }
  1169. //bool killed() //if target stack was killed
  1170. //{
  1171. // return bsa.killed();
  1172. //}
  1173. template <typename Handler> void serialize(Handler &h, const int version)
  1174. {
  1175. h & bsa & stackAttacking & flags;
  1176. }
  1177. };
  1178. struct StartAction : public CPackForClient//3007
  1179. {
  1180. StartAction(){type = 3007;};
  1181. StartAction(const BattleAction &act){ba = act; type = 3007;};
  1182. void applyFirstCl(CClient *cl);
  1183. DLL_LINKAGE void applyGs(CGameState *gs);
  1184. BattleAction ba;
  1185. template <typename Handler> void serialize(Handler &h, const int version)
  1186. {
  1187. h & ba;
  1188. }
  1189. };
  1190. struct EndAction : public CPackForClient//3008
  1191. {
  1192. EndAction(){type = 3008;};
  1193. void applyCl(CClient *cl);
  1194. template <typename Handler> void serialize(Handler &h, const int version)
  1195. {
  1196. }
  1197. };
  1198. struct BattleSpellCast : public CPackForClient//3009
  1199. {
  1200. BattleSpellCast(){type = 3009;};
  1201. DLL_LINKAGE void applyGs(CGameState *gs);
  1202. void applyCl(CClient *cl);
  1203. si32 dmgToDisplay; //this amount will be displayed as amount of damage dealt by spell
  1204. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  1205. ui32 id; //id of spell
  1206. ui8 skill; //caster's skill level
  1207. ui8 spellCost;
  1208. ui8 manaGained; //mana channeling ability
  1209. BattleHex tile; //destination tile (may not be set in some global/mass spells
  1210. std::vector<ui32> resisted; //ids of creatures that resisted this spell
  1211. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  1212. CreatureID attackerType;//id of caster to generate console message; -1 if not set (eg. spell casted by artifact)
  1213. bool castedByHero; //if true - spell has been casted by hero, otherwise by a creature
  1214. template <typename Handler> void serialize(Handler &h, const int version)
  1215. {
  1216. h & dmgToDisplay & side & id & skill & spellCost & manaGained & tile & resisted & affectedCres & attackerType & castedByHero;
  1217. }
  1218. };
  1219. struct SetStackEffect : public CPackForClient //3010
  1220. {
  1221. SetStackEffect(){type = 3010;};
  1222. DLL_LINKAGE void applyGs(CGameState *gs);
  1223. void applyCl(CClient *cl);
  1224. std::vector<ui32> stacks; //affected stacks (IDs)
  1225. std::vector<Bonus> effect; //bonuses to apply
  1226. std::vector<std::pair<ui32, Bonus> > uniqueBonuses; //bonuses per single stack
  1227. template <typename Handler> void serialize(Handler &h, const int version)
  1228. {
  1229. h & stacks & effect & uniqueBonuses;
  1230. }
  1231. };
  1232. struct StacksInjured : public CPackForClient //3011
  1233. {
  1234. StacksInjured(){type = 3011;}
  1235. DLL_LINKAGE void applyGs(CGameState *gs);
  1236. void applyCl(CClient *cl);
  1237. std::vector<BattleStackAttacked> stacks;
  1238. template <typename Handler> void serialize(Handler &h, const int version)
  1239. {
  1240. h & stacks;
  1241. }
  1242. };
  1243. struct BattleResultsApplied : public CPackForClient //3012
  1244. {
  1245. BattleResultsApplied(){type = 3012;}
  1246. PlayerColor player1, player2;
  1247. void applyCl(CClient *cl);
  1248. template <typename Handler> void serialize(Handler &h, const int version)
  1249. {
  1250. h & player1 & player2;
  1251. }
  1252. };
  1253. struct ObstaclesRemoved : public CPackForClient //3014
  1254. {
  1255. ObstaclesRemoved(){type = 3014;}
  1256. DLL_LINKAGE void applyGs(CGameState *gs);
  1257. void applyCl(CClient *cl);
  1258. std::set<si32> obstacles; //uniqueIDs of removed obstacles
  1259. template <typename Handler> void serialize(Handler &h, const int version)
  1260. {
  1261. h & obstacles;
  1262. }
  1263. };
  1264. struct DLL_LINKAGE CatapultAttack : public CPackForClient //3015
  1265. {
  1266. struct AttackInfo
  1267. {
  1268. si16 destinationTile;
  1269. ui8 attackedPart;
  1270. ui8 damageDealt;
  1271. DLL_LINKAGE std::string toString() const;
  1272. template <typename Handler> void serialize(Handler &h, const int version)
  1273. {
  1274. h & destinationTile & attackedPart & damageDealt;
  1275. }
  1276. };
  1277. CatapultAttack() {type = 3015;}
  1278. DLL_LINKAGE void applyGs(CGameState *gs);
  1279. void applyCl(CClient *cl);
  1280. DLL_LINKAGE std::string toString() const override;
  1281. std::vector< AttackInfo > attackedParts;
  1282. int attacker; //if -1, then a spell caused this
  1283. template <typename Handler> void serialize(Handler &h, const int version)
  1284. {
  1285. h & attackedParts & attacker;
  1286. }
  1287. };
  1288. DLL_LINKAGE std::ostream & operator<<(std::ostream & out, const CatapultAttack::AttackInfo & attackInfo);
  1289. struct BattleStacksRemoved : public CPackForClient //3016
  1290. {
  1291. BattleStacksRemoved(){type = 3016;}
  1292. DLL_LINKAGE void applyGs(CGameState *gs);
  1293. void applyCl(CClient *cl);
  1294. std::set<ui32> stackIDs; //IDs of removed stacks
  1295. template <typename Handler> void serialize(Handler &h, const int version)
  1296. {
  1297. h & stackIDs;
  1298. }
  1299. };
  1300. struct BattleStackAdded : public CPackForClient //3017
  1301. {
  1302. BattleStackAdded(){type = 3017;};
  1303. DLL_LINKAGE void applyGs(CGameState *gs);
  1304. void applyCl(CClient *cl);
  1305. int attacker; // if true, stack belongs to attacker
  1306. CreatureID creID;
  1307. int amount;
  1308. int pos;
  1309. int summoned; //if true, remove it afterwards
  1310. template <typename Handler> void serialize(Handler &h, const int version)
  1311. {
  1312. h & attacker & creID & amount & pos & summoned;
  1313. }
  1314. };
  1315. struct BattleSetStackProperty : public CPackForClient //3018
  1316. {
  1317. BattleSetStackProperty(){type = 3018;};
  1318. enum BattleStackProperty {CASTS, ENCHANTER_COUNTER, UNBIND, CLONED};
  1319. DLL_LINKAGE void applyGs(CGameState *gs);
  1320. //void applyCl(CClient *cl){};
  1321. int stackID;
  1322. BattleStackProperty which;
  1323. int val;
  1324. int absolute;
  1325. template <typename Handler> void serialize(Handler &h, const int version)
  1326. {
  1327. h & stackID & which & val & absolute;
  1328. }
  1329. };
  1330. struct BattleTriggerEffect : public CPackForClient //3019
  1331. { //activated at the beginning of turn
  1332. BattleTriggerEffect(){type = 3019;};
  1333. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1334. void applyCl(CClient *cl); //play animations & stuff
  1335. //enum BattleEffect {REGENERATION, MANA_DRAIN, FEAR, MANA_CHANNELING, ENCHANTER, UNBIND, POISON, ENCHANTED, SUMMONER};
  1336. int stackID;
  1337. int effect; //use enumBattleEffect or corresponding Bonus type for sanity?
  1338. int val;
  1339. int additionalInfo;
  1340. template <typename Handler> void serialize(Handler &h, const int version)
  1341. {
  1342. h & stackID & effect & val & additionalInfo;
  1343. }
  1344. };
  1345. struct BattleObstaclePlaced : public CPackForClient //3020
  1346. { //activated at the beginning of turn
  1347. BattleObstaclePlaced(){type = 3020;};
  1348. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1349. void applyCl(CClient *cl); //play animations & stuff
  1350. shared_ptr<CObstacleInstance> obstacle;
  1351. template <typename Handler> void serialize(Handler &h, const int version)
  1352. {
  1353. h & obstacle;
  1354. }
  1355. };
  1356. struct ShowInInfobox : public CPackForClient //107
  1357. {
  1358. ShowInInfobox(){type = 107;};
  1359. PlayerColor player;
  1360. Component c;
  1361. MetaString text;
  1362. void applyCl(CClient *cl);
  1363. template <typename Handler> void serialize(Handler &h, const int version)
  1364. {
  1365. h & player & c & text;
  1366. }
  1367. };
  1368. struct AdvmapSpellCast : public CPackForClient //108
  1369. {
  1370. AdvmapSpellCast(){type = 108;}
  1371. const CGHeroInstance * caster;
  1372. SpellID spellID;
  1373. void applyCl(CClient *cl);
  1374. template <typename Handler> void serialize(Handler &h, const int version)
  1375. {
  1376. h & caster & spellID;
  1377. }
  1378. };
  1379. /***********************************************************************************************************/
  1380. struct CommitPackage : public CPackForServer
  1381. {
  1382. bool freePack; //for local usage, DO NOT serialize
  1383. bool applyGh(CGameHandler *gh);
  1384. CPackForClient *packToCommit;
  1385. CommitPackage()
  1386. {
  1387. freePack = true;
  1388. }
  1389. ~CommitPackage()
  1390. {
  1391. if(freePack)
  1392. delete packToCommit;
  1393. }
  1394. template <typename Handler> void serialize(Handler &h, const int version)
  1395. {
  1396. h & packToCommit;
  1397. }
  1398. };
  1399. struct CloseServer : public CPackForServer
  1400. {
  1401. bool applyGh(CGameHandler *gh);
  1402. template <typename Handler> void serialize(Handler &h, const int version)
  1403. {}
  1404. };
  1405. struct EndTurn : public CPackForServer
  1406. {
  1407. bool applyGh(CGameHandler *gh);
  1408. template <typename Handler> void serialize(Handler &h, const int version)
  1409. {}
  1410. };
  1411. struct DismissHero : public CPackForServer
  1412. {
  1413. DismissHero(){};
  1414. DismissHero(ObjectInstanceID HID) : hid(HID) {};
  1415. ObjectInstanceID hid;
  1416. bool applyGh(CGameHandler *gh);
  1417. template <typename Handler> void serialize(Handler &h, const int version)
  1418. {
  1419. h & hid;
  1420. }
  1421. };
  1422. struct MoveHero : public CPackForServer
  1423. {
  1424. MoveHero(){};
  1425. MoveHero(const int3 &Dest, ObjectInstanceID HID) : dest(Dest), hid(HID){};
  1426. int3 dest;
  1427. ObjectInstanceID hid;
  1428. bool applyGh(CGameHandler *gh);
  1429. template <typename Handler> void serialize(Handler &h, const int version)
  1430. {
  1431. h & dest & hid;
  1432. }
  1433. };
  1434. struct CastleTeleportHero : public CPackForServer
  1435. {
  1436. CastleTeleportHero(){};
  1437. CastleTeleportHero(const ObjectInstanceID HID, ObjectInstanceID Dest, ui8 Source ) : dest(Dest), hid(HID), source(Source){};
  1438. ObjectInstanceID dest;
  1439. ObjectInstanceID hid;
  1440. si8 source;//who give teleporting, 1=castle gate
  1441. bool applyGh(CGameHandler *gh);
  1442. template <typename Handler> void serialize(Handler &h, const int version)
  1443. {
  1444. h & dest & hid;
  1445. }
  1446. };
  1447. struct ArrangeStacks : public CPackForServer
  1448. {
  1449. ArrangeStacks(){};
  1450. ArrangeStacks(ui8 W, SlotID P1, SlotID P2, ObjectInstanceID ID1, ObjectInstanceID ID2, si32 VAL)
  1451. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  1452. ui8 what; //1 - swap; 2 - merge; 3 - split
  1453. SlotID p1, p2; //positions of first and second stack
  1454. ObjectInstanceID id1, id2; //ids of objects with garrison
  1455. si32 val;
  1456. bool applyGh(CGameHandler *gh);
  1457. template <typename Handler> void serialize(Handler &h, const int version)
  1458. {
  1459. h & what & p1 & p2 & id1 & id2 & val;
  1460. }
  1461. };
  1462. struct DisbandCreature : public CPackForServer
  1463. {
  1464. DisbandCreature(){};
  1465. DisbandCreature(SlotID Pos, ObjectInstanceID ID):pos(Pos),id(ID){};
  1466. SlotID pos; //stack pos
  1467. ObjectInstanceID id; //object id
  1468. bool applyGh(CGameHandler *gh);
  1469. template <typename Handler> void serialize(Handler &h, const int version)
  1470. {
  1471. h & pos & id;
  1472. }
  1473. };
  1474. struct BuildStructure : public CPackForServer
  1475. {
  1476. BuildStructure(){};
  1477. BuildStructure(ObjectInstanceID TID, BuildingID BID):tid(TID), bid(BID){};
  1478. ObjectInstanceID tid; //town id
  1479. BuildingID bid; //structure id
  1480. bool applyGh(CGameHandler *gh);
  1481. template <typename Handler> void serialize(Handler &h, const int version)
  1482. {
  1483. h & tid & bid;
  1484. }
  1485. };
  1486. struct RazeStructure : public BuildStructure
  1487. {
  1488. RazeStructure(){};
  1489. //RazeStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  1490. bool applyGh(CGameHandler *gh);
  1491. };
  1492. struct RecruitCreatures : public CPackForServer
  1493. {
  1494. RecruitCreatures(){};
  1495. RecruitCreatures(ObjectInstanceID TID, CreatureID CRID, si32 Amount, si32 Level):tid(TID),crid(CRID),amount(Amount),level(Level){};
  1496. ObjectInstanceID tid; //town id
  1497. CreatureID crid;
  1498. ui32 amount;//creature amount
  1499. si32 level;//dwelling level to buy from, -1 if any
  1500. bool applyGh(CGameHandler *gh);
  1501. template <typename Handler> void serialize(Handler &h, const int version)
  1502. {
  1503. h & tid & crid & amount & level;
  1504. }
  1505. };
  1506. struct UpgradeCreature : public CPackForServer
  1507. {
  1508. UpgradeCreature(){};
  1509. UpgradeCreature(SlotID Pos, ObjectInstanceID ID, CreatureID CRID):pos(Pos),id(ID), cid(CRID){};
  1510. SlotID pos; //stack pos
  1511. ObjectInstanceID id; //object id
  1512. CreatureID cid; //id of type to which we want make upgrade
  1513. bool applyGh(CGameHandler *gh);
  1514. template <typename Handler> void serialize(Handler &h, const int version)
  1515. {
  1516. h & pos & id & cid;
  1517. }
  1518. };
  1519. struct GarrisonHeroSwap : public CPackForServer
  1520. {
  1521. GarrisonHeroSwap(){};
  1522. GarrisonHeroSwap(ObjectInstanceID TID):tid(TID){};
  1523. ObjectInstanceID tid;
  1524. bool applyGh(CGameHandler *gh);
  1525. template <typename Handler> void serialize(Handler &h, const int version)
  1526. {
  1527. h & tid;
  1528. }
  1529. };
  1530. struct ExchangeArtifacts : public CPackForServer
  1531. //TODO: allow exchange between heroes, stacks and commanders
  1532. {
  1533. ArtifactLocation src, dst;
  1534. ExchangeArtifacts(){};
  1535. bool applyGh(CGameHandler *gh);
  1536. template <typename Handler> void serialize(Handler &h, const int version)
  1537. {
  1538. h & src & dst;
  1539. }
  1540. };
  1541. struct AssembleArtifacts : public CPackForServer
  1542. {
  1543. AssembleArtifacts(){};
  1544. AssembleArtifacts(ObjectInstanceID _heroID, ArtifactPosition _artifactSlot, bool _assemble, ArtifactID _assembleTo)
  1545. : heroID(_heroID), artifactSlot(_artifactSlot), assemble(_assemble), assembleTo(_assembleTo){};
  1546. ObjectInstanceID heroID;
  1547. ArtifactPosition artifactSlot;
  1548. bool assemble; // True to assemble artifact, false to disassemble.
  1549. ArtifactID assembleTo; // Artifact to assemble into.
  1550. bool applyGh(CGameHandler *gh);
  1551. template <typename Handler> void serialize(Handler &h, const int version)
  1552. {
  1553. h & heroID & artifactSlot & assemble & assembleTo;
  1554. }
  1555. };
  1556. struct BuyArtifact : public CPackForServer
  1557. {
  1558. BuyArtifact(){};
  1559. BuyArtifact(ObjectInstanceID HID, ArtifactID AID):hid(HID),aid(AID){};
  1560. ObjectInstanceID hid;
  1561. ArtifactID aid;
  1562. bool applyGh(CGameHandler *gh);
  1563. template <typename Handler> void serialize(Handler &h, const int version)
  1564. {
  1565. h & hid & aid;
  1566. }
  1567. };
  1568. struct TradeOnMarketplace : public CPackForServer
  1569. {
  1570. TradeOnMarketplace(){};
  1571. const CGObjectInstance *market;
  1572. const CGHeroInstance *hero; //needed when trading artifacts / creatures
  1573. EMarketMode::EMarketMode mode;
  1574. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res (exception: when sacrificing art r1 is art id [todo: make r2 preferred slot?]
  1575. ui32 val; //units of sold resource
  1576. bool applyGh(CGameHandler *gh);
  1577. template <typename Handler> void serialize(Handler &h, const int version)
  1578. {
  1579. h & market & hero & mode & r1 & r2 & val;
  1580. }
  1581. };
  1582. struct SetFormation : public CPackForServer
  1583. {
  1584. SetFormation(){};
  1585. SetFormation(ObjectInstanceID HID, ui8 Formation):hid(HID),formation(Formation){};
  1586. ObjectInstanceID hid;
  1587. ui8 formation;
  1588. bool applyGh(CGameHandler *gh);
  1589. template <typename Handler> void serialize(Handler &h, const int version)
  1590. {
  1591. h & hid & formation;
  1592. }
  1593. };
  1594. struct HireHero : public CPackForServer
  1595. {
  1596. HireHero(){};
  1597. HireHero(si32 HID, ObjectInstanceID TID):hid(HID),tid(TID){};
  1598. si32 hid; //available hero serial
  1599. ObjectInstanceID tid; //town (tavern) id
  1600. PlayerColor player;
  1601. bool applyGh(CGameHandler *gh);
  1602. template <typename Handler> void serialize(Handler &h, const int version)
  1603. {
  1604. h & hid & tid & player;
  1605. }
  1606. };
  1607. struct BuildBoat : public CPackForServer
  1608. {
  1609. BuildBoat(){};
  1610. ObjectInstanceID objid; //where player wants to buy a boat
  1611. bool applyGh(CGameHandler *gh);
  1612. template <typename Handler> void serialize(Handler &h, const int version)
  1613. {
  1614. h & objid;
  1615. }
  1616. };
  1617. struct QueryReply : public CPackForServer
  1618. {
  1619. QueryReply(){type = 6000;};
  1620. QueryReply(QueryID QID, ui32 Answer):qid(QID),answer(Answer){type = 6000;};
  1621. QueryID qid;
  1622. ui32 answer; //hero and artifact id
  1623. PlayerColor player;
  1624. bool applyGh(CGameHandler *gh);
  1625. template <typename Handler> void serialize(Handler &h, const int version)
  1626. {
  1627. h & qid & answer & player;
  1628. }
  1629. };
  1630. struct MakeAction : public CPackForServer
  1631. {
  1632. MakeAction(){};
  1633. MakeAction(const BattleAction &BA):ba(BA){};
  1634. BattleAction ba;
  1635. bool applyGh(CGameHandler *gh);
  1636. template <typename Handler> void serialize(Handler &h, const int version)
  1637. {
  1638. h & ba;
  1639. }
  1640. };
  1641. struct MakeCustomAction : public CPackForServer
  1642. {
  1643. MakeCustomAction(){};
  1644. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1645. BattleAction ba;
  1646. bool applyGh(CGameHandler *gh);
  1647. template <typename Handler> void serialize(Handler &h, const int version)
  1648. {
  1649. h & ba;
  1650. }
  1651. };
  1652. struct DigWithHero : public CPackForServer
  1653. {
  1654. DigWithHero(){}
  1655. ObjectInstanceID id; //digging hero id
  1656. bool applyGh(CGameHandler *gh);
  1657. template <typename Handler> void serialize(Handler &h, const int version)
  1658. {
  1659. h & id;
  1660. }
  1661. };
  1662. struct CastAdvSpell : public CPackForServer
  1663. {
  1664. CastAdvSpell(){}
  1665. ObjectInstanceID hid; //hero id
  1666. SpellID sid; //spell id
  1667. int3 pos; //selected tile (not always used)
  1668. bool applyGh(CGameHandler *gh);
  1669. template <typename Handler> void serialize(Handler &h, const int version)
  1670. {
  1671. h & hid & sid & pos;
  1672. }
  1673. };
  1674. /***********************************************************************************************************/
  1675. struct SaveGame : public CPackForClient, public CPackForServer
  1676. {
  1677. SaveGame(){};
  1678. SaveGame(const std::string &Fname) :fname(Fname){};
  1679. std::string fname;
  1680. void applyCl(CClient *cl);
  1681. void applyGs(CGameState *gs){};
  1682. bool applyGh(CGameHandler *gh);
  1683. template <typename Handler> void serialize(Handler &h, const int version)
  1684. {
  1685. h & fname;
  1686. }
  1687. };
  1688. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  1689. {
  1690. PlayerMessage(){CPackForClient::type = 513;};
  1691. PlayerMessage(PlayerColor Player, const std::string &Text)
  1692. :player(Player),text(Text)
  1693. {CPackForClient::type = 513;};
  1694. void applyCl(CClient *cl);
  1695. void applyGs(CGameState *gs){};
  1696. bool applyGh(CGameHandler *gh);
  1697. PlayerColor player;
  1698. std::string text;
  1699. template <typename Handler> void serialize(Handler &h, const int version)
  1700. {
  1701. h & text & player;
  1702. }
  1703. };
  1704. struct SetSelection : public CPackForClient, public CPackForServer //514
  1705. {
  1706. SetSelection(){CPackForClient::type = 514;};
  1707. DLL_LINKAGE void applyGs(CGameState *gs);
  1708. bool applyGh(CGameHandler *gh);
  1709. void applyCl(CClient *cl);
  1710. PlayerColor player;
  1711. ObjectInstanceID id;
  1712. template <typename Handler> void serialize(Handler &h, const int version)
  1713. {
  1714. h & id & player;
  1715. }
  1716. };
  1717. struct CenterView : public CPackForClient//515
  1718. {
  1719. CenterView(){CPackForClient::type = 515;};
  1720. void applyCl(CClient *cl);
  1721. PlayerColor player;
  1722. int3 pos;
  1723. ui32 focusTime; //ms
  1724. template <typename Handler> void serialize(Handler &h, const int version)
  1725. {
  1726. h & pos & player & focusTime;
  1727. }
  1728. };
  1729. /***********************************************************************************************************/
  1730. struct CPackForSelectionScreen : public CPack
  1731. {
  1732. void apply(CSelectionScreen *selScreen){}; //that functions are implemented in CPreGame.cpp
  1733. };
  1734. class CPregamePackToPropagate : public CPackForSelectionScreen
  1735. {};
  1736. class CPregamePackToHost : public CPackForSelectionScreen
  1737. {};
  1738. struct ChatMessage : public CPregamePackToPropagate
  1739. {
  1740. std::string playerName, message;
  1741. void apply(CSelectionScreen *selScreen);
  1742. template <typename Handler> void serialize(Handler &h, const int version)
  1743. {
  1744. h & playerName & message;
  1745. }
  1746. };
  1747. struct QuitMenuWithoutStarting : public CPregamePackToPropagate
  1748. {
  1749. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1750. template <typename Handler> void serialize(Handler &h, const int version)
  1751. {}
  1752. };
  1753. struct PlayerJoined : public CPregamePackToHost
  1754. {
  1755. std::string playerName;
  1756. ui8 connectionID;
  1757. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1758. template <typename Handler> void serialize(Handler &h, const int version)
  1759. {
  1760. h & playerName & connectionID;
  1761. }
  1762. };
  1763. struct SelectMap : public CPregamePackToPropagate
  1764. {
  1765. const CMapInfo *mapInfo;
  1766. bool free;
  1767. SelectMap(const CMapInfo &src)
  1768. {
  1769. mapInfo = &src;
  1770. free = false;
  1771. }
  1772. SelectMap()
  1773. {
  1774. mapInfo = nullptr;
  1775. free = true;
  1776. }
  1777. ~SelectMap()
  1778. {
  1779. if(free)
  1780. delete mapInfo;
  1781. }
  1782. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1783. template <typename Handler> void serialize(Handler &h, const int version)
  1784. {
  1785. h & mapInfo;
  1786. }
  1787. };
  1788. struct UpdateStartOptions : public CPregamePackToPropagate
  1789. {
  1790. StartInfo *options;
  1791. bool free;
  1792. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1793. UpdateStartOptions(StartInfo &src)
  1794. {
  1795. options = &src;
  1796. free = false;
  1797. }
  1798. UpdateStartOptions()
  1799. {
  1800. options = nullptr;
  1801. free = true;
  1802. }
  1803. ~UpdateStartOptions()
  1804. {
  1805. if(free)
  1806. delete options;
  1807. }
  1808. template <typename Handler> void serialize(Handler &h, const int version)
  1809. {
  1810. h & options;
  1811. }
  1812. };
  1813. struct PregameGuiAction : public CPregamePackToPropagate
  1814. {
  1815. enum {NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST, OPEN_RANDOM_MAP_OPTIONS}
  1816. action;
  1817. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1818. template <typename Handler> void serialize(Handler &h, const int version)
  1819. {
  1820. h & action;
  1821. }
  1822. };
  1823. struct RequestOptionsChange : public CPregamePackToHost
  1824. {
  1825. enum EWhat {TOWN, HERO, BONUS};
  1826. ui8 what;
  1827. si8 direction; //-1 or +1
  1828. ui8 playerID;
  1829. RequestOptionsChange(ui8 What, si8 Dir, ui8 Player)
  1830. :what(What), direction(Dir), playerID(Player)
  1831. {}
  1832. RequestOptionsChange(){}
  1833. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1834. template <typename Handler> void serialize(Handler &h, const int version)
  1835. {
  1836. h & what & direction & playerID;
  1837. }
  1838. };
  1839. struct PlayerLeft : public CPregamePackToPropagate
  1840. {
  1841. ui8 playerID;
  1842. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1843. template <typename Handler> void serialize(Handler &h, const int version)
  1844. {
  1845. h & playerID;
  1846. }
  1847. };
  1848. struct PlayersNames : public CPregamePackToPropagate
  1849. {
  1850. public:
  1851. std::map<ui8, std::string> playerNames;
  1852. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1853. template <typename Handler> void serialize(Handler &h, const int version)
  1854. {
  1855. h & playerNames;
  1856. }
  1857. };
  1858. struct StartWithCurrentSettings : public CPregamePackToPropagate
  1859. {
  1860. public:
  1861. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1862. template <typename Handler> void serialize(Handler &h, const int version)
  1863. {
  1864. //h & playerNames;
  1865. }
  1866. };