CObjectHandler.h 41 KB

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