CObjectHandler.h 48 KB

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