NetPacks.h 57 KB

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