NetPacks.h 54 KB

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