NetPacks.h 54 KB

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