NetPacks.h 56 KB

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