2
0

NetPacks.h 55 KB

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