CObjectHandler.h 50 KB

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