2
0

NetPacks.h 58 KB

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