NetPacks.h 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266
  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 "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_RESET, BANK_CLEAR,
  838. //object with reward
  839. REWARD_RESET, REWARD_SELECT
  840. };
  841. }
  842. struct SetObjectProperty : public CPackForClient//1001
  843. {
  844. DLL_LINKAGE void applyGs(CGameState *gs);
  845. void applyCl(CClient *cl);
  846. ObjectInstanceID id;
  847. ui8 what; // see ObjProperty enum
  848. ui32 val;
  849. SetObjectProperty(){type = 1001;};
  850. SetObjectProperty(ObjectInstanceID ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
  851. template <typename Handler> void serialize(Handler &h, const int version)
  852. {
  853. h & id & what & val;
  854. }
  855. };
  856. struct SetHoverName : public CPackForClient//1002
  857. {
  858. DLL_LINKAGE void applyGs(CGameState *gs);
  859. ObjectInstanceID id;
  860. MetaString name;
  861. SetHoverName(){type = 1002;}
  862. SetHoverName(ObjectInstanceID ID, MetaString& Name):id(ID),name(Name){type = 1002;}
  863. template <typename Handler> void serialize(Handler &h, const int version)
  864. {
  865. h & id & name;
  866. }
  867. };
  868. struct ChangeObjectVisitors : public CPackForClient // 1003
  869. {
  870. enum VisitMode
  871. {
  872. VISITOR_ADD, // mark hero as one that have visited this object
  873. VISITOR_REMOVE, // unmark visitor, reversed to ADD
  874. VISITOR_CLEAR // clear all visitors from this object (object reset)
  875. };
  876. ui32 mode; // uses VisitMode enum
  877. ObjectInstanceID object;
  878. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  879. DLL_LINKAGE void applyGs(CGameState *gs);
  880. ChangeObjectVisitors()
  881. { type = 1003; }
  882. ChangeObjectVisitors(ui32 mode, ObjectInstanceID object, ObjectInstanceID heroID = ObjectInstanceID(-1)):
  883. mode(mode),
  884. object(object),
  885. hero(heroID)
  886. { type = 1003; }
  887. template <typename Handler> void serialize(Handler &h, const int version)
  888. {
  889. h & object & hero & mode;
  890. }
  891. };
  892. struct HeroLevelUp : public Query//2000
  893. {
  894. void applyCl(CClient *cl);
  895. DLL_LINKAGE void applyGs(CGameState *gs);
  896. const CGHeroInstance *hero;
  897. PrimarySkill::PrimarySkill primskill;
  898. std::vector<SecondarySkill> skills;
  899. HeroLevelUp(){type = 2000;};
  900. template <typename Handler> void serialize(Handler &h, const int version)
  901. {
  902. h & queryID & hero & primskill & skills;
  903. }
  904. };
  905. struct CommanderLevelUp : public Query
  906. {
  907. void applyCl(CClient *cl);
  908. DLL_LINKAGE void applyGs(CGameState *gs);
  909. const CGHeroInstance *hero;
  910. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  911. CommanderLevelUp(){type = 2005;};
  912. template <typename Handler> void serialize(Handler &h, const int version)
  913. {
  914. h & queryID & hero & skills;
  915. }
  916. };
  917. struct TradeComponents : public CPackForClient, public CPackForServer
  918. {
  919. ///used to handle info about components available in shops
  920. void applyCl(CClient *cl);
  921. DLL_LINKAGE void applyGs(CGameState *gs);
  922. si32 heroid;
  923. ui32 objectid;
  924. std::map<ui16, Component> available, chosen, bought;
  925. template <typename Handler> void serialize(Handler &h, const int version)
  926. {
  927. h & heroid & objectid & available & chosen & bought;
  928. }
  929. };
  930. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  931. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  932. //Until sending reply player won't be allowed to take any actions
  933. struct BlockingDialog : public Query//2003
  934. {
  935. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  936. void applyCl(CClient *cl);
  937. MetaString text;
  938. std::vector<Component> components;
  939. PlayerColor player;
  940. ui8 flags;
  941. ui16 soundID;
  942. bool cancel() const
  943. {
  944. return flags & ALLOW_CANCEL;
  945. }
  946. bool selection() const
  947. {
  948. return flags & SELECTION;
  949. }
  950. BlockingDialog(bool yesno, bool Selection)
  951. {
  952. type = 2003;
  953. flags = 0;
  954. soundID = 0;
  955. if(yesno) flags |= ALLOW_CANCEL;
  956. if(Selection) flags |= SELECTION;
  957. }
  958. BlockingDialog()
  959. {
  960. type = 2003;
  961. flags = 0;
  962. soundID = 0;
  963. };
  964. void addResourceComponents(TResources resources)
  965. {
  966. for(TResources::nziterator i(resources); i.valid(); i++)
  967. components.push_back(Component(Component::RESOURCE, i->resType, i->resVal, 0));
  968. }
  969. template <typename Handler> void serialize(Handler &h, const int version)
  970. {
  971. h & queryID & text & components & player & flags & soundID;
  972. }
  973. };
  974. struct GarrisonDialog : public Query//2004
  975. {
  976. GarrisonDialog(){type = 2004;}
  977. void applyCl(CClient *cl);
  978. ObjectInstanceID objid, hid;
  979. bool removableUnits;
  980. template <typename Handler> void serialize(Handler &h, const int version)
  981. {
  982. h & queryID & objid & hid & removableUnits;
  983. }
  984. };
  985. struct ExchangeDialog : public Query//2005
  986. {
  987. ExchangeDialog(){type = 2005;}
  988. void applyCl(CClient *cl);
  989. std::array<const CGHeroInstance*, 2> heroes;
  990. template <typename Handler> void serialize(Handler &h, const int version)
  991. {
  992. h & queryID & heroes;
  993. }
  994. };
  995. struct BattleInfo;
  996. struct BattleStart : public CPackForClient//3000
  997. {
  998. BattleStart(){type = 3000;};
  999. void applyFirstCl(CClient *cl);
  1000. void applyCl(CClient *cl);
  1001. DLL_LINKAGE void applyGs(CGameState *gs);
  1002. BattleInfo * info;
  1003. template <typename Handler> void serialize(Handler &h, const int version)
  1004. {
  1005. h & info;
  1006. }
  1007. };
  1008. struct BattleNextRound : public CPackForClient//3001
  1009. {
  1010. BattleNextRound(){type = 3001;};
  1011. void applyFirstCl(CClient *cl);
  1012. void applyCl(CClient *cl);
  1013. DLL_LINKAGE void applyGs( CGameState *gs );
  1014. si32 round;
  1015. template <typename Handler> void serialize(Handler &h, const int version)
  1016. {
  1017. h & round;
  1018. }
  1019. };
  1020. struct BattleSetActiveStack : public CPackForClient//3002
  1021. {
  1022. BattleSetActiveStack()
  1023. {
  1024. type = 3002;
  1025. askPlayerInterface = true;
  1026. }
  1027. void applyCl(CClient *cl);
  1028. DLL_LINKAGE void applyGs(CGameState *gs);
  1029. ui32 stack;
  1030. ui8 askPlayerInterface;
  1031. template <typename Handler> void serialize(Handler &h, const int version)
  1032. {
  1033. h & stack & askPlayerInterface;
  1034. }
  1035. };
  1036. struct BattleResult : public CPackForClient//3003
  1037. {
  1038. enum EResult {NORMAL = 0, ESCAPE = 1, SURRENDER = 2};
  1039. BattleResult(){type = 3003;};
  1040. void applyFirstCl(CClient *cl);
  1041. void applyGs(CGameState *gs);
  1042. EResult result;
  1043. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  1044. std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
  1045. TExpType exp[2]; //exp for attacker and defender
  1046. std::set<ArtifactInstanceID> artifacts; //artifacts taken from loser to winner - currently unused
  1047. template <typename Handler> void serialize(Handler &h, const int version)
  1048. {
  1049. h & result & winner & casualties[0] & casualties[1] & exp & artifacts;
  1050. }
  1051. };
  1052. struct BattleStackMoved : public CPackForClient//3004
  1053. {
  1054. ui32 stack;
  1055. std::vector<BattleHex> tilesToMove;
  1056. ui8 distance, teleporting;
  1057. BattleStackMoved(){type = 3004;};
  1058. void applyFirstCl(CClient *cl);
  1059. void applyGs(CGameState *gs);
  1060. template <typename Handler> void serialize(Handler &h, const int version)
  1061. {
  1062. h & stack & tilesToMove & distance;
  1063. }
  1064. };
  1065. struct StacksHealedOrResurrected : public CPackForClient //3013
  1066. {
  1067. StacksHealedOrResurrected(){type = 3013;}
  1068. DLL_LINKAGE void applyGs(CGameState *gs);
  1069. void applyCl(CClient *cl);
  1070. struct HealInfo
  1071. {
  1072. ui32 stackID;
  1073. ui32 healedHP;
  1074. ui8 lowLevelResurrection; //in case this stack is resurrected by this heal, it will be marked as SUMMONED //TODO: replace with separate counter
  1075. template <typename Handler> void serialize(Handler &h, const int version)
  1076. {
  1077. h & stackID & healedHP & lowLevelResurrection;
  1078. }
  1079. };
  1080. std::vector<HealInfo> healedStacks;
  1081. bool lifeDrain; //if true, this heal is an effect of life drain
  1082. bool tentHealing; //if true, than it's healing via First Aid Tent
  1083. si32 drainedFrom; //if life drain - then stack life was drain from, if tentHealing - stack that is a healer
  1084. template <typename Handler> void serialize(Handler &h, const int version)
  1085. {
  1086. h & healedStacks & lifeDrain & tentHealing & drainedFrom;
  1087. }
  1088. };
  1089. struct BattleStackAttacked : public CPackForClient//3005
  1090. {
  1091. BattleStackAttacked(){flags = 0; type = 3005;};
  1092. void applyFirstCl(CClient * cl);
  1093. //void applyCl(CClient *cl);
  1094. DLL_LINKAGE void applyGs(CGameState *gs);
  1095. ui32 stackAttacked, attackerID;
  1096. ui32 newAmount, newHP, killedAmount, damageAmount;
  1097. enum EFlags {KILLED = 1, EFFECT = 2, SECONDARY = 4, REBIRTH = 8, CLONE_KILLED = 16};
  1098. ui8 flags; //uses EFlags (above)
  1099. ui32 effect; //set only if flag EFFECT is set
  1100. std::vector<StacksHealedOrResurrected> healedStacks; //used when life drain
  1101. bool killed() const//if target stack was killed
  1102. {
  1103. return flags & KILLED || flags & CLONE_KILLED;
  1104. }
  1105. bool cloneKilled() const
  1106. {
  1107. return flags & CLONE_KILLED;
  1108. }
  1109. bool isEffect() const//if stack has been attacked by a spell
  1110. {
  1111. return flags & EFFECT;
  1112. }
  1113. bool isSecondary() const//if stack was not a primary target (receives no spell effects)
  1114. {
  1115. return flags & SECONDARY;
  1116. }
  1117. bool willRebirth() const//resurrection, e.g. Phoenix
  1118. {
  1119. return flags & REBIRTH;
  1120. }
  1121. bool lifeDrain() const //if this attack involves life drain effect
  1122. {
  1123. return healedStacks.size() > 0;
  1124. }
  1125. template <typename Handler> void serialize(Handler &h, const int version)
  1126. {
  1127. h & stackAttacked & attackerID & newAmount & newHP & flags & killedAmount & damageAmount & effect
  1128. & healedStacks;
  1129. }
  1130. bool operator<(const BattleStackAttacked &b) const
  1131. {
  1132. return stackAttacked < b.stackAttacked;
  1133. }
  1134. };
  1135. struct BattleAttack : public CPackForClient//3006
  1136. {
  1137. BattleAttack(){flags = 0; type = 3006;};
  1138. void applyFirstCl(CClient *cl);
  1139. DLL_LINKAGE void applyGs(CGameState *gs);
  1140. void applyCl(CClient *cl);
  1141. std::vector<BattleStackAttacked> bsa;
  1142. ui32 stackAttacking;
  1143. ui8 flags; //uses Eflags (below)
  1144. enum EFlags{SHOT = 1, COUNTER = 2, LUCKY = 4, UNLUCKY = 8, BALLISTA_DOUBLE_DMG = 16, DEATH_BLOW = 32};
  1145. bool shot() const//distance attack - decrease number of shots
  1146. {
  1147. return flags & SHOT;
  1148. }
  1149. bool counter() const//is it counterattack?
  1150. {
  1151. return flags & COUNTER;
  1152. }
  1153. bool lucky() const
  1154. {
  1155. return flags & LUCKY;
  1156. }
  1157. bool unlucky() const
  1158. {
  1159. return flags & UNLUCKY;
  1160. }
  1161. bool ballistaDoubleDmg() const //if it's ballista attack and does double dmg
  1162. {
  1163. return flags & BALLISTA_DOUBLE_DMG;
  1164. }
  1165. bool deathBlow() const
  1166. {
  1167. return flags & DEATH_BLOW;
  1168. }
  1169. //bool killed() //if target stack was killed
  1170. //{
  1171. // return bsa.killed();
  1172. //}
  1173. template <typename Handler> void serialize(Handler &h, const int version)
  1174. {
  1175. h & bsa & stackAttacking & flags;
  1176. }
  1177. };
  1178. struct StartAction : public CPackForClient//3007
  1179. {
  1180. StartAction(){type = 3007;};
  1181. StartAction(const BattleAction &act){ba = act; type = 3007;};
  1182. void applyFirstCl(CClient *cl);
  1183. DLL_LINKAGE void applyGs(CGameState *gs);
  1184. BattleAction ba;
  1185. template <typename Handler> void serialize(Handler &h, const int version)
  1186. {
  1187. h & ba;
  1188. }
  1189. };
  1190. struct EndAction : public CPackForClient//3008
  1191. {
  1192. EndAction(){type = 3008;};
  1193. void applyCl(CClient *cl);
  1194. template <typename Handler> void serialize(Handler &h, const int version)
  1195. {
  1196. }
  1197. };
  1198. struct BattleSpellCast : public CPackForClient//3009
  1199. {
  1200. BattleSpellCast(){type = 3009;};
  1201. DLL_LINKAGE void applyGs(CGameState *gs);
  1202. void applyCl(CClient *cl);
  1203. si32 dmgToDisplay; //this amount will be displayed as amount of damage dealt by spell
  1204. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  1205. ui32 id; //id of spell
  1206. ui8 skill; //caster's skill level
  1207. ui8 spellCost;
  1208. ui8 manaGained; //mana channeling ability
  1209. BattleHex tile; //destination tile (may not be set in some global/mass spells
  1210. std::vector<ui32> resisted; //ids of creatures that resisted this spell
  1211. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  1212. CreatureID attackerType;//id of caster to generate console message; -1 if not set (eg. spell casted by artifact)
  1213. bool castedByHero; //if true - spell has been casted by hero, otherwise by a creature
  1214. template <typename Handler> void serialize(Handler &h, const int version)
  1215. {
  1216. h & dmgToDisplay & side & id & skill & spellCost & manaGained & tile & resisted & affectedCres & attackerType & castedByHero;
  1217. }
  1218. };
  1219. struct SetStackEffect : public CPackForClient //3010
  1220. {
  1221. SetStackEffect(){type = 3010;};
  1222. DLL_LINKAGE void applyGs(CGameState *gs);
  1223. void applyCl(CClient *cl);
  1224. std::vector<ui32> stacks; //affected stacks (IDs)
  1225. std::vector<Bonus> effect; //bonuses to apply
  1226. std::vector<std::pair<ui32, Bonus> > uniqueBonuses; //bonuses per single stack
  1227. template <typename Handler> void serialize(Handler &h, const int version)
  1228. {
  1229. h & stacks & effect & uniqueBonuses;
  1230. }
  1231. };
  1232. struct StacksInjured : public CPackForClient //3011
  1233. {
  1234. StacksInjured(){type = 3011;}
  1235. DLL_LINKAGE void applyGs(CGameState *gs);
  1236. void applyCl(CClient *cl);
  1237. std::vector<BattleStackAttacked> stacks;
  1238. template <typename Handler> void serialize(Handler &h, const int version)
  1239. {
  1240. h & stacks;
  1241. }
  1242. };
  1243. struct BattleResultsApplied : public CPackForClient //3012
  1244. {
  1245. BattleResultsApplied(){type = 3012;}
  1246. PlayerColor player1, player2;
  1247. void applyCl(CClient *cl);
  1248. template <typename Handler> void serialize(Handler &h, const int version)
  1249. {
  1250. h & player1 & player2;
  1251. }
  1252. };
  1253. struct ObstaclesRemoved : public CPackForClient //3014
  1254. {
  1255. ObstaclesRemoved(){type = 3014;}
  1256. DLL_LINKAGE void applyGs(CGameState *gs);
  1257. void applyCl(CClient *cl);
  1258. std::set<si32> obstacles; //uniqueIDs of removed obstacles
  1259. template <typename Handler> void serialize(Handler &h, const int version)
  1260. {
  1261. h & obstacles;
  1262. }
  1263. };
  1264. struct CatapultAttack : public CPackForClient //3015
  1265. {
  1266. struct AttackInfo
  1267. {
  1268. si16 destinationTile;
  1269. ui8 attackedPart;
  1270. ui8 damageDealt;
  1271. DLL_LINKAGE std::string toString() const;
  1272. template <typename Handler> void serialize(Handler &h, const int version)
  1273. {
  1274. h & destinationTile & attackedPart & damageDealt;
  1275. }
  1276. };
  1277. DLL_LINKAGE CatapultAttack();
  1278. DLL_LINKAGE ~CatapultAttack();
  1279. DLL_LINKAGE void applyGs(CGameState *gs);
  1280. void applyCl(CClient *cl);
  1281. DLL_LINKAGE std::string toString() const override;
  1282. std::vector< AttackInfo > attackedParts;
  1283. int attacker; //if -1, then a spell caused this
  1284. template <typename Handler> void serialize(Handler &h, const int version)
  1285. {
  1286. h & attackedParts & attacker;
  1287. }
  1288. };
  1289. DLL_LINKAGE std::ostream & operator<<(std::ostream & out, const CatapultAttack::AttackInfo & attackInfo);
  1290. struct BattleStacksRemoved : public CPackForClient //3016
  1291. {
  1292. BattleStacksRemoved(){type = 3016;}
  1293. DLL_LINKAGE void applyGs(CGameState *gs);
  1294. void applyCl(CClient *cl);
  1295. std::set<ui32> stackIDs; //IDs of removed stacks
  1296. template <typename Handler> void serialize(Handler &h, const int version)
  1297. {
  1298. h & stackIDs;
  1299. }
  1300. };
  1301. struct BattleStackAdded : public CPackForClient //3017
  1302. {
  1303. BattleStackAdded(){type = 3017;};
  1304. DLL_LINKAGE void applyGs(CGameState *gs);
  1305. void applyCl(CClient *cl);
  1306. int attacker; // if true, stack belongs to attacker
  1307. CreatureID creID;
  1308. int amount;
  1309. int pos;
  1310. int summoned; //if true, remove it afterwards
  1311. template <typename Handler> void serialize(Handler &h, const int version)
  1312. {
  1313. h & attacker & creID & amount & pos & summoned;
  1314. }
  1315. };
  1316. struct BattleSetStackProperty : public CPackForClient //3018
  1317. {
  1318. BattleSetStackProperty(){type = 3018;};
  1319. enum BattleStackProperty {CASTS, ENCHANTER_COUNTER, UNBIND, CLONED};
  1320. DLL_LINKAGE void applyGs(CGameState *gs);
  1321. //void applyCl(CClient *cl){};
  1322. int stackID;
  1323. BattleStackProperty which;
  1324. int val;
  1325. int absolute;
  1326. template <typename Handler> void serialize(Handler &h, const int version)
  1327. {
  1328. h & stackID & which & val & absolute;
  1329. }
  1330. };
  1331. struct BattleTriggerEffect : public CPackForClient //3019
  1332. { //activated at the beginning of turn
  1333. BattleTriggerEffect(){type = 3019;};
  1334. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1335. void applyCl(CClient *cl); //play animations & stuff
  1336. //enum BattleEffect {REGENERATION, MANA_DRAIN, FEAR, MANA_CHANNELING, ENCHANTER, UNBIND, POISON, ENCHANTED, SUMMONER};
  1337. int stackID;
  1338. int effect; //use enumBattleEffect or corresponding Bonus type for sanity?
  1339. int val;
  1340. int additionalInfo;
  1341. template <typename Handler> void serialize(Handler &h, const int version)
  1342. {
  1343. h & stackID & effect & val & additionalInfo;
  1344. }
  1345. };
  1346. struct BattleObstaclePlaced : public CPackForClient //3020
  1347. { //activated at the beginning of turn
  1348. BattleObstaclePlaced(){type = 3020;};
  1349. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1350. void applyCl(CClient *cl); //play animations & stuff
  1351. shared_ptr<CObstacleInstance> obstacle;
  1352. template <typename Handler> void serialize(Handler &h, const int version)
  1353. {
  1354. h & obstacle;
  1355. }
  1356. };
  1357. struct ShowInInfobox : public CPackForClient //107
  1358. {
  1359. ShowInInfobox(){type = 107;};
  1360. PlayerColor player;
  1361. Component c;
  1362. MetaString text;
  1363. void applyCl(CClient *cl);
  1364. template <typename Handler> void serialize(Handler &h, const int version)
  1365. {
  1366. h & player & c & text;
  1367. }
  1368. };
  1369. struct AdvmapSpellCast : public CPackForClient //108
  1370. {
  1371. AdvmapSpellCast(){type = 108;}
  1372. const CGHeroInstance * caster;
  1373. SpellID spellID;
  1374. void applyCl(CClient *cl);
  1375. template <typename Handler> void serialize(Handler &h, const int version)
  1376. {
  1377. h & caster & spellID;
  1378. }
  1379. };
  1380. /***********************************************************************************************************/
  1381. struct CommitPackage : public CPackForServer
  1382. {
  1383. bool freePack; //for local usage, DO NOT serialize
  1384. bool applyGh(CGameHandler *gh);
  1385. CPackForClient *packToCommit;
  1386. CommitPackage()
  1387. {
  1388. freePack = true;
  1389. }
  1390. ~CommitPackage()
  1391. {
  1392. if(freePack)
  1393. delete packToCommit;
  1394. }
  1395. template <typename Handler> void serialize(Handler &h, const int version)
  1396. {
  1397. h & packToCommit;
  1398. }
  1399. };
  1400. struct CloseServer : public CPackForServer
  1401. {
  1402. bool applyGh(CGameHandler *gh);
  1403. template <typename Handler> void serialize(Handler &h, const int version)
  1404. {}
  1405. };
  1406. struct EndTurn : public CPackForServer
  1407. {
  1408. bool applyGh(CGameHandler *gh);
  1409. template <typename Handler> void serialize(Handler &h, const int version)
  1410. {}
  1411. };
  1412. struct DismissHero : public CPackForServer
  1413. {
  1414. DismissHero(){};
  1415. DismissHero(ObjectInstanceID HID) : hid(HID) {};
  1416. ObjectInstanceID hid;
  1417. bool applyGh(CGameHandler *gh);
  1418. template <typename Handler> void serialize(Handler &h, const int version)
  1419. {
  1420. h & hid;
  1421. }
  1422. };
  1423. struct MoveHero : public CPackForServer
  1424. {
  1425. MoveHero(){};
  1426. MoveHero(const int3 &Dest, ObjectInstanceID HID) : dest(Dest), hid(HID){};
  1427. int3 dest;
  1428. ObjectInstanceID hid;
  1429. bool applyGh(CGameHandler *gh);
  1430. template <typename Handler> void serialize(Handler &h, const int version)
  1431. {
  1432. h & dest & hid;
  1433. }
  1434. };
  1435. struct CastleTeleportHero : public CPackForServer
  1436. {
  1437. CastleTeleportHero(){};
  1438. CastleTeleportHero(const ObjectInstanceID HID, ObjectInstanceID Dest, ui8 Source ) : dest(Dest), hid(HID), source(Source){};
  1439. ObjectInstanceID dest;
  1440. ObjectInstanceID hid;
  1441. si8 source;//who give teleporting, 1=castle gate
  1442. bool applyGh(CGameHandler *gh);
  1443. template <typename Handler> void serialize(Handler &h, const int version)
  1444. {
  1445. h & dest & hid;
  1446. }
  1447. };
  1448. struct ArrangeStacks : public CPackForServer
  1449. {
  1450. ArrangeStacks(){};
  1451. ArrangeStacks(ui8 W, SlotID P1, SlotID P2, ObjectInstanceID ID1, ObjectInstanceID ID2, si32 VAL)
  1452. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  1453. ui8 what; //1 - swap; 2 - merge; 3 - split
  1454. SlotID p1, p2; //positions of first and second stack
  1455. ObjectInstanceID id1, id2; //ids of objects with garrison
  1456. si32 val;
  1457. bool applyGh(CGameHandler *gh);
  1458. template <typename Handler> void serialize(Handler &h, const int version)
  1459. {
  1460. h & what & p1 & p2 & id1 & id2 & val;
  1461. }
  1462. };
  1463. struct DisbandCreature : public CPackForServer
  1464. {
  1465. DisbandCreature(){};
  1466. DisbandCreature(SlotID Pos, ObjectInstanceID ID):pos(Pos),id(ID){};
  1467. SlotID pos; //stack pos
  1468. ObjectInstanceID id; //object id
  1469. bool applyGh(CGameHandler *gh);
  1470. template <typename Handler> void serialize(Handler &h, const int version)
  1471. {
  1472. h & pos & id;
  1473. }
  1474. };
  1475. struct BuildStructure : public CPackForServer
  1476. {
  1477. BuildStructure(){};
  1478. BuildStructure(ObjectInstanceID TID, BuildingID BID):tid(TID), bid(BID){};
  1479. ObjectInstanceID tid; //town id
  1480. BuildingID bid; //structure id
  1481. bool applyGh(CGameHandler *gh);
  1482. template <typename Handler> void serialize(Handler &h, const int version)
  1483. {
  1484. h & tid & bid;
  1485. }
  1486. };
  1487. struct RazeStructure : public BuildStructure
  1488. {
  1489. RazeStructure(){};
  1490. //RazeStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  1491. bool applyGh(CGameHandler *gh);
  1492. };
  1493. struct RecruitCreatures : public CPackForServer
  1494. {
  1495. RecruitCreatures(){};
  1496. RecruitCreatures(ObjectInstanceID TID, CreatureID CRID, si32 Amount, si32 Level):tid(TID),crid(CRID),amount(Amount),level(Level){};
  1497. ObjectInstanceID tid; //town id
  1498. CreatureID crid;
  1499. ui32 amount;//creature amount
  1500. si32 level;//dwelling level to buy from, -1 if any
  1501. bool applyGh(CGameHandler *gh);
  1502. template <typename Handler> void serialize(Handler &h, const int version)
  1503. {
  1504. h & tid & crid & amount & level;
  1505. }
  1506. };
  1507. struct UpgradeCreature : public CPackForServer
  1508. {
  1509. UpgradeCreature(){};
  1510. UpgradeCreature(SlotID Pos, ObjectInstanceID ID, CreatureID CRID):pos(Pos),id(ID), cid(CRID){};
  1511. SlotID pos; //stack pos
  1512. ObjectInstanceID id; //object id
  1513. CreatureID cid; //id of type to which we want make upgrade
  1514. bool applyGh(CGameHandler *gh);
  1515. template <typename Handler> void serialize(Handler &h, const int version)
  1516. {
  1517. h & pos & id & cid;
  1518. }
  1519. };
  1520. struct GarrisonHeroSwap : public CPackForServer
  1521. {
  1522. GarrisonHeroSwap(){};
  1523. GarrisonHeroSwap(ObjectInstanceID TID):tid(TID){};
  1524. ObjectInstanceID tid;
  1525. bool applyGh(CGameHandler *gh);
  1526. template <typename Handler> void serialize(Handler &h, const int version)
  1527. {
  1528. h & tid;
  1529. }
  1530. };
  1531. struct ExchangeArtifacts : public CPackForServer
  1532. //TODO: allow exchange between heroes, stacks and commanders
  1533. {
  1534. ArtifactLocation src, dst;
  1535. ExchangeArtifacts(){};
  1536. bool applyGh(CGameHandler *gh);
  1537. template <typename Handler> void serialize(Handler &h, const int version)
  1538. {
  1539. h & src & dst;
  1540. }
  1541. };
  1542. struct AssembleArtifacts : public CPackForServer
  1543. {
  1544. AssembleArtifacts(){};
  1545. AssembleArtifacts(ObjectInstanceID _heroID, ArtifactPosition _artifactSlot, bool _assemble, ArtifactID _assembleTo)
  1546. : heroID(_heroID), artifactSlot(_artifactSlot), assemble(_assemble), assembleTo(_assembleTo){};
  1547. ObjectInstanceID heroID;
  1548. ArtifactPosition artifactSlot;
  1549. bool assemble; // True to assemble artifact, false to disassemble.
  1550. ArtifactID assembleTo; // Artifact to assemble into.
  1551. bool applyGh(CGameHandler *gh);
  1552. template <typename Handler> void serialize(Handler &h, const int version)
  1553. {
  1554. h & heroID & artifactSlot & assemble & assembleTo;
  1555. }
  1556. };
  1557. struct BuyArtifact : public CPackForServer
  1558. {
  1559. BuyArtifact(){};
  1560. BuyArtifact(ObjectInstanceID HID, ArtifactID AID):hid(HID),aid(AID){};
  1561. ObjectInstanceID hid;
  1562. ArtifactID aid;
  1563. bool applyGh(CGameHandler *gh);
  1564. template <typename Handler> void serialize(Handler &h, const int version)
  1565. {
  1566. h & hid & aid;
  1567. }
  1568. };
  1569. struct TradeOnMarketplace : public CPackForServer
  1570. {
  1571. TradeOnMarketplace(){};
  1572. const CGObjectInstance *market;
  1573. const CGHeroInstance *hero; //needed when trading artifacts / creatures
  1574. EMarketMode::EMarketMode mode;
  1575. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res (exception: when sacrificing art r1 is art id [todo: make r2 preferred slot?]
  1576. ui32 val; //units of sold resource
  1577. bool applyGh(CGameHandler *gh);
  1578. template <typename Handler> void serialize(Handler &h, const int version)
  1579. {
  1580. h & market & hero & mode & r1 & r2 & val;
  1581. }
  1582. };
  1583. struct SetFormation : public CPackForServer
  1584. {
  1585. SetFormation(){};
  1586. SetFormation(ObjectInstanceID HID, ui8 Formation):hid(HID),formation(Formation){};
  1587. ObjectInstanceID hid;
  1588. ui8 formation;
  1589. bool applyGh(CGameHandler *gh);
  1590. template <typename Handler> void serialize(Handler &h, const int version)
  1591. {
  1592. h & hid & formation;
  1593. }
  1594. };
  1595. struct HireHero : public CPackForServer
  1596. {
  1597. HireHero(){};
  1598. HireHero(si32 HID, ObjectInstanceID TID):hid(HID),tid(TID){};
  1599. si32 hid; //available hero serial
  1600. ObjectInstanceID tid; //town (tavern) id
  1601. PlayerColor player;
  1602. bool applyGh(CGameHandler *gh);
  1603. template <typename Handler> void serialize(Handler &h, const int version)
  1604. {
  1605. h & hid & tid & player;
  1606. }
  1607. };
  1608. struct BuildBoat : public CPackForServer
  1609. {
  1610. BuildBoat(){};
  1611. ObjectInstanceID objid; //where player wants to buy a boat
  1612. bool applyGh(CGameHandler *gh);
  1613. template <typename Handler> void serialize(Handler &h, const int version)
  1614. {
  1615. h & objid;
  1616. }
  1617. };
  1618. struct QueryReply : public CPackForServer
  1619. {
  1620. QueryReply(){type = 6000;};
  1621. QueryReply(QueryID QID, ui32 Answer):qid(QID),answer(Answer){type = 6000;};
  1622. QueryID qid;
  1623. ui32 answer; //hero and artifact id
  1624. PlayerColor player;
  1625. bool applyGh(CGameHandler *gh);
  1626. template <typename Handler> void serialize(Handler &h, const int version)
  1627. {
  1628. h & qid & answer & player;
  1629. }
  1630. };
  1631. struct MakeAction : public CPackForServer
  1632. {
  1633. MakeAction(){};
  1634. MakeAction(const BattleAction &BA):ba(BA){};
  1635. BattleAction ba;
  1636. bool applyGh(CGameHandler *gh);
  1637. template <typename Handler> void serialize(Handler &h, const int version)
  1638. {
  1639. h & ba;
  1640. }
  1641. };
  1642. struct MakeCustomAction : public CPackForServer
  1643. {
  1644. MakeCustomAction(){};
  1645. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1646. BattleAction ba;
  1647. bool applyGh(CGameHandler *gh);
  1648. template <typename Handler> void serialize(Handler &h, const int version)
  1649. {
  1650. h & ba;
  1651. }
  1652. };
  1653. struct DigWithHero : public CPackForServer
  1654. {
  1655. DigWithHero(){}
  1656. ObjectInstanceID id; //digging hero id
  1657. bool applyGh(CGameHandler *gh);
  1658. template <typename Handler> void serialize(Handler &h, const int version)
  1659. {
  1660. h & id;
  1661. }
  1662. };
  1663. struct CastAdvSpell : public CPackForServer
  1664. {
  1665. CastAdvSpell(){}
  1666. ObjectInstanceID hid; //hero id
  1667. SpellID sid; //spell id
  1668. int3 pos; //selected tile (not always used)
  1669. bool applyGh(CGameHandler *gh);
  1670. template <typename Handler> void serialize(Handler &h, const int version)
  1671. {
  1672. h & hid & sid & pos;
  1673. }
  1674. };
  1675. /***********************************************************************************************************/
  1676. struct SaveGame : public CPackForClient, public CPackForServer
  1677. {
  1678. SaveGame(){};
  1679. SaveGame(const std::string &Fname) :fname(Fname){};
  1680. std::string fname;
  1681. void applyCl(CClient *cl);
  1682. void applyGs(CGameState *gs){};
  1683. bool applyGh(CGameHandler *gh);
  1684. template <typename Handler> void serialize(Handler &h, const int version)
  1685. {
  1686. h & fname;
  1687. }
  1688. };
  1689. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  1690. {
  1691. PlayerMessage(){CPackForClient::type = 513;};
  1692. PlayerMessage(PlayerColor Player, const std::string &Text)
  1693. :player(Player),text(Text)
  1694. {CPackForClient::type = 513;};
  1695. void applyCl(CClient *cl);
  1696. void applyGs(CGameState *gs){};
  1697. bool applyGh(CGameHandler *gh);
  1698. PlayerColor player;
  1699. std::string text;
  1700. template <typename Handler> void serialize(Handler &h, const int version)
  1701. {
  1702. h & text & player;
  1703. }
  1704. };
  1705. struct SetSelection : public CPackForClient, public CPackForServer //514
  1706. {
  1707. SetSelection(){CPackForClient::type = 514;};
  1708. DLL_LINKAGE void applyGs(CGameState *gs);
  1709. bool applyGh(CGameHandler *gh);
  1710. void applyCl(CClient *cl);
  1711. PlayerColor player;
  1712. ObjectInstanceID id;
  1713. template <typename Handler> void serialize(Handler &h, const int version)
  1714. {
  1715. h & id & player;
  1716. }
  1717. };
  1718. struct CenterView : public CPackForClient//515
  1719. {
  1720. CenterView(){CPackForClient::type = 515;};
  1721. void applyCl(CClient *cl);
  1722. PlayerColor player;
  1723. int3 pos;
  1724. ui32 focusTime; //ms
  1725. template <typename Handler> void serialize(Handler &h, const int version)
  1726. {
  1727. h & pos & player & focusTime;
  1728. }
  1729. };
  1730. /***********************************************************************************************************/
  1731. struct CPackForSelectionScreen : public CPack
  1732. {
  1733. void apply(CSelectionScreen *selScreen){}; //that functions are implemented in CPreGame.cpp
  1734. };
  1735. class CPregamePackToPropagate : public CPackForSelectionScreen
  1736. {};
  1737. class CPregamePackToHost : public CPackForSelectionScreen
  1738. {};
  1739. struct ChatMessage : public CPregamePackToPropagate
  1740. {
  1741. std::string playerName, message;
  1742. void apply(CSelectionScreen *selScreen);
  1743. template <typename Handler> void serialize(Handler &h, const int version)
  1744. {
  1745. h & playerName & message;
  1746. }
  1747. };
  1748. struct QuitMenuWithoutStarting : public CPregamePackToPropagate
  1749. {
  1750. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1751. template <typename Handler> void serialize(Handler &h, const int version)
  1752. {}
  1753. };
  1754. struct PlayerJoined : public CPregamePackToHost
  1755. {
  1756. std::string playerName;
  1757. ui8 connectionID;
  1758. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1759. template <typename Handler> void serialize(Handler &h, const int version)
  1760. {
  1761. h & playerName & connectionID;
  1762. }
  1763. };
  1764. struct SelectMap : public CPregamePackToPropagate
  1765. {
  1766. const CMapInfo *mapInfo;
  1767. bool free;
  1768. SelectMap(const CMapInfo &src)
  1769. {
  1770. mapInfo = &src;
  1771. free = false;
  1772. }
  1773. SelectMap()
  1774. {
  1775. mapInfo = nullptr;
  1776. free = true;
  1777. }
  1778. ~SelectMap()
  1779. {
  1780. if(free)
  1781. delete mapInfo;
  1782. }
  1783. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1784. template <typename Handler> void serialize(Handler &h, const int version)
  1785. {
  1786. h & mapInfo;
  1787. }
  1788. };
  1789. struct UpdateStartOptions : public CPregamePackToPropagate
  1790. {
  1791. StartInfo *options;
  1792. bool free;
  1793. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1794. UpdateStartOptions(StartInfo &src)
  1795. {
  1796. options = &src;
  1797. free = false;
  1798. }
  1799. UpdateStartOptions()
  1800. {
  1801. options = nullptr;
  1802. free = true;
  1803. }
  1804. ~UpdateStartOptions()
  1805. {
  1806. if(free)
  1807. delete options;
  1808. }
  1809. template <typename Handler> void serialize(Handler &h, const int version)
  1810. {
  1811. h & options;
  1812. }
  1813. };
  1814. struct PregameGuiAction : public CPregamePackToPropagate
  1815. {
  1816. enum {NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST, OPEN_RANDOM_MAP_OPTIONS}
  1817. action;
  1818. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1819. template <typename Handler> void serialize(Handler &h, const int version)
  1820. {
  1821. h & action;
  1822. }
  1823. };
  1824. struct RequestOptionsChange : public CPregamePackToHost
  1825. {
  1826. enum EWhat {TOWN, HERO, BONUS};
  1827. ui8 what;
  1828. si8 direction; //-1 or +1
  1829. ui8 playerID;
  1830. RequestOptionsChange(ui8 What, si8 Dir, ui8 Player)
  1831. :what(What), direction(Dir), playerID(Player)
  1832. {}
  1833. RequestOptionsChange(){}
  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 & what & direction & playerID;
  1838. }
  1839. };
  1840. struct PlayerLeft : public CPregamePackToPropagate
  1841. {
  1842. ui8 playerID;
  1843. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1844. template <typename Handler> void serialize(Handler &h, const int version)
  1845. {
  1846. h & playerID;
  1847. }
  1848. };
  1849. struct PlayersNames : public CPregamePackToPropagate
  1850. {
  1851. public:
  1852. std::map<ui8, std::string> playerNames;
  1853. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1854. template <typename Handler> void serialize(Handler &h, const int version)
  1855. {
  1856. h & playerNames;
  1857. }
  1858. };
  1859. struct StartWithCurrentSettings : public CPregamePackToPropagate
  1860. {
  1861. public:
  1862. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1863. template <typename Handler> void serialize(Handler &h, const int version)
  1864. {
  1865. //h & playerNames;
  1866. }
  1867. };