NetPacks.h 56 KB

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