NetPacks.h 55 KB

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