NetPacks.h 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453
  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 BulkRebalanceStacks : CGarrisonOperationPack
  747. {
  748. std::vector<RebalanceStacks> moves;
  749. void applyCl(CClient * cl);
  750. DLL_LINKAGE void applyGs(CGameState * gs);
  751. template <typename Handler>
  752. void serialize(Handler & h, const int version)
  753. {
  754. h & moves;
  755. }
  756. };
  757. struct BulkSmartRebalanceStacks : CGarrisonOperationPack
  758. {
  759. std::vector<RebalanceStacks> moves;
  760. std::vector<ChangeStackCount> changes;
  761. void applyCl(CClient * cl);
  762. DLL_LINKAGE void applyGs(CGameState * gs);
  763. template <typename Handler>
  764. void serialize(Handler & h, const int version)
  765. {
  766. h & moves;
  767. h & changes;
  768. }
  769. };
  770. struct GetEngagedHeroIds : boost::static_visitor<boost::optional<ObjectInstanceID>>
  771. {
  772. boost::optional<ObjectInstanceID> operator()(const ConstTransitivePtr<CGHeroInstance> &h) const
  773. {
  774. return h->id;
  775. }
  776. boost::optional<ObjectInstanceID> operator()(const ConstTransitivePtr<CStackInstance> &s) const
  777. {
  778. if(s->armyObj && s->armyObj->ID == Obj::HERO)
  779. return s->armyObj->id;
  780. return boost::optional<ObjectInstanceID>();
  781. }
  782. };
  783. struct CArtifactOperationPack : CPackForClient
  784. {
  785. };
  786. struct PutArtifact : CArtifactOperationPack
  787. {
  788. ArtifactLocation al;
  789. ConstTransitivePtr<CArtifactInstance> art;
  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 & art;
  796. }
  797. };
  798. struct EraseArtifact : 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 MoveArtifact : CArtifactOperationPack
  809. {
  810. ArtifactLocation src, dst;
  811. void applyCl(CClient *cl);
  812. DLL_LINKAGE void applyGs(CGameState *gs);
  813. template <typename Handler> void serialize(Handler &h, const int version)
  814. {
  815. h & src;
  816. h & dst;
  817. }
  818. };
  819. struct AssembledArtifact : CArtifactOperationPack
  820. {
  821. ArtifactLocation al; //where assembly will be put
  822. CArtifact *builtArt;
  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 & al;
  828. h & builtArt;
  829. }
  830. };
  831. struct DisassembledArtifact : CArtifactOperationPack
  832. {
  833. ArtifactLocation al;
  834. void applyCl(CClient *cl);
  835. DLL_LINKAGE void applyGs(CGameState *gs);
  836. template <typename Handler> void serialize(Handler &h, const int version)
  837. {
  838. h & al;
  839. }
  840. };
  841. struct HeroVisit : public CPackForClient
  842. {
  843. PlayerColor player;
  844. ObjectInstanceID heroId;
  845. ObjectInstanceID objId;
  846. bool starting; //false -> ending
  847. void applyCl(CClient * cl);
  848. DLL_LINKAGE void applyGs(CGameState * gs);
  849. template <typename Handler> void serialize(Handler & h, const int version)
  850. {
  851. h & player;
  852. h & heroId;
  853. h & objId;
  854. h & starting;
  855. }
  856. };
  857. struct NewTurn : public CPackForClient
  858. {
  859. enum weekType {NORMAL, DOUBLE_GROWTH, BONUS_GROWTH, DEITYOFFIRE, PLAGUE, NO_ACTION};
  860. void applyCl(CClient *cl);
  861. DLL_LINKAGE void applyGs(CGameState *gs);
  862. struct Hero
  863. {
  864. ObjectInstanceID id;
  865. ui32 move, mana; //id is a general serial id
  866. template <typename Handler> void serialize(Handler &h, const int version)
  867. {
  868. h & id;
  869. h & move;
  870. h & mana;
  871. }
  872. bool operator<(const Hero&h)const{return id < h.id;}
  873. };
  874. std::set<Hero> heroes; //updates movement and mana points
  875. std::map<PlayerColor, TResources> res; //player ID => resource value[res_id]
  876. std::map<ObjectInstanceID, SetAvailableCreatures> cres;//creatures to be placed in towns
  877. ui32 day;
  878. ui8 specialWeek; //weekType
  879. CreatureID creatureid; //for creature weeks
  880. NewTurn():day(0),specialWeek(0){};
  881. template <typename Handler> void serialize(Handler &h, const int version)
  882. {
  883. h & heroes;
  884. h & cres;
  885. h & res;
  886. h & day;
  887. h & specialWeek;
  888. h & creatureid;
  889. }
  890. };
  891. struct InfoWindow : public CPackForClient //103 - displays simple info window
  892. {
  893. void applyCl(CClient *cl);
  894. MetaString text;
  895. std::vector<Component> components;
  896. PlayerColor player;
  897. ui16 soundID;
  898. template <typename Handler> void serialize(Handler &h, const int version)
  899. {
  900. h & text;
  901. h & components;
  902. h & player;
  903. h & soundID;
  904. }
  905. InfoWindow()
  906. {
  907. soundID = 0;
  908. }
  909. };
  910. namespace ObjProperty
  911. {
  912. enum {OWNER = 1, BLOCKVIS = 2, PRIMARY_STACK_COUNT = 3, VISITORS = 4, VISITED = 5, ID = 6, AVAILABLE_CREATURE = 7, SUBID = 8,
  913. MONSTER_COUNT = 10, MONSTER_POWER = 11, MONSTER_EXP = 12, MONSTER_RESTORE_TYPE = 13, MONSTER_REFUSED_JOIN,
  914. //town-specific
  915. STRUCTURE_ADD_VISITING_HERO, STRUCTURE_CLEAR_VISITORS, STRUCTURE_ADD_GARRISONED_HERO, //changing buildings state
  916. BONUS_VALUE_FIRST, BONUS_VALUE_SECOND, //used in Rampart for special building that generates resources (storing resource type and quantity)
  917. //creature-bank specific
  918. BANK_DAYCOUNTER, BANK_RESET, BANK_CLEAR,
  919. //object with reward
  920. REWARD_RESET, REWARD_SELECT
  921. };
  922. }
  923. struct SetObjectProperty : public CPackForClient
  924. {
  925. DLL_LINKAGE void applyGs(CGameState *gs);
  926. void applyCl(CClient *cl);
  927. ObjectInstanceID id;
  928. ui8 what; // see ObjProperty enum
  929. ui32 val;
  930. SetObjectProperty():what(0),val(0){}
  931. SetObjectProperty(ObjectInstanceID ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){};
  932. template <typename Handler> void serialize(Handler &h, const int version)
  933. {
  934. h & id;
  935. h & what;
  936. h & val;
  937. }
  938. };
  939. struct ChangeObjectVisitors : public CPackForClient
  940. {
  941. enum VisitMode
  942. {
  943. VISITOR_ADD, // mark hero as one that have visited this object
  944. VISITOR_ADD_TEAM, // mark team as one that have visited this object
  945. VISITOR_REMOVE, // unmark visitor, reversed to ADD
  946. VISITOR_CLEAR // clear all visitors from this object (object reset)
  947. };
  948. ui32 mode; // uses VisitMode enum
  949. ObjectInstanceID object;
  950. ObjectInstanceID hero; // note: hero owner will be also marked as "visited" this object
  951. DLL_LINKAGE void applyGs(CGameState *gs);
  952. ChangeObjectVisitors()
  953. : mode(VISITOR_CLEAR)
  954. {}
  955. ChangeObjectVisitors(ui32 mode, ObjectInstanceID object, ObjectInstanceID heroID = ObjectInstanceID(-1)):
  956. mode(mode),
  957. object(object),
  958. hero(heroID)
  959. {}
  960. template <typename Handler> void serialize(Handler &h, const int version)
  961. {
  962. h & object;
  963. h & hero;
  964. h & mode;
  965. }
  966. };
  967. struct PrepareHeroLevelUp : public CPackForClient
  968. {
  969. ObjectInstanceID heroId;
  970. /// Do not serialize, used by server only
  971. std::vector<SecondarySkill> skills;
  972. PrepareHeroLevelUp(){}
  973. DLL_LINKAGE void applyGs(CGameState * gs);
  974. template <typename Handler> void serialize(Handler &h, const int version)
  975. {
  976. h & heroId;
  977. }
  978. };
  979. struct HeroLevelUp : public Query
  980. {
  981. PlayerColor player;
  982. ObjectInstanceID heroId;
  983. PrimarySkill::PrimarySkill primskill;
  984. std::vector<SecondarySkill> skills;
  985. HeroLevelUp(): primskill(PrimarySkill::ATTACK){}
  986. void applyCl(CClient * cl);
  987. DLL_LINKAGE void applyGs(CGameState * gs);
  988. template <typename Handler> void serialize(Handler & h, const int version)
  989. {
  990. h & queryID;
  991. h & player;
  992. h & heroId;
  993. h & primskill;
  994. h & skills;
  995. }
  996. };
  997. struct CommanderLevelUp : public Query
  998. {
  999. PlayerColor player;
  1000. ObjectInstanceID heroId;
  1001. std::vector<ui32> skills; //0-5 - secondary skills, val-100 - special skill
  1002. CommanderLevelUp(){}
  1003. void applyCl(CClient * cl);
  1004. DLL_LINKAGE void applyGs(CGameState * gs);
  1005. template <typename Handler> void serialize(Handler & h, const int version)
  1006. {
  1007. h & queryID;
  1008. h & player;
  1009. h & heroId;
  1010. h & skills;
  1011. }
  1012. };
  1013. //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options
  1014. //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed
  1015. //Until sending reply player won't be allowed to take any actions
  1016. struct BlockingDialog : public Query
  1017. {
  1018. enum {ALLOW_CANCEL = 1, SELECTION = 2};
  1019. void applyCl(CClient *cl);
  1020. MetaString text;
  1021. std::vector<Component> components;
  1022. PlayerColor player;
  1023. ui8 flags;
  1024. ui16 soundID;
  1025. bool cancel() const
  1026. {
  1027. return flags & ALLOW_CANCEL;
  1028. }
  1029. bool selection() const
  1030. {
  1031. return flags & SELECTION;
  1032. }
  1033. BlockingDialog(bool yesno, bool Selection)
  1034. {
  1035. flags = 0;
  1036. soundID = 0;
  1037. if(yesno) flags |= ALLOW_CANCEL;
  1038. if(Selection) flags |= SELECTION;
  1039. }
  1040. BlockingDialog()
  1041. {
  1042. flags = 0;
  1043. soundID = 0;
  1044. };
  1045. template <typename Handler> void serialize(Handler &h, const int version)
  1046. {
  1047. h & queryID;
  1048. h & text;
  1049. h & components;
  1050. h & player;
  1051. h & flags;
  1052. h & soundID;
  1053. }
  1054. };
  1055. struct GarrisonDialog : public Query
  1056. {
  1057. GarrisonDialog():removableUnits(false){}
  1058. void applyCl(CClient *cl);
  1059. ObjectInstanceID objid, hid;
  1060. bool removableUnits;
  1061. template <typename Handler> void serialize(Handler &h, const int version)
  1062. {
  1063. h & queryID;
  1064. h & objid;
  1065. h & hid;
  1066. h & removableUnits;
  1067. }
  1068. };
  1069. struct ExchangeDialog : public Query
  1070. {
  1071. ExchangeDialog() {}
  1072. void applyCl(CClient *cl);
  1073. PlayerColor player;
  1074. ObjectInstanceID hero1;
  1075. ObjectInstanceID hero2;
  1076. template <typename Handler> void serialize(Handler &h, const int version)
  1077. {
  1078. h & queryID;
  1079. h & player;
  1080. h & hero1;
  1081. h & hero2;
  1082. }
  1083. };
  1084. struct TeleportDialog : public Query
  1085. {
  1086. TeleportDialog()
  1087. : impassable(false)
  1088. {}
  1089. TeleportDialog(PlayerColor Player, TeleportChannelID Channel)
  1090. : player(Player), channel(Channel), impassable(false)
  1091. {}
  1092. void applyCl(CClient *cl);
  1093. PlayerColor player;
  1094. TeleportChannelID channel;
  1095. TTeleportExitsList exits;
  1096. bool impassable;
  1097. template <typename Handler> void serialize(Handler &h, const int version)
  1098. {
  1099. h & queryID;
  1100. h & player;
  1101. h & channel;
  1102. h & exits;
  1103. h & impassable;
  1104. }
  1105. };
  1106. struct MapObjectSelectDialog : public Query
  1107. {
  1108. PlayerColor player;
  1109. Component icon;
  1110. MetaString title;
  1111. MetaString description;
  1112. std::vector<ObjectInstanceID> objects;
  1113. MapObjectSelectDialog(){};
  1114. void applyCl(CClient * cl);
  1115. template <typename Handler> void serialize(Handler & h, const int version)
  1116. {
  1117. h & queryID;
  1118. h & player;
  1119. h & icon;
  1120. h & title;
  1121. h & description;
  1122. h & objects;
  1123. }
  1124. };
  1125. class BattleInfo;
  1126. struct BattleStart : public CPackForClient
  1127. {
  1128. BattleStart()
  1129. :info(nullptr)
  1130. {}
  1131. void applyFirstCl(CClient *cl);
  1132. void applyCl(CClient *cl);
  1133. DLL_LINKAGE void applyGs(CGameState *gs);
  1134. BattleInfo * info;
  1135. template <typename Handler> void serialize(Handler &h, const int version)
  1136. {
  1137. h & info;
  1138. }
  1139. };
  1140. struct BattleNextRound : public CPackForClient
  1141. {
  1142. BattleNextRound():round(0){};
  1143. void applyFirstCl(CClient *cl);
  1144. void applyCl(CClient *cl);
  1145. DLL_LINKAGE void applyGs( CGameState *gs );
  1146. si32 round;
  1147. template <typename Handler> void serialize(Handler &h, const int version)
  1148. {
  1149. h & round;
  1150. }
  1151. };
  1152. struct BattleSetActiveStack : public CPackForClient
  1153. {
  1154. BattleSetActiveStack()
  1155. {
  1156. stack = 0;
  1157. askPlayerInterface = true;
  1158. }
  1159. void applyCl(CClient *cl);
  1160. DLL_LINKAGE void applyGs(CGameState *gs);
  1161. ui32 stack;
  1162. ui8 askPlayerInterface;
  1163. template <typename Handler> void serialize(Handler &h, const int version)
  1164. {
  1165. h & stack;
  1166. h & askPlayerInterface;
  1167. }
  1168. };
  1169. struct BattleResult : public CPackForClient
  1170. {
  1171. enum EResult {NORMAL = 0, ESCAPE = 1, SURRENDER = 2};
  1172. BattleResult()
  1173. : result(NORMAL), winner(2)
  1174. {
  1175. exp[0] = 0;
  1176. exp[1] = 0;
  1177. };
  1178. void applyFirstCl(CClient *cl);
  1179. void applyGs(CGameState *gs);
  1180. EResult result;
  1181. ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
  1182. std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
  1183. TExpType exp[2]; //exp for attacker and defender
  1184. std::set<ArtifactInstanceID> artifacts; //artifacts taken from loser to winner - currently unused
  1185. template <typename Handler> void serialize(Handler &h, const int version)
  1186. {
  1187. h & result;
  1188. h & winner;
  1189. h & casualties[0];
  1190. h & casualties[1];
  1191. h & exp;
  1192. h & artifacts;
  1193. }
  1194. };
  1195. struct BattleLogMessage : public CPackForClient
  1196. {
  1197. std::vector<MetaString> lines;
  1198. BattleLogMessage(){}
  1199. void applyCl(CClient * cl);
  1200. DLL_LINKAGE void applyGs(CGameState * gs);
  1201. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1202. template <typename Handler> void serialize(Handler & h, const int version)
  1203. {
  1204. h & lines;
  1205. }
  1206. };
  1207. struct BattleStackMoved : public CPackForClient
  1208. {
  1209. ui32 stack;
  1210. std::vector<BattleHex> tilesToMove;
  1211. int distance;
  1212. bool teleporting;
  1213. BattleStackMoved()
  1214. : stack(0),
  1215. distance(0),
  1216. teleporting(false)
  1217. {};
  1218. void applyFirstCl(CClient *cl);
  1219. DLL_LINKAGE void applyGs(CGameState *gs);
  1220. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1221. template <typename Handler> void serialize(Handler &h, const int version)
  1222. {
  1223. h & stack;
  1224. h & tilesToMove;
  1225. h & distance;
  1226. }
  1227. };
  1228. struct BattleUnitsChanged : public CPackForClient
  1229. {
  1230. BattleUnitsChanged(){}
  1231. DLL_LINKAGE void applyGs(CGameState *gs);
  1232. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1233. void applyCl(CClient *cl);
  1234. std::vector<UnitChanges> changedStacks;
  1235. std::vector<CustomEffectInfo> customEffects;
  1236. template <typename Handler> void serialize(Handler & h, const int version)
  1237. {
  1238. h & changedStacks;
  1239. h & customEffects;
  1240. }
  1241. };
  1242. struct BattleStackAttacked
  1243. {
  1244. BattleStackAttacked():
  1245. stackAttacked(0), attackerID(0),
  1246. killedAmount(0), damageAmount(0),
  1247. newState(),
  1248. flags(0), effect(0), spellID(SpellID::NONE)
  1249. {};
  1250. DLL_LINKAGE void applyGs(CGameState *gs);
  1251. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1252. ui32 stackAttacked, attackerID;
  1253. ui32 killedAmount;
  1254. int64_t damageAmount;
  1255. UnitChanges newState;
  1256. enum EFlags {KILLED = 1, EFFECT = 2/*deprecated */, SECONDARY = 4, REBIRTH = 8, CLONE_KILLED = 16, SPELL_EFFECT = 32 /*, BONUS_EFFECT = 64 */};
  1257. ui32 flags; //uses EFlags (above)
  1258. ui32 effect; //set only if flag EFFECT is set
  1259. SpellID spellID; //only if flag SPELL_EFFECT is set
  1260. bool killed() const//if target stack was killed
  1261. {
  1262. return flags & KILLED || flags & CLONE_KILLED;
  1263. }
  1264. bool cloneKilled() const
  1265. {
  1266. return flags & CLONE_KILLED;
  1267. }
  1268. bool isEffect() const//if stack has been attacked by a spell
  1269. {
  1270. return flags & EFFECT;
  1271. }
  1272. bool isSecondary() const//if stack was not a primary target (receives no spell effects)
  1273. {
  1274. return flags & SECONDARY;
  1275. }
  1276. ///Attacked with spell (SPELL_LIKE_ATTACK)
  1277. bool isSpell() const
  1278. {
  1279. return flags & SPELL_EFFECT;
  1280. }
  1281. bool willRebirth() const//resurrection, e.g. Phoenix
  1282. {
  1283. return flags & REBIRTH;
  1284. }
  1285. template <typename Handler> void serialize(Handler &h, const int version)
  1286. {
  1287. h & stackAttacked;
  1288. h & attackerID;
  1289. h & newState;
  1290. h & flags;
  1291. h & killedAmount;
  1292. h & damageAmount;
  1293. h & effect;
  1294. h & spellID;
  1295. }
  1296. bool operator<(const BattleStackAttacked &b) const
  1297. {
  1298. return stackAttacked < b.stackAttacked;
  1299. }
  1300. };
  1301. struct BattleAttack : public CPackForClient
  1302. {
  1303. BattleAttack()
  1304. : stackAttacking(0), flags(0), spellID(SpellID::NONE)
  1305. {};
  1306. void applyFirstCl(CClient *cl);
  1307. DLL_LINKAGE void applyGs(CGameState *gs);
  1308. void applyCl(CClient *cl);
  1309. BattleUnitsChanged attackerChanges;
  1310. std::vector<BattleStackAttacked> bsa;
  1311. ui32 stackAttacking;
  1312. ui32 flags; //uses Eflags (below)
  1313. enum EFlags{SHOT = 1, COUNTER = 2, LUCKY = 4, UNLUCKY = 8, BALLISTA_DOUBLE_DMG = 16, DEATH_BLOW = 32, SPELL_LIKE = 64};
  1314. SpellID spellID; //for SPELL_LIKE
  1315. std::vector<CustomEffectInfo> customEffects;
  1316. bool shot() const//distance attack - decrease number of shots
  1317. {
  1318. return flags & SHOT;
  1319. }
  1320. bool counter() const//is it counterattack?
  1321. {
  1322. return flags & COUNTER;
  1323. }
  1324. bool lucky() const
  1325. {
  1326. return flags & LUCKY;
  1327. }
  1328. bool unlucky() const
  1329. {
  1330. return flags & UNLUCKY;
  1331. }
  1332. bool ballistaDoubleDmg() const //if it's ballista attack and does double dmg
  1333. {
  1334. return flags & BALLISTA_DOUBLE_DMG;
  1335. }
  1336. bool deathBlow() const
  1337. {
  1338. return flags & DEATH_BLOW;
  1339. }
  1340. bool spellLike() const
  1341. {
  1342. return flags & SPELL_LIKE;
  1343. }
  1344. template <typename Handler> void serialize(Handler &h, const int version)
  1345. {
  1346. h & bsa;
  1347. h & stackAttacking;
  1348. h & flags;
  1349. h & spellID;
  1350. h & customEffects;
  1351. h & attackerChanges;
  1352. }
  1353. };
  1354. struct StartAction : public CPackForClient
  1355. {
  1356. StartAction(){};
  1357. StartAction(const BattleAction &act){ba = act; };
  1358. void applyFirstCl(CClient *cl);
  1359. DLL_LINKAGE void applyGs(CGameState *gs);
  1360. BattleAction ba;
  1361. template <typename Handler> void serialize(Handler &h, const int version)
  1362. {
  1363. h & ba;
  1364. }
  1365. };
  1366. struct EndAction : public CPackForClient
  1367. {
  1368. EndAction(){};
  1369. void applyCl(CClient *cl);
  1370. template <typename Handler> void serialize(Handler &h, const int version)
  1371. {
  1372. }
  1373. };
  1374. struct BattleSpellCast : public CPackForClient
  1375. {
  1376. BattleSpellCast()
  1377. {
  1378. side = 0;
  1379. manaGained = 0;
  1380. casterStack = -1;
  1381. castByHero = true;
  1382. activeCast = true;
  1383. };
  1384. DLL_LINKAGE void applyGs(CGameState *gs);
  1385. void applyCl(CClient *cl);
  1386. bool activeCast;
  1387. ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
  1388. SpellID spellID; //id of spell
  1389. ui8 manaGained; //mana channeling ability
  1390. BattleHex tile; //destination tile (may not be set in some global/mass spells
  1391. std::vector<CustomEffectInfo> customEffects;
  1392. std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
  1393. si32 casterStack;// -1 if not cated by creature, >=0 caster stack ID
  1394. bool castByHero; //if true - spell has been cast by hero, otherwise by a creature
  1395. template <typename Handler> void serialize(Handler &h, const int version)
  1396. {
  1397. h & side;
  1398. h & spellID;
  1399. h & manaGained;
  1400. h & tile;
  1401. h & customEffects;
  1402. h & affectedCres;
  1403. h & casterStack;
  1404. h & castByHero;
  1405. h & activeCast;
  1406. }
  1407. };
  1408. struct SetStackEffect : public CPackForClient
  1409. {
  1410. SetStackEffect(){};
  1411. DLL_LINKAGE void applyGs(CGameState * gs);
  1412. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1413. void applyCl(CClient * cl);
  1414. std::vector<std::pair<ui32, std::vector<Bonus>>> toAdd;
  1415. std::vector<std::pair<ui32, std::vector<Bonus>>> toUpdate;
  1416. std::vector<std::pair<ui32, std::vector<Bonus>>> toRemove;
  1417. template <typename Handler> void serialize(Handler & h, const int version)
  1418. {
  1419. h & toAdd;
  1420. h & toUpdate;
  1421. h & toRemove;
  1422. }
  1423. };
  1424. struct StacksInjured : public CPackForClient
  1425. {
  1426. StacksInjured(){}
  1427. DLL_LINKAGE void applyGs(CGameState * gs);
  1428. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1429. void applyCl(CClient * cl);
  1430. std::vector<BattleStackAttacked> stacks;
  1431. template <typename Handler> void serialize(Handler & h, const int version)
  1432. {
  1433. h & stacks;
  1434. }
  1435. };
  1436. struct BattleResultsApplied : public CPackForClient
  1437. {
  1438. BattleResultsApplied(){}
  1439. PlayerColor player1, player2;
  1440. void applyCl(CClient *cl);
  1441. template <typename Handler> void serialize(Handler &h, const int version)
  1442. {
  1443. h & player1;
  1444. h & player2;
  1445. }
  1446. };
  1447. struct BattleObstaclesChanged : public CPackForClient
  1448. {
  1449. BattleObstaclesChanged(){}
  1450. DLL_LINKAGE void applyGs(CGameState * gs);
  1451. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1452. void applyCl(CClient * cl);
  1453. std::vector<ObstacleChanges> changes;
  1454. template <typename Handler> void serialize(Handler & h, const int version)
  1455. {
  1456. h & changes;
  1457. }
  1458. };
  1459. struct ELF_VISIBILITY CatapultAttack : public CPackForClient
  1460. {
  1461. struct AttackInfo
  1462. {
  1463. si16 destinationTile;
  1464. ui8 attackedPart;
  1465. ui8 damageDealt;
  1466. template <typename Handler> void serialize(Handler & h, const int version)
  1467. {
  1468. h & destinationTile;
  1469. h & attackedPart;
  1470. h & damageDealt;
  1471. }
  1472. };
  1473. DLL_LINKAGE CatapultAttack();
  1474. DLL_LINKAGE ~CatapultAttack();
  1475. DLL_LINKAGE void applyGs(CGameState * gs);
  1476. DLL_LINKAGE void applyBattle(IBattleState * battleState);
  1477. void applyCl(CClient * cl);
  1478. std::vector< AttackInfo > attackedParts;
  1479. int attacker; //if -1, then a spell caused this
  1480. template <typename Handler> void serialize(Handler &h, const int version)
  1481. {
  1482. h & attackedParts;
  1483. h & attacker;
  1484. }
  1485. };
  1486. struct BattleSetStackProperty : public CPackForClient
  1487. {
  1488. BattleSetStackProperty()
  1489. : stackID(0), which(CASTS), val(0), absolute(0)
  1490. {};
  1491. enum BattleStackProperty {CASTS, ENCHANTER_COUNTER, UNBIND, CLONED, HAS_CLONE};
  1492. DLL_LINKAGE void applyGs(CGameState *gs);
  1493. int stackID;
  1494. BattleStackProperty which;
  1495. int val;
  1496. int absolute;
  1497. template <typename Handler> void serialize(Handler &h, const int version)
  1498. {
  1499. h & stackID;
  1500. h & which;
  1501. h & val;
  1502. h & absolute;
  1503. }
  1504. };
  1505. ///activated at the beginning of turn
  1506. struct BattleTriggerEffect : public CPackForClient
  1507. {
  1508. BattleTriggerEffect()
  1509. : stackID(0), effect(0), val(0), additionalInfo(0)
  1510. {};
  1511. DLL_LINKAGE void applyGs(CGameState *gs); //effect
  1512. void applyCl(CClient *cl); //play animations & stuff
  1513. int stackID;
  1514. int effect; //use corresponding Bonus type
  1515. int val;
  1516. int additionalInfo;
  1517. template <typename Handler> void serialize(Handler &h, const int version)
  1518. {
  1519. h & stackID;
  1520. h & effect;
  1521. h & val;
  1522. h & additionalInfo;
  1523. }
  1524. };
  1525. struct BattleUpdateGateState : public CPackForClient
  1526. {
  1527. BattleUpdateGateState():state(EGateState::NONE){};
  1528. void applyFirstCl(CClient *cl);
  1529. DLL_LINKAGE void applyGs(CGameState *gs);
  1530. EGateState state;
  1531. template <typename Handler> void serialize(Handler &h, const int version)
  1532. {
  1533. h & state;
  1534. }
  1535. };
  1536. struct ShowInInfobox : public CPackForClient
  1537. {
  1538. ShowInInfobox(){};
  1539. PlayerColor player;
  1540. Component c;
  1541. MetaString text;
  1542. void applyCl(CClient *cl);
  1543. template <typename Handler> void serialize(Handler &h, const int version)
  1544. {
  1545. h & player;
  1546. h & c;
  1547. h & text;
  1548. }
  1549. };
  1550. struct AdvmapSpellCast : public CPackForClient
  1551. {
  1552. AdvmapSpellCast():casterID(){}
  1553. ObjectInstanceID casterID;
  1554. SpellID spellID;
  1555. void applyCl(CClient *cl);
  1556. template <typename Handler> void serialize(Handler &h, const int version)
  1557. {
  1558. h & casterID;
  1559. h & spellID;
  1560. }
  1561. };
  1562. struct ShowWorldViewEx : public CPackForClient
  1563. {
  1564. PlayerColor player;
  1565. std::vector<ObjectPosInfo> objectPositions;
  1566. ShowWorldViewEx(){}
  1567. void applyCl(CClient *cl);
  1568. template <typename Handler> void serialize(Handler &h, const int version)
  1569. {
  1570. h & player;
  1571. h & objectPositions;
  1572. }
  1573. };
  1574. /***********************************************************************************************************/
  1575. struct EndTurn : public CPackForServer
  1576. {
  1577. bool applyGh(CGameHandler *gh);
  1578. template <typename Handler> void serialize(Handler &h, const int version)
  1579. {
  1580. h & static_cast<CPackForServer &>(*this);
  1581. }
  1582. };
  1583. struct DismissHero : public CPackForServer
  1584. {
  1585. DismissHero(){};
  1586. DismissHero(ObjectInstanceID HID) : hid(HID) {};
  1587. ObjectInstanceID hid;
  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 & hid;
  1593. }
  1594. };
  1595. struct MoveHero : public CPackForServer
  1596. {
  1597. MoveHero():transit(false){};
  1598. MoveHero(const int3 &Dest, ObjectInstanceID HID, bool Transit) : dest(Dest), hid(HID), transit(Transit) {};
  1599. int3 dest;
  1600. ObjectInstanceID hid;
  1601. bool transit;
  1602. bool applyGh(CGameHandler *gh);
  1603. template <typename Handler> void serialize(Handler &h, const int version)
  1604. {
  1605. h & static_cast<CPackForServer &>(*this);
  1606. h & dest;
  1607. h & hid;
  1608. h & transit;
  1609. }
  1610. };
  1611. struct CastleTeleportHero : public CPackForServer
  1612. {
  1613. CastleTeleportHero():source(0){};
  1614. CastleTeleportHero(const ObjectInstanceID HID, ObjectInstanceID Dest, ui8 Source ) : dest(Dest), hid(HID), source(Source){};
  1615. ObjectInstanceID dest;
  1616. ObjectInstanceID hid;
  1617. si8 source;//who give teleporting, 1=castle gate
  1618. bool applyGh(CGameHandler *gh);
  1619. template <typename Handler> void serialize(Handler &h, const int version)
  1620. {
  1621. h & static_cast<CPackForServer &>(*this);
  1622. h & dest;
  1623. h & hid;
  1624. }
  1625. };
  1626. struct ArrangeStacks : public CPackForServer
  1627. {
  1628. ArrangeStacks():what(0), val(0){};
  1629. ArrangeStacks(ui8 W, SlotID P1, SlotID P2, ObjectInstanceID ID1, ObjectInstanceID ID2, si32 VAL)
  1630. :what(W),p1(P1),p2(P2),id1(ID1),id2(ID2),val(VAL) {};
  1631. ui8 what; //1 - swap; 2 - merge; 3 - split
  1632. SlotID p1, p2; //positions of first and second stack
  1633. ObjectInstanceID id1, id2; //ids of objects with garrison
  1634. si32 val;
  1635. bool applyGh(CGameHandler *gh);
  1636. template <typename Handler> void serialize(Handler &h, const int version)
  1637. {
  1638. h & static_cast<CPackForServer &>(*this);
  1639. h & what;
  1640. h & p1;
  1641. h & p2;
  1642. h & id1;
  1643. h & id2;
  1644. h & val;
  1645. }
  1646. };
  1647. struct BulkMoveArmy : public CPackForServer
  1648. {
  1649. SlotID srcSlot;
  1650. ObjectInstanceID srcArmy;
  1651. ObjectInstanceID destArmy;
  1652. BulkMoveArmy()
  1653. {};
  1654. BulkMoveArmy(ObjectInstanceID srcArmy, ObjectInstanceID destArmy, SlotID srcSlot)
  1655. : srcArmy(srcArmy), destArmy(destArmy), srcSlot(srcSlot)
  1656. {};
  1657. bool applyGh(CGameHandler * gh);
  1658. template <typename Handler>
  1659. void serialize(Handler & h, const int version)
  1660. {
  1661. h & static_cast<CPackForServer&>(*this);
  1662. h & srcSlot;
  1663. h & srcArmy;
  1664. h & destArmy;
  1665. }
  1666. };
  1667. struct BulkSplitStack : public CPackForServer
  1668. {
  1669. SlotID src;
  1670. ObjectInstanceID srcOwner;
  1671. si32 amount;
  1672. BulkSplitStack() : amount(0)
  1673. {};
  1674. BulkSplitStack(ObjectInstanceID srcOwner, SlotID src, si32 howMany)
  1675. : src(src), srcOwner(srcOwner), amount(howMany)
  1676. {};
  1677. bool applyGh(CGameHandler * gh);
  1678. template <typename Handler>
  1679. void serialize(Handler & h, const int version)
  1680. {
  1681. h & static_cast<CPackForServer&>(*this);
  1682. h & src;
  1683. h & srcOwner;
  1684. h & amount;
  1685. }
  1686. };
  1687. struct BulkMergeStacks : public CPackForServer
  1688. {
  1689. SlotID src;
  1690. ObjectInstanceID srcOwner;
  1691. BulkMergeStacks()
  1692. {};
  1693. BulkMergeStacks(ObjectInstanceID srcOwner, SlotID src)
  1694. : src(src), srcOwner(srcOwner)
  1695. {};
  1696. bool applyGh(CGameHandler * gh);
  1697. template <typename Handler>
  1698. void serialize(Handler & h, const int version)
  1699. {
  1700. h & static_cast<CPackForServer&>(*this);
  1701. h & src;
  1702. h & srcOwner;
  1703. }
  1704. };
  1705. struct BulkSmartSplitStack : public CPackForServer
  1706. {
  1707. SlotID src;
  1708. ObjectInstanceID srcOwner;
  1709. BulkSmartSplitStack()
  1710. {};
  1711. BulkSmartSplitStack(ObjectInstanceID srcOwner, SlotID src)
  1712. : src(src), srcOwner(srcOwner)
  1713. {};
  1714. bool applyGh(CGameHandler * gh);
  1715. template <typename Handler>
  1716. void serialize(Handler & h, const int version)
  1717. {
  1718. h & static_cast<CPackForServer&>(*this);
  1719. h & src;
  1720. h & srcOwner;
  1721. }
  1722. };
  1723. struct DisbandCreature : public CPackForServer
  1724. {
  1725. DisbandCreature(){};
  1726. DisbandCreature(SlotID Pos, ObjectInstanceID ID):pos(Pos),id(ID){};
  1727. SlotID pos; //stack pos
  1728. ObjectInstanceID id; //object id
  1729. bool applyGh(CGameHandler *gh);
  1730. template <typename Handler> void serialize(Handler &h, const int version)
  1731. {
  1732. h & static_cast<CPackForServer &>(*this);
  1733. h & pos;
  1734. h & id;
  1735. }
  1736. };
  1737. struct BuildStructure : public CPackForServer
  1738. {
  1739. BuildStructure(){};
  1740. BuildStructure(ObjectInstanceID TID, BuildingID BID):tid(TID), bid(BID){};
  1741. ObjectInstanceID tid; //town id
  1742. BuildingID bid; //structure id
  1743. bool applyGh(CGameHandler *gh);
  1744. template <typename Handler> void serialize(Handler &h, const int version)
  1745. {
  1746. h & static_cast<CPackForServer &>(*this);
  1747. h & tid;
  1748. h & bid;
  1749. }
  1750. };
  1751. struct RazeStructure : public BuildStructure
  1752. {
  1753. RazeStructure(){};
  1754. bool applyGh(CGameHandler *gh);
  1755. };
  1756. struct RecruitCreatures : public CPackForServer
  1757. {
  1758. RecruitCreatures():amount(0), level(0){};
  1759. RecruitCreatures(ObjectInstanceID TID, ObjectInstanceID DST, CreatureID CRID, si32 Amount, si32 Level):
  1760. tid(TID), dst(DST), crid(CRID), amount(Amount), level(Level){};
  1761. ObjectInstanceID tid; //dwelling id, or town
  1762. ObjectInstanceID dst; //destination ID, e.g. hero
  1763. CreatureID crid;
  1764. ui32 amount;//creature amount
  1765. si32 level;//dwelling level to buy from, -1 if any
  1766. bool applyGh(CGameHandler *gh);
  1767. template <typename Handler> void serialize(Handler &h, const int version)
  1768. {
  1769. h & static_cast<CPackForServer &>(*this);
  1770. h & tid;
  1771. h & dst;
  1772. h & crid;
  1773. h & amount;
  1774. h & level;
  1775. }
  1776. };
  1777. struct UpgradeCreature : public CPackForServer
  1778. {
  1779. UpgradeCreature(){};
  1780. UpgradeCreature(SlotID Pos, ObjectInstanceID ID, CreatureID CRID):pos(Pos),id(ID), cid(CRID){};
  1781. SlotID pos; //stack pos
  1782. ObjectInstanceID id; //object id
  1783. CreatureID cid; //id of type to which we want make upgrade
  1784. bool applyGh(CGameHandler *gh);
  1785. template <typename Handler> void serialize(Handler &h, const int version)
  1786. {
  1787. h & static_cast<CPackForServer &>(*this);
  1788. h & pos;
  1789. h & id;
  1790. h & cid;
  1791. }
  1792. };
  1793. struct GarrisonHeroSwap : public CPackForServer
  1794. {
  1795. GarrisonHeroSwap(){};
  1796. GarrisonHeroSwap(ObjectInstanceID TID):tid(TID){};
  1797. ObjectInstanceID tid;
  1798. bool applyGh(CGameHandler *gh);
  1799. template <typename Handler> void serialize(Handler &h, const int version)
  1800. {
  1801. h & static_cast<CPackForServer &>(*this);
  1802. h & tid;
  1803. }
  1804. };
  1805. struct ExchangeArtifacts : public CPackForServer
  1806. {
  1807. ArtifactLocation src, dst;
  1808. ExchangeArtifacts(){};
  1809. bool applyGh(CGameHandler *gh);
  1810. template <typename Handler> void serialize(Handler &h, const int version)
  1811. {
  1812. h & static_cast<CPackForServer &>(*this);
  1813. h & src;
  1814. h & dst;
  1815. }
  1816. };
  1817. struct AssembleArtifacts : public CPackForServer
  1818. {
  1819. AssembleArtifacts():assemble(false){};
  1820. AssembleArtifacts(ObjectInstanceID _heroID, ArtifactPosition _artifactSlot, bool _assemble, ArtifactID _assembleTo)
  1821. : heroID(_heroID), artifactSlot(_artifactSlot), assemble(_assemble), assembleTo(_assembleTo){};
  1822. ObjectInstanceID heroID;
  1823. ArtifactPosition artifactSlot;
  1824. bool assemble; // True to assemble artifact, false to disassemble.
  1825. ArtifactID assembleTo; // Artifact to assemble into.
  1826. bool applyGh(CGameHandler *gh);
  1827. template <typename Handler> void serialize(Handler &h, const int version)
  1828. {
  1829. h & static_cast<CPackForServer &>(*this);
  1830. h & heroID;
  1831. h & artifactSlot;
  1832. h & assemble;
  1833. h & assembleTo;
  1834. }
  1835. };
  1836. struct BuyArtifact : public CPackForServer
  1837. {
  1838. BuyArtifact(){};
  1839. BuyArtifact(ObjectInstanceID HID, ArtifactID AID):hid(HID),aid(AID){};
  1840. ObjectInstanceID hid;
  1841. ArtifactID aid;
  1842. bool applyGh(CGameHandler *gh);
  1843. template <typename Handler> void serialize(Handler &h, const int version)
  1844. {
  1845. h & static_cast<CPackForServer &>(*this);
  1846. h & hid;
  1847. h & aid;
  1848. }
  1849. };
  1850. struct TradeOnMarketplace : public CPackForServer
  1851. {
  1852. TradeOnMarketplace()
  1853. :marketId(), heroId(), mode(EMarketMode::RESOURCE_RESOURCE)
  1854. {};
  1855. ObjectInstanceID marketId;
  1856. ObjectInstanceID heroId;
  1857. EMarketMode::EMarketMode mode;
  1858. 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?]
  1859. std::vector<ui32> val; //units of sold resource
  1860. bool applyGh(CGameHandler *gh);
  1861. template <typename Handler> void serialize(Handler &h, const int version)
  1862. {
  1863. h & static_cast<CPackForServer &>(*this);
  1864. h & marketId;
  1865. h & heroId;
  1866. h & mode;
  1867. h & r1;
  1868. h & r2;
  1869. h & val;
  1870. }
  1871. };
  1872. struct SetFormation : public CPackForServer
  1873. {
  1874. SetFormation():formation(0){};
  1875. SetFormation(ObjectInstanceID HID, ui8 Formation):hid(HID),formation(Formation){};
  1876. ObjectInstanceID hid;
  1877. ui8 formation;
  1878. bool applyGh(CGameHandler *gh);
  1879. template <typename Handler> void serialize(Handler &h, const int version)
  1880. {
  1881. h & static_cast<CPackForServer &>(*this);
  1882. h & hid;
  1883. h & formation;
  1884. }
  1885. };
  1886. struct HireHero : public CPackForServer
  1887. {
  1888. HireHero():hid(0){};
  1889. HireHero(si32 HID, ObjectInstanceID TID):hid(HID),tid(TID){};
  1890. si32 hid; //available hero serial
  1891. ObjectInstanceID tid; //town (tavern) id
  1892. PlayerColor player;
  1893. bool applyGh(CGameHandler *gh);
  1894. template <typename Handler> void serialize(Handler &h, const int version)
  1895. {
  1896. h & static_cast<CPackForServer &>(*this);
  1897. h & hid;
  1898. h & tid;
  1899. h & player;
  1900. }
  1901. };
  1902. struct BuildBoat : public CPackForServer
  1903. {
  1904. BuildBoat(){};
  1905. ObjectInstanceID objid; //where player wants to buy a boat
  1906. bool applyGh(CGameHandler *gh);
  1907. template <typename Handler> void serialize(Handler &h, const int version)
  1908. {
  1909. h & static_cast<CPackForServer &>(*this);
  1910. h & objid;
  1911. }
  1912. };
  1913. struct QueryReply : public CPackForServer
  1914. {
  1915. QueryReply(){};
  1916. QueryReply(QueryID QID, const JsonNode & Reply):qid(QID), reply(Reply){};
  1917. QueryID qid;
  1918. PlayerColor player;
  1919. JsonNode reply;
  1920. bool applyGh(CGameHandler *gh);
  1921. template <typename Handler> void serialize(Handler &h, const int version)
  1922. {
  1923. h & static_cast<CPackForServer &>(*this);
  1924. h & qid;
  1925. h & player;
  1926. h & reply;
  1927. }
  1928. };
  1929. struct MakeAction : public CPackForServer
  1930. {
  1931. MakeAction(){};
  1932. MakeAction(const BattleAction &BA):ba(BA){};
  1933. BattleAction ba;
  1934. bool applyGh(CGameHandler *gh);
  1935. template <typename Handler> void serialize(Handler &h, const int version)
  1936. {
  1937. h & static_cast<CPackForServer &>(*this);
  1938. h & ba;
  1939. }
  1940. };
  1941. struct MakeCustomAction : public CPackForServer
  1942. {
  1943. MakeCustomAction(){};
  1944. MakeCustomAction(const BattleAction &BA):ba(BA){};
  1945. BattleAction ba;
  1946. bool applyGh(CGameHandler *gh);
  1947. template <typename Handler> void serialize(Handler &h, const int version)
  1948. {
  1949. h & static_cast<CPackForServer &>(*this);
  1950. h & ba;
  1951. }
  1952. };
  1953. struct DigWithHero : public CPackForServer
  1954. {
  1955. DigWithHero(){}
  1956. ObjectInstanceID id; //digging hero id
  1957. bool applyGh(CGameHandler *gh);
  1958. template <typename Handler> void serialize(Handler &h, const int version)
  1959. {
  1960. h & static_cast<CPackForServer &>(*this);
  1961. h & id;
  1962. }
  1963. };
  1964. struct CastAdvSpell : public CPackForServer
  1965. {
  1966. CastAdvSpell(){}
  1967. ObjectInstanceID hid; //hero id
  1968. SpellID sid; //spell id
  1969. int3 pos; //selected tile (not always used)
  1970. bool applyGh(CGameHandler *gh);
  1971. template <typename Handler> void serialize(Handler &h, const int version)
  1972. {
  1973. h & static_cast<CPackForServer &>(*this);
  1974. h & hid;
  1975. h & sid;
  1976. h & pos;
  1977. }
  1978. };
  1979. /***********************************************************************************************************/
  1980. struct SaveGame : public CPackForServer
  1981. {
  1982. SaveGame(){};
  1983. SaveGame(const std::string &Fname) :fname(Fname){};
  1984. std::string fname;
  1985. void applyGs(CGameState *gs){};
  1986. bool applyGh(CGameHandler *gh);
  1987. template <typename Handler> void serialize(Handler &h, const int version)
  1988. {
  1989. h & static_cast<CPackForServer &>(*this);
  1990. h & fname;
  1991. }
  1992. };
  1993. // TODO: Eventually we should re-merge both SaveGame and PlayerMessage
  1994. struct SaveGameClient : public CPackForClient
  1995. {
  1996. SaveGameClient(){};
  1997. SaveGameClient(const std::string &Fname) :fname(Fname){};
  1998. std::string fname;
  1999. void applyCl(CClient *cl);
  2000. template <typename Handler> void serialize(Handler &h, const int version)
  2001. {
  2002. h & fname;
  2003. }
  2004. };
  2005. struct PlayerMessage : public CPackForServer
  2006. {
  2007. PlayerMessage(){};
  2008. PlayerMessage(const std::string &Text, ObjectInstanceID obj)
  2009. : text(Text), currObj(obj)
  2010. {};
  2011. void applyGs(CGameState *gs){};
  2012. bool applyGh(CGameHandler *gh);
  2013. std::string text;
  2014. ObjectInstanceID currObj; // optional parameter that specifies current object. For cheats :)
  2015. template <typename Handler> void serialize(Handler &h, const int version)
  2016. {
  2017. h & static_cast<CPackForServer &>(*this);
  2018. h & text;
  2019. h & currObj;
  2020. }
  2021. };
  2022. struct PlayerMessageClient : public CPackForClient
  2023. {
  2024. PlayerMessageClient(){};
  2025. PlayerMessageClient(PlayerColor Player, const std::string &Text)
  2026. : player(Player), text(Text)
  2027. {}
  2028. void applyCl(CClient *cl);
  2029. PlayerColor player;
  2030. std::string text;
  2031. template <typename Handler> void serialize(Handler &h, const int version)
  2032. {
  2033. h & player;
  2034. h & text;
  2035. }
  2036. };
  2037. struct CenterView : public CPackForClient
  2038. {
  2039. CenterView():focusTime(0){};
  2040. void applyCl(CClient *cl);
  2041. PlayerColor player;
  2042. int3 pos;
  2043. ui32 focusTime; //ms
  2044. template <typename Handler> void serialize(Handler &h, const int version)
  2045. {
  2046. h & pos;
  2047. h & player;
  2048. h & focusTime;
  2049. }
  2050. };