CObjectHandler.h 44 KB

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