NetPacks.h 56 KB

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