CObjectHandler.h 50 KB

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