NetPacks.h 54 KB

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