CObjectHandler.h 49 KB

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