CObjectHandler.h 45 KB

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