NetPacks.h 55 KB

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