CObjectHandler.h 50 KB

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