CObjectHandler.h 51 KB

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