CObjectHandler.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. #ifndef __COBJECTHANDLER_H__
  2. #define __COBJECTHANDLER_H__
  3. #include "../global.h"
  4. #include <string>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <list>
  9. #include "CCreatureHandler.h"
  10. #include "../lib/HeroBonus.h"
  11. #ifndef _MSC_VER
  12. #include "CHeroHandler.h"
  13. #include "CTownHandler.h"
  14. #include "../lib/VCMI_Lib.h"
  15. #endif
  16. /*
  17. * CObjectHandler.h, part of VCMI engine
  18. *
  19. * Authors: listed in file AUTHORS in main folder
  20. *
  21. * License: GNU General Public License v2.0 or later
  22. * Full text of license available in license.txt file, in main folder
  23. *
  24. */
  25. class IGameCallback;
  26. struct BattleResult;
  27. class CCPPObjectScript;
  28. class CGObjectInstance;
  29. class CScript;
  30. class CObjectScript;
  31. class CGHeroInstance;
  32. class CTown;
  33. class CHero;
  34. class CBuilding;
  35. class CSpell;
  36. class CGTownInstance;
  37. class CGTownBuilding;
  38. class CArtifact;
  39. class CGDefInfo;
  40. class CSpecObjInfo;
  41. struct TerrainTile;
  42. struct InfoWindow;
  43. struct Component;
  44. struct BankConfig;
  45. class CGBoat;
  46. class DLL_EXPORT CCastleEvent
  47. {
  48. public:
  49. std::string name, message;
  50. std::vector<si32> resources; //gain / loss of resources
  51. ui8 players; //players for whom this event can be applied
  52. ui8 forHuman, forComputer;
  53. ui32 firstShow; //postpone of first encounter time in days
  54. ui32 forEvery; //every n days this event will occure
  55. ui8 bytes[6]; //build specific buildings (raw format, similar to town's)
  56. si32 gen[7]; //additional creatures in i-th level dwelling
  57. bool operator<(const CCastleEvent &drugie) const
  58. {
  59. return firstShow<drugie.firstShow;
  60. }
  61. template <typename Handler> void serialize(Handler &h, const int version)
  62. {
  63. h & name & message & resources & players & forHuman & forComputer & firstShow
  64. & forEvery & bytes & gen;
  65. }
  66. };
  67. class DLL_EXPORT CQuest
  68. {
  69. public:
  70. enum Emission {MISSION_NONE = 0, MISSION_LEVEL = 1, MISSION_PRIMARY_STAT = 2, MISSION_KILL_HERO = 3, MISSION_KILL_CREATURE = 4,
  71. MISSION_ART = 5, MISSION_ARMY = 6, MISSION_RESOURCES = 7, MISSION_HERO = 8, MISSION_PLAYER = 9};
  72. ui8 missionType, progress;
  73. si32 lastDay; //after this day (first day is 0) mission cannot be completed; if -1 - no limit
  74. ui32 m13489val;
  75. std::vector<ui32> m2stats;
  76. std::vector<ui16> m5arts; //artifacts id
  77. TSlots m6creatures; //pair[cre id, cre count], CreatureSet info irrelevant
  78. std::vector<ui32> m7resources;
  79. std::string firstVisitText, nextVisitText, completedText;
  80. bool checkQuest (const CGHeroInstance * h) const; //determines whether the quest is complete or not
  81. virtual void completeQuest (const CGHeroInstance * h) const {};
  82. template <typename Handler> void serialize(Handler &h, const int version)
  83. {
  84. h & missionType & progress & lastDay & m13489val & m2stats & m5arts & m6creatures & m7resources
  85. & firstVisitText & nextVisitText & completedText;
  86. }
  87. };
  88. class DLL_EXPORT IObjectInterface
  89. {
  90. public:
  91. static IGameCallback *cb;
  92. IObjectInterface();
  93. virtual ~IObjectInterface();
  94. virtual void onHeroVisit(const CGHeroInstance * h) const;
  95. virtual void onHeroLeave(const CGHeroInstance * h) const;
  96. virtual void newTurn() const;
  97. virtual void initObj(); //synchr
  98. virtual void setProperty(ui8 what, ui32 val);//synchr
  99. static void preInit(); //called before objs receive their initObj
  100. static void postInit();//caleed after objs receive their initObj
  101. };
  102. class DLL_EXPORT IBoatGenerator
  103. {
  104. public:
  105. const CGObjectInstance *o;
  106. IBoatGenerator(const CGObjectInstance *O);
  107. virtual int getBoatType() const; //0 - evil (if a ship can be evil...?), 1 - good, 2 - neutral
  108. virtual void getOutOffsets(std::vector<int3> &offsets) const =0; //offsets to obj pos when we boat can be placed
  109. int3 bestLocation() const; //returns location when the boat should be placed
  110. int state() const; //0 - can buid, 1 - there is already a boat at dest tile, 2 - dest tile is blocked, 3 - no water
  111. };
  112. class DLL_EXPORT IShipyard : public IBoatGenerator
  113. {
  114. public:
  115. IShipyard(const CGObjectInstance *O);
  116. virtual void getBoatCost(std::vector<si32> &cost) const;
  117. static const IShipyard *castFrom(const CGObjectInstance *obj);
  118. static IShipyard *castFrom(CGObjectInstance *obj);
  119. };
  120. class DLL_EXPORT CGObjectInstance : public IObjectInterface
  121. {
  122. protected:
  123. void getNameVis(std::string &hname) const;
  124. void giveDummyBonus(int heroID, ui8 duration = HeroBonus::ONE_DAY) const;
  125. public:
  126. mutable std::string hoverName;
  127. int3 pos; //h3m pos
  128. si32 ID, subID; //normal ID (this one from OH3 maps ;]) - eg. town=98; hero=34
  129. si32 id;//number of object in CObjectHandler's vector
  130. CGDefInfo * defInfo;
  131. ui8 animPhaseShift;
  132. ui8 tempOwner;
  133. ui8 blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile
  134. virtual ui8 getPassableness() const; //bitmap - if the bit is set the corresponding player can pass through the visitable tiles of object, even if it's blockvis; if not set - default properties from definfo are used
  135. virtual int3 getSightCenter() const; //"center" tile from which the sight distance is calculated
  136. virtual int getSightRadious() const; //sight distance (should be used if player-owned structure)
  137. void getSightTiles(std::set<int3> &tiles) const; //returns reference to the set
  138. int getOwner() const;
  139. void setOwner(int ow);
  140. int getWidth() const; //returns width of object graphic in tiles
  141. int getHeight() const; //returns height of object graphic in tiles
  142. bool visitableAt(int x, int y) const; //returns true if object is visitable at location (x, y) form left top tile of image (x, y in tiles)
  143. int3 getVisitableOffset() const; //returns (x,y,0) offset to first visitable tile from bottom right obj tile (0,0,0) (h3m pos)
  144. bool blockingAt(int x, int y) const; //returns true if object is blocking location (x, y) form left top tile of image (x, y in tiles)
  145. bool coveringAt(int x, int y) const; //returns true if object covers with picture location (x, y) form left top tile of maximal possible image (8 x 6 tiles) (x, y in tiles)
  146. bool hasShadowAt(int x, int y) const;//returns true if object covers with shadow location (x, y) form left top tile of maximal possible image (8 x 6 tiles) (x, y in tiles)
  147. std::set<int3> getBlockedPos() const; //returns set of positions blocked by this object
  148. bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing
  149. CGObjectInstance();
  150. virtual ~CGObjectInstance();
  151. //CGObjectInstance(const CGObjectInstance & right);
  152. //CGObjectInstance& operator=(const CGObjectInstance & right);
  153. virtual const std::string & getHoverText() const;
  154. //////////////////////////////////////////////////////////////////////////
  155. void initObj();
  156. void onHeroVisit(const CGHeroInstance * h) const;
  157. void setProperty(ui8 what, ui32 val);//synchr
  158. virtual void setPropertyDer(ui8 what, ui32 val);//synchr
  159. friend class CGameHandler;
  160. template <typename Handler> void serialize(Handler &h, const int version)
  161. {
  162. h & hoverName & pos & ID & subID & id & animPhaseShift & tempOwner & blockVisit;
  163. //definfo is handled by map serializer
  164. }
  165. };
  166. class CGHeroPlaceholder : public CGObjectInstance
  167. {
  168. public:
  169. //subID stores id of hero type. If it's 0xff then following field is used
  170. ui8 power;
  171. template <typename Handler> void serialize(Handler &h, const int version)
  172. {
  173. h & static_cast<CGObjectInstance&>(*this);
  174. h & power;
  175. }
  176. };
  177. class DLL_EXPORT CPlayersVisited: public CGObjectInstance
  178. {
  179. public:
  180. std::set<ui8> players; //players that visited this object
  181. bool hasVisited(ui8 player) const;
  182. virtual void setPropertyDer( ui8 what, ui32 val );
  183. template <typename Handler> void serialize(Handler &h, const int version)
  184. {
  185. h & static_cast<CGObjectInstance&>(*this);
  186. h & players;
  187. }
  188. };
  189. class DLL_EXPORT CArmedInstance: public CGObjectInstance
  190. {
  191. public:
  192. CCreatureSet army; //army
  193. virtual bool needsLastStack() const; //true if last stack cannot be taken
  194. int getArmyStrength() const; //sum of AI values of creatures
  195. ui64 getPower (TSlot slot) const; //value of specific stack
  196. std::string getRoughAmount (TSlot slot) const; //rought size of specific stack
  197. template <typename Handler> void serialize(Handler &h, const int version)
  198. {
  199. h & static_cast<CGObjectInstance&>(*this);
  200. h & army;
  201. }
  202. };
  203. class DLL_EXPORT CGHeroInstance : public CArmedInstance, public IBoatGenerator
  204. {
  205. public:
  206. //////////////////////////////////////////////////////////////////////////
  207. ui8 moveDir; //format: 123
  208. // 8 4
  209. // 765
  210. mutable ui8 isStanding, tacticFormationEnabled;
  211. //////////////////////////////////////////////////////////////////////////
  212. CHero * type;
  213. ui64 exp; //experience points
  214. si32 level; //current level of hero
  215. std::string name; //may be custom
  216. std::string biography; //if custom
  217. si32 portrait; //may be custom
  218. si32 mana; // remaining spell points
  219. std::vector<si32> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
  220. std::vector<std::pair<ui8,ui8> > secSkills; //first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert); if hero has ability (-1, -1) it meansthat it should have default secondary abilities
  221. si32 movement; //remaining movement points
  222. ui8 sex;
  223. ui8 inTownGarrison; // if hero is in town garrison
  224. CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison
  225. CGBoat *boat; //set to CGBoat when sailing
  226. std::vector<ui32> artifacts; //hero's artifacts from bag
  227. std::map<ui16,ui32> 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
  228. std::set<ui32> spells; //known spells (spell IDs)
  229. struct DLL_EXPORT Patrol
  230. {
  231. Patrol(){patrolling=false;patrolRadious=-1;};
  232. ui8 patrolling;
  233. si32 patrolRadious;
  234. template <typename Handler> void serialize(Handler &h, const int version)
  235. {
  236. h & patrolling & patrolRadious;
  237. }
  238. } patrol;
  239. BonusList bonuses;
  240. //////////////////////////////////////////////////////////////////////////
  241. template <typename Handler> void serialize(Handler &h, const int version)
  242. {
  243. h & static_cast<CArmedInstance&>(*this);
  244. h & exp & level & name & biography & portrait & mana & primSkills & secSkills & movement
  245. & sex & inTownGarrison & artifacts & artifWorn & spells & patrol & bonuses
  246. & moveDir;
  247. h & type;
  248. //visitied town pointer will be restored by map serialization method
  249. }
  250. //////////////////////////////////////////////////////////////////////////
  251. int3 getSightCenter() const; //"center" tile from which the sight distance is calculated
  252. int getSightRadious() const; //sight distance (should be used if player-owned structure)
  253. //////////////////////////////////////////////////////////////////////////
  254. int getBoatType() const; //0 - evil (if a ship can be evil...?), 1 - good, 2 - neutral
  255. void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
  256. //////////////////////////////////////////////////////////////////////////
  257. const std::string &getBiography() const;
  258. bool needsLastStack()const;
  259. unsigned int getTileCost(const TerrainTile &dest, const TerrainTile &from) const; //move cost - applying pathfinding skill, road and terrain modifiers. NOT includes diagonal move penalty, last move levelling
  260. unsigned int getLowestCreatureSpeed() const;
  261. int3 getPosition(bool h3m = false) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
  262. si32 manaLimit() const; //maximum mana value for this hero (basically 10*knowledge)
  263. si32 manaRegain() const; //how many points of mana can hero regain "naturally" in one day
  264. bool canWalkOnSea() const;
  265. int getCurrentLuck(int stack=-1, bool town=false) const;
  266. int getSpellCost(const CSpell *sp) const; //do not use during battles -> bonuses from army would be ignored
  267. const BonusList *ownerBonuses() const;
  268. const HeroBonus *getBonus(int from, int id) const;
  269. int getBonusesCount(int from, int id) const;
  270. int valOfBonuses(HeroBonus::BonusType type, int subtype = -1) const; //subtype -> subtype of bonus, if -1 then any
  271. bool hasBonusOfType(HeroBonus::BonusType type, int subtype = -1) const; //determines if hero has a bonus of given type (and optionally subtype)
  272. void getModifiersWDescr(std::vector<std::pair<int,std::string> > &out, HeroBonus::BonusType type, int subtype = -1) const; //out: pairs<modifier value, modifier description>
  273. template<int N> void getModifiersWDescr(std::vector<std::pair<int,std::string> > &out, const HeroBonus::BonusType (&types)[N]) const //retreive array of types
  274. {
  275. for (int i = 0; i < N; i++)
  276. getModifiersWDescr(out, types[i]);
  277. }
  278. std::vector<std::pair<int,std::string> > getCurrentLuckModifiers(int stack=-1, bool town=false) const; //args as above
  279. int getCurrentMorale(int stack=-1, bool town=false) const; //if stack - position of creature, if -1 then morale for hero is calculated; town - if bonuses from town (tavern) should be considered
  280. std::vector<std::pair<int,std::string> > getCurrentMoraleModifiers(int stack=-1, bool town=false) const; //args as above
  281. int getPrimSkillLevel(int id) const; //0-attack, 1-defence, 2-spell power, 3-knowledge
  282. ui8 getSecSkillLevel(const int & ID) const; //0 - no skill
  283. int maxMovePoints(bool onLand) const;
  284. ui32 getArtAtPos(ui16 pos) const; //-1 - no artifact
  285. const CArtifact * getArt(int pos) const;
  286. si32 getArtPos(int aid) const; //looks for equipped artifact with given ID and returns its slot ID or -1 if none(if more than one such artifact lower ID is returned)
  287. bool hasArt(ui32 aid) const; //checks if hero possess artifact of given id (either in backack or worn)
  288. int getSpellSecLevel(int spell) const; //returns level of secondary ability (fire, water, earth, air magic) known to this hero and applicable to given spell; -1 if error
  289. static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
  290. double getHeroStrength() const;
  291. int getTotalStrength() const;
  292. ui8 getSpellSchoolLevel(const CSpell * spell) const; //returns level on which given spell would be cast by this hero (0 - none, 1 - basic etc)
  293. bool canCastThisSpell(const CSpell * spell) const; //determines if this hero can cast given spell; takes into account existing spell in spellbook, existing spellbook and artifact bonuses
  294. std::pair<ui32, si32> calculateNecromancy (const BattleResult &battleResult) const;
  295. void showNecromancyDialog (std::pair<ui32, si32> raisedStack) const;
  296. //////////////////////////////////////////////////////////////////////////
  297. void initHero();
  298. void initHero(int SUBID);
  299. void recreateArtBonuses();
  300. void giveArtifact (ui32 aid);
  301. void initHeroDefInfo();
  302. CGHeroInstance();
  303. virtual ~CGHeroInstance();
  304. //////////////////////////////////////////////////////////////////////////
  305. void setPropertyDer(ui8 what, ui32 val);//synchr
  306. void initObj();
  307. void onHeroVisit(const CGHeroInstance * h) const;
  308. };
  309. class DLL_EXPORT CGDwelling : public CArmedInstance
  310. {
  311. public:
  312. CSpecObjInfo * info; //h3m info about dewlling
  313. std::vector<std::pair<ui32, std::vector<ui32> > > creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
  314. template <typename Handler> void serialize(Handler &h, const int version)
  315. {
  316. h & static_cast<CArmedInstance&>(*this) & creatures;
  317. }
  318. void initObj();
  319. void setProperty(ui8 what, ui32 val);
  320. void onHeroVisit(const CGHeroInstance * h) const;
  321. void newTurn() const;
  322. void heroAcceptsCreatures(const CGHeroInstance *h, ui32 answer) const;
  323. void fightOver(const CGHeroInstance *h, BattleResult *result) const;
  324. void wantsFight(const CGHeroInstance *h, ui32 answer) const;
  325. };
  326. class DLL_EXPORT CGVisitableOPH : public CGObjectInstance //objects visitable only once per hero
  327. {
  328. public:
  329. std::set<si32> visitors; //ids of heroes who have visited this obj
  330. si8 ttype; //tree type - used only by trees of knowledge: 0 - give level for free; 1 - take 2000 gold; 2 - take 10 gems
  331. const std::string & getHoverText() const;
  332. void setPropertyDer(ui8 what, ui32 val);//synchr
  333. void onHeroVisit(const CGHeroInstance * h) const;
  334. void onNAHeroVisit(int heroID, bool alreadyVisited) const;
  335. void initObj();
  336. void treeSelected(int heroID, int resType, int resVal, ui64 expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog
  337. void schoolSelected(int heroID, ui32 which) const;
  338. void arenaSelected(int heroID, int primSkill) const;
  339. template <typename Handler> void serialize(Handler &h, const int version)
  340. {
  341. h & static_cast<CGObjectInstance&>(*this);
  342. h & visitors & ttype;
  343. }
  344. };
  345. class DLL_EXPORT CGTownBuilding : public IObjectInterface
  346. {
  347. ///basic class for town structures handled as map objects
  348. public:
  349. si32 ID; //from buildig list
  350. si32 id; //identifies its index on towns vector
  351. CGTownInstance *town;
  352. template <typename Handler> void serialize(Handler &h, const int version)
  353. {
  354. h & ID & id;
  355. }
  356. };
  357. class DLL_EXPORT COPWBonus : public CGTownBuilding
  358. {///used for OPW bonusing structures
  359. public:
  360. std::set<si32> visitors;
  361. void setProperty(ui8 what, ui32 val);
  362. void onHeroVisit (const CGHeroInstance * h) const;
  363. COPWBonus (int index, CGTownInstance *TOWN);
  364. COPWBonus (){ID = 0; town = NULL;};
  365. template <typename Handler> void serialize(Handler &h, const int version)
  366. {
  367. h & static_cast<CGTownBuilding&>(*this);
  368. h & visitors;
  369. }
  370. };
  371. class DLL_EXPORT CTownBonus : public CGTownBuilding
  372. {
  373. ///used for one-time bonusing structures
  374. ///feel free to merge inheritance tree
  375. public:
  376. std::set<si32> visitors;
  377. void setProperty(ui8 what, ui32 val);
  378. void onHeroVisit (const CGHeroInstance * h) const;
  379. CTownBonus (int index, CGTownInstance *TOWN);
  380. CTownBonus (){ID = 0; town = NULL;};
  381. template <typename Handler> void serialize(Handler &h, const int version)
  382. {
  383. h & static_cast<CGTownBuilding&>(*this);
  384. h & visitors;
  385. }
  386. };
  387. class DLL_EXPORT CGTownInstance : public CGDwelling, public IShipyard
  388. {
  389. public:
  390. CTown * town;
  391. std::string name; // name of town
  392. si32 builded; //how many buildings has been built this turn
  393. si32 destroyed; //how many buildings has been destroyed this turn
  394. const CGHeroInstance * garrisonHero, *visitingHero;
  395. ui32 identifier; //special identifier from h3m (only > RoE maps)
  396. si32 alignment;
  397. std::set<si32> forbiddenBuildings, builtBuildings;
  398. std::vector<CGTownBuilding*> bonusingBuildings;
  399. std::vector<ui32> possibleSpells, obligatorySpells;
  400. std::vector<std::vector<ui32> > spells; //spells[level] -> vector of spells, first will be available in guild
  401. std::set<CCastleEvent> events;
  402. std::pair<si32, si32> bonusValue;//var to store town bonuses (rampart = resources from mystic pond);
  403. //////////////////////////////////////////////////////////////////////////
  404. template <typename Handler> void serialize(Handler &h, const int version)
  405. {
  406. h & static_cast<CGDwelling&>(*this);
  407. h & name & builded & destroyed & identifier & alignment & forbiddenBuildings & builtBuildings & bonusValue
  408. & possibleSpells & obligatorySpells & spells & /*strInfo & */events & bonusingBuildings;
  409. for (std::vector<CGTownBuilding*>::iterator i = bonusingBuildings.begin(); i!=bonusingBuildings.end(); i++)
  410. (*i)->town = this;
  411. h & town;
  412. //garrison/visiting hero pointers will be restored in the map serialization
  413. }
  414. //////////////////////////////////////////////////////////////////////////
  415. ui8 getPassableness() const; //bitmap - if the bit is set the corresponding player can pass through the visitable tiles of object, even if it's blockvis; if not set - default properties from definfo are used
  416. int3 getSightCenter() const; //"center" tile from which the sight distance is calculated
  417. int getSightRadious() const; //returns sight distance
  418. int getBoatType() const; //0 - evil (if a ship can be evil...?), 1 - good, 2 - neutral
  419. void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
  420. void setPropertyDer(ui8 what, ui32 val);
  421. void newTurn() const;
  422. //////////////////////////////////////////////////////////////////////////
  423. bool needsLastStack() const;
  424. int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle
  425. int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  426. int mageGuildLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  427. bool creatureDwelling(const int & level, bool upgraded=false) const;
  428. int getHordeLevel(const int & HID) const; //HID - 0 or 1; returns creature level or -1 if that horde structure is not present
  429. int creatureGrowth(const int & level) const;
  430. bool hasFort() const;
  431. bool hasCapitol() const;
  432. int dailyIncome() const; //calculates daily income of this town
  433. int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
  434. void removeCapitols (ui8 owner) const;
  435. int defenceBonus(int type) const;//primary skills bonuses for defending hero
  436. CGTownInstance();
  437. virtual ~CGTownInstance();
  438. //////////////////////////////////////////////////////////////////////////
  439. void fightOver(const CGHeroInstance *h, BattleResult *result) const;
  440. void onHeroVisit(const CGHeroInstance * h) const;
  441. void onHeroLeave(const CGHeroInstance * h) const;
  442. void initObj();
  443. };
  444. class DLL_EXPORT CGPandoraBox : public CArmedInstance
  445. {
  446. public:
  447. std::string message;
  448. ui8 removeAfterVisit; //true if event is removed after occurring
  449. //gained things:
  450. ui32 gainedExp;
  451. si32 manaDiff; //amount of gained / lost mana
  452. si32 moraleDiff; //morale modifier
  453. si32 luckDiff; //luck modifier
  454. std::vector<si32> resources;//gained / lost resources
  455. std::vector<si32> primskills;//gained / lost resources
  456. std::vector<si32> abilities; //gained abilities
  457. std::vector<si32> abilityLevels; //levels of gained abilities
  458. std::vector<si32> artifacts; //gained artifacts
  459. std::vector<si32> spells; //gained spells
  460. CCreatureSet creatures; //gained creatures
  461. void initObj();
  462. void onHeroVisit(const CGHeroInstance * h) const;
  463. void open (const CGHeroInstance * h, ui32 accept) const;
  464. void endBattle(const CGHeroInstance *h, BattleResult *result) const;
  465. void giveContents(const CGHeroInstance *h, bool afterBattle) const;
  466. void getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const;
  467. void getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const;
  468. template <typename Handler> void serialize(Handler &h, const int version)
  469. {
  470. h & static_cast<CArmedInstance&>(*this);
  471. h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
  472. & abilities & abilityLevels & artifacts & spells & creatures & army;
  473. }
  474. };
  475. class DLL_EXPORT CGEvent : public CGPandoraBox //event objects
  476. {
  477. public:
  478. ui8 availableFor; //players whom this event is available for
  479. ui8 computerActivate; //true if computre player can activate this event
  480. ui8 humanActivate; //true if human player can activate this event
  481. template <typename Handler> void serialize(Handler &h, const int version)
  482. {
  483. h & static_cast<CArmedInstance&>(*this);
  484. h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
  485. & abilities & abilityLevels & artifacts & spells & creatures & availableFor
  486. & computerActivate & humanActivate & army;
  487. }
  488. void onHeroVisit(const CGHeroInstance * h) const;
  489. void activated(const CGHeroInstance * h) const;
  490. };
  491. class DLL_EXPORT CGCreature : public CArmedInstance //creatures on map
  492. {
  493. public:
  494. ui32 identifier; //unique code for this monster (used in missions)
  495. si8 character; //chracter of this set of creatures (0 - the most friendly, 4 - the most hostile) => on init changed to 0 (compliant) - 10 value (savage)
  496. std::string message; //message printed for attacking hero
  497. std::vector<ui32> resources; //[res_id], resources given to hero that has won with monsters
  498. si32 gainedArtifact; //ID of artifact gained to hero, -1 if none
  499. ui8 neverFlees; //if true, the troops will never flee
  500. ui8 notGrowingTeam; //if true, number of units won't grow
  501. void fight(const CGHeroInstance *h) const;
  502. void onHeroVisit(const CGHeroInstance * h) const;
  503. //const std::string & getHoverText() const;
  504. void flee( const CGHeroInstance * h ) const;
  505. void endBattle(BattleResult *result) const;
  506. void fleeDecision(const CGHeroInstance *h, ui32 pursue) const;
  507. void joinDecision(const CGHeroInstance *h, int cost, ui32 accept) const;
  508. void initObj();
  509. int takenAction(const CGHeroInstance *h, bool allowJoin=true) const; //action on confrontation: -2 - fight, -1 - flee, >=0 - will join for given value of gold (may be 0)
  510. template <typename Handler> void serialize(Handler &h, const int version)
  511. {
  512. h & static_cast<CArmedInstance&>(*this);
  513. h & identifier & character & message & resources & gainedArtifact & neverFlees & notGrowingTeam;
  514. }
  515. };
  516. class DLL_EXPORT CGSignBottle : public CGObjectInstance //signs and ocean bottles
  517. {
  518. public:
  519. std::string message;
  520. void onHeroVisit(const CGHeroInstance * h) const;
  521. void initObj();
  522. template <typename Handler> void serialize(Handler &h, const int version)
  523. {
  524. h & static_cast<CGObjectInstance&>(*this);
  525. h & message;
  526. }
  527. };
  528. class DLL_EXPORT CGSeerHut : public CGObjectInstance, public CQuest
  529. {
  530. public:
  531. ui8 rewardType; //type of reward: 0 - no reward; 1 - experience; 2 - mana points; 3 - morale bonus; 4 - luck bonus; 5 - resources; 6 - main ability bonus (attak, defence etd.); 7 - secondary ability gain; 8 - artifact; 9 - spell; 10 - creature
  532. si32 rID; //reward ID
  533. si32 rVal; //reward value
  534. ui8 textOption; //store randomized mission write-ups rather than entire string (?)
  535. std::string seerName;
  536. void initObj();
  537. const std::string & getHoverText() const;
  538. void setPropertyDer (ui8 what, ui32 val);
  539. int checkDirection() const; //calculates the region of map where monster is placed
  540. void newTurn() const;
  541. void onHeroVisit (const CGHeroInstance * h) const;
  542. void finishQuest (const CGHeroInstance * h, ui32 accept) const; //common for both objects
  543. void completeQuest (const CGHeroInstance * h) const;
  544. template <typename Handler> void serialize(Handler &h, const int version)
  545. {
  546. h & static_cast<CGObjectInstance&>(*this) & static_cast<CQuest&>(*this);
  547. h & rewardType & rID & rVal & textOption & seerName;
  548. }
  549. };
  550. class DLL_EXPORT CGQuestGuard : public CGSeerHut
  551. {
  552. public:
  553. void initObj();
  554. void completeQuest (const CGHeroInstance * h) const;
  555. template <typename Handler> void serialize(Handler &h, const int version)
  556. {
  557. h & static_cast<CGSeerHut&>(*this);
  558. }
  559. };
  560. class DLL_EXPORT CGWitchHut : public CPlayersVisited
  561. {
  562. public:
  563. std::vector<si32> allowedAbilities;
  564. ui32 ability;
  565. const std::string & getHoverText() const;
  566. void onHeroVisit(const CGHeroInstance * h) const;
  567. void initObj();
  568. template <typename Handler> void serialize(Handler &h, const int version)
  569. {
  570. h & static_cast<CPlayersVisited&>(*this);
  571. h & allowedAbilities & ability;
  572. }
  573. };
  574. class DLL_EXPORT CGScholar : public CGObjectInstance
  575. {
  576. public:
  577. ui8 bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell
  578. ui16 bonusID; //ID of skill/spell
  579. void giveAnyBonus(const CGHeroInstance * h) const;
  580. void onHeroVisit(const CGHeroInstance * h) const;
  581. void initObj();
  582. template <typename Handler> void serialize(Handler &h, const int version)
  583. {
  584. h & static_cast<CGObjectInstance&>(*this);
  585. h & bonusType & bonusID;
  586. }
  587. };
  588. class DLL_EXPORT CGGarrison : public CArmedInstance
  589. {
  590. public:
  591. ui8 removableUnits;
  592. ui8 getPassableness() const;
  593. void onHeroVisit (const CGHeroInstance *h) const;
  594. void fightOver (const CGHeroInstance *h, BattleResult *result) const;
  595. template <typename Handler> void serialize(Handler &h, const int version)
  596. {
  597. h & static_cast<CArmedInstance&>(*this);
  598. h & removableUnits;
  599. }
  600. };
  601. class DLL_EXPORT CGArtifact : public CArmedInstance
  602. {
  603. public:
  604. std::string message;
  605. ui32 spell; //if it's spell scroll
  606. void onHeroVisit(const CGHeroInstance * h) const;
  607. void fightForArt(ui32 agreed, const CGHeroInstance *h) const;
  608. void endBattle(BattleResult *result, const CGHeroInstance *h) const;
  609. void pick( const CGHeroInstance * h ) const;
  610. void initObj();
  611. template <typename Handler> void serialize(Handler &h, const int version)
  612. {
  613. h & static_cast<CArmedInstance&>(*this);
  614. h & message & spell;
  615. }
  616. };
  617. class DLL_EXPORT CGResource : public CArmedInstance
  618. {
  619. public:
  620. ui32 amount; //0 if random
  621. std::string message;
  622. void onHeroVisit(const CGHeroInstance * h) const;
  623. void collectRes(int player) const;
  624. void initObj();
  625. void fightForRes(ui32 agreed, const CGHeroInstance *h) const;
  626. void endBattle(BattleResult *result, const CGHeroInstance *h) const;
  627. template <typename Handler> void serialize(Handler &h, const int version)
  628. {
  629. h & static_cast<CArmedInstance&>(*this);
  630. h & amount & message;
  631. }
  632. };
  633. class DLL_EXPORT CGPickable : public CGObjectInstance //campfire, treasure chest, Flotsam, Shipwreck Survivor, Sea Chest
  634. {
  635. public:
  636. ui32 type, val1, val2;
  637. void onHeroVisit(const CGHeroInstance * h) const;
  638. void initObj();
  639. void chosen(int which, int heroID) const;
  640. template <typename Handler> void serialize(Handler &h, const int version)
  641. {
  642. h & static_cast<CGObjectInstance&>(*this);
  643. h & type & val1 & val2;
  644. }
  645. };
  646. class DLL_EXPORT CGShrine : public CPlayersVisited
  647. {
  648. public:
  649. ui8 spell; //number of spell or 255 if random
  650. void onHeroVisit(const CGHeroInstance * h) const;
  651. void initObj();
  652. const std::string & getHoverText() const;
  653. template <typename Handler> void serialize(Handler &h, const int version)
  654. {
  655. h & static_cast<CPlayersVisited&>(*this);;
  656. h & spell;
  657. }
  658. };
  659. class DLL_EXPORT CGMine : public CArmedInstance
  660. {
  661. public:
  662. void offerLeavingGuards(const CGHeroInstance *h) const;
  663. void onHeroVisit(const CGHeroInstance * h) const;
  664. void newTurn() const;
  665. void initObj();
  666. template <typename Handler> void serialize(Handler &h, const int version)
  667. {
  668. h & static_cast<CArmedInstance&>(*this);
  669. }
  670. };
  671. class DLL_EXPORT CGVisitableOPW : public CGObjectInstance //objects visitable OPW
  672. {
  673. public:
  674. ui8 visited; //true if object has been visited this week
  675. void setPropertyDer(ui8 what, ui32 val);//synchr
  676. void onHeroVisit(const CGHeroInstance * h) const;
  677. void newTurn() const;
  678. template <typename Handler> void serialize(Handler &h, const int version)
  679. {
  680. h & static_cast<CGObjectInstance&>(*this);
  681. h & visited;
  682. }
  683. };
  684. class DLL_EXPORT CGTeleport : public CGObjectInstance //teleports and subterranean gates
  685. {
  686. public:
  687. static std::map<int,std::map<int, std::vector<int> > > objs; //teleports: map[ID][subID] => vector of ids
  688. static std::vector<std::pair<int, int> > gates; //subterranean gates: pairs of ids
  689. void onHeroVisit(const CGHeroInstance * h) const;
  690. void initObj();
  691. static void postInit();
  692. template <typename Handler> void serialize(Handler &h, const int version)
  693. {
  694. h & static_cast<CGObjectInstance&>(*this);
  695. }
  696. };
  697. class DLL_EXPORT CGBonusingObject : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  698. {
  699. public:
  700. void onHeroVisit(const CGHeroInstance * h) const;
  701. const std::string & getHoverText() const;
  702. void initObj();
  703. template <typename Handler> void serialize(Handler &h, const int version)
  704. {
  705. h & static_cast<CGObjectInstance&>(*this);
  706. }
  707. };
  708. class DLL_EXPORT CGMagicSpring : public CGVisitableOPW
  709. {///unfortunatelly, this one is quite different than others
  710. public:
  711. void onHeroVisit(const CGHeroInstance * h) const;
  712. const std::string & getHoverText() const;
  713. template <typename Handler> void serialize(Handler &h, const int version)
  714. {
  715. h & static_cast<CGObjectInstance&>(*this);
  716. h & visited;
  717. }
  718. };
  719. class DLL_EXPORT CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  720. {
  721. public:
  722. void onHeroVisit(const CGHeroInstance * h) const;
  723. const std::string & getHoverText() const;
  724. template <typename Handler> void serialize(Handler &h, const int version)
  725. {
  726. h & static_cast<CGObjectInstance&>(*this);
  727. }
  728. };
  729. class DLL_EXPORT CGSirens : public CGObjectInstance
  730. {
  731. public:
  732. void onHeroVisit(const CGHeroInstance * h) const;
  733. const std::string & getHoverText() const;
  734. void initObj();
  735. template <typename Handler> void serialize(Handler &h, const int version)
  736. {
  737. h & static_cast<CGObjectInstance&>(*this);
  738. }
  739. };
  740. class DLL_EXPORT CGObservatory : public CGObjectInstance //Redwood observatory
  741. {
  742. public:
  743. void onHeroVisit(const CGHeroInstance * h) const;
  744. template <typename Handler> void serialize(Handler &h, const int version)
  745. {
  746. h & static_cast<CGObjectInstance&>(*this);
  747. }
  748. };
  749. class DLL_EXPORT CGKeys : public CGObjectInstance //Base class for Keymaster and guards
  750. {
  751. public:
  752. static std::map <ui8, std::set <ui8> > playerKeyMap; //[players][keysowned]
  753. //SubID 0 - lightblue, 1 - green, 2 - red, 3 - darkblue, 4 - brown, 5 - purple, 6 - white, 7 - black
  754. void setPropertyDer (ui8 what, ui32 val);
  755. bool wasMyColorVisited (int player) const;
  756. template <typename Handler> void serialize(Handler &h, const int version)
  757. {
  758. h & static_cast<CGObjectInstance&>(*this);
  759. }
  760. };
  761. class DLL_EXPORT CGKeymasterTent : public CGKeys
  762. {
  763. public:
  764. void onHeroVisit(const CGHeroInstance * h) const;
  765. const std::string & getHoverText() const;
  766. template <typename Handler> void serialize(Handler &h, const int version)
  767. {
  768. h & static_cast<CGObjectInstance&>(*this);
  769. }
  770. };
  771. class DLL_EXPORT CGBorderGuard : public CGKeys
  772. {
  773. public:
  774. void initObj();
  775. const std::string & getHoverText() const;
  776. void onHeroVisit(const CGHeroInstance * h) const;
  777. void openGate(const CGHeroInstance *h, ui32 accept) const;
  778. template <typename Handler> void serialize(Handler &h, const int version)
  779. {
  780. h & static_cast<CGObjectInstance&>(*this);
  781. h & blockVisit;
  782. }
  783. };
  784. class DLL_EXPORT CGBorderGate : public CGBorderGuard //not fully imlemented, waiting for garrison
  785. {
  786. public:
  787. void onHeroVisit(const CGHeroInstance * h) const;
  788. ui8 getPassableness() const;
  789. };
  790. class DLL_EXPORT CGBoat : public CGObjectInstance
  791. {
  792. public:
  793. ui8 direction;
  794. const CGHeroInstance *hero; //hero on board
  795. void initObj();
  796. CGBoat()
  797. {
  798. hero = NULL;
  799. direction = 4;
  800. }
  801. template <typename Handler> void serialize(Handler &h, const int version)
  802. {
  803. h & static_cast<CGObjectInstance&>(*this) & direction;
  804. }
  805. };
  806. class DLL_EXPORT CGOnceVisitable : public CPlayersVisited
  807. ///wagon, corpse, lean to, warriors tomb
  808. {
  809. public:
  810. ui8 artOrRes; //0 - nothing; 1 - artifact; 2 - resource
  811. ui32 bonusType, //id of res or artifact
  812. bonusVal; //resource amount (or not used)
  813. void onHeroVisit(const CGHeroInstance * h) const;
  814. const std::string & getHoverText() const;
  815. void initObj();
  816. void searchTomb(const CGHeroInstance *h, ui32 accept) const;
  817. template <typename Handler> void serialize(Handler &h, const int version)
  818. {
  819. h & static_cast<CPlayersVisited&>(*this);;
  820. h & artOrRes & bonusType & bonusVal;
  821. }
  822. };
  823. class DLL_EXPORT CBank : public CArmedInstance
  824. {
  825. public:
  826. int index; //banks have unusal numbering - see ZCRBANK.txt and initObj()
  827. BankConfig *bc;
  828. float multiplier; //for improved banks script
  829. std::vector<ui32> artifacts; //fixed and deterministic
  830. ui32 daycounter;
  831. void initObj();
  832. const std::string & getHoverText() const;
  833. void setPropertyDer (ui8 what, ui32 val);
  834. void initialize() const;
  835. void reset(ui16 var1);
  836. void newTurn() const;
  837. virtual void onHeroVisit (const CGHeroInstance * h) const;
  838. virtual void fightGuards (const CGHeroInstance *h, ui32 accept) const;
  839. virtual void endBattle (const CGHeroInstance *h, const BattleResult *result) const;
  840. template <typename Handler> void serialize(Handler &h, const int version)
  841. {
  842. h & static_cast<CGObjectInstance&>(*this);
  843. h & index & multiplier & artifacts & daycounter & bc;
  844. }
  845. };
  846. class DLL_EXPORT CGPyramid : public CBank
  847. {
  848. public:
  849. static BankConfig pyramidConfig;
  850. ui16 spell;
  851. void initObj();
  852. const std::string & getHoverText() const;
  853. void newTurn() const {}; //empty, no reset
  854. void onHeroVisit (const CGHeroInstance * h) const;
  855. void endBattle (const CGHeroInstance *h, const BattleResult *result) const;
  856. template <typename Handler> void serialize(Handler &h, const int version)
  857. {
  858. h & static_cast<CBank&>(*this);
  859. h & spell;
  860. }
  861. };
  862. class CGShipyard : public CGObjectInstance, public IShipyard
  863. {
  864. public:
  865. void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
  866. CGShipyard();
  867. void onHeroVisit(const CGHeroInstance * h) const;
  868. };
  869. class DLL_EXPORT CGMagi : public CGObjectInstance
  870. {
  871. public:
  872. static std::map <si32, std::vector<si32> > eyelist; //[subID][id], supports multiple sets as in H5
  873. void initObj();
  874. void onHeroVisit(const CGHeroInstance * h) const;
  875. template <typename Handler> void serialize(Handler &h, const int version)
  876. {
  877. h & static_cast<CGObjectInstance&>(*this);
  878. }
  879. };
  880. class DLL_EXPORT CCartographer : public CPlayersVisited
  881. {
  882. ///behaviour varies depending on surface and floor
  883. public:
  884. void onHeroVisit( const CGHeroInstance * h ) const;
  885. void buyMap (const CGHeroInstance *h, ui32 accept) const;
  886. template <typename Handler> void serialize(Handler &h, const int version)
  887. {
  888. h & static_cast<CPlayersVisited&>(*this);
  889. h & players;
  890. }
  891. };
  892. class DLL_EXPORT CShop : public CGObjectInstance
  893. {
  894. ///base class for university, art merchant, slave market etc.
  895. public:
  896. std::map<ui16, Component*> available;
  897. std::map<ui16, Component*> chosen, bought; //redundant?
  898. //keys are unique for all three maps
  899. std::map<ui16, ui32> price;
  900. void initObj() {};
  901. void setPropertyDer (ui8 what, ui32 val);
  902. void newTurn() const;
  903. virtual void reset (ui32 val) {}; //get new items for Black Market, Tavern, Refugee Camp
  904. virtual void onHeroVisit (const CGHeroInstance * h) const {};
  905. virtual void trade (const CGHeroInstance * h) const {};
  906. template <typename Handler> void serialize(Handler &h, const int version)
  907. {
  908. h & available & chosen & bought & price;
  909. }
  910. };
  911. class DLL_EXPORT CGArtMerchant : public CShop
  912. {
  913. public:
  914. void reset (ui32 val);
  915. void onHeroVisit (const CGHeroInstance * h) const {};
  916. };
  917. class DLL_EXPORT CGRefugeeCamp : public CShop
  918. {
  919. public:
  920. void reset (ui32 val);
  921. void onHeroVisit (const CGHeroInstance * h) const {};
  922. };
  923. class DLL_EXPORT CGDenOfthieves : public CGObjectInstance
  924. {
  925. void onHeroVisit (const CGHeroInstance * h) const;
  926. };
  927. class DLL_EXPORT CGObelisk : public CPlayersVisited
  928. {
  929. public:
  930. static ui8 obeliskCount; //how many obelisks are on map
  931. static std::map<ui8, ui8> visited; //map: color_id => how many obelisks has been visited
  932. void setPropertyDer (ui8 what, ui32 val);
  933. void onHeroVisit(const CGHeroInstance * h) const;
  934. void initObj();
  935. const std::string & getHoverText() const;
  936. template <typename Handler> void serialize(Handler &h, const int version)
  937. {
  938. h & static_cast<CPlayersVisited&>(*this);;
  939. }
  940. };
  941. class DLL_EXPORT CGLighthouse : public CGObjectInstance
  942. {
  943. public:
  944. void onHeroVisit(const CGHeroInstance * h) const;
  945. void initObj();
  946. const std::string & getHoverText() const;
  947. template <typename Handler> void serialize(Handler &h, const int version)
  948. {
  949. h & static_cast<CGObjectInstance&>(*this);;
  950. }
  951. void giveBonusTo( ui8 player ) const;
  952. };
  953. struct BankConfig
  954. {
  955. BankConfig() {level = chance = upgradeChance = combatValue = value = rewardDifficulty = easiest = 0; };
  956. ui8 level; //1 - 4, how hard the battle will be
  957. ui8 chance; //chance for this level being chosen
  958. ui8 upgradeChance; //chance for creatures to be in upgraded versions
  959. std::vector< std::pair <ui16, ui32> > guards; //creature ID, amount
  960. ui32 combatValue; //how hard are guards of this level
  961. std::vector<si32> resources; //resources given in case of victory
  962. std::vector< std::pair <ui16, ui32> > creatures; //creatures granted in case of victory (creature ID, amount)
  963. std::vector<ui16> artifacts; //number of artifacts given in case of victory [0] -> treasure, [1] -> minor [2] -> major [3] -> relic
  964. ui32 value; //overall value of given things
  965. ui32 rewardDifficulty; //proportion of reward value to difficulty of guards; how profitable is this creature Bank config
  966. ui16 easiest; //?!?
  967. template <typename Handler> void serialize(Handler &h, const int version)
  968. {
  969. h & level & chance & upgradeChance & guards & combatValue & resources & creatures & artifacts & value & rewardDifficulty & easiest;
  970. }
  971. };
  972. class DLL_EXPORT CObjectHandler
  973. {
  974. public:
  975. std::vector<si32> cregens; //type 17. dwelling subid -> creature ID
  976. std::map <ui32, std::vector <BankConfig*> > banksInfo; //[index][preset]
  977. std::map <ui32, std::string> creBanksNames; //[crebank index] -> name of this creature bank
  978. void loadObjects();
  979. template <typename Handler> void serialize(Handler &h, const int version)
  980. {
  981. h & cregens & banksInfo & creBanksNames;
  982. }
  983. };
  984. #endif // __COBJECTHANDLER_H__