NetPacks.h 55 KB

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