CObjectHandler.h 47 KB

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