NetPacks.h 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341
  1. #pragma once
  2. #include "NetPacksBase.h"
  3. #include "battle/BattleAction.h"
  4. #include "JsonNode.h"
  5. #include "mapObjects/CGHeroInstance.h"
  6. #include "ConstTransitivePtr.h"
  7. #include "int3.h"
  8. #include "ResourceSet.h"
  9. #include "CGameStateFwd.h"
  10. #include "mapping/CMapDefines.h"
  11. #include "battle/CObstacleInstance.h"
  12. #include "spells/ViewSpellInt.h"
  13. /*
  14. * NetPacks.h, part of VCMI engine
  15. *
  16. * Authors: listed in file AUTHORS in main folder
  17. *
  18. * License: GNU General Public License v2.0 or later
  19. * Full text of license available in license.txt file, in main folder
  20. *
  21. */
  22. class CClient;
  23. class CGameState;
  24. class CGameHandler;
  25. class CConnection;
  26. class CCampaignState;
  27. class CArtifact;
  28. class CSelectionScreen;
  29. class CGObjectInstance;
  30. class CArtifactInstance;
  31. struct StackLocation;
  32. struct ArtSlotInfo;
  33. struct QuestInfo;
  34. class CMapInfo;
  35. struct StartInfo;
  36. struct CPackForClient : public CPack
  37. {
  38. CPackForClient(){};
  39. CGameState* GS(CClient *cl);
  40. void applyFirstCl(CClient *cl)//called before applying to gs
  41. {}
  42. void applyCl(CClient *cl)//called after applying to gs
  43. {}
  44. };
  45. struct CPackForServer : public CPack
  46. {
  47. PlayerColor player;
  48. CConnection *c;
  49. CGameState* GS(CGameHandler *gh);
  50. CPackForServer():
  51. player(PlayerColor::NEUTRAL),
  52. c(nullptr)
  53. {
  54. }
  55. bool applyGh(CGameHandler *gh) //called after applying to gs
  56. {
  57. logGlobal->errorStream() << "Should not happen... applying plain CPackForServer";
  58. return false;
  59. }
  60. };
  61. struct Query : public CPackForClient
  62. {
  63. QueryID queryID; // equals to -1 if it is not an actual query (and should not be answered)
  64. Query()
  65. {
  66. }
  67. };
  68. struct StackLocation
  69. {
  70. ConstTransitivePtr<CArmedInstance> army;
  71. SlotID slot;
  72. StackLocation()
  73. {}
  74. StackLocation(const CArmedInstance *Army, SlotID Slot):
  75. army(const_cast<CArmedInstance*>(Army)), //we are allowed here to const cast -> change will go through one of our packages... do not abuse!
  76. slot(Slot)
  77. {
  78. }
  79. DLL_LINKAGE const CStackInstance *getStack();
  80. template <typename Handler> void serialize(Handler &h, const int version)
  81. {
  82. h & army & slot;
  83. }
  84. };
  85. /***********************************************************************************************************/
  86. struct PackageApplied : public CPackForClient
  87. {
  88. PackageApplied()
  89. : result(0), packType(0),requestID(0)
  90. {}
  91. PackageApplied(ui8 Result)
  92. : result(Result), packType(0), requestID(0)
  93. {}
  94. void applyCl(CClient *cl);
  95. ui8 result; //0 - something went wrong, request hasn't been realized; 1 - OK
  96. ui32 packType; //type id of applied package
  97. ui32 requestID; //an ID given by client to the request that was applied
  98. PlayerColor player;
  99. template <typename Handler> void serialize(Handler &h, const int version)
  100. {
  101. h & result & packType & requestID & player;
  102. }
  103. };
  104. struct SystemMessage : public CPackForClient
  105. {
  106. SystemMessage(const std::string & Text) : text(Text){}
  107. SystemMessage(){}
  108. void applyCl(CClient *cl);
  109. std::string text;
  110. template <typename Handler> void serialize(Handler &h, const int version)
  111. {
  112. h & text;
  113. }
  114. };
  115. struct PlayerBlocked : public CPackForClient
  116. {
  117. PlayerBlocked() : reason(UPCOMING_BATTLE), startOrEnd(BLOCKADE_STARTED) {}
  118. void applyCl(CClient *cl);
  119. enum EReason { UPCOMING_BATTLE, ONGOING_MOVEMENT };
  120. enum EMode { BLOCKADE_STARTED, BLOCKADE_ENDED };
  121. EReason reason;
  122. EMode startOrEnd;
  123. PlayerColor player;
  124. template <typename Handler> void serialize(Handler &h, const int version)
  125. {
  126. h & reason & startOrEnd & player;
  127. }
  128. };
  129. struct PlayerCheated : public CPackForClient
  130. {
  131. PlayerCheated() : losingCheatCode(false), winningCheatCode(false) {}
  132. DLL_LINKAGE void applyGs(CGameState *gs);
  133. PlayerColor player;
  134. bool losingCheatCode;
  135. bool winningCheatCode;
  136. template <typename Handler> void serialize(Handler &h, const int version)
  137. {
  138. h & player & losingCheatCode & winningCheatCode;
  139. }
  140. };
  141. struct YourTurn : public CPackForClient
  142. {
  143. YourTurn(){}
  144. void applyCl(CClient *cl);
  145. DLL_LINKAGE void applyGs(CGameState *gs);
  146. PlayerColor player;
  147. boost::optional<ui8> daysWithoutCastle;
  148. template <typename Handler> void serialize(Handler &h, const int version)
  149. {
  150. h & player & daysWithoutCastle;
  151. }
  152. };
  153. struct SetResources : public CPackForClient
  154. {
  155. SetResources():abs(true){};
  156. void applyCl(CClient *cl);
  157. DLL_LINKAGE void applyGs(CGameState *gs);
  158. bool abs; //false - changes by value; 1 - sets to value
  159. PlayerColor player;
  160. TResources res; //res[resid] => res amount
  161. template <typename Handler> void serialize(Handler &h, const int version)
  162. {
  163. h & abs & player & res;
  164. }
  165. };
  166. struct SetPrimSkill : public CPackForClient
  167. {
  168. SetPrimSkill()
  169. : abs(0), which(PrimarySkill::ATTACK), val(0)
  170. {}
  171. void applyCl(CClient *cl);
  172. DLL_LINKAGE void applyGs(CGameState *gs);
  173. ui8 abs; //0 - changes by value; 1 - sets to value
  174. ObjectInstanceID id;
  175. PrimarySkill::PrimarySkill which;
  176. si64 val;
  177. template <typename Handler> void serialize(Handler &h, const int version)
  178. {
  179. h & abs & id & which & val;
  180. }
  181. };
  182. struct SetSecSkill : public CPackForClient
  183. {
  184. SetSecSkill()
  185. : abs(0), val(0)
  186. {}
  187. void applyCl(CClient *cl);
  188. DLL_LINKAGE void applyGs(CGameState *gs);
  189. ui8 abs; //0 - changes by value; 1 - sets to value
  190. ObjectInstanceID id;
  191. SecondarySkill which;
  192. ui16 val;
  193. template <typename Handler> void serialize(Handler &h, const int version)
  194. {
  195. h & abs & id & which & val;
  196. }
  197. };
  198. struct HeroVisitCastle : public CPackForClient
  199. {
  200. HeroVisitCastle(){flags=0;};
  201. void applyCl(CClient *cl);
  202. DLL_LINKAGE void applyGs(CGameState *gs);
  203. ui8 flags; //1 - start
  204. ObjectInstanceID tid, hid;
  205. bool start() //if hero is entering castle (if false - leaving)
  206. {
  207. return flags & 1;
  208. }
  209. template <typename Handler> void serialize(Handler &h, const int version)
  210. {
  211. h & flags & tid & hid;
  212. }
  213. };
  214. struct ChangeSpells : public CPackForClient
  215. {
  216. ChangeSpells():learn(1){}
  217. void applyCl(CClient *cl);
  218. DLL_LINKAGE void applyGs(CGameState *gs);
  219. ui8 learn; //1 - gives spell, 0 - takes
  220. ObjectInstanceID hid;
  221. std::set<SpellID> spells;
  222. template <typename Handler> void serialize(Handler &h, const int version)
  223. {
  224. h & learn & hid & spells;
  225. }
  226. };
  227. struct SetMana : public CPackForClient
  228. {
  229. SetMana(){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 SetMovePoints : public CPackForClient
  241. {
  242. SetMovePoints(){val = 0; absolute=true;}
  243. void applyCl(CClient *cl);
  244. DLL_LINKAGE void applyGs(CGameState *gs);
  245. ObjectInstanceID hid;
  246. si32 val;
  247. bool absolute;
  248. template <typename Handler> void serialize(Handler &h, const int version)
  249. {
  250. h & val & hid & absolute;
  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. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  897. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  898. //Until sending reply player won't be allowed to take any actions
  899. struct BlockingDialog : public Query
  900. {
  901. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  902. void applyCl(CClient *cl);
  903. MetaString text;
  904. std::vector<Component> components;
  905. PlayerColor player;
  906. ui8 flags;
  907. ui16 soundID;
  908. bool cancel() const
  909. {
  910. return flags & ALLOW_CANCEL;
  911. }
  912. bool selection() const
  913. {
  914. return flags & SELECTION;
  915. }
  916. BlockingDialog(bool yesno, bool Selection)
  917. {
  918. flags = 0;
  919. soundID = 0;
  920. if(yesno) flags |= ALLOW_CANCEL;
  921. if(Selection) flags |= SELECTION;
  922. }
  923. BlockingDialog()
  924. {
  925. flags = 0;
  926. soundID = 0;
  927. };
  928. template <typename Handler> void serialize(Handler &h, const int version)
  929. {
  930. h & queryID & text & components & player & flags & soundID;
  931. }
  932. };
  933. struct GarrisonDialog : public Query
  934. {
  935. GarrisonDialog():removableUnits(false){}
  936. void applyCl(CClient *cl);
  937. ObjectInstanceID objid, hid;
  938. bool removableUnits;
  939. template <typename Handler> void serialize(Handler &h, const int version)
  940. {
  941. h & queryID & objid & hid & removableUnits;
  942. }
  943. };
  944. struct ExchangeDialog : public Query
  945. {
  946. ExchangeDialog()
  947. {
  948. heroes = {nullptr,nullptr};
  949. }
  950. void applyCl(CClient *cl);
  951. std::array<const CGHeroInstance*, 2> heroes;
  952. template <typename Handler> void serialize(Handler &h, const int version)
  953. {
  954. h & queryID & heroes;
  955. }
  956. };
  957. struct TeleportDialog : public Query
  958. {
  959. TeleportDialog()
  960. : hero(nullptr), impassable(false)
  961. {}
  962. TeleportDialog(const CGHeroInstance *Hero, TeleportChannelID Channel)
  963. : hero(Hero), channel(Channel), impassable(false)
  964. {}
  965. void applyCl(CClient *cl);
  966. const CGHeroInstance *hero;
  967. TeleportChannelID channel;
  968. TTeleportExitsList exits;
  969. bool impassable;
  970. template <typename Handler> void serialize(Handler &h, const int version)
  971. {
  972. h & queryID & hero & channel & exits & impassable;
  973. }
  974. };
  975. struct MapObjectSelectDialog : public Query
  976. {
  977. PlayerColor player;
  978. Component icon;
  979. MetaString title;
  980. MetaString description;
  981. std::vector<ObjectInstanceID> objects;
  982. MapObjectSelectDialog(){};
  983. void applyCl(CClient * cl);
  984. template <typename Handler> void serialize(Handler & h, const int version)
  985. {
  986. h & queryID & player & icon & title & description & objects;
  987. }
  988. };
  989. struct BattleInfo;
  990. struct BattleStart : public CPackForClient
  991. {
  992. BattleStart()
  993. :info(nullptr)
  994. {}
  995. void applyFirstCl(CClient *cl);
  996. void applyCl(CClient *cl);
  997. DLL_LINKAGE void applyGs(CGameState *gs);
  998. BattleInfo * info;
  999. template <typename Handler> void serialize(Handler &h, const int version)
  1000. {
  1001. h & info;
  1002. }
  1003. };
  1004. struct BattleNextRound : public CPackForClient
  1005. {
  1006. BattleNextRound():round(0){};
  1007. void applyFirstCl(CClient *cl);
  1008. void applyCl(CClient *cl);
  1009. DLL_LINKAGE void applyGs( CGameState *gs );
  1010. si32 round;
  1011. template <typename Handler> void serialize(Handler &h, const int version)
  1012. {
  1013. h & round;
  1014. }
  1015. };
  1016. struct BattleSetActiveStack : public CPackForClient
  1017. {
  1018. BattleSetActiveStack()
  1019. {
  1020. stack = 0;
  1021. askPlayerInterface = true;
  1022. }
  1023. void applyCl(CClient *cl);
  1024. DLL_LINKAGE void applyGs(CGameState *gs);
  1025. ui32 stack;
  1026. ui8 askPlayerInterface;
  1027. template <typename Handler> void serialize(Handler &h, const int version)
  1028. {
  1029. h & stack & askPlayerInterface;
  1030. }
  1031. };
  1032. struct BattleResult : public CPackForClient
  1033. {
  1034. enum EResult {NORMAL = 0, ESCAPE = 1, SURRENDER = 2};
  1035. BattleResult()
  1036. : result(NORMAL), winner(2)
  1037. {
  1038. exp[0] = 0;
  1039. exp[1] = 0;
  1040. };
  1041. void applyFirstCl(CClient *cl);
  1042. void applyGs(CGameState *gs);
  1043. EResult result;
  1044. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  1045. std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
  1046. TExpType exp[2]; //exp for attacker and defender
  1047. std::set<ArtifactInstanceID> artifacts; //artifacts taken from loser to winner - currently unused
  1048. template <typename Handler> void serialize(Handler &h, const int version)
  1049. {
  1050. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  1051. }
  1052. };
  1053. struct BattleStackMoved : public CPackForClient
  1054. {
  1055. ui32 stack;
  1056. std::vector<BattleHex> tilesToMove;
  1057. ui8 distance, teleporting;
  1058. BattleStackMoved()
  1059. :stack(0), distance(0), teleporting(0)
  1060. {};
  1061. void applyFirstCl(CClient *cl);
  1062. void applyGs(CGameState *gs);
  1063. template <typename Handler> void serialize(Handler &h, const int version)
  1064. {
  1065. h & stack & tilesToMove & distance;
  1066. }
  1067. };
  1068. struct StacksHealedOrResurrected : public CPackForClient
  1069. {
  1070. StacksHealedOrResurrected()
  1071. :lifeDrain(false), tentHealing(false), drainedFrom(0), cure(false), canOverheal(false)
  1072. {}
  1073. DLL_LINKAGE void applyGs(CGameState *gs);
  1074. void applyCl(CClient *cl);
  1075. struct HealInfo
  1076. {
  1077. ui32 stackID;
  1078. ui32 healedHP;
  1079. bool lowLevelResurrection; //in case this stack is resurrected by this heal, it will be marked as SUMMONED //TODO: replace with separate counter
  1080. template <typename Handler> void serialize(Handler &h, const int version)
  1081. {
  1082. h & stackID & healedHP & lowLevelResurrection;
  1083. }
  1084. };
  1085. std::vector<HealInfo> healedStacks;
  1086. bool lifeDrain; //if true, this heal is an effect of life drain or soul steal
  1087. bool tentHealing; //if true, than it's healing via First Aid Tent
  1088. si32 drainedFrom; //if life drain or soul steal - then stack life was drain from, if tentHealing - stack that is a healer
  1089. bool cure; //archangel cast also remove negative effects
  1090. bool canOverheal; //to allow healing over initial stack amount
  1091. template <typename Handler> void serialize(Handler &h, const int version)
  1092. {
  1093. h & healedStacks & lifeDrain & tentHealing & drainedFrom;
  1094. h & cure & canOverheal;
  1095. }
  1096. };
  1097. struct BattleStackAttacked : public CPackForClient
  1098. {
  1099. BattleStackAttacked():
  1100. stackAttacked(0), attackerID(0),
  1101. newAmount(0), newHP(0), killedAmount(0), damageAmount(0),
  1102. flags(0), effect(0), spellID(SpellID::NONE)
  1103. {};
  1104. void applyFirstCl(CClient * cl);
  1105. //void applyCl(CClient *cl);
  1106. DLL_LINKAGE void applyGs(CGameState *gs);
  1107. ui32 stackAttacked, attackerID;
  1108. ui32 newAmount, newHP, killedAmount, damageAmount;
  1109. enum EFlags {KILLED = 1, EFFECT = 2/*deprecated */, SECONDARY = 4, REBIRTH = 8, CLONE_KILLED = 16, SPELL_EFFECT = 32 /*, BONUS_EFFECT = 64 */};
  1110. ui32 flags; //uses EFlags (above)
  1111. ui32 effect; //set only if flag EFFECT is set
  1112. SpellID spellID; //only if flag SPELL_EFFECT is set
  1113. std::vector<StacksHealedOrResurrected> healedStacks; //used when life drain
  1114. bool killed() const//if target stack was killed
  1115. {
  1116. return flags & KILLED || flags & CLONE_KILLED;
  1117. }
  1118. bool cloneKilled() const
  1119. {
  1120. return flags & CLONE_KILLED;
  1121. }
  1122. bool isEffect() const//if stack has been attacked by a spell
  1123. {
  1124. return flags & EFFECT;
  1125. }
  1126. bool isSecondary() const//if stack was not a primary target (receives no spell effects)
  1127. {
  1128. return flags & SECONDARY;
  1129. }
  1130. ///Attacked with spell (SPELL_LIKE_ATTACK)
  1131. bool isSpell() const
  1132. {
  1133. return flags & SPELL_EFFECT;
  1134. }
  1135. bool willRebirth() const//resurrection, e.g. Phoenix
  1136. {
  1137. return flags & REBIRTH;
  1138. }
  1139. bool lifeDrain() const //if this attack involves life drain effect
  1140. {
  1141. return healedStacks.size() > 0;
  1142. }
  1143. template <typename Handler> void serialize(Handler &h, const int version)
  1144. {
  1145. h & stackAttacked & attackerID & newAmount & newHP & flags & killedAmount & damageAmount & effect
  1146. & healedStacks;
  1147. h & spellID;
  1148. }
  1149. bool operator<(const BattleStackAttacked &b) const
  1150. {
  1151. return stackAttacked < b.stackAttacked;
  1152. }
  1153. };
  1154. struct BattleAttack : public CPackForClient
  1155. {
  1156. BattleAttack()
  1157. : stackAttacking(0), flags(0), spellID(SpellID::NONE)
  1158. {};
  1159. void applyFirstCl(CClient *cl);
  1160. DLL_LINKAGE void applyGs(CGameState *gs);
  1161. void applyCl(CClient *cl);
  1162. std::vector<BattleStackAttacked> bsa;
  1163. ui32 stackAttacking;
  1164. ui32 flags; //uses Eflags (below)
  1165. enum EFlags{SHOT = 1, COUNTER = 2, LUCKY = 4, UNLUCKY = 8, BALLISTA_DOUBLE_DMG = 16, DEATH_BLOW = 32, SPELL_LIKE = 64};
  1166. SpellID spellID; //for SPELL_LIKE
  1167. bool shot() const//distance attack - decrease number of shots
  1168. {
  1169. return flags & SHOT;
  1170. }
  1171. bool counter() const//is it counterattack?
  1172. {
  1173. return flags & COUNTER;
  1174. }
  1175. bool lucky() const
  1176. {
  1177. return flags & LUCKY;
  1178. }
  1179. bool unlucky() const
  1180. {
  1181. return flags & UNLUCKY;
  1182. }
  1183. bool ballistaDoubleDmg() const //if it's ballista attack and does double dmg
  1184. {
  1185. return flags & BALLISTA_DOUBLE_DMG;
  1186. }
  1187. bool deathBlow() const
  1188. {
  1189. return flags & DEATH_BLOW;
  1190. }
  1191. bool spellLike() const
  1192. {
  1193. return flags & SPELL_LIKE;
  1194. }
  1195. template <typename Handler> void serialize(Handler &h, const int version)
  1196. {
  1197. h & bsa & stackAttacking & flags & spellID;
  1198. }
  1199. };
  1200. struct StartAction : public CPackForClient
  1201. {
  1202. StartAction(){};
  1203. StartAction(const BattleAction &act){ba = act; };
  1204. void applyFirstCl(CClient *cl);
  1205. DLL_LINKAGE void applyGs(CGameState *gs);
  1206. BattleAction ba;
  1207. template <typename Handler> void serialize(Handler &h, const int version)
  1208. {
  1209. h & ba;
  1210. }
  1211. };
  1212. struct EndAction : public CPackForClient
  1213. {
  1214. EndAction(){};
  1215. void applyCl(CClient *cl);
  1216. template <typename Handler> void serialize(Handler &h, const int version)
  1217. {
  1218. }
  1219. };
  1220. struct BattleSpellCast : public CPackForClient
  1221. {
  1222. ///custom effect (resistance, reflection, etc)
  1223. struct CustomEffect
  1224. {
  1225. /// WoG AC format
  1226. ui32 effect;
  1227. ui32 stack;
  1228. template <typename Handler> void serialize(Handler &h, const int version)
  1229. {
  1230. h & effect & stack;
  1231. }
  1232. };
  1233. BattleSpellCast()
  1234. {
  1235. side = 0;
  1236. id = 0;
  1237. skill = 0;
  1238. manaGained = 0;
  1239. casterStack = -1;
  1240. castByHero = true;
  1241. };
  1242. DLL_LINKAGE void applyGs(CGameState *gs);
  1243. void applyCl(CClient *cl);
  1244. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  1245. ui32 id; //id of spell
  1246. ui8 skill; //caster's skill level
  1247. ui8 manaGained; //mana channeling ability
  1248. BattleHex tile; //destination tile (may not be set in some global/mass spells
  1249. std::vector<CustomEffect> customEffects;
  1250. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  1251. si32 casterStack;// -1 if not cated by creature, >=0 caster stack ID
  1252. bool castByHero; //if true - spell has been cast by hero, otherwise by a creature
  1253. std::vector<MetaString> battleLog;
  1254. template <typename Handler> void serialize(Handler &h, const int version)
  1255. {
  1256. h & side & id & skill & manaGained & tile & customEffects & affectedCres & casterStack & castByHero;
  1257. h & battleLog;
  1258. }
  1259. };
  1260. struct SetStackEffect : public CPackForClient
  1261. {
  1262. SetStackEffect(){};
  1263. DLL_LINKAGE void applyGs(CGameState *gs);
  1264. void applyCl(CClient *cl);
  1265. std::vector<ui32> stacks; //affected stacks (IDs)
  1266. //regular effects
  1267. std::vector<Bonus> effect; //bonuses to apply
  1268. std::vector<std::pair<ui32, Bonus> > uniqueBonuses; //bonuses per single stack
  1269. //cumulative effects
  1270. std::vector<Bonus> cumulativeEffects; //bonuses to apply
  1271. std::vector<std::pair<ui32, Bonus> > cumulativeUniqueBonuses; //bonuses per single stack
  1272. template <typename Handler> void serialize(Handler &h, const int version)
  1273. {
  1274. h & stacks & effect & uniqueBonuses;
  1275. h & cumulativeEffects & cumulativeUniqueBonuses;
  1276. }
  1277. };
  1278. struct StacksInjured : public CPackForClient
  1279. {
  1280. StacksInjured(){}
  1281. DLL_LINKAGE void applyGs(CGameState *gs);
  1282. void applyCl(CClient *cl);
  1283. std::vector<BattleStackAttacked> stacks;
  1284. template <typename Handler> void serialize(Handler &h, const int version)
  1285. {
  1286. h & stacks;
  1287. }
  1288. };
  1289. struct BattleResultsApplied : public CPackForClient
  1290. {
  1291. BattleResultsApplied(){}
  1292. PlayerColor player1, player2;
  1293. void applyCl(CClient *cl);
  1294. template <typename Handler> void serialize(Handler &h, const int version)
  1295. {
  1296. h & player1 & player2;
  1297. }
  1298. };
  1299. struct ObstaclesRemoved : public CPackForClient
  1300. {
  1301. ObstaclesRemoved(){}
  1302. DLL_LINKAGE void applyGs(CGameState *gs);
  1303. void applyCl(CClient *cl);
  1304. std::set<si32> obstacles; //uniqueIDs of removed obstacles
  1305. template <typename Handler> void serialize(Handler &h, const int version)
  1306. {
  1307. h & obstacles;
  1308. }
  1309. };
  1310. struct ELF_VISIBILITY CatapultAttack : public CPackForClient
  1311. {
  1312. struct AttackInfo
  1313. {
  1314. si16 destinationTile;
  1315. ui8 attackedPart;
  1316. ui8 damageDealt;
  1317. DLL_LINKAGE std::string toString() const;
  1318. template <typename Handler> void serialize(Handler &h, const int version)
  1319. {
  1320. h & destinationTile & attackedPart & damageDealt;
  1321. }
  1322. };
  1323. DLL_LINKAGE CatapultAttack();
  1324. DLL_LINKAGE ~CatapultAttack();
  1325. DLL_LINKAGE void applyGs(CGameState *gs);
  1326. void applyCl(CClient *cl);
  1327. DLL_LINKAGE std::string toString() const override;
  1328. std::vector< AttackInfo > attackedParts;
  1329. int attacker; //if -1, then a spell caused this
  1330. template <typename Handler> void serialize(Handler &h, const int version)
  1331. {
  1332. h & attackedParts & attacker;
  1333. }
  1334. };
  1335. DLL_LINKAGE std::ostream & operator<<(std::ostream & out, const CatapultAttack::AttackInfo & attackInfo);
  1336. struct BattleStacksRemoved : public CPackForClient
  1337. {
  1338. BattleStacksRemoved(){}
  1339. DLL_LINKAGE void applyGs(CGameState *gs);
  1340. void applyFirstCl(CClient *cl);//inform client before stack objects are destroyed
  1341. std::set<ui32> stackIDs; //IDs of removed stacks
  1342. template <typename Handler> void serialize(Handler &h, const int version)
  1343. {
  1344. h & stackIDs;
  1345. }
  1346. };
  1347. struct BattleStackAdded : public CPackForClient
  1348. {
  1349. BattleStackAdded()
  1350. : side(0), amount(0), pos(0), summoned(0), newStackID(0)
  1351. {};
  1352. DLL_LINKAGE void applyGs(CGameState *gs);
  1353. void applyCl(CClient *cl);
  1354. ui8 side;
  1355. CreatureID creID;
  1356. int amount;
  1357. int pos;
  1358. int summoned; //if true, remove it afterwards
  1359. ///Actual stack ID, set on apply, do not serialize
  1360. int newStackID;
  1361. template <typename Handler> void serialize(Handler &h, const int version)
  1362. {
  1363. h & side & creID & amount & pos & summoned;
  1364. }
  1365. };
  1366. struct BattleSetStackProperty : public CPackForClient
  1367. {
  1368. BattleSetStackProperty()
  1369. : stackID(0), which(CASTS), val(0), absolute(0)
  1370. {};
  1371. enum BattleStackProperty {CASTS, ENCHANTER_COUNTER, UNBIND, CLONED, HAS_CLONE};
  1372. DLL_LINKAGE void applyGs(CGameState *gs);
  1373. int stackID;
  1374. BattleStackProperty which;
  1375. int val;
  1376. int absolute;
  1377. template <typename Handler> void serialize(Handler &h, const int version)
  1378. {
  1379. h & stackID & which & val & absolute;
  1380. }
  1381. };
  1382. ///activated at the beginning of turn
  1383. struct BattleTriggerEffect : public CPackForClient
  1384. {
  1385. BattleTriggerEffect()
  1386. : stackID(0), effect(0), val(0), additionalInfo(0)
  1387. {};
  1388. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1389. void applyCl(CClient *cl); //play animations & stuff
  1390. int stackID;
  1391. int effect; //use corresponding Bonus type
  1392. int val;
  1393. int additionalInfo;
  1394. template <typename Handler> void serialize(Handler &h, const int version)
  1395. {
  1396. h & stackID & effect & val & additionalInfo;
  1397. }
  1398. };
  1399. struct BattleObstaclePlaced : public CPackForClient
  1400. {
  1401. BattleObstaclePlaced(){};
  1402. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1403. void applyCl(CClient *cl); //play animations & stuff
  1404. std::shared_ptr<CObstacleInstance> obstacle;
  1405. template <typename Handler> void serialize(Handler &h, const int version)
  1406. {
  1407. h & obstacle;
  1408. }
  1409. };
  1410. struct BattleUpdateGateState : public CPackForClient
  1411. {
  1412. BattleUpdateGateState():state(EGateState::NONE){};
  1413. void applyFirstCl(CClient *cl);
  1414. DLL_LINKAGE void applyGs(CGameState *gs);
  1415. EGateState state;
  1416. template <typename Handler> void serialize(Handler &h, const int version)
  1417. {
  1418. h & state;
  1419. }
  1420. };
  1421. struct ShowInInfobox : public CPackForClient
  1422. {
  1423. ShowInInfobox(){};
  1424. PlayerColor player;
  1425. Component c;
  1426. MetaString text;
  1427. void applyCl(CClient *cl);
  1428. template <typename Handler> void serialize(Handler &h, const int version)
  1429. {
  1430. h & player & c & text;
  1431. }
  1432. };
  1433. struct AdvmapSpellCast : public CPackForClient
  1434. {
  1435. AdvmapSpellCast():caster(nullptr){}
  1436. const CGHeroInstance * caster;//todo: replace with ObjectInstanceID
  1437. SpellID spellID;
  1438. void applyCl(CClient *cl);
  1439. template <typename Handler> void serialize(Handler &h, const int version)
  1440. {
  1441. h & caster & spellID;
  1442. }
  1443. };
  1444. struct ShowWorldViewEx : public CPackForClient
  1445. {
  1446. PlayerColor player;
  1447. std::vector<ObjectPosInfo> objectPositions;
  1448. ShowWorldViewEx(){}
  1449. void applyCl(CClient *cl);
  1450. template <typename Handler> void serialize(Handler &h, const int version)
  1451. {
  1452. h & player & objectPositions;
  1453. }
  1454. };
  1455. /***********************************************************************************************************/
  1456. struct CommitPackage : public CPackForServer
  1457. {
  1458. bool freePack; //for local usage, DO NOT serialize
  1459. bool applyGh(CGameHandler *gh);
  1460. CPackForClient *packToCommit;
  1461. CommitPackage()
  1462. {
  1463. freePack = true;
  1464. packToCommit = nullptr;
  1465. }
  1466. ~CommitPackage()
  1467. {
  1468. if(freePack)
  1469. delete packToCommit;
  1470. }
  1471. template <typename Handler> void serialize(Handler &h, const int version)
  1472. {
  1473. h & packToCommit;
  1474. }
  1475. };
  1476. struct CloseServer : public CPackForServer
  1477. {
  1478. bool applyGh(CGameHandler *gh);
  1479. template <typename Handler> void serialize(Handler &h, const int version)
  1480. {}
  1481. };
  1482. struct LeaveGame : public CPackForServer
  1483. {
  1484. bool applyGh(CGameHandler *gh);
  1485. template <typename Handler> void serialize(Handler &h, const int version)
  1486. {}
  1487. };
  1488. struct EndTurn : public CPackForServer
  1489. {
  1490. bool applyGh(CGameHandler *gh);
  1491. template <typename Handler> void serialize(Handler &h, const int version)
  1492. {}
  1493. };
  1494. struct DismissHero : public CPackForServer
  1495. {
  1496. DismissHero(){};
  1497. DismissHero(ObjectInstanceID HID) : hid(HID) {};
  1498. ObjectInstanceID hid;
  1499. bool applyGh(CGameHandler *gh);
  1500. template <typename Handler> void serialize(Handler &h, const int version)
  1501. {
  1502. h & hid;
  1503. }
  1504. };
  1505. struct MoveHero : public CPackForServer
  1506. {
  1507. MoveHero():transit(false){};
  1508. MoveHero(const int3 &Dest, ObjectInstanceID HID, bool Transit) : dest(Dest), hid(HID), transit(Transit) {};
  1509. int3 dest;
  1510. ObjectInstanceID hid;
  1511. bool transit;
  1512. bool applyGh(CGameHandler *gh);
  1513. template <typename Handler> void serialize(Handler &h, const int version)
  1514. {
  1515. h & dest & hid & transit;
  1516. }
  1517. };
  1518. struct CastleTeleportHero : public CPackForServer
  1519. {
  1520. CastleTeleportHero():source(0){};
  1521. CastleTeleportHero(const ObjectInstanceID HID, ObjectInstanceID Dest, ui8 Source ) : dest(Dest), hid(HID), source(Source){};
  1522. ObjectInstanceID dest;
  1523. ObjectInstanceID hid;
  1524. si8 source;//who give teleporting, 1=castle gate
  1525. bool applyGh(CGameHandler *gh);
  1526. template <typename Handler> void serialize(Handler &h, const int version)
  1527. {
  1528. h & dest & hid;
  1529. }
  1530. };
  1531. struct ArrangeStacks : public CPackForServer
  1532. {
  1533. ArrangeStacks():what(0), val(0){};
  1534. ArrangeStacks(ui8 W, SlotID P1, SlotID P2, ObjectInstanceID ID1, ObjectInstanceID ID2, si32 VAL)
  1535. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  1536. ui8 what; //1 - swap; 2 - merge; 3 - split
  1537. SlotID p1, p2; //positions of first and second stack
  1538. ObjectInstanceID id1, id2; //ids of objects with garrison
  1539. si32 val;
  1540. bool applyGh(CGameHandler *gh);
  1541. template <typename Handler> void serialize(Handler &h, const int version)
  1542. {
  1543. h & what & p1 & p2 & id1 & id2 & val;
  1544. }
  1545. };
  1546. struct DisbandCreature : public CPackForServer
  1547. {
  1548. DisbandCreature(){};
  1549. DisbandCreature(SlotID Pos, ObjectInstanceID ID):pos(Pos),id(ID){};
  1550. SlotID pos; //stack pos
  1551. ObjectInstanceID id; //object id
  1552. bool applyGh(CGameHandler *gh);
  1553. template <typename Handler> void serialize(Handler &h, const int version)
  1554. {
  1555. h & pos & id;
  1556. }
  1557. };
  1558. struct BuildStructure : public CPackForServer
  1559. {
  1560. BuildStructure(){};
  1561. BuildStructure(ObjectInstanceID TID, BuildingID BID):tid(TID), bid(BID){};
  1562. ObjectInstanceID tid; //town id
  1563. BuildingID bid; //structure id
  1564. bool applyGh(CGameHandler *gh);
  1565. template <typename Handler> void serialize(Handler &h, const int version)
  1566. {
  1567. h & tid & bid;
  1568. }
  1569. };
  1570. struct RazeStructure : public BuildStructure
  1571. {
  1572. RazeStructure(){};
  1573. bool applyGh(CGameHandler *gh);
  1574. };
  1575. struct RecruitCreatures : public CPackForServer
  1576. {
  1577. RecruitCreatures():amount(0), level(0){};
  1578. RecruitCreatures(ObjectInstanceID TID, ObjectInstanceID DST, CreatureID CRID, si32 Amount, si32 Level):
  1579. tid(TID), dst(DST), crid(CRID), amount(Amount), level(Level){};
  1580. ObjectInstanceID tid; //dwelling id, or town
  1581. ObjectInstanceID dst; //destination ID, e.g. hero
  1582. CreatureID crid;
  1583. ui32 amount;//creature amount
  1584. si32 level;//dwelling level to buy from, -1 if any
  1585. bool applyGh(CGameHandler *gh);
  1586. template <typename Handler> void serialize(Handler &h, const int version)
  1587. {
  1588. h & tid & dst & crid & amount & level;
  1589. }
  1590. };
  1591. struct UpgradeCreature : public CPackForServer
  1592. {
  1593. UpgradeCreature(){};
  1594. UpgradeCreature(SlotID Pos, ObjectInstanceID ID, CreatureID CRID):pos(Pos),id(ID), cid(CRID){};
  1595. SlotID pos; //stack pos
  1596. ObjectInstanceID id; //object id
  1597. CreatureID cid; //id of type to which we want make upgrade
  1598. bool applyGh(CGameHandler *gh);
  1599. template <typename Handler> void serialize(Handler &h, const int version)
  1600. {
  1601. h & pos & id & cid;
  1602. }
  1603. };
  1604. struct GarrisonHeroSwap : public CPackForServer
  1605. {
  1606. GarrisonHeroSwap(){};
  1607. GarrisonHeroSwap(ObjectInstanceID TID):tid(TID){};
  1608. ObjectInstanceID tid;
  1609. bool applyGh(CGameHandler *gh);
  1610. template <typename Handler> void serialize(Handler &h, const int version)
  1611. {
  1612. h & tid;
  1613. }
  1614. };
  1615. struct ExchangeArtifacts : public CPackForServer
  1616. //TODO: allow exchange between heroes, stacks and commanders
  1617. {
  1618. ArtifactLocation src, dst;
  1619. ExchangeArtifacts(){};
  1620. bool applyGh(CGameHandler *gh);
  1621. template <typename Handler> void serialize(Handler &h, const int version)
  1622. {
  1623. h & src & dst;
  1624. }
  1625. };
  1626. struct AssembleArtifacts : public CPackForServer
  1627. {
  1628. AssembleArtifacts():assemble(false){};
  1629. AssembleArtifacts(ObjectInstanceID _heroID, ArtifactPosition _artifactSlot, bool _assemble, ArtifactID _assembleTo)
  1630. : heroID(_heroID), artifactSlot(_artifactSlot), assemble(_assemble), assembleTo(_assembleTo){};
  1631. ObjectInstanceID heroID;
  1632. ArtifactPosition artifactSlot;
  1633. bool assemble; // True to assemble artifact, false to disassemble.
  1634. ArtifactID assembleTo; // Artifact to assemble into.
  1635. bool applyGh(CGameHandler *gh);
  1636. template <typename Handler> void serialize(Handler &h, const int version)
  1637. {
  1638. h & heroID & artifactSlot & assemble & assembleTo;
  1639. }
  1640. };
  1641. struct BuyArtifact : public CPackForServer
  1642. {
  1643. BuyArtifact(){};
  1644. BuyArtifact(ObjectInstanceID HID, ArtifactID AID):hid(HID),aid(AID){};
  1645. ObjectInstanceID hid;
  1646. ArtifactID aid;
  1647. bool applyGh(CGameHandler *gh);
  1648. template <typename Handler> void serialize(Handler &h, const int version)
  1649. {
  1650. h & hid & aid;
  1651. }
  1652. };
  1653. struct TradeOnMarketplace : public CPackForServer
  1654. {
  1655. TradeOnMarketplace()
  1656. :market(nullptr), hero(nullptr), mode(EMarketMode::RESOURCE_RESOURCE), r1(0), r2(0), val(0)
  1657. {};
  1658. const CGObjectInstance *market; //todo: replace with ObjectInstanceID
  1659. const CGHeroInstance *hero; //needed when trading artifacts / creatures
  1660. EMarketMode::EMarketMode mode;
  1661. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res (exception: when sacrificing art r1 is art id [todo: make r2 preferred slot?]
  1662. ui32 val; //units of sold resource
  1663. bool applyGh(CGameHandler *gh);
  1664. template <typename Handler> void serialize(Handler &h, const int version)
  1665. {
  1666. h & market & hero & mode & r1 & r2 & val;
  1667. }
  1668. };
  1669. struct SetFormation : public CPackForServer
  1670. {
  1671. SetFormation():formation(0){};
  1672. SetFormation(ObjectInstanceID HID, ui8 Formation):hid(HID),formation(Formation){};
  1673. ObjectInstanceID hid;
  1674. ui8 formation;
  1675. bool applyGh(CGameHandler *gh);
  1676. template <typename Handler> void serialize(Handler &h, const int version)
  1677. {
  1678. h & hid & formation;
  1679. }
  1680. };
  1681. struct HireHero : public CPackForServer
  1682. {
  1683. HireHero():hid(0){};
  1684. HireHero(si32 HID, ObjectInstanceID TID):hid(HID),tid(TID){};
  1685. si32 hid; //available hero serial
  1686. ObjectInstanceID tid; //town (tavern) id
  1687. PlayerColor player;
  1688. bool applyGh(CGameHandler *gh);
  1689. template <typename Handler> void serialize(Handler &h, const int version)
  1690. {
  1691. h & hid & tid & player;
  1692. }
  1693. };
  1694. struct BuildBoat : public CPackForServer
  1695. {
  1696. BuildBoat(){};
  1697. ObjectInstanceID objid; //where player wants to buy a boat
  1698. bool applyGh(CGameHandler *gh);
  1699. template <typename Handler> void serialize(Handler &h, const int version)
  1700. {
  1701. h & objid;
  1702. }
  1703. };
  1704. struct QueryReply : public CPackForServer
  1705. {
  1706. QueryReply(){};
  1707. QueryReply(QueryID QID, const JsonNode & Reply):qid(QID), reply(Reply){};
  1708. QueryID qid;
  1709. PlayerColor player;
  1710. JsonNode reply;
  1711. bool applyGh(CGameHandler *gh);
  1712. template <typename Handler> void serialize(Handler &h, const int version)
  1713. {
  1714. h & qid & player & reply;
  1715. }
  1716. };
  1717. struct MakeAction : public CPackForServer
  1718. {
  1719. MakeAction(){};
  1720. MakeAction(const BattleAction &BA):ba(BA){};
  1721. BattleAction ba;
  1722. bool applyGh(CGameHandler *gh);
  1723. template <typename Handler> void serialize(Handler &h, const int version)
  1724. {
  1725. h & ba;
  1726. }
  1727. };
  1728. struct MakeCustomAction : public CPackForServer
  1729. {
  1730. MakeCustomAction(){};
  1731. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1732. BattleAction ba;
  1733. bool applyGh(CGameHandler *gh);
  1734. template <typename Handler> void serialize(Handler &h, const int version)
  1735. {
  1736. h & ba;
  1737. }
  1738. };
  1739. struct DigWithHero : public CPackForServer
  1740. {
  1741. DigWithHero(){}
  1742. ObjectInstanceID id; //digging hero id
  1743. bool applyGh(CGameHandler *gh);
  1744. template <typename Handler> void serialize(Handler &h, const int version)
  1745. {
  1746. h & id;
  1747. }
  1748. };
  1749. struct CastAdvSpell : public CPackForServer
  1750. {
  1751. CastAdvSpell(){}
  1752. ObjectInstanceID hid; //hero id
  1753. SpellID sid; //spell id
  1754. int3 pos; //selected tile (not always used)
  1755. bool applyGh(CGameHandler *gh);
  1756. template <typename Handler> void serialize(Handler &h, const int version)
  1757. {
  1758. h & hid & sid & pos;
  1759. }
  1760. };
  1761. /***********************************************************************************************************/
  1762. struct SaveGame : public CPackForClient, public CPackForServer
  1763. {
  1764. SaveGame(){};
  1765. SaveGame(const std::string &Fname) :fname(Fname){};
  1766. std::string fname;
  1767. void applyCl(CClient *cl);
  1768. void applyGs(CGameState *gs){};
  1769. bool applyGh(CGameHandler *gh);
  1770. template <typename Handler> void serialize(Handler &h, const int version)
  1771. {
  1772. h & fname;
  1773. }
  1774. };
  1775. struct PlayerMessage : public CPackForClient, public CPackForServer
  1776. {
  1777. PlayerMessage(){};
  1778. PlayerMessage(PlayerColor Player, const std::string &Text, ObjectInstanceID obj)
  1779. :player(Player),text(Text), currObj(obj)
  1780. {};
  1781. void applyCl(CClient *cl);
  1782. void applyGs(CGameState *gs){};
  1783. bool applyGh(CGameHandler *gh);
  1784. PlayerColor player;
  1785. std::string text;
  1786. ObjectInstanceID currObj; // optional parameter that specifies current object. For cheats :)
  1787. template <typename Handler> void serialize(Handler &h, const int version)
  1788. {
  1789. h & text & player & currObj;
  1790. }
  1791. };
  1792. struct CenterView : public CPackForClient
  1793. {
  1794. CenterView():focusTime(0){};
  1795. void applyCl(CClient *cl);
  1796. PlayerColor player;
  1797. int3 pos;
  1798. ui32 focusTime; //ms
  1799. template <typename Handler> void serialize(Handler &h, const int version)
  1800. {
  1801. h & pos & player & focusTime;
  1802. }
  1803. };
  1804. /***********************************************************************************************************/
  1805. struct CPackForSelectionScreen : public CPack
  1806. {
  1807. void apply(CSelectionScreen *selScreen) {} // implemented in CPreGame.cpp
  1808. };
  1809. class CPregamePackToPropagate : public CPackForSelectionScreen
  1810. {};
  1811. class CPregamePackToHost : public CPackForSelectionScreen
  1812. {};
  1813. struct ChatMessage : public CPregamePackToPropagate
  1814. {
  1815. std::string playerName, message;
  1816. void apply(CSelectionScreen *selScreen);
  1817. template <typename Handler> void serialize(Handler &h, const int version)
  1818. {
  1819. h & playerName & message;
  1820. }
  1821. };
  1822. struct QuitMenuWithoutStarting : public CPregamePackToPropagate
  1823. {
  1824. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1825. template <typename Handler> void serialize(Handler &h, const int version)
  1826. {}
  1827. };
  1828. struct PlayerJoined : public CPregamePackToHost
  1829. {
  1830. std::string playerName;
  1831. ui8 connectionID;
  1832. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1833. template <typename Handler> void serialize(Handler &h, const int version)
  1834. {
  1835. h & playerName & connectionID;
  1836. }
  1837. };
  1838. struct ELF_VISIBILITY SelectMap : public CPregamePackToPropagate
  1839. {
  1840. const CMapInfo *mapInfo;
  1841. bool free;//local flag, do not serialize
  1842. DLL_LINKAGE SelectMap(const CMapInfo &src);
  1843. DLL_LINKAGE SelectMap();
  1844. DLL_LINKAGE ~SelectMap();
  1845. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1846. template <typename Handler> void serialize(Handler &h, const int version)
  1847. {
  1848. h & mapInfo;
  1849. }
  1850. };
  1851. struct ELF_VISIBILITY UpdateStartOptions : public CPregamePackToPropagate
  1852. {
  1853. StartInfo *options;
  1854. bool free;//local flag, do not serialize
  1855. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1856. DLL_LINKAGE UpdateStartOptions(StartInfo &src);
  1857. DLL_LINKAGE UpdateStartOptions();
  1858. DLL_LINKAGE ~UpdateStartOptions();
  1859. template <typename Handler> void serialize(Handler &h, const int version)
  1860. {
  1861. h & options;
  1862. }
  1863. };
  1864. struct PregameGuiAction : public CPregamePackToPropagate
  1865. {
  1866. enum {NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST, OPEN_RANDOM_MAP_OPTIONS}
  1867. action;
  1868. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1869. template <typename Handler> void serialize(Handler &h, const int version)
  1870. {
  1871. h & action;
  1872. }
  1873. };
  1874. struct RequestOptionsChange : public CPregamePackToHost
  1875. {
  1876. enum EWhat {TOWN, HERO, BONUS};
  1877. ui8 what;
  1878. si8 direction; //-1 or +1
  1879. ui8 playerID;
  1880. RequestOptionsChange(ui8 What, si8 Dir, ui8 Player)
  1881. :what(What), direction(Dir), playerID(Player)
  1882. {}
  1883. RequestOptionsChange()
  1884. :what(0), direction(0), playerID(0)
  1885. {}
  1886. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1887. template <typename Handler> void serialize(Handler &h, const int version)
  1888. {
  1889. h & what & direction & playerID;
  1890. }
  1891. };
  1892. struct PlayerLeft : public CPregamePackToPropagate
  1893. {
  1894. ui8 playerID;
  1895. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1896. template <typename Handler> void serialize(Handler &h, const int version)
  1897. {
  1898. h & playerID;
  1899. }
  1900. };
  1901. struct PlayersNames : public CPregamePackToPropagate
  1902. {
  1903. public:
  1904. std::map<ui8, std::string> playerNames;
  1905. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1906. template <typename Handler> void serialize(Handler &h, const int version)
  1907. {
  1908. h & playerNames;
  1909. }
  1910. };
  1911. struct StartWithCurrentSettings : public CPregamePackToPropagate
  1912. {
  1913. public:
  1914. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1915. template <typename Handler> void serialize(Handler &h, const int version)
  1916. {
  1917. //h & playerNames;
  1918. }
  1919. };