CObjectHandler.h 49 KB

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