CObjectHandler.h 49 KB

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