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