NetPacks.h 57 KB

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