NetPacks.h 57 KB

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