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