NetPacks.h 56 KB

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