NetPacks.h 55 KB

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