NetPacks.h 56 KB

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