NetPacks.h 52 KB

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