CObjectHandler.h 46 KB

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