NetPacks.h 57 KB

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