NetPacks.h 55 KB

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