NetPacks.h 56 KB

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