CObjectHandler.h 43 KB

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