NetPacks.h 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285
  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. #include "spells/ViewSpellInt.h"
  17. /*
  18. * NetPacks.h, part of VCMI engine
  19. *
  20. * Authors: listed in file AUTHORS in main folder
  21. *
  22. * License: GNU General Public License v2.0 or later
  23. * Full text of license available in license.txt file, in main folder
  24. *
  25. */
  26. class CClient;
  27. class CGameState;
  28. class CGameHandler;
  29. class CConnection;
  30. class CCampaignState;
  31. class CArtifact;
  32. class CSelectionScreen;
  33. class CGObjectInstance;
  34. class CArtifactInstance;
  35. //class CMapInfo;
  36. struct StackLocation;
  37. struct ArtSlotInfo;
  38. struct QuestInfo;
  39. class CMapInfo;
  40. class StartInfo;
  41. struct CPackForClient : public CPack
  42. {
  43. CPackForClient(){type = 1;};
  44. CGameState* GS(CClient *cl);
  45. void applyFirstCl(CClient *cl)//called before applying to gs
  46. {}
  47. void applyCl(CClient *cl)//called after applying to gs
  48. {}
  49. };
  50. struct CPackForServer : public CPack
  51. {
  52. PlayerColor player;
  53. CConnection *c;
  54. CGameState* GS(CGameHandler *gh);
  55. CPackForServer():
  56. player(PlayerColor::NEUTRAL),
  57. c(nullptr)
  58. {
  59. type = 2;
  60. }
  61. bool applyGh(CGameHandler *gh) //called after applying to gs
  62. {
  63. logGlobal->errorStream() << "Should not happen... applying plain CPackForServer";
  64. return false;
  65. }
  66. };
  67. struct Query : public CPackForClient
  68. {
  69. QueryID queryID; // equals to -1 if it is not an actual query (and should not be answered)
  70. Query()
  71. {
  72. }
  73. };
  74. struct StackLocation
  75. {
  76. ConstTransitivePtr<CArmedInstance> army;
  77. SlotID slot;
  78. StackLocation()
  79. {}
  80. StackLocation(const CArmedInstance *Army, SlotID Slot):
  81. army(const_cast<CArmedInstance*>(Army)), //we are allowed here to const cast -> change will go through one of our packages... do not abuse!
  82. slot(Slot)
  83. {
  84. }
  85. DLL_LINKAGE const CStackInstance *getStack();
  86. template <typename Handler> void serialize(Handler &h, const int version)
  87. {
  88. h & army & slot;
  89. }
  90. };
  91. /***********************************************************************************************************/
  92. struct PackageApplied : public CPackForClient //94
  93. {
  94. PackageApplied() {type = 94;}
  95. PackageApplied(ui8 Result) : result(Result) {type = 94;}
  96. void applyCl(CClient *cl);
  97. ui8 result; //0 - something went wrong, request hasn't been realized; 1 - OK
  98. ui32 packType; //type id of applied package
  99. ui32 requestID; //an ID given by client to the request that was applied
  100. PlayerColor player;
  101. template <typename Handler> void serialize(Handler &h, const int version)
  102. {
  103. h & result & packType & requestID & player;
  104. }
  105. };
  106. struct SystemMessage : public CPackForClient //95
  107. {
  108. SystemMessage(const std::string & Text) : text(Text){type = 95;};
  109. SystemMessage(){type = 95;};
  110. void applyCl(CClient *cl);
  111. std::string text;
  112. template <typename Handler> void serialize(Handler &h, const int version)
  113. {
  114. h & text;
  115. }
  116. };
  117. struct PlayerBlocked : public CPackForClient //96
  118. {
  119. PlayerBlocked(){type = 96;};
  120. void applyCl(CClient *cl);
  121. enum EReason { UPCOMING_BATTLE, ONGOING_MOVEMENT };
  122. enum EMode { BLOCKADE_STARTED, BLOCKADE_ENDED };
  123. EReason reason;
  124. EMode startOrEnd;
  125. PlayerColor player;
  126. template <typename Handler> void serialize(Handler &h, const int version)
  127. {
  128. h & reason & startOrEnd & player;
  129. }
  130. };
  131. struct YourTurn : public CPackForClient //100
  132. {
  133. YourTurn(){type = 100;};
  134. void applyCl(CClient *cl);
  135. DLL_LINKAGE void applyGs(CGameState *gs);
  136. PlayerColor player;
  137. template <typename Handler> void serialize(Handler &h, const int version)
  138. {
  139. h & player;
  140. }
  141. };
  142. struct SetResource : public CPackForClient //102
  143. {
  144. SetResource(){type = 102;};
  145. void applyCl(CClient *cl);
  146. DLL_LINKAGE void applyGs(CGameState *gs);
  147. PlayerColor player;
  148. Res::ERes resid;
  149. TResourceCap val;
  150. template <typename Handler> void serialize(Handler &h, const int version)
  151. {
  152. h & player & resid & val;
  153. }
  154. };
  155. struct SetResources : public CPackForClient //104
  156. {
  157. SetResources(){type = 104;};
  158. void applyCl(CClient *cl);
  159. DLL_LINKAGE void applyGs(CGameState *gs);
  160. PlayerColor player;
  161. TResources res; //res[resid] => res amount
  162. template <typename Handler> void serialize(Handler &h, const int version)
  163. {
  164. h & player & res;
  165. }
  166. };
  167. struct SetPrimSkill : public CPackForClient //105
  168. {
  169. SetPrimSkill(){type = 105;};
  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 //106
  182. {
  183. SetSecSkill(){type = 106;};
  184. void applyCl(CClient *cl);
  185. DLL_LINKAGE void applyGs(CGameState *gs);
  186. ui8 abs; //0 - changes by value; 1 - sets to value
  187. ObjectInstanceID id;
  188. SecondarySkill which;
  189. ui16 val;
  190. template <typename Handler> void serialize(Handler &h, const int version)
  191. {
  192. h & abs & id & which & val;
  193. }
  194. };
  195. struct HeroVisitCastle : public CPackForClient //108
  196. {
  197. HeroVisitCastle(){flags=0;type = 108;};
  198. void applyCl(CClient *cl);
  199. DLL_LINKAGE void applyGs(CGameState *gs);
  200. ui8 flags; //1 - start
  201. ObjectInstanceID tid, hid;
  202. bool start() //if hero is entering castle (if false - leaving)
  203. {
  204. return flags & 1;
  205. }
  206. // bool garrison() //if hero is entering/leaving garrison (if false - it's only visiting hero)
  207. // {
  208. // return flags & 2;
  209. // }
  210. template <typename Handler> void serialize(Handler &h, const int version)
  211. {
  212. h & flags & tid & hid;
  213. }
  214. };
  215. struct ChangeSpells : public CPackForClient //109
  216. {
  217. ChangeSpells(){type = 109;};
  218. void applyCl(CClient *cl);
  219. DLL_LINKAGE void applyGs(CGameState *gs);
  220. ui8 learn; //1 - gives spell, 0 - takes
  221. ObjectInstanceID hid;
  222. std::set<SpellID> spells;
  223. template <typename Handler> void serialize(Handler &h, const int version)
  224. {
  225. h & learn & hid & spells;
  226. }
  227. };
  228. struct SetMana : public CPackForClient //110
  229. {
  230. SetMana(){type = 110;absolute=true;};
  231. void applyCl(CClient *cl);
  232. DLL_LINKAGE void applyGs(CGameState *gs);
  233. ObjectInstanceID hid;
  234. si32 val;
  235. bool absolute;
  236. template <typename Handler> void serialize(Handler &h, const int version)
  237. {
  238. h & val & hid & absolute;
  239. }
  240. };
  241. struct SetMovePoints : public CPackForClient //111
  242. {
  243. SetMovePoints(){type = 111;};
  244. void applyCl(CClient *cl);
  245. DLL_LINKAGE void applyGs(CGameState *gs);
  246. ObjectInstanceID hid;
  247. si32 val;
  248. template <typename Handler> void serialize(Handler &h, const int version)
  249. {
  250. h & val & hid;
  251. }
  252. };
  253. struct FoWChange : public CPackForClient //112
  254. {
  255. FoWChange(){type = 112;waitForDialogs = false;};
  256. void applyCl(CClient *cl);
  257. DLL_LINKAGE void applyGs(CGameState *gs);
  258. std::unordered_set<int3, struct ShashInt3 > tiles;
  259. PlayerColor player;
  260. ui8 mode; //mode==0 - hide, mode==1 - reveal
  261. bool waitForDialogs;
  262. template <typename Handler> void serialize(Handler &h, const int version)
  263. {
  264. h & tiles & player & mode & waitForDialogs;
  265. }
  266. };
  267. struct SetAvailableHeroes : public CPackForClient //113
  268. {
  269. SetAvailableHeroes()
  270. {
  271. type = 113;
  272. for (int i = 0; i < GameConstants::AVAILABLE_HEROES_PER_PLAYER; i++)
  273. army[i].clear();
  274. }
  275. ~SetAvailableHeroes()
  276. {
  277. }
  278. void applyCl(CClient *cl);
  279. DLL_LINKAGE void applyGs(CGameState *gs);
  280. PlayerColor player;
  281. si32 hid[GameConstants::AVAILABLE_HEROES_PER_PLAYER]; //-1 if no hero
  282. CSimpleArmy army[GameConstants::AVAILABLE_HEROES_PER_PLAYER];
  283. template <typename Handler> void serialize(Handler &h, const int version)
  284. {
  285. h & player & hid & army;
  286. }
  287. };
  288. struct GiveBonus : public CPackForClient //115
  289. {
  290. GiveBonus(ui8 Who = 0)
  291. {
  292. who = Who;
  293. type = 115;
  294. }
  295. void applyCl(CClient *cl);
  296. DLL_LINKAGE void applyGs(CGameState *gs);
  297. enum {HERO, PLAYER, TOWN};
  298. ui8 who; //who receives bonus, uses enum above
  299. si32 id; //hero. town or player id - whoever receives it
  300. Bonus bonus;
  301. MetaString bdescr;
  302. template <typename Handler> void serialize(Handler &h, const int version)
  303. {
  304. h & bonus & id & bdescr & who;
  305. }
  306. };
  307. struct ChangeObjPos : public CPackForClient //116
  308. {
  309. ChangeObjPos()
  310. {
  311. type = 116;
  312. flags = 0;
  313. }
  314. void applyFirstCl(CClient *cl);
  315. void applyCl(CClient *cl);
  316. DLL_LINKAGE void applyGs(CGameState *gs);
  317. ObjectInstanceID objid;
  318. int3 nPos;
  319. ui8 flags; //bit flags: 1 - redraw
  320. template <typename Handler> void serialize(Handler &h, const int version)
  321. {
  322. h & objid & nPos & flags;
  323. }
  324. };
  325. struct PlayerEndsGame : public CPackForClient //117
  326. {
  327. PlayerEndsGame()
  328. {
  329. type = 117;
  330. }
  331. void applyCl(CClient *cl);
  332. DLL_LINKAGE void applyGs(CGameState *gs);
  333. PlayerColor player;
  334. EVictoryLossCheckResult victoryLossCheckResult;
  335. template <typename Handler> void serialize(Handler &h, const int version)
  336. {
  337. h & player & victoryLossCheckResult;
  338. }
  339. };
  340. struct RemoveBonus : public CPackForClient //118
  341. {
  342. RemoveBonus(ui8 Who = 0)
  343. {
  344. who = Who;
  345. type = 118;
  346. }
  347. void applyCl(CClient *cl);
  348. DLL_LINKAGE void applyGs(CGameState *gs);
  349. enum {HERO, PLAYER, TOWN};
  350. ui8 who; //who receives bonus, uses enum above
  351. ui32 whoID; //hero, town or player id - whoever loses bonus
  352. //vars to identify bonus: its source
  353. ui8 source;
  354. ui32 id; //source id
  355. //used locally: copy of removed bonus
  356. Bonus bonus;
  357. template <typename Handler> void serialize(Handler &h, const int version)
  358. {
  359. h & source & id & who & whoID;
  360. }
  361. };
  362. struct UpdateCampaignState : public CPackForClient //119
  363. {
  364. UpdateCampaignState()
  365. {
  366. type = 119;
  367. }
  368. shared_ptr<CCampaignState> camp;
  369. void applyCl(CClient *cl);
  370. template <typename Handler> void serialize(Handler &h, const int version)
  371. {
  372. h & camp;
  373. }
  374. };
  375. struct SetCommanderProperty : public CPackForClient //120
  376. {
  377. enum ECommanderProperty {ALIVE, BONUS, SECONDARY_SKILL, EXPERIENCE, SPECIAL_SKILL};
  378. SetCommanderProperty(){type = 120;};
  379. void applyCl(CClient *cl){};
  380. DLL_LINKAGE void applyGs(CGameState *gs);
  381. ObjectInstanceID heroid; //for commander attached to hero
  382. StackLocation sl; //for commander not on the hero?
  383. ECommanderProperty which;
  384. TExpType amount; //0 for dead, >0 for alive
  385. si32 additionalInfo; //for secondary skills choice
  386. Bonus accumulatedBonus;
  387. template <typename Handler> void serialize(Handler &h, const int version)
  388. {
  389. h & heroid & sl & which & amount & additionalInfo & accumulatedBonus;
  390. }
  391. };
  392. struct AddQuest : public CPackForClient //121
  393. {
  394. AddQuest(){type = 121;};
  395. void applyCl(CClient *cl){};
  396. DLL_LINKAGE void applyGs(CGameState *gs);
  397. PlayerColor player;
  398. QuestInfo quest;
  399. template <typename Handler> void serialize(Handler &h, const int version)
  400. {
  401. h & player & quest;
  402. }
  403. };
  404. struct PrepareForAdvancingCampaign : public CPackForClient //122
  405. {
  406. PrepareForAdvancingCampaign() {type = 122;}
  407. void applyCl(CClient *cl);
  408. template <typename Handler> void serialize(Handler &h, const int version)
  409. {
  410. }
  411. };
  412. struct UpdateArtHandlerLists : public CPackForClient //123
  413. {
  414. UpdateArtHandlerLists(){type = 123;};
  415. std::vector<CArtifact*> treasures, minors, majors, relics;
  416. DLL_LINKAGE void applyGs(CGameState *gs);
  417. template <typename Handler> void serialize(Handler &h, const int version)
  418. {
  419. h & treasures & minors & majors & relics;
  420. }
  421. };
  422. struct UpdateMapEvents : public CPackForClient //124
  423. {
  424. UpdateMapEvents(){type = 124;}
  425. std::list<CMapEvent> events;
  426. DLL_LINKAGE void applyGs(CGameState *gs);
  427. template <typename Handler> void serialize(Handler &h, const int version)
  428. {
  429. h & events;
  430. }
  431. };
  432. struct UpdateCastleEvents : public CPackForClient //125
  433. {
  434. UpdateCastleEvents(){type = 125;}
  435. ObjectInstanceID town;
  436. std::list<CCastleEvent> events;
  437. DLL_LINKAGE void applyGs(CGameState *gs);
  438. template <typename Handler> void serialize(Handler &h, const int version)
  439. {
  440. h & town & events;
  441. }
  442. };
  443. struct RemoveObject : public CPackForClient //500
  444. {
  445. RemoveObject(){type = 500;};
  446. RemoveObject(ObjectInstanceID ID){id = ID;type = 500;};
  447. void applyFirstCl(CClient *cl);
  448. void applyCl(CClient *cl);
  449. DLL_LINKAGE void applyGs(CGameState *gs);
  450. ObjectInstanceID id;
  451. template <typename Handler> void serialize(Handler &h, const int version)
  452. {
  453. h & id;
  454. }
  455. };
  456. struct TryMoveHero : public CPackForClient //501
  457. {
  458. TryMoveHero(){type = 501;humanKnows=false;};
  459. void applyFirstCl(CClient *cl);
  460. void applyCl(CClient *cl);
  461. void applyGs(CGameState *gs);
  462. enum EResult
  463. {
  464. FAILED, SUCCESS, TELEPORTATION, RESERVED___, BLOCKING_VISIT, EMBARK, DISEMBARK
  465. };
  466. ObjectInstanceID id;
  467. ui32 movePoints;
  468. EResult result; //uses EResult
  469. int3 start, end; //h3m format
  470. std::unordered_set<int3, ShashInt3> fowRevealed; //revealed tiles
  471. boost::optional<int3> attackedFrom; // Set when stepping into endangered tile.
  472. bool humanKnows; //used locally during applying to client
  473. template <typename Handler> void serialize(Handler &h, const int version)
  474. {
  475. h & id & result & start & end & movePoints & fowRevealed & attackedFrom;
  476. }
  477. };
  478. // struct SetGarrisons : public CPackForClient //502
  479. // {
  480. // SetGarrisons(){type = 502;};
  481. // void applyCl(CClient *cl);
  482. // DLL_LINKAGE void applyGs(CGameState *gs);
  483. //
  484. // std::map<ui32,CCreatureSet> garrs;
  485. //
  486. // template <typename Handler> void serialize(Handler &h, const int version)
  487. // {
  488. // h & garrs;
  489. // }
  490. // };
  491. struct NewStructures : public CPackForClient //504
  492. {
  493. NewStructures(){type = 504;};
  494. void applyCl(CClient *cl);
  495. DLL_LINKAGE void applyGs(CGameState *gs);
  496. ObjectInstanceID tid;
  497. std::set<BuildingID> bid;
  498. si16 builded;
  499. template <typename Handler> void serialize(Handler &h, const int version)
  500. {
  501. h & tid & bid & builded;
  502. }
  503. };
  504. struct RazeStructures : public CPackForClient //505
  505. {
  506. RazeStructures() {type = 505;};
  507. void applyCl (CClient *cl);
  508. DLL_LINKAGE void applyGs(CGameState *gs);
  509. ObjectInstanceID tid;
  510. std::set<BuildingID> bid;
  511. si16 destroyed;
  512. template <typename Handler> void serialize(Handler &h, const int version)
  513. {
  514. h & tid & bid & destroyed;
  515. }
  516. };
  517. struct SetAvailableCreatures : public CPackForClient //506
  518. {
  519. SetAvailableCreatures(){type = 506;};
  520. void applyCl(CClient *cl);
  521. DLL_LINKAGE void applyGs(CGameState *gs);
  522. ObjectInstanceID tid;
  523. std::vector<std::pair<ui32, std::vector<CreatureID> > > creatures;
  524. template <typename Handler> void serialize(Handler &h, const int version)
  525. {
  526. h & tid & creatures;
  527. }
  528. };
  529. struct SetHeroesInTown : public CPackForClient //508
  530. {
  531. SetHeroesInTown(){type = 508;};
  532. void applyCl(CClient *cl);
  533. DLL_LINKAGE void applyGs(CGameState *gs);
  534. ObjectInstanceID tid, visiting, garrison; //id of town, visiting hero, hero in garrison
  535. template <typename Handler> void serialize(Handler &h, const int version)
  536. {
  537. h & tid & visiting & garrison;
  538. }
  539. };
  540. // struct SetHeroArtifacts : public CPackForClient //509
  541. // {
  542. // SetHeroArtifacts(){type = 509;};
  543. // void applyCl(CClient *cl);
  544. // DLL_LINKAGE void applyGs(CGameState *gs);
  545. // DLL_LINKAGE void setArtAtPos(ui16 pos, const CArtifact* art);
  546. //
  547. // si32 hid;
  548. // std::vector<const CArtifact*> artifacts; //hero's artifacts from bag
  549. // 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
  550. //
  551. // template <typename Handler> void serialize(Handler &h, const int version)
  552. // {
  553. // h & hid & artifacts & artifWorn;
  554. // }
  555. //
  556. // std::vector<const CArtifact*> equipped, unequipped; //used locally
  557. // BonusList gained, lost; //used locally as hlp when applying
  558. // };
  559. struct HeroRecruited : public CPackForClient //515
  560. {
  561. HeroRecruited(){type = 515;};
  562. void applyCl(CClient *cl);
  563. DLL_LINKAGE void applyGs(CGameState *gs);
  564. si32 hid;//subID of hero
  565. ObjectInstanceID tid;
  566. int3 tile;
  567. PlayerColor player;
  568. template <typename Handler> void serialize(Handler &h, const int version)
  569. {
  570. h & hid & tid & tile & player;
  571. }
  572. };
  573. struct GiveHero : public CPackForClient //516
  574. {
  575. GiveHero(){type = 516;};
  576. void applyFirstCl(CClient *cl);
  577. void applyCl(CClient *cl);
  578. DLL_LINKAGE void applyGs(CGameState *gs);
  579. ObjectInstanceID id; //object id
  580. PlayerColor player;
  581. template <typename Handler> void serialize(Handler &h, const int version)
  582. {
  583. h & id & player;
  584. }
  585. };
  586. struct OpenWindow : public CPackForClient //517
  587. {
  588. OpenWindow(){type = 517;};
  589. void applyCl(CClient *cl);
  590. enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL, SHIPYARD_WINDOW, THIEVES_GUILD,
  591. UNIVERSITY_WINDOW, HILL_FORT_WINDOW, MARKET_WINDOW, PUZZLE_MAP, TAVERN_WINDOW};
  592. ui8 window;
  593. si32 id1, id2;
  594. template <typename Handler> void serialize(Handler &h, const int version)
  595. {
  596. h & window & id1 & id2;
  597. }
  598. };
  599. struct NewObject : public CPackForClient //518
  600. {
  601. NewObject()
  602. {
  603. type = 518;
  604. }
  605. void applyCl(CClient *cl);
  606. DLL_LINKAGE void applyGs(CGameState *gs);
  607. Obj ID;
  608. ui32 subID;
  609. int3 pos;
  610. ObjectInstanceID id; //used locally, filled during applyGs
  611. template <typename Handler> void serialize(Handler &h, const int version)
  612. {
  613. h & ID & subID & pos;
  614. }
  615. };
  616. struct SetAvailableArtifacts : public CPackForClient //519
  617. {
  618. SetAvailableArtifacts(){type = 519;};
  619. void applyCl(CClient *cl);
  620. DLL_LINKAGE void applyGs(CGameState *gs);
  621. 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)
  622. std::vector<const CArtifact *> arts;
  623. template <typename Handler> void serialize(Handler &h, const int version)
  624. {
  625. h & id & arts;
  626. }
  627. };
  628. struct NewArtifact : public CPackForClient //520
  629. {
  630. NewArtifact(){type = 520;};
  631. //void applyCl(CClient *cl);
  632. DLL_LINKAGE void applyGs(CGameState *gs);
  633. ConstTransitivePtr<CArtifactInstance> art;
  634. template <typename Handler> void serialize(Handler &h, const int version)
  635. {
  636. h & art;
  637. }
  638. };
  639. struct CGarrisonOperationPack : CPackForClient
  640. {
  641. };
  642. struct CArtifactOperationPack : CPackForClient
  643. {
  644. };
  645. struct ChangeStackCount : CGarrisonOperationPack //521
  646. {
  647. StackLocation sl;
  648. TQuantity count;
  649. ui8 absoluteValue; //if not -> count will be added (or subtracted if negative)
  650. void applyCl(CClient *cl);
  651. DLL_LINKAGE void applyGs(CGameState *gs);
  652. template <typename Handler> void serialize(Handler &h, const int version)
  653. {
  654. h & sl & count & absoluteValue;
  655. }
  656. };
  657. struct SetStackType : CGarrisonOperationPack //522
  658. {
  659. StackLocation sl;
  660. const CCreature *type;
  661. void applyCl(CClient *cl);
  662. DLL_LINKAGE void applyGs(CGameState *gs);
  663. template <typename Handler> void serialize(Handler &h, const int version)
  664. {
  665. h & sl & type;
  666. }
  667. };
  668. struct EraseStack : CGarrisonOperationPack //523
  669. {
  670. StackLocation sl;
  671. void applyCl(CClient *cl);
  672. DLL_LINKAGE void applyGs(CGameState *gs);
  673. template <typename Handler> void serialize(Handler &h, const int version)
  674. {
  675. h & sl;
  676. }
  677. };
  678. struct SwapStacks : CGarrisonOperationPack //524
  679. {
  680. StackLocation sl1, sl2;
  681. void applyCl(CClient *cl);
  682. DLL_LINKAGE void applyGs(CGameState *gs);
  683. template <typename Handler> void serialize(Handler &h, const int version)
  684. {
  685. h & sl1 & sl2;
  686. }
  687. };
  688. struct InsertNewStack : CGarrisonOperationPack //525
  689. {
  690. StackLocation sl;
  691. CStackBasicDescriptor stack;
  692. void applyCl(CClient *cl);
  693. DLL_LINKAGE void applyGs(CGameState *gs);
  694. template <typename Handler> void serialize(Handler &h, const int version)
  695. {
  696. h & sl & stack;
  697. }
  698. };
  699. //moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  700. struct RebalanceStacks : CGarrisonOperationPack //526
  701. {
  702. StackLocation src, dst;
  703. TQuantity count;
  704. void applyCl(CClient *cl);
  705. DLL_LINKAGE void applyGs(CGameState *gs);
  706. template <typename Handler> void serialize(Handler &h, const int version)
  707. {
  708. h & src & dst & count;
  709. }
  710. };
  711. struct GetEngagedHeroIds : boost::static_visitor<boost::optional<ObjectInstanceID>>
  712. {
  713. boost::optional<ObjectInstanceID> operator()(const ConstTransitivePtr<CGHeroInstance> &h) const
  714. {
  715. return h->id;
  716. }
  717. boost::optional<ObjectInstanceID> operator()(const ConstTransitivePtr<CStackInstance> &s) const
  718. {
  719. if(s->armyObj && s->armyObj->ID == Obj::HERO)
  720. return s->armyObj->id;
  721. return boost::optional<ObjectInstanceID>();
  722. }
  723. };
  724. struct PutArtifact : CArtifactOperationPack //526
  725. {
  726. ArtifactLocation al;
  727. ConstTransitivePtr<CArtifactInstance> art;
  728. void applyCl(CClient *cl);
  729. DLL_LINKAGE void applyGs(CGameState *gs);
  730. template <typename Handler> void serialize(Handler &h, const int version)
  731. {
  732. h & al & art;
  733. }
  734. };
  735. struct EraseArtifact : CArtifactOperationPack //527
  736. {
  737. ArtifactLocation al;
  738. void applyCl(CClient *cl);
  739. DLL_LINKAGE void applyGs(CGameState *gs);
  740. template <typename Handler> void serialize(Handler &h, const int version)
  741. {
  742. h & al;
  743. }
  744. };
  745. struct MoveArtifact : CArtifactOperationPack //528
  746. {
  747. ArtifactLocation src, dst;
  748. void applyCl(CClient *cl);
  749. DLL_LINKAGE void applyGs(CGameState *gs);
  750. template <typename Handler> void serialize(Handler &h, const int version)
  751. {
  752. h & src & dst;
  753. }
  754. };
  755. struct AssembledArtifact : CArtifactOperationPack //529
  756. {
  757. ArtifactLocation al; //where assembly will be put
  758. CArtifact *builtArt;
  759. //std::vector<CArtifactInstance *> constituents;
  760. void applyCl(CClient *cl);
  761. DLL_LINKAGE void applyGs(CGameState *gs);
  762. template <typename Handler> void serialize(Handler &h, const int version)
  763. {
  764. h & al & builtArt/* & constituents*/;
  765. }
  766. };
  767. struct DisassembledArtifact : CArtifactOperationPack //530
  768. {
  769. ArtifactLocation al;
  770. void applyCl(CClient *cl);
  771. DLL_LINKAGE void applyGs(CGameState *gs);
  772. template <typename Handler> void serialize(Handler &h, const int version)
  773. {
  774. h & al;
  775. }
  776. };
  777. struct HeroVisit : CPackForClient //531
  778. {
  779. const CGHeroInstance *hero;
  780. const CGObjectInstance *obj;
  781. PlayerColor player; //if hero was killed during the visit, its color is already reset
  782. bool starting; //false -> ending
  783. void applyCl(CClient *cl);
  784. DLL_LINKAGE void applyGs(CGameState *gs);
  785. template <typename Handler> void serialize(Handler &h, const int version)
  786. {
  787. h & hero & obj & player & starting;
  788. }
  789. };
  790. struct NewTurn : public CPackForClient //101
  791. {
  792. enum weekType {NORMAL, DOUBLE_GROWTH, BONUS_GROWTH, DEITYOFFIRE, PLAGUE, NO_ACTION};
  793. void applyCl(CClient *cl);
  794. DLL_LINKAGE void applyGs(CGameState *gs);
  795. struct Hero
  796. {
  797. ObjectInstanceID id;
  798. ui32 move, mana; //id is a general serial id
  799. template <typename Handler> void serialize(Handler &h, const int version)
  800. {
  801. h & id & move & mana;
  802. }
  803. bool operator<(const Hero&h)const{return id < h.id;}
  804. };
  805. std::set<Hero> heroes; //updates movement and mana points
  806. //std::vector<SetResources> res;//resource list
  807. std::map<PlayerColor, TResources> res; //player ID => resource value[res_id]
  808. std::map<ObjectInstanceID, SetAvailableCreatures> cres;//creatures to be placed in towns
  809. ui32 day;
  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 & 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. bool 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. ///custom effect (resistance, reflection, etc)
  1226. struct CustomEffect
  1227. {
  1228. /// WoG AC format
  1229. ui32 effect;
  1230. ui32 stack;
  1231. template <typename Handler> void serialize(Handler &h, const int version)
  1232. {
  1233. h & effect & stack;
  1234. }
  1235. };
  1236. BattleSpellCast(){type = 3009; casterStack = -1;};
  1237. DLL_LINKAGE void applyGs(CGameState *gs);
  1238. void applyCl(CClient *cl);
  1239. si32 dmgToDisplay; //this amount will be displayed as amount of damage dealt by spell
  1240. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  1241. ui32 id; //id of spell
  1242. ui8 skill; //caster's skill level
  1243. ui8 manaGained; //mana channeling ability
  1244. BattleHex tile; //destination tile (may not be set in some global/mass spells
  1245. std::vector<CustomEffect> customEffects;
  1246. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  1247. si32 casterStack;// -1 if not cated by creature, >=0 caster stack ID
  1248. bool castByHero; //if true - spell has been cast by hero, otherwise by a creature
  1249. template <typename Handler> void serialize(Handler &h, const int version)
  1250. {
  1251. h & dmgToDisplay & side & id & skill & manaGained & tile & customEffects & affectedCres & casterStack & castByHero;
  1252. }
  1253. };
  1254. struct SetStackEffect : public CPackForClient //3010
  1255. {
  1256. SetStackEffect(){type = 3010;};
  1257. DLL_LINKAGE void applyGs(CGameState *gs);
  1258. void applyCl(CClient *cl);
  1259. std::vector<ui32> stacks; //affected stacks (IDs)
  1260. std::vector<Bonus> effect; //bonuses to apply
  1261. std::vector<std::pair<ui32, Bonus> > uniqueBonuses; //bonuses per single stack
  1262. template <typename Handler> void serialize(Handler &h, const int version)
  1263. {
  1264. h & stacks & effect & uniqueBonuses;
  1265. }
  1266. };
  1267. struct StacksInjured : public CPackForClient //3011
  1268. {
  1269. StacksInjured(){type = 3011;}
  1270. DLL_LINKAGE void applyGs(CGameState *gs);
  1271. void applyCl(CClient *cl);
  1272. std::vector<BattleStackAttacked> stacks;
  1273. template <typename Handler> void serialize(Handler &h, const int version)
  1274. {
  1275. h & stacks;
  1276. }
  1277. };
  1278. struct BattleResultsApplied : public CPackForClient //3012
  1279. {
  1280. BattleResultsApplied(){type = 3012;}
  1281. PlayerColor player1, player2;
  1282. void applyCl(CClient *cl);
  1283. template <typename Handler> void serialize(Handler &h, const int version)
  1284. {
  1285. h & player1 & player2;
  1286. }
  1287. };
  1288. struct ObstaclesRemoved : public CPackForClient //3014
  1289. {
  1290. ObstaclesRemoved(){type = 3014;}
  1291. DLL_LINKAGE void applyGs(CGameState *gs);
  1292. void applyCl(CClient *cl);
  1293. std::set<si32> obstacles; //uniqueIDs of removed obstacles
  1294. template <typename Handler> void serialize(Handler &h, const int version)
  1295. {
  1296. h & obstacles;
  1297. }
  1298. };
  1299. struct ELF_VISIBILITY CatapultAttack : public CPackForClient //3015
  1300. {
  1301. struct AttackInfo
  1302. {
  1303. si16 destinationTile;
  1304. ui8 attackedPart;
  1305. ui8 damageDealt;
  1306. DLL_LINKAGE std::string toString() const;
  1307. template <typename Handler> void serialize(Handler &h, const int version)
  1308. {
  1309. h & destinationTile & attackedPart & damageDealt;
  1310. }
  1311. };
  1312. DLL_LINKAGE CatapultAttack();
  1313. DLL_LINKAGE ~CatapultAttack();
  1314. DLL_LINKAGE void applyGs(CGameState *gs);
  1315. void applyCl(CClient *cl);
  1316. DLL_LINKAGE std::string toString() const override;
  1317. std::vector< AttackInfo > attackedParts;
  1318. int attacker; //if -1, then a spell caused this
  1319. template <typename Handler> void serialize(Handler &h, const int version)
  1320. {
  1321. h & attackedParts & attacker;
  1322. }
  1323. };
  1324. DLL_LINKAGE std::ostream & operator<<(std::ostream & out, const CatapultAttack::AttackInfo & attackInfo);
  1325. struct BattleStacksRemoved : public CPackForClient //3016
  1326. {
  1327. BattleStacksRemoved(){type = 3016;}
  1328. DLL_LINKAGE void applyGs(CGameState *gs);
  1329. void applyFirstCl(CClient *cl);//inform client before stack objects are destroyed
  1330. std::set<ui32> stackIDs; //IDs of removed stacks
  1331. template <typename Handler> void serialize(Handler &h, const int version)
  1332. {
  1333. h & stackIDs;
  1334. }
  1335. };
  1336. struct BattleStackAdded : public CPackForClient //3017
  1337. {
  1338. BattleStackAdded(){type = 3017;};
  1339. DLL_LINKAGE void applyGs(CGameState *gs);
  1340. void applyCl(CClient *cl);
  1341. int attacker; // if true, stack belongs to attacker
  1342. CreatureID creID;
  1343. int amount;
  1344. int pos;
  1345. int summoned; //if true, remove it afterwards
  1346. ///Actual stack ID, set on apply, do not serialize
  1347. int newStackID;
  1348. template <typename Handler> void serialize(Handler &h, const int version)
  1349. {
  1350. h & attacker & creID & amount & pos & summoned;
  1351. }
  1352. };
  1353. struct BattleSetStackProperty : public CPackForClient //3018
  1354. {
  1355. BattleSetStackProperty(){type = 3018;};
  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. struct BattleTriggerEffect : public CPackForClient //3019
  1368. { //activated at the beginning of turn
  1369. BattleTriggerEffect(){type = 3019;};
  1370. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1371. void applyCl(CClient *cl); //play animations & stuff
  1372. //enum BattleEffect {REGENERATION, MANA_DRAIN, FEAR, MANA_CHANNELING, ENCHANTER, UNBIND, POISON, ENCHANTED, SUMMONER};
  1373. int stackID;
  1374. int effect; //use enumBattleEffect or corresponding Bonus type for sanity?
  1375. int val;
  1376. int additionalInfo;
  1377. template <typename Handler> void serialize(Handler &h, const int version)
  1378. {
  1379. h & stackID & effect & val & additionalInfo;
  1380. }
  1381. };
  1382. struct BattleObstaclePlaced : public CPackForClient //3020
  1383. { //activated at the beginning of turn
  1384. BattleObstaclePlaced(){type = 3020;};
  1385. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1386. void applyCl(CClient *cl); //play animations & stuff
  1387. shared_ptr<CObstacleInstance> obstacle;
  1388. template <typename Handler> void serialize(Handler &h, const int version)
  1389. {
  1390. h & obstacle;
  1391. }
  1392. };
  1393. struct ShowInInfobox : public CPackForClient //107
  1394. {
  1395. ShowInInfobox(){type = 107;};
  1396. PlayerColor player;
  1397. Component c;
  1398. MetaString text;
  1399. void applyCl(CClient *cl);
  1400. template <typename Handler> void serialize(Handler &h, const int version)
  1401. {
  1402. h & player & c & text;
  1403. }
  1404. };
  1405. struct AdvmapSpellCast : public CPackForClient //108
  1406. {
  1407. AdvmapSpellCast(){type = 108;}
  1408. const CGHeroInstance * caster;
  1409. SpellID spellID;
  1410. void applyCl(CClient *cl);
  1411. template <typename Handler> void serialize(Handler &h, const int version)
  1412. {
  1413. h & caster & spellID;
  1414. }
  1415. };
  1416. struct ShowWorldViewEx : public CPackForClient //4000
  1417. {
  1418. PlayerColor player;
  1419. std::vector<ObjectPosInfo> objectPositions;
  1420. ShowWorldViewEx(){type = 4000;}
  1421. void applyCl(CClient *cl);
  1422. template <typename Handler> void serialize(Handler &h, const int version)
  1423. {
  1424. h & player & objectPositions;
  1425. }
  1426. };
  1427. /***********************************************************************************************************/
  1428. struct CommitPackage : public CPackForServer
  1429. {
  1430. bool freePack; //for local usage, DO NOT serialize
  1431. bool applyGh(CGameHandler *gh);
  1432. CPackForClient *packToCommit;
  1433. CommitPackage()
  1434. {
  1435. freePack = true;
  1436. }
  1437. ~CommitPackage()
  1438. {
  1439. if(freePack)
  1440. delete packToCommit;
  1441. }
  1442. template <typename Handler> void serialize(Handler &h, const int version)
  1443. {
  1444. h & packToCommit;
  1445. }
  1446. };
  1447. struct CloseServer : public CPackForServer
  1448. {
  1449. bool applyGh(CGameHandler *gh);
  1450. template <typename Handler> void serialize(Handler &h, const int version)
  1451. {}
  1452. };
  1453. struct EndTurn : public CPackForServer
  1454. {
  1455. bool applyGh(CGameHandler *gh);
  1456. template <typename Handler> void serialize(Handler &h, const int version)
  1457. {}
  1458. };
  1459. struct DismissHero : public CPackForServer
  1460. {
  1461. DismissHero(){};
  1462. DismissHero(ObjectInstanceID HID) : hid(HID) {};
  1463. ObjectInstanceID hid;
  1464. bool applyGh(CGameHandler *gh);
  1465. template <typename Handler> void serialize(Handler &h, const int version)
  1466. {
  1467. h & hid;
  1468. }
  1469. };
  1470. struct MoveHero : public CPackForServer
  1471. {
  1472. MoveHero(){};
  1473. MoveHero(const int3 &Dest, ObjectInstanceID HID, bool Transit) : dest(Dest), hid(HID), transit(Transit) {};
  1474. int3 dest;
  1475. ObjectInstanceID hid;
  1476. bool transit;
  1477. bool applyGh(CGameHandler *gh);
  1478. template <typename Handler> void serialize(Handler &h, const int version)
  1479. {
  1480. h & dest & hid & transit;
  1481. }
  1482. };
  1483. struct CastleTeleportHero : public CPackForServer
  1484. {
  1485. CastleTeleportHero(){};
  1486. CastleTeleportHero(const ObjectInstanceID HID, ObjectInstanceID Dest, ui8 Source ) : dest(Dest), hid(HID), source(Source){};
  1487. ObjectInstanceID dest;
  1488. ObjectInstanceID hid;
  1489. si8 source;//who give teleporting, 1=castle gate
  1490. bool applyGh(CGameHandler *gh);
  1491. template <typename Handler> void serialize(Handler &h, const int version)
  1492. {
  1493. h & dest & hid;
  1494. }
  1495. };
  1496. struct ArrangeStacks : public CPackForServer
  1497. {
  1498. ArrangeStacks(){};
  1499. ArrangeStacks(ui8 W, SlotID P1, SlotID P2, ObjectInstanceID ID1, ObjectInstanceID ID2, si32 VAL)
  1500. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  1501. ui8 what; //1 - swap; 2 - merge; 3 - split
  1502. SlotID p1, p2; //positions of first and second stack
  1503. ObjectInstanceID id1, id2; //ids of objects with garrison
  1504. si32 val;
  1505. bool applyGh(CGameHandler *gh);
  1506. template <typename Handler> void serialize(Handler &h, const int version)
  1507. {
  1508. h & what & p1 & p2 & id1 & id2 & val;
  1509. }
  1510. };
  1511. struct DisbandCreature : public CPackForServer
  1512. {
  1513. DisbandCreature(){};
  1514. DisbandCreature(SlotID Pos, ObjectInstanceID ID):pos(Pos),id(ID){};
  1515. SlotID pos; //stack pos
  1516. ObjectInstanceID id; //object id
  1517. bool applyGh(CGameHandler *gh);
  1518. template <typename Handler> void serialize(Handler &h, const int version)
  1519. {
  1520. h & pos & id;
  1521. }
  1522. };
  1523. struct BuildStructure : public CPackForServer
  1524. {
  1525. BuildStructure(){};
  1526. BuildStructure(ObjectInstanceID TID, BuildingID BID):tid(TID), bid(BID){};
  1527. ObjectInstanceID tid; //town id
  1528. BuildingID bid; //structure id
  1529. bool applyGh(CGameHandler *gh);
  1530. template <typename Handler> void serialize(Handler &h, const int version)
  1531. {
  1532. h & tid & bid;
  1533. }
  1534. };
  1535. struct RazeStructure : public BuildStructure
  1536. {
  1537. RazeStructure(){};
  1538. //RazeStructure(si32 TID, si32 BID):bid(BID),tid(TID){};
  1539. bool applyGh(CGameHandler *gh);
  1540. };
  1541. struct RecruitCreatures : public CPackForServer
  1542. {
  1543. RecruitCreatures(){};
  1544. RecruitCreatures(ObjectInstanceID TID, ObjectInstanceID DST, CreatureID CRID, si32 Amount, si32 Level):
  1545. tid(TID), dst(DST), crid(CRID), amount(Amount), level(Level){};
  1546. ObjectInstanceID tid; //dwelling id, or town
  1547. ObjectInstanceID dst; //destination ID, e.g. hero
  1548. CreatureID crid;
  1549. ui32 amount;//creature amount
  1550. si32 level;//dwelling level to buy from, -1 if any
  1551. bool applyGh(CGameHandler *gh);
  1552. template <typename Handler> void serialize(Handler &h, const int version)
  1553. {
  1554. h & tid & dst & crid & amount & level;
  1555. }
  1556. };
  1557. struct UpgradeCreature : public CPackForServer
  1558. {
  1559. UpgradeCreature(){};
  1560. UpgradeCreature(SlotID Pos, ObjectInstanceID ID, CreatureID CRID):pos(Pos),id(ID), cid(CRID){};
  1561. SlotID pos; //stack pos
  1562. ObjectInstanceID id; //object id
  1563. CreatureID cid; //id of type to which we want make upgrade
  1564. bool applyGh(CGameHandler *gh);
  1565. template <typename Handler> void serialize(Handler &h, const int version)
  1566. {
  1567. h & pos & id & cid;
  1568. }
  1569. };
  1570. struct GarrisonHeroSwap : public CPackForServer
  1571. {
  1572. GarrisonHeroSwap(){};
  1573. GarrisonHeroSwap(ObjectInstanceID TID):tid(TID){};
  1574. ObjectInstanceID tid;
  1575. bool applyGh(CGameHandler *gh);
  1576. template <typename Handler> void serialize(Handler &h, const int version)
  1577. {
  1578. h & tid;
  1579. }
  1580. };
  1581. struct ExchangeArtifacts : public CPackForServer
  1582. //TODO: allow exchange between heroes, stacks and commanders
  1583. {
  1584. ArtifactLocation src, dst;
  1585. ExchangeArtifacts(){};
  1586. bool applyGh(CGameHandler *gh);
  1587. template <typename Handler> void serialize(Handler &h, const int version)
  1588. {
  1589. h & src & dst;
  1590. }
  1591. };
  1592. struct AssembleArtifacts : public CPackForServer
  1593. {
  1594. AssembleArtifacts(){};
  1595. AssembleArtifacts(ObjectInstanceID _heroID, ArtifactPosition _artifactSlot, bool _assemble, ArtifactID _assembleTo)
  1596. : heroID(_heroID), artifactSlot(_artifactSlot), assemble(_assemble), assembleTo(_assembleTo){};
  1597. ObjectInstanceID heroID;
  1598. ArtifactPosition artifactSlot;
  1599. bool assemble; // True to assemble artifact, false to disassemble.
  1600. ArtifactID assembleTo; // Artifact to assemble into.
  1601. bool applyGh(CGameHandler *gh);
  1602. template <typename Handler> void serialize(Handler &h, const int version)
  1603. {
  1604. h & heroID & artifactSlot & assemble & assembleTo;
  1605. }
  1606. };
  1607. struct BuyArtifact : public CPackForServer
  1608. {
  1609. BuyArtifact(){};
  1610. BuyArtifact(ObjectInstanceID HID, ArtifactID AID):hid(HID),aid(AID){};
  1611. ObjectInstanceID hid;
  1612. ArtifactID aid;
  1613. bool applyGh(CGameHandler *gh);
  1614. template <typename Handler> void serialize(Handler &h, const int version)
  1615. {
  1616. h & hid & aid;
  1617. }
  1618. };
  1619. struct TradeOnMarketplace : public CPackForServer
  1620. {
  1621. TradeOnMarketplace(){};
  1622. const CGObjectInstance *market;
  1623. const CGHeroInstance *hero; //needed when trading artifacts / creatures
  1624. EMarketMode::EMarketMode mode;
  1625. ui32 r1, r2; //mode 0: r1 - sold resource, r2 - bought res (exception: when sacrificing art r1 is art id [todo: make r2 preferred slot?]
  1626. ui32 val; //units of sold resource
  1627. bool applyGh(CGameHandler *gh);
  1628. template <typename Handler> void serialize(Handler &h, const int version)
  1629. {
  1630. h & market & hero & mode & r1 & r2 & val;
  1631. }
  1632. };
  1633. struct SetFormation : public CPackForServer
  1634. {
  1635. SetFormation(){};
  1636. SetFormation(ObjectInstanceID HID, ui8 Formation):hid(HID),formation(Formation){};
  1637. ObjectInstanceID hid;
  1638. ui8 formation;
  1639. bool applyGh(CGameHandler *gh);
  1640. template <typename Handler> void serialize(Handler &h, const int version)
  1641. {
  1642. h & hid & formation;
  1643. }
  1644. };
  1645. struct HireHero : public CPackForServer
  1646. {
  1647. HireHero(){};
  1648. HireHero(si32 HID, ObjectInstanceID TID):hid(HID),tid(TID){};
  1649. si32 hid; //available hero serial
  1650. ObjectInstanceID tid; //town (tavern) id
  1651. PlayerColor player;
  1652. bool applyGh(CGameHandler *gh);
  1653. template <typename Handler> void serialize(Handler &h, const int version)
  1654. {
  1655. h & hid & tid & player;
  1656. }
  1657. };
  1658. struct BuildBoat : public CPackForServer
  1659. {
  1660. BuildBoat(){};
  1661. ObjectInstanceID objid; //where player wants to buy a boat
  1662. bool applyGh(CGameHandler *gh);
  1663. template <typename Handler> void serialize(Handler &h, const int version)
  1664. {
  1665. h & objid;
  1666. }
  1667. };
  1668. struct QueryReply : public CPackForServer
  1669. {
  1670. QueryReply(){type = 6000;};
  1671. QueryReply(QueryID QID, ui32 Answer):qid(QID),answer(Answer){type = 6000;};
  1672. QueryID qid;
  1673. ui32 answer; //hero and artifact id
  1674. PlayerColor player;
  1675. bool applyGh(CGameHandler *gh);
  1676. template <typename Handler> void serialize(Handler &h, const int version)
  1677. {
  1678. h & qid & answer & player;
  1679. }
  1680. };
  1681. struct MakeAction : public CPackForServer
  1682. {
  1683. MakeAction(){};
  1684. MakeAction(const BattleAction &BA):ba(BA){};
  1685. BattleAction ba;
  1686. bool applyGh(CGameHandler *gh);
  1687. template <typename Handler> void serialize(Handler &h, const int version)
  1688. {
  1689. h & ba;
  1690. }
  1691. };
  1692. struct MakeCustomAction : public CPackForServer
  1693. {
  1694. MakeCustomAction(){};
  1695. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1696. BattleAction ba;
  1697. bool applyGh(CGameHandler *gh);
  1698. template <typename Handler> void serialize(Handler &h, const int version)
  1699. {
  1700. h & ba;
  1701. }
  1702. };
  1703. struct DigWithHero : public CPackForServer
  1704. {
  1705. DigWithHero(){}
  1706. ObjectInstanceID id; //digging hero id
  1707. bool applyGh(CGameHandler *gh);
  1708. template <typename Handler> void serialize(Handler &h, const int version)
  1709. {
  1710. h & id;
  1711. }
  1712. };
  1713. struct CastAdvSpell : public CPackForServer
  1714. {
  1715. CastAdvSpell(){}
  1716. ObjectInstanceID hid; //hero id
  1717. SpellID sid; //spell id
  1718. int3 pos; //selected tile (not always used)
  1719. bool applyGh(CGameHandler *gh);
  1720. template <typename Handler> void serialize(Handler &h, const int version)
  1721. {
  1722. h & hid & sid & pos;
  1723. }
  1724. };
  1725. /***********************************************************************************************************/
  1726. struct SaveGame : public CPackForClient, public CPackForServer
  1727. {
  1728. SaveGame(){};
  1729. SaveGame(const std::string &Fname) :fname(Fname){};
  1730. std::string fname;
  1731. void applyCl(CClient *cl);
  1732. void applyGs(CGameState *gs){};
  1733. bool applyGh(CGameHandler *gh);
  1734. template <typename Handler> void serialize(Handler &h, const int version)
  1735. {
  1736. h & fname;
  1737. }
  1738. };
  1739. struct PlayerMessage : public CPackForClient, public CPackForServer //513
  1740. {
  1741. PlayerMessage(){CPackForClient::type = 513;};
  1742. PlayerMessage(PlayerColor Player, const std::string &Text, ObjectInstanceID obj)
  1743. :player(Player),text(Text), currObj(obj)
  1744. {CPackForClient::type = 513;};
  1745. void applyCl(CClient *cl);
  1746. void applyGs(CGameState *gs){};
  1747. bool applyGh(CGameHandler *gh);
  1748. PlayerColor player;
  1749. std::string text;
  1750. ObjectInstanceID currObj; // optional parameter that specifies current object. For cheats :)
  1751. template <typename Handler> void serialize(Handler &h, const int version)
  1752. {
  1753. h & text & player & currObj;
  1754. }
  1755. };
  1756. struct CenterView : public CPackForClient//515
  1757. {
  1758. CenterView(){CPackForClient::type = 515;};
  1759. void applyCl(CClient *cl);
  1760. PlayerColor player;
  1761. int3 pos;
  1762. ui32 focusTime; //ms
  1763. template <typename Handler> void serialize(Handler &h, const int version)
  1764. {
  1765. h & pos & player & focusTime;
  1766. }
  1767. };
  1768. /***********************************************************************************************************/
  1769. struct CPackForSelectionScreen : public CPack
  1770. {
  1771. void apply(CSelectionScreen *selScreen){}; //that functions are implemented in CPreGame.cpp
  1772. };
  1773. class CPregamePackToPropagate : public CPackForSelectionScreen
  1774. {};
  1775. class CPregamePackToHost : public CPackForSelectionScreen
  1776. {};
  1777. struct ChatMessage : public CPregamePackToPropagate
  1778. {
  1779. std::string playerName, message;
  1780. void apply(CSelectionScreen *selScreen);
  1781. template <typename Handler> void serialize(Handler &h, const int version)
  1782. {
  1783. h & playerName & message;
  1784. }
  1785. };
  1786. struct QuitMenuWithoutStarting : public CPregamePackToPropagate
  1787. {
  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. };
  1792. struct PlayerJoined : public CPregamePackToHost
  1793. {
  1794. std::string playerName;
  1795. ui8 connectionID;
  1796. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1797. template <typename Handler> void serialize(Handler &h, const int version)
  1798. {
  1799. h & playerName & connectionID;
  1800. }
  1801. };
  1802. struct ELF_VISIBILITY SelectMap : public CPregamePackToPropagate
  1803. {
  1804. const CMapInfo *mapInfo;
  1805. bool free;//local flag, do not serialize
  1806. DLL_LINKAGE SelectMap(const CMapInfo &src);
  1807. DLL_LINKAGE SelectMap();
  1808. DLL_LINKAGE ~SelectMap();
  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. h & mapInfo;
  1813. }
  1814. };
  1815. struct ELF_VISIBILITY UpdateStartOptions : public CPregamePackToPropagate
  1816. {
  1817. StartInfo *options;
  1818. bool free;//local flag, do not serialize
  1819. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1820. DLL_LINKAGE UpdateStartOptions(StartInfo &src);
  1821. DLL_LINKAGE UpdateStartOptions();
  1822. DLL_LINKAGE ~UpdateStartOptions();
  1823. template <typename Handler> void serialize(Handler &h, const int version)
  1824. {
  1825. h & options;
  1826. }
  1827. };
  1828. struct PregameGuiAction : public CPregamePackToPropagate
  1829. {
  1830. enum {NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST, OPEN_RANDOM_MAP_OPTIONS}
  1831. action;
  1832. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1833. template <typename Handler> void serialize(Handler &h, const int version)
  1834. {
  1835. h & action;
  1836. }
  1837. };
  1838. struct RequestOptionsChange : public CPregamePackToHost
  1839. {
  1840. enum EWhat {TOWN, HERO, BONUS};
  1841. ui8 what;
  1842. si8 direction; //-1 or +1
  1843. ui8 playerID;
  1844. RequestOptionsChange(ui8 What, si8 Dir, ui8 Player)
  1845. :what(What), direction(Dir), playerID(Player)
  1846. {}
  1847. RequestOptionsChange(){}
  1848. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1849. template <typename Handler> void serialize(Handler &h, const int version)
  1850. {
  1851. h & what & direction & playerID;
  1852. }
  1853. };
  1854. struct PlayerLeft : public CPregamePackToPropagate
  1855. {
  1856. ui8 playerID;
  1857. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1858. template <typename Handler> void serialize(Handler &h, const int version)
  1859. {
  1860. h & playerID;
  1861. }
  1862. };
  1863. struct PlayersNames : public CPregamePackToPropagate
  1864. {
  1865. public:
  1866. std::map<ui8, std::string> playerNames;
  1867. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1868. template <typename Handler> void serialize(Handler &h, const int version)
  1869. {
  1870. h & playerNames;
  1871. }
  1872. };
  1873. struct StartWithCurrentSettings : public CPregamePackToPropagate
  1874. {
  1875. public:
  1876. void apply(CSelectionScreen *selScreen); //that functions are implemented in CPreGame.cpp
  1877. template <typename Handler> void serialize(Handler &h, const int version)
  1878. {
  1879. //h & playerNames;
  1880. }
  1881. };