NetPacks.h 56 KB

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