CObjectHandler.h 48 KB

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