NetPacks.h 55 KB

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