CObjectHandler.h 50 KB

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