CObjectHandler.h 50 KB

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