CObjectHandler.h 50 KB

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