NetPacks.h 55 KB

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