NetPacks.h 52 KB

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