NetPacks.h 56 KB

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