NetPacks.h 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545
  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 LinkedSlots
  838. {
  839. ArtifactPosition srcPos;
  840. ArtifactPosition dstPos;
  841. LinkedSlots() {}
  842. LinkedSlots(ArtifactPosition srcPos, ArtifactPosition dstPos)
  843. : srcPos(srcPos), dstPos(dstPos) {}
  844. template <typename Handler> void serialize(Handler & h, const int version)
  845. {
  846. h & srcPos;
  847. h & dstPos;
  848. }
  849. };
  850. TArtHolder srcArtHolder;
  851. TArtHolder dstArtHolder;
  852. BulkMoveArtifacts()
  853. : swap(false) {}
  854. BulkMoveArtifacts(TArtHolder srcArtHolder, TArtHolder dstArtHolder, bool swap)
  855. : srcArtHolder(srcArtHolder), dstArtHolder(dstArtHolder), swap(swap) {}
  856. void applyCl(CClient * cl);
  857. DLL_LINKAGE void applyGs(CGameState * gs);
  858. std::vector<LinkedSlots> artsPack0;
  859. std::vector<LinkedSlots> artsPack1;
  860. bool swap;
  861. CArtifactSet * getSrcHolderArtSet();
  862. CArtifactSet * getDstHolderArtSet();
  863. template <typename Handler> void serialize(Handler & h, const int version)
  864. {
  865. h & artsPack0;
  866. h & artsPack1;
  867. h & srcArtHolder;
  868. h & dstArtHolder;
  869. h & swap;
  870. }
  871. };
  872. struct AssembledArtifact : CArtifactOperationPack
  873. {
  874. ArtifactLocation al; //where assembly will be put
  875. CArtifact *builtArt;
  876. void applyCl(CClient *cl);
  877. DLL_LINKAGE void applyGs(CGameState *gs);
  878. template <typename Handler> void serialize(Handler &h, const int version)
  879. {
  880. h & al;
  881. h & builtArt;
  882. }
  883. };
  884. struct DisassembledArtifact : CArtifactOperationPack
  885. {
  886. ArtifactLocation al;
  887. void applyCl(CClient *cl);
  888. DLL_LINKAGE void applyGs(CGameState *gs);
  889. template <typename Handler> void serialize(Handler &h, const int version)
  890. {
  891. h & al;
  892. }
  893. };
  894. struct HeroVisit : public CPackForClient
  895. {
  896. PlayerColor player;
  897. ObjectInstanceID heroId;
  898. ObjectInstanceID objId;
  899. bool starting; //false -> ending
  900. void applyCl(CClient * cl);
  901. DLL_LINKAGE void applyGs(CGameState * gs);
  902. template <typename Handler> void serialize(Handler & h, const int version)
  903. {
  904. h & player;
  905. h & heroId;
  906. h & objId;
  907. h & starting;
  908. }
  909. };
  910. struct NewTurn : public CPackForClient
  911. {
  912. enum weekType {NORMAL, DOUBLE_GROWTH, BONUS_GROWTH, DEITYOFFIRE, PLAGUE, NO_ACTION};
  913. void applyCl(CClient *cl);
  914. DLL_LINKAGE void applyGs(CGameState *gs);
  915. struct Hero
  916. {
  917. ObjectInstanceID id;
  918. ui32 move, mana; //id is a general serial id
  919. template <typename Handler> void serialize(Handler &h, const int version)
  920. {
  921. h & id;
  922. h & move;
  923. h & mana;
  924. }
  925. bool operator<(const Hero&h)const{return id < h.id;}
  926. };
  927. std::set<Hero> heroes; //updates movement and mana points
  928. std::map<PlayerColor, TResources> res; //player ID => resource value[res_id]
  929. std::map<ObjectInstanceID, SetAvailableCreatures> cres;//creatures to be placed in towns
  930. ui32 day;
  931. ui8 specialWeek; //weekType
  932. CreatureID creatureid; //for creature weeks
  933. NewTurn():day(0),specialWeek(0){};
  934. template <typename Handler> void serialize(Handler &h, const int version)
  935. {
  936. h & heroes;
  937. h & cres;
  938. h & res;
  939. h & day;
  940. h & specialWeek;
  941. h & creatureid;
  942. }
  943. };
  944. struct InfoWindow : public CPackForClient //103 - displays simple info window
  945. {
  946. void applyCl(CClient *cl);
  947. MetaString text;
  948. std::vector<Component> components;
  949. PlayerColor player;
  950. ui16 soundID;
  951. template <typename Handler> void serialize(Handler &h, const int version)
  952. {
  953. h & text;
  954. h & components;
  955. h & player;
  956. h & soundID;
  957. }
  958. InfoWindow()
  959. {
  960. soundID = 0;
  961. }
  962. };
  963. namespace ObjProperty
  964. {
  965. enum {OWNER = 1, BLOCKVIS = 2, PRIMARY_STACK_COUNT = 3, VISITORS = 4, VISITED = 5, ID = 6, AVAILABLE_CREATURE = 7, SUBID = 8,
  966. MONSTER_COUNT = 10, MONSTER_POWER = 11, MONSTER_EXP = 12, MONSTER_RESTORE_TYPE = 13, MONSTER_REFUSED_JOIN,
  967. //town-specific
  968. STRUCTURE_ADD_VISITING_HERO, STRUCTURE_CLEAR_VISITORS, STRUCTURE_ADD_GARRISONED_HERO, //changing buildings state
  969. BONUS_VALUE_FIRST, BONUS_VALUE_SECOND, //used in Rampart for special building that generates resources (storing resource type and quantity)
  970. //creature-bank specific
  971. BANK_DAYCOUNTER, BANK_RESET, BANK_CLEAR,
  972. //object with reward
  973. REWARD_RESET, REWARD_SELECT
  974. };
  975. }
  976. struct SetObjectProperty : public CPackForClient
  977. {
  978. DLL_LINKAGE void applyGs(CGameState *gs);
  979. void applyCl(CClient *cl);
  980. ObjectInstanceID id;
  981. ui8 what; // see ObjProperty enum
  982. ui32 val;
  983. SetObjectProperty():what(0),val(0){}
  984. SetObjectProperty(ObjectInstanceID ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){};
  985. template <typename Handler> void serialize(Handler &h, const int version)
  986. {
  987. h & id;
  988. h & what;
  989. h & val;
  990. }
  991. };
  992. struct ChangeObjectVisitors : public CPackForClient
  993. {
  994. enum VisitMode
  995. {
  996. VISITOR_ADD, // mark hero as one that have visited this object
  997. VISITOR_ADD_TEAM, // mark team as one that have visited this object
  998. VISITOR_REMOVE, // unmark visitor, reversed to ADD
  999. VISITOR_CLEAR // clear all visitors from this object (object reset)
  1000. };
  1001. ui32 mode; // uses VisitMode enum
  1002. ObjectInstanceID object;
  1003. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  1004. DLL_LINKAGE void applyGs(CGameState *gs);
  1005. ChangeObjectVisitors()
  1006. : mode(VISITOR_CLEAR)
  1007. {}
  1008. ChangeObjectVisitors(ui32 mode, ObjectInstanceID object, ObjectInstanceID heroID = ObjectInstanceID(-1)):
  1009. mode(mode),
  1010. object(object),
  1011. hero(heroID)
  1012. {}
  1013. template <typename Handler> void serialize(Handler &h, const int version)
  1014. {
  1015. h & object;
  1016. h & hero;
  1017. h & mode;
  1018. }
  1019. };
  1020. struct PrepareHeroLevelUp : public CPackForClient
  1021. {
  1022. ObjectInstanceID heroId;
  1023. /// Do not serialize, used by server only
  1024. std::vector<SecondarySkill> skills;
  1025. PrepareHeroLevelUp(){}
  1026. DLL_LINKAGE void applyGs(CGameState * gs);
  1027. template <typename Handler> void serialize(Handler &h, const int version)
  1028. {
  1029. h & heroId;
  1030. }
  1031. };
  1032. struct HeroLevelUp : public Query
  1033. {
  1034. PlayerColor player;
  1035. ObjectInstanceID heroId;
  1036. PrimarySkill::PrimarySkill primskill;
  1037. std::vector<SecondarySkill> skills;
  1038. HeroLevelUp(): primskill(PrimarySkill::ATTACK){}
  1039. void applyCl(CClient * cl);
  1040. DLL_LINKAGE void applyGs(CGameState * gs);
  1041. template <typename Handler> void serialize(Handler & h, const int version)
  1042. {
  1043. h & queryID;
  1044. h & player;
  1045. h & heroId;
  1046. h & primskill;
  1047. h & skills;
  1048. }
  1049. };
  1050. struct CommanderLevelUp : public Query
  1051. {
  1052. PlayerColor player;
  1053. ObjectInstanceID heroId;
  1054. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1055. CommanderLevelUp(){}
  1056. void applyCl(CClient * cl);
  1057. DLL_LINKAGE void applyGs(CGameState * gs);
  1058. template <typename Handler> void serialize(Handler & h, const int version)
  1059. {
  1060. h & queryID;
  1061. h & player;
  1062. h & heroId;
  1063. h & skills;
  1064. }
  1065. };
  1066. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1067. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1068. //Until sending reply player won't be allowed to take any actions
  1069. struct BlockingDialog : public Query
  1070. {
  1071. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  1072. void applyCl(CClient *cl);
  1073. MetaString text;
  1074. std::vector<Component> components;
  1075. PlayerColor player;
  1076. ui8 flags;
  1077. ui16 soundID;
  1078. bool cancel() const
  1079. {
  1080. return flags & ALLOW_CANCEL;
  1081. }
  1082. bool selection() const
  1083. {
  1084. return flags & SELECTION;
  1085. }
  1086. BlockingDialog(bool yesno, bool Selection)
  1087. {
  1088. flags = 0;
  1089. soundID = 0;
  1090. if(yesno) flags |= ALLOW_CANCEL;
  1091. if(Selection) flags |= SELECTION;
  1092. }
  1093. BlockingDialog()
  1094. {
  1095. flags = 0;
  1096. soundID = 0;
  1097. };
  1098. template <typename Handler> void serialize(Handler &h, const int version)
  1099. {
  1100. h & queryID;
  1101. h & text;
  1102. h & components;
  1103. h & player;
  1104. h & flags;
  1105. h & soundID;
  1106. }
  1107. };
  1108. struct GarrisonDialog : public Query
  1109. {
  1110. GarrisonDialog():removableUnits(false){}
  1111. void applyCl(CClient *cl);
  1112. ObjectInstanceID objid, hid;
  1113. bool removableUnits;
  1114. template <typename Handler> void serialize(Handler &h, const int version)
  1115. {
  1116. h & queryID;
  1117. h & objid;
  1118. h & hid;
  1119. h & removableUnits;
  1120. }
  1121. };
  1122. struct ExchangeDialog : public Query
  1123. {
  1124. ExchangeDialog() {}
  1125. void applyCl(CClient *cl);
  1126. PlayerColor player;
  1127. ObjectInstanceID hero1;
  1128. ObjectInstanceID hero2;
  1129. template <typename Handler> void serialize(Handler &h, const int version)
  1130. {
  1131. h & queryID;
  1132. h & player;
  1133. h & hero1;
  1134. h & hero2;
  1135. }
  1136. };
  1137. struct TeleportDialog : public Query
  1138. {
  1139. TeleportDialog()
  1140. : impassable(false)
  1141. {}
  1142. TeleportDialog(PlayerColor Player, TeleportChannelID Channel)
  1143. : player(Player), channel(Channel), impassable(false)
  1144. {}
  1145. void applyCl(CClient *cl);
  1146. PlayerColor player;
  1147. TeleportChannelID channel;
  1148. TTeleportExitsList exits;
  1149. bool impassable;
  1150. template <typename Handler> void serialize(Handler &h, const int version)
  1151. {
  1152. h & queryID;
  1153. h & player;
  1154. h & channel;
  1155. h & exits;
  1156. h & impassable;
  1157. }
  1158. };
  1159. struct MapObjectSelectDialog : public Query
  1160. {
  1161. PlayerColor player;
  1162. Component icon;
  1163. MetaString title;
  1164. MetaString description;
  1165. std::vector<ObjectInstanceID> objects;
  1166. MapObjectSelectDialog(){};
  1167. void applyCl(CClient * cl);
  1168. template <typename Handler> void serialize(Handler & h, const int version)
  1169. {
  1170. h & queryID;
  1171. h & player;
  1172. h & icon;
  1173. h & title;
  1174. h & description;
  1175. h & objects;
  1176. }
  1177. };
  1178. class BattleInfo;
  1179. struct BattleStart : public CPackForClient
  1180. {
  1181. BattleStart()
  1182. :info(nullptr)
  1183. {}
  1184. void applyFirstCl(CClient *cl);
  1185. void applyCl(CClient *cl);
  1186. DLL_LINKAGE void applyGs(CGameState *gs);
  1187. BattleInfo * info;
  1188. template <typename Handler> void serialize(Handler &h, const int version)
  1189. {
  1190. h & info;
  1191. }
  1192. };
  1193. struct BattleNextRound : public CPackForClient
  1194. {
  1195. BattleNextRound():round(0){};
  1196. void applyFirstCl(CClient *cl);
  1197. void applyCl(CClient *cl);
  1198. DLL_LINKAGE void applyGs( CGameState *gs );
  1199. si32 round;
  1200. template <typename Handler> void serialize(Handler &h, const int version)
  1201. {
  1202. h & round;
  1203. }
  1204. };
  1205. struct BattleSetActiveStack : public CPackForClient
  1206. {
  1207. BattleSetActiveStack()
  1208. {
  1209. stack = 0;
  1210. askPlayerInterface = true;
  1211. }
  1212. void applyCl(CClient *cl);
  1213. DLL_LINKAGE void applyGs(CGameState *gs);
  1214. ui32 stack;
  1215. ui8 askPlayerInterface;
  1216. template <typename Handler> void serialize(Handler &h, const int version)
  1217. {
  1218. h & stack;
  1219. h & askPlayerInterface;
  1220. }
  1221. };
  1222. struct BattleResult : public CPackForClient
  1223. {
  1224. enum EResult {NORMAL = 0, ESCAPE = 1, SURRENDER = 2};
  1225. BattleResult()
  1226. : result(NORMAL), winner(2)
  1227. {
  1228. exp[0] = 0;
  1229. exp[1] = 0;
  1230. };
  1231. void applyFirstCl(CClient *cl);
  1232. void applyGs(CGameState *gs);
  1233. EResult result;
  1234. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  1235. std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
  1236. TExpType exp[2]; //exp for attacker and defender
  1237. std::set<ArtifactInstanceID> artifacts; //artifacts taken from loser to winner - currently unused
  1238. template <typename Handler> void serialize(Handler &h, const int version)
  1239. {
  1240. h & result;
  1241. h & winner;
  1242. h & casualties[0];
  1243. h & casualties[1];
  1244. h & exp;
  1245. h & artifacts;
  1246. }
  1247. };
  1248. struct BattleLogMessage : public CPackForClient
  1249. {
  1250. std::vector<MetaString> lines;
  1251. BattleLogMessage(){}
  1252. void applyCl(CClient * cl);
  1253. DLL_LINKAGE void applyGs(CGameState * gs);
  1254. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1255. template <typename Handler> void serialize(Handler & h, const int version)
  1256. {
  1257. h & lines;
  1258. }
  1259. };
  1260. struct BattleStackMoved : public CPackForClient
  1261. {
  1262. ui32 stack;
  1263. std::vector<BattleHex> tilesToMove;
  1264. int distance;
  1265. bool teleporting;
  1266. BattleStackMoved()
  1267. : stack(0),
  1268. distance(0),
  1269. teleporting(false)
  1270. {};
  1271. void applyFirstCl(CClient *cl);
  1272. DLL_LINKAGE void applyGs(CGameState *gs);
  1273. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1274. template <typename Handler> void serialize(Handler &h, const int version)
  1275. {
  1276. h & stack;
  1277. h & tilesToMove;
  1278. h & distance;
  1279. h & teleporting;
  1280. }
  1281. };
  1282. struct BattleUnitsChanged : public CPackForClient
  1283. {
  1284. BattleUnitsChanged(){}
  1285. DLL_LINKAGE void applyGs(CGameState *gs);
  1286. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1287. void applyCl(CClient *cl);
  1288. std::vector<UnitChanges> changedStacks;
  1289. template <typename Handler> void serialize(Handler & h, const int version)
  1290. {
  1291. h & changedStacks;
  1292. }
  1293. };
  1294. struct BattleStackAttacked
  1295. {
  1296. BattleStackAttacked():
  1297. stackAttacked(0),
  1298. attackerID(0),
  1299. killedAmount(0),
  1300. damageAmount(0),
  1301. newState(),
  1302. flags(0),
  1303. spellID(SpellID::NONE)
  1304. {};
  1305. DLL_LINKAGE void applyGs(CGameState *gs);
  1306. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1307. ui32 stackAttacked, attackerID;
  1308. ui32 killedAmount;
  1309. int64_t damageAmount;
  1310. UnitChanges newState;
  1311. enum EFlags {KILLED = 1, SECONDARY = 2, REBIRTH = 4, CLONE_KILLED = 8, SPELL_EFFECT = 16, FIRE_SHIELD = 32, };
  1312. ui32 flags; //uses EFlags (above)
  1313. SpellID spellID; //only if flag SPELL_EFFECT is set
  1314. bool killed() const//if target stack was killed
  1315. {
  1316. return flags & KILLED || flags & CLONE_KILLED;
  1317. }
  1318. bool cloneKilled() const
  1319. {
  1320. return flags & CLONE_KILLED;
  1321. }
  1322. bool isSecondary() const//if stack was not a primary target (receives no spell effects)
  1323. {
  1324. return flags & SECONDARY;
  1325. }
  1326. ///Attacked with spell (SPELL_LIKE_ATTACK)
  1327. bool isSpell() const
  1328. {
  1329. return flags & SPELL_EFFECT;
  1330. }
  1331. bool willRebirth() const//resurrection, e.g. Phoenix
  1332. {
  1333. return flags & REBIRTH;
  1334. }
  1335. bool fireShield() const
  1336. {
  1337. return flags & FIRE_SHIELD;
  1338. }
  1339. template <typename Handler> void serialize(Handler &h, const int version)
  1340. {
  1341. h & stackAttacked;
  1342. h & attackerID;
  1343. h & newState;
  1344. h & flags;
  1345. h & killedAmount;
  1346. h & damageAmount;
  1347. h & spellID;
  1348. }
  1349. bool operator<(const BattleStackAttacked &b) const
  1350. {
  1351. return stackAttacked < b.stackAttacked;
  1352. }
  1353. };
  1354. struct BattleAttack : public CPackForClient
  1355. {
  1356. BattleAttack()
  1357. : stackAttacking(0), flags(0), spellID(SpellID::NONE)
  1358. {};
  1359. void applyFirstCl(CClient *cl);
  1360. DLL_LINKAGE void applyGs(CGameState *gs);
  1361. void applyCl(CClient *cl);
  1362. BattleUnitsChanged attackerChanges;
  1363. std::vector<BattleStackAttacked> bsa;
  1364. ui32 stackAttacking;
  1365. ui32 flags; //uses Eflags (below)
  1366. enum EFlags{SHOT = 1, COUNTER = 2, LUCKY = 4, UNLUCKY = 8, BALLISTA_DOUBLE_DMG = 16, DEATH_BLOW = 32, SPELL_LIKE = 64, LIFE_DRAIN = 128};
  1367. BattleHex tile;
  1368. SpellID spellID; //for SPELL_LIKE
  1369. bool shot() const//distance attack - decrease number of shots
  1370. {
  1371. return flags & SHOT;
  1372. }
  1373. bool counter() const//is it counterattack?
  1374. {
  1375. return flags & COUNTER;
  1376. }
  1377. bool lucky() const
  1378. {
  1379. return flags & LUCKY;
  1380. }
  1381. bool unlucky() const
  1382. {
  1383. return flags & UNLUCKY;
  1384. }
  1385. bool ballistaDoubleDmg() const //if it's ballista attack and does double dmg
  1386. {
  1387. return flags & BALLISTA_DOUBLE_DMG;
  1388. }
  1389. bool deathBlow() const
  1390. {
  1391. return flags & DEATH_BLOW;
  1392. }
  1393. bool spellLike() const
  1394. {
  1395. return flags & SPELL_LIKE;
  1396. }
  1397. bool lifeDrain() const
  1398. {
  1399. return flags & LIFE_DRAIN;
  1400. }
  1401. template <typename Handler> void serialize(Handler &h, const int version)
  1402. {
  1403. h & bsa;
  1404. h & stackAttacking;
  1405. h & flags;
  1406. h & tile;
  1407. h & spellID;
  1408. h & attackerChanges;
  1409. }
  1410. };
  1411. struct StartAction : public CPackForClient
  1412. {
  1413. StartAction(){};
  1414. StartAction(const BattleAction &act){ba = act; };
  1415. void applyFirstCl(CClient *cl);
  1416. DLL_LINKAGE void applyGs(CGameState *gs);
  1417. BattleAction ba;
  1418. template <typename Handler> void serialize(Handler &h, const int version)
  1419. {
  1420. h & ba;
  1421. }
  1422. };
  1423. struct EndAction : public CPackForClient
  1424. {
  1425. EndAction(){};
  1426. void applyCl(CClient *cl);
  1427. template <typename Handler> void serialize(Handler &h, const int version)
  1428. {
  1429. }
  1430. };
  1431. struct BattleSpellCast : public CPackForClient
  1432. {
  1433. BattleSpellCast()
  1434. {
  1435. side = 0;
  1436. manaGained = 0;
  1437. casterStack = -1;
  1438. castByHero = true;
  1439. activeCast = true;
  1440. };
  1441. DLL_LINKAGE void applyGs(CGameState *gs);
  1442. void applyCl(CClient *cl);
  1443. bool activeCast;
  1444. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  1445. SpellID spellID; //id of spell
  1446. ui8 manaGained; //mana channeling ability
  1447. BattleHex tile; //destination tile (may not be set in some global/mass spells
  1448. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  1449. std::set<ui32> resistedCres; // creatures that resisted the spell (e.g. Dwarves)
  1450. std::set<ui32> reflectedCres; // creatures that reflected the spell (e.g. Magic Mirror spell)
  1451. si32 casterStack;// -1 if not cated by creature, >=0 caster stack ID
  1452. bool castByHero; //if true - spell has been cast by hero, otherwise by a creature
  1453. template <typename Handler> void serialize(Handler &h, const int version)
  1454. {
  1455. h & side;
  1456. h & spellID;
  1457. h & manaGained;
  1458. h & tile;
  1459. h & affectedCres;
  1460. h & resistedCres;
  1461. h & reflectedCres;
  1462. h & casterStack;
  1463. h & castByHero;
  1464. h & activeCast;
  1465. }
  1466. };
  1467. struct SetStackEffect : public CPackForClient
  1468. {
  1469. SetStackEffect(){};
  1470. DLL_LINKAGE void applyGs(CGameState * gs);
  1471. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1472. void applyCl(CClient * cl);
  1473. std::vector<std::pair<ui32, std::vector<Bonus>>> toAdd;
  1474. std::vector<std::pair<ui32, std::vector<Bonus>>> toUpdate;
  1475. std::vector<std::pair<ui32, std::vector<Bonus>>> toRemove;
  1476. template <typename Handler> void serialize(Handler & h, const int version)
  1477. {
  1478. h & toAdd;
  1479. h & toUpdate;
  1480. h & toRemove;
  1481. }
  1482. };
  1483. struct StacksInjured : public CPackForClient
  1484. {
  1485. StacksInjured(){}
  1486. DLL_LINKAGE void applyGs(CGameState * gs);
  1487. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1488. void applyCl(CClient * cl);
  1489. std::vector<BattleStackAttacked> stacks;
  1490. template <typename Handler> void serialize(Handler & h, const int version)
  1491. {
  1492. h & stacks;
  1493. }
  1494. };
  1495. struct BattleResultsApplied : public CPackForClient
  1496. {
  1497. BattleResultsApplied(){}
  1498. PlayerColor player1, player2;
  1499. void applyCl(CClient *cl);
  1500. template <typename Handler> void serialize(Handler &h, const int version)
  1501. {
  1502. h & player1;
  1503. h & player2;
  1504. }
  1505. };
  1506. struct BattleObstaclesChanged : public CPackForClient
  1507. {
  1508. BattleObstaclesChanged(){}
  1509. DLL_LINKAGE void applyGs(CGameState * gs);
  1510. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1511. void applyCl(CClient * cl);
  1512. std::vector<ObstacleChanges> changes;
  1513. template <typename Handler> void serialize(Handler & h, const int version)
  1514. {
  1515. h & changes;
  1516. }
  1517. };
  1518. struct ELF_VISIBILITY CatapultAttack : public CPackForClient
  1519. {
  1520. struct AttackInfo
  1521. {
  1522. si16 destinationTile;
  1523. ui8 attackedPart;
  1524. ui8 damageDealt;
  1525. template <typename Handler> void serialize(Handler & h, const int version)
  1526. {
  1527. h & destinationTile;
  1528. h & attackedPart;
  1529. h & damageDealt;
  1530. }
  1531. };
  1532. DLL_LINKAGE CatapultAttack();
  1533. DLL_LINKAGE ~CatapultAttack();
  1534. DLL_LINKAGE void applyGs(CGameState * gs);
  1535. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1536. void applyCl(CClient * cl);
  1537. std::vector< AttackInfo > attackedParts;
  1538. int attacker; //if -1, then a spell caused this
  1539. template <typename Handler> void serialize(Handler &h, const int version)
  1540. {
  1541. h & attackedParts;
  1542. h & attacker;
  1543. }
  1544. };
  1545. struct BattleSetStackProperty : public CPackForClient
  1546. {
  1547. BattleSetStackProperty()
  1548. : stackID(0), which(CASTS), val(0), absolute(0)
  1549. {};
  1550. enum BattleStackProperty {CASTS, ENCHANTER_COUNTER, UNBIND, CLONED, HAS_CLONE};
  1551. DLL_LINKAGE void applyGs(CGameState *gs);
  1552. int stackID;
  1553. BattleStackProperty which;
  1554. int val;
  1555. int absolute;
  1556. template <typename Handler> void serialize(Handler &h, const int version)
  1557. {
  1558. h & stackID;
  1559. h & which;
  1560. h & val;
  1561. h & absolute;
  1562. }
  1563. };
  1564. ///activated at the beginning of turn
  1565. struct BattleTriggerEffect : public CPackForClient
  1566. {
  1567. BattleTriggerEffect()
  1568. : stackID(0), effect(0), val(0), additionalInfo(0)
  1569. {};
  1570. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1571. void applyCl(CClient *cl); //play animations & stuff
  1572. int stackID;
  1573. int effect; //use corresponding Bonus type
  1574. int val;
  1575. int additionalInfo;
  1576. template <typename Handler> void serialize(Handler &h, const int version)
  1577. {
  1578. h & stackID;
  1579. h & effect;
  1580. h & val;
  1581. h & additionalInfo;
  1582. }
  1583. };
  1584. struct BattleUpdateGateState : public CPackForClient
  1585. {
  1586. BattleUpdateGateState():state(EGateState::NONE){};
  1587. void applyFirstCl(CClient *cl);
  1588. DLL_LINKAGE void applyGs(CGameState *gs);
  1589. EGateState state;
  1590. template <typename Handler> void serialize(Handler &h, const int version)
  1591. {
  1592. h & state;
  1593. }
  1594. };
  1595. struct ShowInInfobox : public CPackForClient
  1596. {
  1597. ShowInInfobox(){};
  1598. PlayerColor player;
  1599. Component c;
  1600. MetaString text;
  1601. void applyCl(CClient *cl);
  1602. template <typename Handler> void serialize(Handler &h, const int version)
  1603. {
  1604. h & player;
  1605. h & c;
  1606. h & text;
  1607. }
  1608. };
  1609. struct AdvmapSpellCast : public CPackForClient
  1610. {
  1611. AdvmapSpellCast():casterID(){}
  1612. ObjectInstanceID casterID;
  1613. SpellID spellID;
  1614. void applyCl(CClient *cl);
  1615. template <typename Handler> void serialize(Handler &h, const int version)
  1616. {
  1617. h & casterID;
  1618. h & spellID;
  1619. }
  1620. };
  1621. struct ShowWorldViewEx : public CPackForClient
  1622. {
  1623. PlayerColor player;
  1624. std::vector<ObjectPosInfo> objectPositions;
  1625. ShowWorldViewEx(){}
  1626. void applyCl(CClient *cl);
  1627. template <typename Handler> void serialize(Handler &h, const int version)
  1628. {
  1629. h & player;
  1630. h & objectPositions;
  1631. }
  1632. };
  1633. /***********************************************************************************************************/
  1634. struct EndTurn : public CPackForServer
  1635. {
  1636. bool applyGh(CGameHandler *gh);
  1637. template <typename Handler> void serialize(Handler &h, const int version)
  1638. {
  1639. h & static_cast<CPackForServer &>(*this);
  1640. }
  1641. };
  1642. struct DismissHero : public CPackForServer
  1643. {
  1644. DismissHero(){};
  1645. DismissHero(ObjectInstanceID HID) : hid(HID) {};
  1646. ObjectInstanceID hid;
  1647. bool applyGh(CGameHandler *gh);
  1648. template <typename Handler> void serialize(Handler &h, const int version)
  1649. {
  1650. h & static_cast<CPackForServer &>(*this);
  1651. h & hid;
  1652. }
  1653. };
  1654. struct MoveHero : public CPackForServer
  1655. {
  1656. MoveHero():transit(false){};
  1657. MoveHero(const int3 &Dest, ObjectInstanceID HID, bool Transit) : dest(Dest), hid(HID), transit(Transit) {};
  1658. int3 dest;
  1659. ObjectInstanceID hid;
  1660. bool transit;
  1661. bool applyGh(CGameHandler *gh);
  1662. template <typename Handler> void serialize(Handler &h, const int version)
  1663. {
  1664. h & static_cast<CPackForServer &>(*this);
  1665. h & dest;
  1666. h & hid;
  1667. h & transit;
  1668. }
  1669. };
  1670. struct CastleTeleportHero : public CPackForServer
  1671. {
  1672. CastleTeleportHero():source(0){};
  1673. CastleTeleportHero(const ObjectInstanceID HID, ObjectInstanceID Dest, ui8 Source ) : dest(Dest), hid(HID), source(Source){};
  1674. ObjectInstanceID dest;
  1675. ObjectInstanceID hid;
  1676. si8 source;//who give teleporting, 1=castle gate
  1677. bool applyGh(CGameHandler *gh);
  1678. template <typename Handler> void serialize(Handler &h, const int version)
  1679. {
  1680. h & static_cast<CPackForServer &>(*this);
  1681. h & dest;
  1682. h & hid;
  1683. }
  1684. };
  1685. struct ArrangeStacks : public CPackForServer
  1686. {
  1687. ArrangeStacks():what(0), val(0){};
  1688. ArrangeStacks(ui8 W, SlotID P1, SlotID P2, ObjectInstanceID ID1, ObjectInstanceID ID2, si32 VAL)
  1689. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  1690. ui8 what; //1 - swap; 2 - merge; 3 - split
  1691. SlotID p1, p2; //positions of first and second stack
  1692. ObjectInstanceID id1, id2; //ids of objects with garrison
  1693. si32 val;
  1694. bool applyGh(CGameHandler *gh);
  1695. template <typename Handler> void serialize(Handler &h, const int version)
  1696. {
  1697. h & static_cast<CPackForServer &>(*this);
  1698. h & what;
  1699. h & p1;
  1700. h & p2;
  1701. h & id1;
  1702. h & id2;
  1703. h & val;
  1704. }
  1705. };
  1706. struct BulkMoveArmy : public CPackForServer
  1707. {
  1708. SlotID srcSlot;
  1709. ObjectInstanceID srcArmy;
  1710. ObjectInstanceID destArmy;
  1711. BulkMoveArmy()
  1712. {};
  1713. BulkMoveArmy(ObjectInstanceID srcArmy, ObjectInstanceID destArmy, SlotID srcSlot)
  1714. : srcArmy(srcArmy), destArmy(destArmy), srcSlot(srcSlot)
  1715. {};
  1716. bool applyGh(CGameHandler * gh);
  1717. template <typename Handler>
  1718. void serialize(Handler & h, const int version)
  1719. {
  1720. h & static_cast<CPackForServer&>(*this);
  1721. h & srcSlot;
  1722. h & srcArmy;
  1723. h & destArmy;
  1724. }
  1725. };
  1726. struct BulkSplitStack : public CPackForServer
  1727. {
  1728. SlotID src;
  1729. ObjectInstanceID srcOwner;
  1730. si32 amount;
  1731. BulkSplitStack() : amount(0)
  1732. {};
  1733. BulkSplitStack(ObjectInstanceID srcOwner, SlotID src, si32 howMany)
  1734. : src(src), srcOwner(srcOwner), amount(howMany)
  1735. {};
  1736. bool applyGh(CGameHandler * gh);
  1737. template <typename Handler>
  1738. void serialize(Handler & h, const int version)
  1739. {
  1740. h & static_cast<CPackForServer&>(*this);
  1741. h & src;
  1742. h & srcOwner;
  1743. h & amount;
  1744. }
  1745. };
  1746. struct BulkMergeStacks : public CPackForServer
  1747. {
  1748. SlotID src;
  1749. ObjectInstanceID srcOwner;
  1750. BulkMergeStacks()
  1751. {};
  1752. BulkMergeStacks(ObjectInstanceID srcOwner, SlotID src)
  1753. : src(src), srcOwner(srcOwner)
  1754. {};
  1755. bool applyGh(CGameHandler * gh);
  1756. template <typename Handler>
  1757. void serialize(Handler & h, const int version)
  1758. {
  1759. h & static_cast<CPackForServer&>(*this);
  1760. h & src;
  1761. h & srcOwner;
  1762. }
  1763. };
  1764. struct BulkSmartSplitStack : public CPackForServer
  1765. {
  1766. SlotID src;
  1767. ObjectInstanceID srcOwner;
  1768. BulkSmartSplitStack()
  1769. {};
  1770. BulkSmartSplitStack(ObjectInstanceID srcOwner, SlotID src)
  1771. : src(src), srcOwner(srcOwner)
  1772. {};
  1773. bool applyGh(CGameHandler * gh);
  1774. template <typename Handler>
  1775. void serialize(Handler & h, const int version)
  1776. {
  1777. h & static_cast<CPackForServer&>(*this);
  1778. h & src;
  1779. h & srcOwner;
  1780. }
  1781. };
  1782. struct DisbandCreature : public CPackForServer
  1783. {
  1784. DisbandCreature(){};
  1785. DisbandCreature(SlotID Pos, ObjectInstanceID ID):pos(Pos),id(ID){};
  1786. SlotID pos; //stack pos
  1787. ObjectInstanceID id; //object id
  1788. bool applyGh(CGameHandler *gh);
  1789. template <typename Handler> void serialize(Handler &h, const int version)
  1790. {
  1791. h & static_cast<CPackForServer &>(*this);
  1792. h & pos;
  1793. h & id;
  1794. }
  1795. };
  1796. struct BuildStructure : public CPackForServer
  1797. {
  1798. BuildStructure(){};
  1799. BuildStructure(ObjectInstanceID TID, BuildingID BID):tid(TID), bid(BID){};
  1800. ObjectInstanceID tid; //town id
  1801. BuildingID bid; //structure id
  1802. bool applyGh(CGameHandler *gh);
  1803. template <typename Handler> void serialize(Handler &h, const int version)
  1804. {
  1805. h & static_cast<CPackForServer &>(*this);
  1806. h & tid;
  1807. h & bid;
  1808. }
  1809. };
  1810. struct RazeStructure : public BuildStructure
  1811. {
  1812. RazeStructure(){};
  1813. bool applyGh(CGameHandler *gh);
  1814. };
  1815. struct RecruitCreatures : public CPackForServer
  1816. {
  1817. RecruitCreatures():amount(0), level(0){};
  1818. RecruitCreatures(ObjectInstanceID TID, ObjectInstanceID DST, CreatureID CRID, si32 Amount, si32 Level):
  1819. tid(TID), dst(DST), crid(CRID), amount(Amount), level(Level){};
  1820. ObjectInstanceID tid; //dwelling id, or town
  1821. ObjectInstanceID dst; //destination ID, e.g. hero
  1822. CreatureID crid;
  1823. ui32 amount;//creature amount
  1824. si32 level;//dwelling level to buy from, -1 if any
  1825. bool applyGh(CGameHandler *gh);
  1826. template <typename Handler> void serialize(Handler &h, const int version)
  1827. {
  1828. h & static_cast<CPackForServer &>(*this);
  1829. h & tid;
  1830. h & dst;
  1831. h & crid;
  1832. h & amount;
  1833. h & level;
  1834. }
  1835. };
  1836. struct UpgradeCreature : public CPackForServer
  1837. {
  1838. UpgradeCreature(){};
  1839. UpgradeCreature(SlotID Pos, ObjectInstanceID ID, CreatureID CRID):pos(Pos),id(ID), cid(CRID){};
  1840. SlotID pos; //stack pos
  1841. ObjectInstanceID id; //object id
  1842. CreatureID cid; //id of type to which we want make upgrade
  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 & pos;
  1848. h & id;
  1849. h & cid;
  1850. }
  1851. };
  1852. struct GarrisonHeroSwap : public CPackForServer
  1853. {
  1854. GarrisonHeroSwap(){};
  1855. GarrisonHeroSwap(ObjectInstanceID TID):tid(TID){};
  1856. ObjectInstanceID tid;
  1857. bool applyGh(CGameHandler *gh);
  1858. template <typename Handler> void serialize(Handler &h, const int version)
  1859. {
  1860. h & static_cast<CPackForServer &>(*this);
  1861. h & tid;
  1862. }
  1863. };
  1864. struct ExchangeArtifacts : public CPackForServer
  1865. {
  1866. ArtifactLocation src, dst;
  1867. ExchangeArtifacts(){};
  1868. bool applyGh(CGameHandler *gh);
  1869. template <typename Handler> void serialize(Handler &h, const int version)
  1870. {
  1871. h & static_cast<CPackForServer &>(*this);
  1872. h & src;
  1873. h & dst;
  1874. }
  1875. };
  1876. struct BulkExchangeArtifacts : public CPackForServer
  1877. {
  1878. ObjectInstanceID srcHero;
  1879. ObjectInstanceID dstHero;
  1880. bool swap;
  1881. BulkExchangeArtifacts()
  1882. : swap(false) {}
  1883. BulkExchangeArtifacts(ObjectInstanceID srcHero, ObjectInstanceID dstHero, bool swap)
  1884. : srcHero(srcHero), dstHero(dstHero), swap(swap) {}
  1885. bool applyGh(CGameHandler * gh);
  1886. template <typename Handler> void serialize(Handler & h, const int version)
  1887. {
  1888. h & static_cast<CPackForServer&>(*this);
  1889. h & srcHero;
  1890. h & dstHero;
  1891. h & swap;
  1892. }
  1893. };
  1894. struct AssembleArtifacts : public CPackForServer
  1895. {
  1896. AssembleArtifacts():assemble(false){};
  1897. AssembleArtifacts(ObjectInstanceID _heroID, ArtifactPosition _artifactSlot, bool _assemble, ArtifactID _assembleTo)
  1898. : heroID(_heroID), artifactSlot(_artifactSlot), assemble(_assemble), assembleTo(_assembleTo){};
  1899. ObjectInstanceID heroID;
  1900. ArtifactPosition artifactSlot;
  1901. bool assemble; // True to assemble artifact, false to disassemble.
  1902. ArtifactID assembleTo; // Artifact to assemble into.
  1903. bool applyGh(CGameHandler *gh);
  1904. template <typename Handler> void serialize(Handler &h, const int version)
  1905. {
  1906. h & static_cast<CPackForServer &>(*this);
  1907. h & heroID;
  1908. h & artifactSlot;
  1909. h & assemble;
  1910. h & assembleTo;
  1911. }
  1912. };
  1913. struct BuyArtifact : public CPackForServer
  1914. {
  1915. BuyArtifact(){};
  1916. BuyArtifact(ObjectInstanceID HID, ArtifactID AID):hid(HID),aid(AID){};
  1917. ObjectInstanceID hid;
  1918. ArtifactID aid;
  1919. bool applyGh(CGameHandler *gh);
  1920. template <typename Handler> void serialize(Handler &h, const int version)
  1921. {
  1922. h & static_cast<CPackForServer &>(*this);
  1923. h & hid;
  1924. h & aid;
  1925. }
  1926. };
  1927. struct TradeOnMarketplace : public CPackForServer
  1928. {
  1929. TradeOnMarketplace()
  1930. :marketId(), heroId(), mode(EMarketMode::RESOURCE_RESOURCE)
  1931. {};
  1932. ObjectInstanceID marketId;
  1933. ObjectInstanceID heroId;
  1934. EMarketMode::EMarketMode mode;
  1935. 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?]
  1936. std::vector<ui32> val; //units of sold resource
  1937. bool applyGh(CGameHandler *gh);
  1938. template <typename Handler> void serialize(Handler &h, const int version)
  1939. {
  1940. h & static_cast<CPackForServer &>(*this);
  1941. h & marketId;
  1942. h & heroId;
  1943. h & mode;
  1944. h & r1;
  1945. h & r2;
  1946. h & val;
  1947. }
  1948. };
  1949. struct SetFormation : public CPackForServer
  1950. {
  1951. SetFormation():formation(0){};
  1952. SetFormation(ObjectInstanceID HID, ui8 Formation):hid(HID),formation(Formation){};
  1953. ObjectInstanceID hid;
  1954. ui8 formation;
  1955. bool applyGh(CGameHandler *gh);
  1956. template <typename Handler> void serialize(Handler &h, const int version)
  1957. {
  1958. h & static_cast<CPackForServer &>(*this);
  1959. h & hid;
  1960. h & formation;
  1961. }
  1962. };
  1963. struct HireHero : public CPackForServer
  1964. {
  1965. HireHero():hid(0){};
  1966. HireHero(si32 HID, ObjectInstanceID TID):hid(HID),tid(TID){};
  1967. si32 hid; //available hero serial
  1968. ObjectInstanceID tid; //town (tavern) id
  1969. PlayerColor player;
  1970. bool applyGh(CGameHandler *gh);
  1971. template <typename Handler> void serialize(Handler &h, const int version)
  1972. {
  1973. h & static_cast<CPackForServer &>(*this);
  1974. h & hid;
  1975. h & tid;
  1976. h & player;
  1977. }
  1978. };
  1979. struct BuildBoat : public CPackForServer
  1980. {
  1981. BuildBoat(){};
  1982. ObjectInstanceID objid; //where player wants to buy a boat
  1983. bool applyGh(CGameHandler *gh);
  1984. template <typename Handler> void serialize(Handler &h, const int version)
  1985. {
  1986. h & static_cast<CPackForServer &>(*this);
  1987. h & objid;
  1988. }
  1989. };
  1990. struct QueryReply : public CPackForServer
  1991. {
  1992. QueryReply(){};
  1993. QueryReply(QueryID QID, const JsonNode & Reply):qid(QID), reply(Reply){};
  1994. QueryID qid;
  1995. PlayerColor player;
  1996. JsonNode reply;
  1997. bool applyGh(CGameHandler *gh);
  1998. template <typename Handler> void serialize(Handler &h, const int version)
  1999. {
  2000. h & static_cast<CPackForServer &>(*this);
  2001. h & qid;
  2002. h & player;
  2003. h & reply;
  2004. }
  2005. };
  2006. struct MakeAction : public CPackForServer
  2007. {
  2008. MakeAction(){};
  2009. MakeAction(const BattleAction &BA):ba(BA){};
  2010. BattleAction ba;
  2011. bool applyGh(CGameHandler *gh);
  2012. template <typename Handler> void serialize(Handler &h, const int version)
  2013. {
  2014. h & static_cast<CPackForServer &>(*this);
  2015. h & ba;
  2016. }
  2017. };
  2018. struct MakeCustomAction : public CPackForServer
  2019. {
  2020. MakeCustomAction(){};
  2021. MakeCustomAction(const BattleAction &BA):ba(BA){};
  2022. BattleAction ba;
  2023. bool applyGh(CGameHandler *gh);
  2024. template <typename Handler> void serialize(Handler &h, const int version)
  2025. {
  2026. h & static_cast<CPackForServer &>(*this);
  2027. h & ba;
  2028. }
  2029. };
  2030. struct DigWithHero : public CPackForServer
  2031. {
  2032. DigWithHero(){}
  2033. ObjectInstanceID id; //digging hero id
  2034. bool applyGh(CGameHandler *gh);
  2035. template <typename Handler> void serialize(Handler &h, const int version)
  2036. {
  2037. h & static_cast<CPackForServer &>(*this);
  2038. h & id;
  2039. }
  2040. };
  2041. struct CastAdvSpell : public CPackForServer
  2042. {
  2043. CastAdvSpell(){}
  2044. ObjectInstanceID hid; //hero id
  2045. SpellID sid; //spell id
  2046. int3 pos; //selected tile (not always used)
  2047. bool applyGh(CGameHandler *gh);
  2048. template <typename Handler> void serialize(Handler &h, const int version)
  2049. {
  2050. h & static_cast<CPackForServer &>(*this);
  2051. h & hid;
  2052. h & sid;
  2053. h & pos;
  2054. }
  2055. };
  2056. /***********************************************************************************************************/
  2057. struct SaveGame : public CPackForServer
  2058. {
  2059. SaveGame(){};
  2060. SaveGame(const std::string &Fname) :fname(Fname){};
  2061. std::string fname;
  2062. void applyGs(CGameState *gs){};
  2063. bool applyGh(CGameHandler *gh);
  2064. template <typename Handler> void serialize(Handler &h, const int version)
  2065. {
  2066. h & static_cast<CPackForServer &>(*this);
  2067. h & fname;
  2068. }
  2069. };
  2070. // TODO: Eventually we should re-merge both SaveGame and PlayerMessage
  2071. struct SaveGameClient : public CPackForClient
  2072. {
  2073. SaveGameClient(){};
  2074. SaveGameClient(const std::string &Fname) :fname(Fname){};
  2075. std::string fname;
  2076. void applyCl(CClient *cl);
  2077. template <typename Handler> void serialize(Handler &h, const int version)
  2078. {
  2079. h & fname;
  2080. }
  2081. };
  2082. struct PlayerMessage : public CPackForServer
  2083. {
  2084. PlayerMessage(){};
  2085. PlayerMessage(const std::string &Text, ObjectInstanceID obj)
  2086. : text(Text), currObj(obj)
  2087. {};
  2088. void applyGs(CGameState *gs){};
  2089. bool applyGh(CGameHandler *gh);
  2090. std::string text;
  2091. ObjectInstanceID currObj; // optional parameter that specifies current object. For cheats :)
  2092. template <typename Handler> void serialize(Handler &h, const int version)
  2093. {
  2094. h & static_cast<CPackForServer &>(*this);
  2095. h & text;
  2096. h & currObj;
  2097. }
  2098. };
  2099. struct PlayerMessageClient : public CPackForClient
  2100. {
  2101. PlayerMessageClient(){};
  2102. PlayerMessageClient(PlayerColor Player, const std::string &Text)
  2103. : player(Player), text(Text)
  2104. {}
  2105. void applyCl(CClient *cl);
  2106. PlayerColor player;
  2107. std::string text;
  2108. template <typename Handler> void serialize(Handler &h, const int version)
  2109. {
  2110. h & player;
  2111. h & text;
  2112. }
  2113. };
  2114. struct CenterView : public CPackForClient
  2115. {
  2116. CenterView():focusTime(0){};
  2117. void applyCl(CClient *cl);
  2118. PlayerColor player;
  2119. int3 pos;
  2120. ui32 focusTime; //ms
  2121. template <typename Handler> void serialize(Handler &h, const int version)
  2122. {
  2123. h & pos;
  2124. h & player;
  2125. h & focusTime;
  2126. }
  2127. };
  2128. VCMI_LIB_NAMESPACE_END