2
0

NetPacks.h 55 KB

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