CObjectHandler.h 49 KB

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