CObjectHandler.h 48 KB

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