NetPacks.h 54 KB

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