NetPacks.h 55 KB

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