CObjectHandler.h 51 KB

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