NetPacks.h 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547
  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. std::vector<CustomEffectInfo> customEffects;
  1289. template <typename Handler> void serialize(Handler & h, const int version)
  1290. {
  1291. h & changedStacks;
  1292. h & customEffects;
  1293. }
  1294. };
  1295. struct BattleStackAttacked
  1296. {
  1297. BattleStackAttacked():
  1298. stackAttacked(0),
  1299. attackerID(0),
  1300. killedAmount(0),
  1301. damageAmount(0),
  1302. newState(),
  1303. flags(0),
  1304. effect(0),
  1305. spellID(SpellID::NONE)
  1306. {};
  1307. DLL_LINKAGE void applyGs(CGameState *gs);
  1308. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1309. ui32 stackAttacked, attackerID;
  1310. ui32 killedAmount;
  1311. int64_t damageAmount;
  1312. UnitChanges newState;
  1313. enum EFlags {KILLED = 1, EFFECT = 2/*deprecated */, SECONDARY = 4, REBIRTH = 8, CLONE_KILLED = 16, SPELL_EFFECT = 32 /*, BONUS_EFFECT = 64 */};
  1314. ui32 flags; //uses EFlags (above)
  1315. ui32 effect; //set only if flag EFFECT is set
  1316. SpellID spellID; //only if flag SPELL_EFFECT is set
  1317. bool killed() const//if target stack was killed
  1318. {
  1319. return flags & KILLED || flags & CLONE_KILLED;
  1320. }
  1321. bool cloneKilled() const
  1322. {
  1323. return flags & CLONE_KILLED;
  1324. }
  1325. bool isEffect() const//if stack has been attacked by a spell
  1326. {
  1327. return flags & EFFECT;
  1328. }
  1329. bool isSecondary() const//if stack was not a primary target (receives no spell effects)
  1330. {
  1331. return flags & SECONDARY;
  1332. }
  1333. ///Attacked with spell (SPELL_LIKE_ATTACK)
  1334. bool isSpell() const
  1335. {
  1336. return flags & SPELL_EFFECT;
  1337. }
  1338. bool willRebirth() const//resurrection, e.g. Phoenix
  1339. {
  1340. return flags & REBIRTH;
  1341. }
  1342. template <typename Handler> void serialize(Handler &h, const int version)
  1343. {
  1344. h & stackAttacked;
  1345. h & attackerID;
  1346. h & newState;
  1347. h & flags;
  1348. h & killedAmount;
  1349. h & damageAmount;
  1350. h & effect;
  1351. h & spellID;
  1352. }
  1353. bool operator<(const BattleStackAttacked &b) const
  1354. {
  1355. return stackAttacked < b.stackAttacked;
  1356. }
  1357. };
  1358. struct BattleAttack : public CPackForClient
  1359. {
  1360. BattleAttack()
  1361. : stackAttacking(0), flags(0), spellID(SpellID::NONE)
  1362. {};
  1363. void applyFirstCl(CClient *cl);
  1364. DLL_LINKAGE void applyGs(CGameState *gs);
  1365. void applyCl(CClient *cl);
  1366. BattleUnitsChanged attackerChanges;
  1367. std::vector<BattleStackAttacked> bsa;
  1368. ui32 stackAttacking;
  1369. ui32 flags; //uses Eflags (below)
  1370. enum EFlags{SHOT = 1, COUNTER = 2, LUCKY = 4, UNLUCKY = 8, BALLISTA_DOUBLE_DMG = 16, DEATH_BLOW = 32, SPELL_LIKE = 64, LIFE_DRAIN = 128};
  1371. BattleHex tile;
  1372. SpellID spellID; //for SPELL_LIKE
  1373. bool shot() const//distance attack - decrease number of shots
  1374. {
  1375. return flags & SHOT;
  1376. }
  1377. bool counter() const//is it counterattack?
  1378. {
  1379. return flags & COUNTER;
  1380. }
  1381. bool lucky() const
  1382. {
  1383. return flags & LUCKY;
  1384. }
  1385. bool unlucky() const
  1386. {
  1387. return flags & UNLUCKY;
  1388. }
  1389. bool ballistaDoubleDmg() const //if it's ballista attack and does double dmg
  1390. {
  1391. return flags & BALLISTA_DOUBLE_DMG;
  1392. }
  1393. bool deathBlow() const
  1394. {
  1395. return flags & DEATH_BLOW;
  1396. }
  1397. bool spellLike() const
  1398. {
  1399. return flags & SPELL_LIKE;
  1400. }
  1401. bool lifeDrain() const
  1402. {
  1403. return flags & LIFE_DRAIN;
  1404. }
  1405. template <typename Handler> void serialize(Handler &h, const int version)
  1406. {
  1407. h & bsa;
  1408. h & stackAttacking;
  1409. h & flags;
  1410. h & tile;
  1411. h & spellID;
  1412. h & attackerChanges;
  1413. }
  1414. };
  1415. struct StartAction : public CPackForClient
  1416. {
  1417. StartAction(){};
  1418. StartAction(const BattleAction &act){ba = act; };
  1419. void applyFirstCl(CClient *cl);
  1420. DLL_LINKAGE void applyGs(CGameState *gs);
  1421. BattleAction ba;
  1422. template <typename Handler> void serialize(Handler &h, const int version)
  1423. {
  1424. h & ba;
  1425. }
  1426. };
  1427. struct EndAction : public CPackForClient
  1428. {
  1429. EndAction(){};
  1430. void applyCl(CClient *cl);
  1431. template <typename Handler> void serialize(Handler &h, const int version)
  1432. {
  1433. }
  1434. };
  1435. struct BattleSpellCast : public CPackForClient
  1436. {
  1437. BattleSpellCast()
  1438. {
  1439. side = 0;
  1440. manaGained = 0;
  1441. casterStack = -1;
  1442. castByHero = true;
  1443. activeCast = true;
  1444. };
  1445. DLL_LINKAGE void applyGs(CGameState *gs);
  1446. void applyCl(CClient *cl);
  1447. bool activeCast;
  1448. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  1449. SpellID spellID; //id of spell
  1450. ui8 manaGained; //mana channeling ability
  1451. BattleHex tile; //destination tile (may not be set in some global/mass spells
  1452. std::vector<CustomEffectInfo> customEffects;
  1453. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  1454. si32 casterStack;// -1 if not cated by creature, >=0 caster stack ID
  1455. bool castByHero; //if true - spell has been cast by hero, otherwise by a creature
  1456. template <typename Handler> void serialize(Handler &h, const int version)
  1457. {
  1458. h & side;
  1459. h & spellID;
  1460. h & manaGained;
  1461. h & tile;
  1462. h & customEffects;
  1463. h & affectedCres;
  1464. h & casterStack;
  1465. h & castByHero;
  1466. h & activeCast;
  1467. }
  1468. };
  1469. struct SetStackEffect : public CPackForClient
  1470. {
  1471. SetStackEffect(){};
  1472. DLL_LINKAGE void applyGs(CGameState * gs);
  1473. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1474. void applyCl(CClient * cl);
  1475. std::vector<std::pair<ui32, std::vector<Bonus>>> toAdd;
  1476. std::vector<std::pair<ui32, std::vector<Bonus>>> toUpdate;
  1477. std::vector<std::pair<ui32, std::vector<Bonus>>> toRemove;
  1478. template <typename Handler> void serialize(Handler & h, const int version)
  1479. {
  1480. h & toAdd;
  1481. h & toUpdate;
  1482. h & toRemove;
  1483. }
  1484. };
  1485. struct StacksInjured : public CPackForClient
  1486. {
  1487. StacksInjured(){}
  1488. DLL_LINKAGE void applyGs(CGameState * gs);
  1489. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1490. void applyCl(CClient * cl);
  1491. std::vector<BattleStackAttacked> stacks;
  1492. template <typename Handler> void serialize(Handler & h, const int version)
  1493. {
  1494. h & stacks;
  1495. }
  1496. };
  1497. struct BattleResultsApplied : public CPackForClient
  1498. {
  1499. BattleResultsApplied(){}
  1500. PlayerColor player1, player2;
  1501. void applyCl(CClient *cl);
  1502. template <typename Handler> void serialize(Handler &h, const int version)
  1503. {
  1504. h & player1;
  1505. h & player2;
  1506. }
  1507. };
  1508. struct BattleObstaclesChanged : public CPackForClient
  1509. {
  1510. BattleObstaclesChanged(){}
  1511. DLL_LINKAGE void applyGs(CGameState * gs);
  1512. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1513. void applyCl(CClient * cl);
  1514. std::vector<ObstacleChanges> changes;
  1515. template <typename Handler> void serialize(Handler & h, const int version)
  1516. {
  1517. h & changes;
  1518. }
  1519. };
  1520. struct ELF_VISIBILITY CatapultAttack : public CPackForClient
  1521. {
  1522. struct AttackInfo
  1523. {
  1524. si16 destinationTile;
  1525. ui8 attackedPart;
  1526. ui8 damageDealt;
  1527. template <typename Handler> void serialize(Handler & h, const int version)
  1528. {
  1529. h & destinationTile;
  1530. h & attackedPart;
  1531. h & damageDealt;
  1532. }
  1533. };
  1534. DLL_LINKAGE CatapultAttack();
  1535. DLL_LINKAGE ~CatapultAttack();
  1536. DLL_LINKAGE void applyGs(CGameState * gs);
  1537. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1538. void applyCl(CClient * cl);
  1539. std::vector< AttackInfo > attackedParts;
  1540. int attacker; //if -1, then a spell caused this
  1541. template <typename Handler> void serialize(Handler &h, const int version)
  1542. {
  1543. h & attackedParts;
  1544. h & attacker;
  1545. }
  1546. };
  1547. struct BattleSetStackProperty : public CPackForClient
  1548. {
  1549. BattleSetStackProperty()
  1550. : stackID(0), which(CASTS), val(0), absolute(0)
  1551. {};
  1552. enum BattleStackProperty {CASTS, ENCHANTER_COUNTER, UNBIND, CLONED, HAS_CLONE};
  1553. DLL_LINKAGE void applyGs(CGameState *gs);
  1554. int stackID;
  1555. BattleStackProperty which;
  1556. int val;
  1557. int absolute;
  1558. template <typename Handler> void serialize(Handler &h, const int version)
  1559. {
  1560. h & stackID;
  1561. h & which;
  1562. h & val;
  1563. h & absolute;
  1564. }
  1565. };
  1566. ///activated at the beginning of turn
  1567. struct BattleTriggerEffect : public CPackForClient
  1568. {
  1569. BattleTriggerEffect()
  1570. : stackID(0), effect(0), val(0), additionalInfo(0)
  1571. {};
  1572. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1573. void applyCl(CClient *cl); //play animations & stuff
  1574. int stackID;
  1575. int effect; //use corresponding Bonus type
  1576. int val;
  1577. int additionalInfo;
  1578. template <typename Handler> void serialize(Handler &h, const int version)
  1579. {
  1580. h & stackID;
  1581. h & effect;
  1582. h & val;
  1583. h & additionalInfo;
  1584. }
  1585. };
  1586. struct BattleUpdateGateState : public CPackForClient
  1587. {
  1588. BattleUpdateGateState():state(EGateState::NONE){};
  1589. void applyFirstCl(CClient *cl);
  1590. DLL_LINKAGE void applyGs(CGameState *gs);
  1591. EGateState state;
  1592. template <typename Handler> void serialize(Handler &h, const int version)
  1593. {
  1594. h & state;
  1595. }
  1596. };
  1597. struct ShowInInfobox : public CPackForClient
  1598. {
  1599. ShowInInfobox(){};
  1600. PlayerColor player;
  1601. Component c;
  1602. MetaString text;
  1603. void applyCl(CClient *cl);
  1604. template <typename Handler> void serialize(Handler &h, const int version)
  1605. {
  1606. h & player;
  1607. h & c;
  1608. h & text;
  1609. }
  1610. };
  1611. struct AdvmapSpellCast : public CPackForClient
  1612. {
  1613. AdvmapSpellCast():casterID(){}
  1614. ObjectInstanceID casterID;
  1615. SpellID spellID;
  1616. void applyCl(CClient *cl);
  1617. template <typename Handler> void serialize(Handler &h, const int version)
  1618. {
  1619. h & casterID;
  1620. h & spellID;
  1621. }
  1622. };
  1623. struct ShowWorldViewEx : public CPackForClient
  1624. {
  1625. PlayerColor player;
  1626. std::vector<ObjectPosInfo> objectPositions;
  1627. ShowWorldViewEx(){}
  1628. void applyCl(CClient *cl);
  1629. template <typename Handler> void serialize(Handler &h, const int version)
  1630. {
  1631. h & player;
  1632. h & objectPositions;
  1633. }
  1634. };
  1635. /***********************************************************************************************************/
  1636. struct EndTurn : public CPackForServer
  1637. {
  1638. bool applyGh(CGameHandler *gh);
  1639. template <typename Handler> void serialize(Handler &h, const int version)
  1640. {
  1641. h & static_cast<CPackForServer &>(*this);
  1642. }
  1643. };
  1644. struct DismissHero : public CPackForServer
  1645. {
  1646. DismissHero(){};
  1647. DismissHero(ObjectInstanceID HID) : hid(HID) {};
  1648. ObjectInstanceID hid;
  1649. bool applyGh(CGameHandler *gh);
  1650. template <typename Handler> void serialize(Handler &h, const int version)
  1651. {
  1652. h & static_cast<CPackForServer &>(*this);
  1653. h & hid;
  1654. }
  1655. };
  1656. struct MoveHero : public CPackForServer
  1657. {
  1658. MoveHero():transit(false){};
  1659. MoveHero(const int3 &Dest, ObjectInstanceID HID, bool Transit) : dest(Dest), hid(HID), transit(Transit) {};
  1660. int3 dest;
  1661. ObjectInstanceID hid;
  1662. bool transit;
  1663. bool applyGh(CGameHandler *gh);
  1664. template <typename Handler> void serialize(Handler &h, const int version)
  1665. {
  1666. h & static_cast<CPackForServer &>(*this);
  1667. h & dest;
  1668. h & hid;
  1669. h & transit;
  1670. }
  1671. };
  1672. struct CastleTeleportHero : public CPackForServer
  1673. {
  1674. CastleTeleportHero():source(0){};
  1675. CastleTeleportHero(const ObjectInstanceID HID, ObjectInstanceID Dest, ui8 Source ) : dest(Dest), hid(HID), source(Source){};
  1676. ObjectInstanceID dest;
  1677. ObjectInstanceID hid;
  1678. si8 source;//who give teleporting, 1=castle gate
  1679. bool applyGh(CGameHandler *gh);
  1680. template <typename Handler> void serialize(Handler &h, const int version)
  1681. {
  1682. h & static_cast<CPackForServer &>(*this);
  1683. h & dest;
  1684. h & hid;
  1685. }
  1686. };
  1687. struct ArrangeStacks : public CPackForServer
  1688. {
  1689. ArrangeStacks():what(0), val(0){};
  1690. ArrangeStacks(ui8 W, SlotID P1, SlotID P2, ObjectInstanceID ID1, ObjectInstanceID ID2, si32 VAL)
  1691. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  1692. ui8 what; //1 - swap; 2 - merge; 3 - split
  1693. SlotID p1, p2; //positions of first and second stack
  1694. ObjectInstanceID id1, id2; //ids of objects with garrison
  1695. si32 val;
  1696. bool applyGh(CGameHandler *gh);
  1697. template <typename Handler> void serialize(Handler &h, const int version)
  1698. {
  1699. h & static_cast<CPackForServer &>(*this);
  1700. h & what;
  1701. h & p1;
  1702. h & p2;
  1703. h & id1;
  1704. h & id2;
  1705. h & val;
  1706. }
  1707. };
  1708. struct BulkMoveArmy : public CPackForServer
  1709. {
  1710. SlotID srcSlot;
  1711. ObjectInstanceID srcArmy;
  1712. ObjectInstanceID destArmy;
  1713. BulkMoveArmy()
  1714. {};
  1715. BulkMoveArmy(ObjectInstanceID srcArmy, ObjectInstanceID destArmy, SlotID srcSlot)
  1716. : srcArmy(srcArmy), destArmy(destArmy), srcSlot(srcSlot)
  1717. {};
  1718. bool applyGh(CGameHandler * gh);
  1719. template <typename Handler>
  1720. void serialize(Handler & h, const int version)
  1721. {
  1722. h & static_cast<CPackForServer&>(*this);
  1723. h & srcSlot;
  1724. h & srcArmy;
  1725. h & destArmy;
  1726. }
  1727. };
  1728. struct BulkSplitStack : public CPackForServer
  1729. {
  1730. SlotID src;
  1731. ObjectInstanceID srcOwner;
  1732. si32 amount;
  1733. BulkSplitStack() : amount(0)
  1734. {};
  1735. BulkSplitStack(ObjectInstanceID srcOwner, SlotID src, si32 howMany)
  1736. : src(src), srcOwner(srcOwner), amount(howMany)
  1737. {};
  1738. bool applyGh(CGameHandler * gh);
  1739. template <typename Handler>
  1740. void serialize(Handler & h, const int version)
  1741. {
  1742. h & static_cast<CPackForServer&>(*this);
  1743. h & src;
  1744. h & srcOwner;
  1745. h & amount;
  1746. }
  1747. };
  1748. struct BulkMergeStacks : public CPackForServer
  1749. {
  1750. SlotID src;
  1751. ObjectInstanceID srcOwner;
  1752. BulkMergeStacks()
  1753. {};
  1754. BulkMergeStacks(ObjectInstanceID srcOwner, SlotID src)
  1755. : src(src), srcOwner(srcOwner)
  1756. {};
  1757. bool applyGh(CGameHandler * gh);
  1758. template <typename Handler>
  1759. void serialize(Handler & h, const int version)
  1760. {
  1761. h & static_cast<CPackForServer&>(*this);
  1762. h & src;
  1763. h & srcOwner;
  1764. }
  1765. };
  1766. struct BulkSmartSplitStack : public CPackForServer
  1767. {
  1768. SlotID src;
  1769. ObjectInstanceID srcOwner;
  1770. BulkSmartSplitStack()
  1771. {};
  1772. BulkSmartSplitStack(ObjectInstanceID srcOwner, SlotID src)
  1773. : src(src), srcOwner(srcOwner)
  1774. {};
  1775. bool applyGh(CGameHandler * gh);
  1776. template <typename Handler>
  1777. void serialize(Handler & h, const int version)
  1778. {
  1779. h & static_cast<CPackForServer&>(*this);
  1780. h & src;
  1781. h & srcOwner;
  1782. }
  1783. };
  1784. struct DisbandCreature : public CPackForServer
  1785. {
  1786. DisbandCreature(){};
  1787. DisbandCreature(SlotID Pos, ObjectInstanceID ID):pos(Pos),id(ID){};
  1788. SlotID pos; //stack pos
  1789. ObjectInstanceID id; //object id
  1790. bool applyGh(CGameHandler *gh);
  1791. template <typename Handler> void serialize(Handler &h, const int version)
  1792. {
  1793. h & static_cast<CPackForServer &>(*this);
  1794. h & pos;
  1795. h & id;
  1796. }
  1797. };
  1798. struct BuildStructure : public CPackForServer
  1799. {
  1800. BuildStructure(){};
  1801. BuildStructure(ObjectInstanceID TID, BuildingID BID):tid(TID), bid(BID){};
  1802. ObjectInstanceID tid; //town id
  1803. BuildingID bid; //structure id
  1804. bool applyGh(CGameHandler *gh);
  1805. template <typename Handler> void serialize(Handler &h, const int version)
  1806. {
  1807. h & static_cast<CPackForServer &>(*this);
  1808. h & tid;
  1809. h & bid;
  1810. }
  1811. };
  1812. struct RazeStructure : public BuildStructure
  1813. {
  1814. RazeStructure(){};
  1815. bool applyGh(CGameHandler *gh);
  1816. };
  1817. struct RecruitCreatures : public CPackForServer
  1818. {
  1819. RecruitCreatures():amount(0), level(0){};
  1820. RecruitCreatures(ObjectInstanceID TID, ObjectInstanceID DST, CreatureID CRID, si32 Amount, si32 Level):
  1821. tid(TID), dst(DST), crid(CRID), amount(Amount), level(Level){};
  1822. ObjectInstanceID tid; //dwelling id, or town
  1823. ObjectInstanceID dst; //destination ID, e.g. hero
  1824. CreatureID crid;
  1825. ui32 amount;//creature amount
  1826. si32 level;//dwelling level to buy from, -1 if any
  1827. bool applyGh(CGameHandler *gh);
  1828. template <typename Handler> void serialize(Handler &h, const int version)
  1829. {
  1830. h & static_cast<CPackForServer &>(*this);
  1831. h & tid;
  1832. h & dst;
  1833. h & crid;
  1834. h & amount;
  1835. h & level;
  1836. }
  1837. };
  1838. struct UpgradeCreature : public CPackForServer
  1839. {
  1840. UpgradeCreature(){};
  1841. UpgradeCreature(SlotID Pos, ObjectInstanceID ID, CreatureID CRID):pos(Pos),id(ID), cid(CRID){};
  1842. SlotID pos; //stack pos
  1843. ObjectInstanceID id; //object id
  1844. CreatureID cid; //id of type to which we want make upgrade
  1845. bool applyGh(CGameHandler *gh);
  1846. template <typename Handler> void serialize(Handler &h, const int version)
  1847. {
  1848. h & static_cast<CPackForServer &>(*this);
  1849. h & pos;
  1850. h & id;
  1851. h & cid;
  1852. }
  1853. };
  1854. struct GarrisonHeroSwap : public CPackForServer
  1855. {
  1856. GarrisonHeroSwap(){};
  1857. GarrisonHeroSwap(ObjectInstanceID TID):tid(TID){};
  1858. ObjectInstanceID tid;
  1859. bool applyGh(CGameHandler *gh);
  1860. template <typename Handler> void serialize(Handler &h, const int version)
  1861. {
  1862. h & static_cast<CPackForServer &>(*this);
  1863. h & tid;
  1864. }
  1865. };
  1866. struct ExchangeArtifacts : public CPackForServer
  1867. {
  1868. ArtifactLocation src, dst;
  1869. ExchangeArtifacts(){};
  1870. bool applyGh(CGameHandler *gh);
  1871. template <typename Handler> void serialize(Handler &h, const int version)
  1872. {
  1873. h & static_cast<CPackForServer &>(*this);
  1874. h & src;
  1875. h & dst;
  1876. }
  1877. };
  1878. struct BulkExchangeArtifacts : public CPackForServer
  1879. {
  1880. ObjectInstanceID srcHero;
  1881. ObjectInstanceID dstHero;
  1882. bool swap;
  1883. BulkExchangeArtifacts()
  1884. : swap(false) {}
  1885. BulkExchangeArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap)
  1886. : srcHero(srcHero), dstHero(dstHero), swap(swap) {}
  1887. bool applyGh(CGameHandler * gh);
  1888. template <typename Handler> void serialize(Handler & h, const int version)
  1889. {
  1890. h & static_cast<CPackForServer&>(*this);
  1891. h & srcHero;
  1892. h & dstHero;
  1893. h & swap;
  1894. }
  1895. };
  1896. struct AssembleArtifacts : public CPackForServer
  1897. {
  1898. AssembleArtifacts():assemble(false){};
  1899. AssembleArtifacts(ObjectInstanceID _heroID, ArtifactPosition _artifactSlot, bool _assemble, ArtifactID _assembleTo)
  1900. : heroID(_heroID), artifactSlot(_artifactSlot), assemble(_assemble), assembleTo(_assembleTo){};
  1901. ObjectInstanceID heroID;
  1902. ArtifactPosition artifactSlot;
  1903. bool assemble; // True to assemble artifact, false to disassemble.
  1904. ArtifactID assembleTo; // Artifact to assemble into.
  1905. bool applyGh(CGameHandler *gh);
  1906. template <typename Handler> void serialize(Handler &h, const int version)
  1907. {
  1908. h & static_cast<CPackForServer &>(*this);
  1909. h & heroID;
  1910. h & artifactSlot;
  1911. h & assemble;
  1912. h & assembleTo;
  1913. }
  1914. };
  1915. struct BuyArtifact : public CPackForServer
  1916. {
  1917. BuyArtifact(){};
  1918. BuyArtifact(ObjectInstanceID HID, ArtifactID AID):hid(HID),aid(AID){};
  1919. ObjectInstanceID hid;
  1920. ArtifactID aid;
  1921. bool applyGh(CGameHandler *gh);
  1922. template <typename Handler> void serialize(Handler &h, const int version)
  1923. {
  1924. h & static_cast<CPackForServer &>(*this);
  1925. h & hid;
  1926. h & aid;
  1927. }
  1928. };
  1929. struct TradeOnMarketplace : public CPackForServer
  1930. {
  1931. TradeOnMarketplace()
  1932. :marketId(), heroId(), mode(EMarketMode::RESOURCE_RESOURCE)
  1933. {};
  1934. ObjectInstanceID marketId;
  1935. ObjectInstanceID heroId;
  1936. EMarketMode::EMarketMode mode;
  1937. 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?]
  1938. std::vector<ui32> val; //units of sold resource
  1939. bool applyGh(CGameHandler *gh);
  1940. template <typename Handler> void serialize(Handler &h, const int version)
  1941. {
  1942. h & static_cast<CPackForServer &>(*this);
  1943. h & marketId;
  1944. h & heroId;
  1945. h & mode;
  1946. h & r1;
  1947. h & r2;
  1948. h & val;
  1949. }
  1950. };
  1951. struct SetFormation : public CPackForServer
  1952. {
  1953. SetFormation():formation(0){};
  1954. SetFormation(ObjectInstanceID HID, ui8 Formation):hid(HID),formation(Formation){};
  1955. ObjectInstanceID hid;
  1956. ui8 formation;
  1957. bool applyGh(CGameHandler *gh);
  1958. template <typename Handler> void serialize(Handler &h, const int version)
  1959. {
  1960. h & static_cast<CPackForServer &>(*this);
  1961. h & hid;
  1962. h & formation;
  1963. }
  1964. };
  1965. struct HireHero : public CPackForServer
  1966. {
  1967. HireHero():hid(0){};
  1968. HireHero(si32 HID, ObjectInstanceID TID):hid(HID),tid(TID){};
  1969. si32 hid; //available hero serial
  1970. ObjectInstanceID tid; //town (tavern) id
  1971. PlayerColor player;
  1972. bool applyGh(CGameHandler *gh);
  1973. template <typename Handler> void serialize(Handler &h, const int version)
  1974. {
  1975. h & static_cast<CPackForServer &>(*this);
  1976. h & hid;
  1977. h & tid;
  1978. h & player;
  1979. }
  1980. };
  1981. struct BuildBoat : public CPackForServer
  1982. {
  1983. BuildBoat(){};
  1984. ObjectInstanceID objid; //where player wants to buy a boat
  1985. bool applyGh(CGameHandler *gh);
  1986. template <typename Handler> void serialize(Handler &h, const int version)
  1987. {
  1988. h & static_cast<CPackForServer &>(*this);
  1989. h & objid;
  1990. }
  1991. };
  1992. struct QueryReply : public CPackForServer
  1993. {
  1994. QueryReply(){};
  1995. QueryReply(QueryID QID, const JsonNode & Reply):qid(QID), reply(Reply){};
  1996. QueryID qid;
  1997. PlayerColor player;
  1998. JsonNode reply;
  1999. bool applyGh(CGameHandler *gh);
  2000. template <typename Handler> void serialize(Handler &h, const int version)
  2001. {
  2002. h & static_cast<CPackForServer &>(*this);
  2003. h & qid;
  2004. h & player;
  2005. h & reply;
  2006. }
  2007. };
  2008. struct MakeAction : public CPackForServer
  2009. {
  2010. MakeAction(){};
  2011. MakeAction(const BattleAction &BA):ba(BA){};
  2012. BattleAction ba;
  2013. bool applyGh(CGameHandler *gh);
  2014. template <typename Handler> void serialize(Handler &h, const int version)
  2015. {
  2016. h & static_cast<CPackForServer &>(*this);
  2017. h & ba;
  2018. }
  2019. };
  2020. struct MakeCustomAction : public CPackForServer
  2021. {
  2022. MakeCustomAction(){};
  2023. MakeCustomAction(const BattleAction &BA):ba(BA){};
  2024. BattleAction ba;
  2025. bool applyGh(CGameHandler *gh);
  2026. template <typename Handler> void serialize(Handler &h, const int version)
  2027. {
  2028. h & static_cast<CPackForServer &>(*this);
  2029. h & ba;
  2030. }
  2031. };
  2032. struct DigWithHero : public CPackForServer
  2033. {
  2034. DigWithHero(){}
  2035. ObjectInstanceID id; //digging hero id
  2036. bool applyGh(CGameHandler *gh);
  2037. template <typename Handler> void serialize(Handler &h, const int version)
  2038. {
  2039. h & static_cast<CPackForServer &>(*this);
  2040. h & id;
  2041. }
  2042. };
  2043. struct CastAdvSpell : public CPackForServer
  2044. {
  2045. CastAdvSpell(){}
  2046. ObjectInstanceID hid; //hero id
  2047. SpellID sid; //spell id
  2048. int3 pos; //selected tile (not always used)
  2049. bool applyGh(CGameHandler *gh);
  2050. template <typename Handler> void serialize(Handler &h, const int version)
  2051. {
  2052. h & static_cast<CPackForServer &>(*this);
  2053. h & hid;
  2054. h & sid;
  2055. h & pos;
  2056. }
  2057. };
  2058. /***********************************************************************************************************/
  2059. struct SaveGame : public CPackForServer
  2060. {
  2061. SaveGame(){};
  2062. SaveGame(const std::string &Fname) :fname(Fname){};
  2063. std::string fname;
  2064. void applyGs(CGameState *gs){};
  2065. bool applyGh(CGameHandler *gh);
  2066. template <typename Handler> void serialize(Handler &h, const int version)
  2067. {
  2068. h & static_cast<CPackForServer &>(*this);
  2069. h & fname;
  2070. }
  2071. };
  2072. // TODO: Eventually we should re-merge both SaveGame and PlayerMessage
  2073. struct SaveGameClient : public CPackForClient
  2074. {
  2075. SaveGameClient(){};
  2076. SaveGameClient(const std::string &Fname) :fname(Fname){};
  2077. std::string fname;
  2078. void applyCl(CClient *cl);
  2079. template <typename Handler> void serialize(Handler &h, const int version)
  2080. {
  2081. h & fname;
  2082. }
  2083. };
  2084. struct PlayerMessage : public CPackForServer
  2085. {
  2086. PlayerMessage(){};
  2087. PlayerMessage(const std::string &Text, ObjectInstanceID obj)
  2088. : text(Text), currObj(obj)
  2089. {};
  2090. void applyGs(CGameState *gs){};
  2091. bool applyGh(CGameHandler *gh);
  2092. std::string text;
  2093. ObjectInstanceID currObj; // optional parameter that specifies current object. For cheats :)
  2094. template <typename Handler> void serialize(Handler &h, const int version)
  2095. {
  2096. h & static_cast<CPackForServer &>(*this);
  2097. h & text;
  2098. h & currObj;
  2099. }
  2100. };
  2101. struct PlayerMessageClient : public CPackForClient
  2102. {
  2103. PlayerMessageClient(){};
  2104. PlayerMessageClient(PlayerColor Player, const std::string &Text)
  2105. : player(Player), text(Text)
  2106. {}
  2107. void applyCl(CClient *cl);
  2108. PlayerColor player;
  2109. std::string text;
  2110. template <typename Handler> void serialize(Handler &h, const int version)
  2111. {
  2112. h & player;
  2113. h & text;
  2114. }
  2115. };
  2116. struct CenterView : public CPackForClient
  2117. {
  2118. CenterView():focusTime(0){};
  2119. void applyCl(CClient *cl);
  2120. PlayerColor player;
  2121. int3 pos;
  2122. ui32 focusTime; //ms
  2123. template <typename Handler> void serialize(Handler &h, const int version)
  2124. {
  2125. h & pos;
  2126. h & player;
  2127. h & focusTime;
  2128. }
  2129. };
  2130. VCMI_LIB_NAMESPACE_END