CObjectHandler.h 44 KB

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