CObjectHandler.h 44 KB

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