CObjectHandler.h 47 KB

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