CObjectHandler.h 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  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}; //TODO?
  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 getCompletionText(MetaString &text, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h = NULL) const;
  663. void finishQuest (const CGHeroInstance * h, ui32 accept) const; //common for both objects
  664. void completeQuest (const CGHeroInstance * h) const;
  665. const CGHeroInstance *getHeroToKill(bool allowNull = false) const;
  666. const CGCreature *getCreatureToKill(bool allowNull = false) const;
  667. template <typename Handler> void serialize(Handler &h, const int version)
  668. {
  669. h & static_cast<CGObjectInstance&>(*this) & static_cast<CQuest&>(*this);
  670. h & rewardType & rID & rVal & textOption & seerName;
  671. }
  672. };
  673. class DLL_LINKAGE CGQuestGuard : public CGSeerHut
  674. {
  675. public:
  676. void initObj();
  677. void completeQuest (const CGHeroInstance * h) const;
  678. template <typename Handler> void serialize(Handler &h, const int version)
  679. {
  680. h & static_cast<CGSeerHut&>(*this);
  681. }
  682. };
  683. class DLL_LINKAGE CGWitchHut : public CPlayersVisited
  684. {
  685. public:
  686. std::vector<si32> allowedAbilities;
  687. ui32 ability;
  688. const std::string & getHoverText() const;
  689. void onHeroVisit(const CGHeroInstance * h) const;
  690. void initObj();
  691. template <typename Handler> void serialize(Handler &h, const int version)
  692. {
  693. h & static_cast<CPlayersVisited&>(*this);
  694. h & allowedAbilities & ability;
  695. }
  696. };
  697. class DLL_LINKAGE CGScholar : public CGObjectInstance
  698. {
  699. public:
  700. ui8 bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell
  701. ui16 bonusID; //ID of skill/spell
  702. void giveAnyBonus(const CGHeroInstance * h) const;
  703. void onHeroVisit(const CGHeroInstance * h) const;
  704. void initObj();
  705. template <typename Handler> void serialize(Handler &h, const int version)
  706. {
  707. h & static_cast<CGObjectInstance&>(*this);
  708. h & bonusType & bonusID;
  709. }
  710. };
  711. class DLL_LINKAGE CGGarrison : public CArmedInstance
  712. {
  713. public:
  714. ui8 removableUnits;
  715. ui8 getPassableness() const;
  716. void onHeroVisit (const CGHeroInstance *h) const;
  717. void fightOver (const CGHeroInstance *h, BattleResult *result) const;
  718. template <typename Handler> void serialize(Handler &h, const int version)
  719. {
  720. h & static_cast<CArmedInstance&>(*this);
  721. h & removableUnits;
  722. }
  723. };
  724. class DLL_LINKAGE CGArtifact : public CArmedInstance
  725. {
  726. public:
  727. CArtifactInstance *storedArtifact;
  728. std::string message;
  729. void onHeroVisit(const CGHeroInstance * h) const;
  730. void fightForArt(ui32 agreed, const CGHeroInstance *h) const;
  731. void endBattle(BattleResult *result, const CGHeroInstance *h) const;
  732. void pick( const CGHeroInstance * h ) const;
  733. void initObj();
  734. template <typename Handler> void serialize(Handler &h, const int version)
  735. {
  736. h & static_cast<CArmedInstance&>(*this);
  737. h & message & storedArtifact;
  738. }
  739. };
  740. class DLL_LINKAGE CGResource : public CArmedInstance
  741. {
  742. public:
  743. ui32 amount; //0 if random
  744. std::string message;
  745. void onHeroVisit(const CGHeroInstance * h) const;
  746. void collectRes(int player) const;
  747. void initObj();
  748. void fightForRes(ui32 agreed, const CGHeroInstance *h) const;
  749. void endBattle(BattleResult *result, const CGHeroInstance *h) const;
  750. template <typename Handler> void serialize(Handler &h, const int version)
  751. {
  752. h & static_cast<CArmedInstance&>(*this);
  753. h & amount & message;
  754. }
  755. };
  756. class DLL_LINKAGE CGPickable : public CGObjectInstance //campfire, treasure chest, Flotsam, Shipwreck Survivor, Sea Chest
  757. {
  758. public:
  759. ui32 type, val1, val2;
  760. void onHeroVisit(const CGHeroInstance * h) const;
  761. void initObj();
  762. void chosen(int which, int heroID) const;
  763. template <typename Handler> void serialize(Handler &h, const int version)
  764. {
  765. h & static_cast<CGObjectInstance&>(*this);
  766. h & type & val1 & val2;
  767. }
  768. };
  769. class DLL_LINKAGE CGShrine : public CPlayersVisited
  770. {
  771. public:
  772. ui8 spell; //number of spell or 255 if random
  773. void onHeroVisit(const CGHeroInstance * h) const;
  774. void initObj();
  775. const std::string & getHoverText() const;
  776. template <typename Handler> void serialize(Handler &h, const int version)
  777. {
  778. h & static_cast<CPlayersVisited&>(*this);;
  779. h & spell;
  780. }
  781. };
  782. class DLL_LINKAGE CGMine : public CArmedInstance
  783. {
  784. public:
  785. ui8 producedResource;
  786. ui32 producedQuantity;
  787. void offerLeavingGuards(const CGHeroInstance *h) const;
  788. void endBattle(BattleResult *result, ui8 attackingPlayer) const;
  789. void fight(ui32 agreed, const CGHeroInstance *h) const;
  790. void onHeroVisit(const CGHeroInstance * h) const;
  791. void flagMine(ui8 player) const;
  792. void newTurn() const;
  793. void initObj();
  794. template <typename Handler> void serialize(Handler &h, const int version)
  795. {
  796. h & static_cast<CArmedInstance&>(*this);
  797. h & producedResource & producedQuantity;
  798. }
  799. ui32 defaultResProduction();
  800. };
  801. class DLL_LINKAGE CGVisitableOPW : public CGObjectInstance //objects visitable OPW
  802. {
  803. public:
  804. ui8 visited; //true if object has been visited this week
  805. void setPropertyDer(ui8 what, ui32 val);//synchr
  806. bool wasVisited(ui8 player) const;
  807. void onHeroVisit(const CGHeroInstance * h) const;
  808. void newTurn() const;
  809. template <typename Handler> void serialize(Handler &h, const int version)
  810. {
  811. h & static_cast<CGObjectInstance&>(*this);
  812. h & visited;
  813. }
  814. };
  815. class DLL_LINKAGE CGTeleport : public CGObjectInstance //teleports and subterranean gates
  816. {
  817. public:
  818. static std::map<int,std::map<int, std::vector<int> > > objs; //teleports: map[ID][subID] => vector of ids
  819. static std::vector<std::pair<int, int> > gates; //subterranean gates: pairs of ids
  820. void onHeroVisit(const CGHeroInstance * h) const;
  821. void initObj();
  822. static void postInit();
  823. static int getMatchingGate(int id); //receives id of one subterranean gate and returns id of the paired one, -1 if none
  824. template <typename Handler> void serialize(Handler &h, const int version)
  825. {
  826. h & static_cast<CGObjectInstance&>(*this);
  827. }
  828. };
  829. class DLL_LINKAGE CGBonusingObject : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  830. {
  831. public:
  832. bool wasVisited (const CGHeroInstance * h) const;
  833. void onHeroVisit(const CGHeroInstance * h) const;
  834. const std::string & getHoverText() const;
  835. void initObj();
  836. template <typename Handler> void serialize(Handler &h, const int version)
  837. {
  838. h & static_cast<CGObjectInstance&>(*this);
  839. }
  840. };
  841. class DLL_LINKAGE CGMagicSpring : public CGVisitableOPW
  842. {///unfortunatelly, this one is quite different than others
  843. public:
  844. void onHeroVisit(const CGHeroInstance * h) const;
  845. const std::string & getHoverText() const;
  846. template <typename Handler> void serialize(Handler &h, const int version)
  847. {
  848. h & static_cast<CGObjectInstance&>(*this);
  849. h & visited;
  850. }
  851. };
  852. class DLL_LINKAGE CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  853. {
  854. public:
  855. void onHeroVisit(const CGHeroInstance * h) const;
  856. const std::string & getHoverText() const;
  857. template <typename Handler> void serialize(Handler &h, const int version)
  858. {
  859. h & static_cast<CGObjectInstance&>(*this);
  860. }
  861. };
  862. class DLL_LINKAGE CGSirens : public CGObjectInstance
  863. {
  864. public:
  865. void onHeroVisit(const CGHeroInstance * h) const;
  866. const std::string & getHoverText() const;
  867. void initObj();
  868. template <typename Handler> void serialize(Handler &h, const int version)
  869. {
  870. h & static_cast<CGObjectInstance&>(*this);
  871. }
  872. };
  873. class DLL_LINKAGE CGObservatory : public CGObjectInstance //Redwood observatory
  874. {
  875. public:
  876. void onHeroVisit(const CGHeroInstance * h) const;
  877. template <typename Handler> void serialize(Handler &h, const int version)
  878. {
  879. h & static_cast<CGObjectInstance&>(*this);
  880. }
  881. };
  882. class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards
  883. {
  884. public:
  885. static std::map <ui8, std::set <ui8> > playerKeyMap; //[players][keysowned]
  886. //SubID 0 - lightblue, 1 - green, 2 - red, 3 - darkblue, 4 - brown, 5 - purple, 6 - white, 7 - black
  887. void setPropertyDer (ui8 what, ui32 val);
  888. bool wasMyColorVisited (int player) const;
  889. template <typename Handler> void serialize(Handler &h, const int version)
  890. {
  891. h & static_cast<CGObjectInstance&>(*this);
  892. }
  893. };
  894. class DLL_LINKAGE CGKeymasterTent : public CGKeys
  895. {
  896. public:
  897. bool wasVisited (ui8 player) const;
  898. void onHeroVisit(const CGHeroInstance * h) const;
  899. const std::string & getHoverText() const;
  900. template <typename Handler> void serialize(Handler &h, const int version)
  901. {
  902. h & static_cast<CGObjectInstance&>(*this);
  903. }
  904. };
  905. class DLL_LINKAGE CGBorderGuard : public CGKeys
  906. {
  907. public:
  908. void initObj();
  909. const std::string & getHoverText() const;
  910. void onHeroVisit(const CGHeroInstance * h) const;
  911. void openGate(const CGHeroInstance *h, ui32 accept) const;
  912. template <typename Handler> void serialize(Handler &h, const int version)
  913. {
  914. h & static_cast<CGObjectInstance&>(*this);
  915. h & blockVisit;
  916. }
  917. };
  918. class DLL_LINKAGE CGBorderGate : public CGBorderGuard //not fully imlemented, waiting for garrison
  919. {
  920. public:
  921. void onHeroVisit(const CGHeroInstance * h) const;
  922. ui8 getPassableness() const;
  923. };
  924. class DLL_LINKAGE CGBoat : public CGObjectInstance
  925. {
  926. public:
  927. ui8 direction;
  928. const CGHeroInstance *hero; //hero on board
  929. void initObj();
  930. CGBoat()
  931. {
  932. hero = NULL;
  933. direction = 4;
  934. }
  935. template <typename Handler> void serialize(Handler &h, const int version)
  936. {
  937. h & static_cast<CGObjectInstance&>(*this) & direction;
  938. }
  939. };
  940. class DLL_LINKAGE CGOnceVisitable : public CPlayersVisited
  941. ///wagon, corpse, lean to, warriors tomb
  942. {
  943. public:
  944. ui8 artOrRes; //0 - nothing; 1 - artifact; 2 - resource
  945. ui32 bonusType, //id of res or artifact
  946. bonusVal; //resource amount (or not used)
  947. void onHeroVisit(const CGHeroInstance * h) const;
  948. const std::string & getHoverText() const;
  949. void initObj();
  950. void searchTomb(const CGHeroInstance *h, ui32 accept) const;
  951. template <typename Handler> void serialize(Handler &h, const int version)
  952. {
  953. h & static_cast<CPlayersVisited&>(*this);;
  954. h & artOrRes & bonusType & bonusVal;
  955. }
  956. };
  957. class DLL_LINKAGE CBank : public CArmedInstance
  958. {
  959. public:
  960. int index; //banks have unusal numbering - see ZCRBANK.txt and initObj()
  961. BankConfig *bc;
  962. double multiplier; //for improved banks script
  963. std::vector<ui32> artifacts; //fixed and deterministic
  964. ui32 daycounter;
  965. void initObj();
  966. const std::string & getHoverText() const;
  967. void setPropertyDer (ui8 what, ui32 val);
  968. void initialize() const;
  969. void reset(ui16 var1);
  970. void newTurn() const;
  971. bool wasVisited (ui8 player) const;
  972. virtual void onHeroVisit (const CGHeroInstance * h) const;
  973. virtual void fightGuards (const CGHeroInstance *h, ui32 accept) const;
  974. virtual void endBattle (const CGHeroInstance *h, const BattleResult *result) const;
  975. template <typename Handler> void serialize(Handler &h, const int version)
  976. {
  977. h & static_cast<CArmedInstance&>(*this);
  978. h & index & multiplier & artifacts & daycounter & bc;
  979. }
  980. };
  981. class DLL_LINKAGE CGPyramid : public CBank
  982. {
  983. public:
  984. ui16 spell;
  985. void initObj();
  986. const std::string & getHoverText() const;
  987. void newTurn() const {}; //empty, no reset
  988. void onHeroVisit (const CGHeroInstance * h) const;
  989. void endBattle (const CGHeroInstance *h, const BattleResult *result) const;
  990. template <typename Handler> void serialize(Handler &h, const int version)
  991. {
  992. h & static_cast<CBank&>(*this);
  993. h & spell;
  994. }
  995. };
  996. class CGShipyard : public CGObjectInstance, public IShipyard
  997. {
  998. public:
  999. void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
  1000. CGShipyard();
  1001. void onHeroVisit(const CGHeroInstance * h) const;
  1002. };
  1003. class DLL_LINKAGE CGMagi : public CGObjectInstance
  1004. {
  1005. public:
  1006. static std::map <si32, std::vector<si32> > eyelist; //[subID][id], supports multiple sets as in H5
  1007. void initObj();
  1008. void onHeroVisit(const CGHeroInstance * h) const;
  1009. template <typename Handler> void serialize(Handler &h, const int version)
  1010. {
  1011. h & static_cast<CGObjectInstance&>(*this);
  1012. }
  1013. };
  1014. class DLL_LINKAGE CCartographer : public CPlayersVisited
  1015. {
  1016. ///behaviour varies depending on surface and floor
  1017. public:
  1018. void onHeroVisit( const CGHeroInstance * h ) const;
  1019. void buyMap (const CGHeroInstance *h, ui32 accept) const;
  1020. template <typename Handler> void serialize(Handler &h, const int version)
  1021. {
  1022. h & static_cast<CPlayersVisited&>(*this);
  1023. }
  1024. };
  1025. class DLL_LINKAGE CGDenOfthieves : public CGObjectInstance
  1026. {
  1027. void onHeroVisit (const CGHeroInstance * h) const;
  1028. };
  1029. class DLL_LINKAGE CGObelisk : public CPlayersVisited
  1030. {
  1031. public:
  1032. static ui8 obeliskCount; //how many obelisks are on map
  1033. static std::map<ui8, ui8> visited; //map: team_id => how many obelisks has been visited
  1034. void setPropertyDer (ui8 what, ui32 val);
  1035. void onHeroVisit(const CGHeroInstance * h) const;
  1036. void initObj();
  1037. const std::string & getHoverText() const;
  1038. template <typename Handler> void serialize(Handler &h, const int version)
  1039. {
  1040. h & static_cast<CPlayersVisited&>(*this);
  1041. }
  1042. };
  1043. class DLL_LINKAGE CGLighthouse : public CGObjectInstance
  1044. {
  1045. public:
  1046. void onHeroVisit(const CGHeroInstance * h) const;
  1047. void initObj();
  1048. const std::string & getHoverText() const;
  1049. template <typename Handler> void serialize(Handler &h, const int version)
  1050. {
  1051. h & static_cast<CGObjectInstance&>(*this);
  1052. }
  1053. void giveBonusTo( ui8 player ) const;
  1054. };
  1055. class DLL_LINKAGE CGMarket : public CGObjectInstance, public IMarket
  1056. {
  1057. public:
  1058. CGMarket();
  1059. void onHeroVisit(const CGHeroInstance * h) const; //open trading window
  1060. int getMarketEfficiency() const;
  1061. bool allowsTrade(EMarketMode::EMarketMode mode) const;
  1062. int availableUnits(EMarketMode::EMarketMode mode, int marketItemSerial) const; //-1 if unlimited
  1063. std::vector<int> availableItemsIds(EMarketMode::EMarketMode mode) const;
  1064. template <typename Handler> void serialize(Handler &h, const int version)
  1065. {
  1066. h & static_cast<CGObjectInstance&>(*this);
  1067. }
  1068. };
  1069. class DLL_LINKAGE CGBlackMarket : public CGMarket
  1070. {
  1071. public:
  1072. std::vector<const CArtifact *> artifacts; //available artifacts
  1073. void newTurn() const; //reset artifacts for black market every month
  1074. std::vector<int> availableItemsIds(EMarketMode::EMarketMode mode) const;
  1075. template <typename Handler> void serialize(Handler &h, const int version)
  1076. {
  1077. h & static_cast<CGMarket&>(*this);
  1078. h & artifacts;
  1079. }
  1080. };
  1081. class DLL_LINKAGE CGUniversity : public CGMarket
  1082. {
  1083. public:
  1084. std::vector<int> skills; //available skills
  1085. std::vector<int> availableItemsIds(EMarketMode::EMarketMode mode) const;
  1086. void initObj();//set skills for trade
  1087. void onHeroVisit(const CGHeroInstance * h) const; //open window
  1088. template <typename Handler> void serialize(Handler &h, const int version)
  1089. {
  1090. h & static_cast<CGMarket&>(*this);
  1091. h & skills;
  1092. }
  1093. };
  1094. struct BankConfig
  1095. {
  1096. BankConfig() {level = chance = upgradeChance = combatValue = value = rewardDifficulty = easiest = 0; };
  1097. ui8 level; //1 - 4, how hard the battle will be
  1098. ui8 chance; //chance for this level being chosen
  1099. ui8 upgradeChance; //chance for creatures to be in upgraded versions
  1100. std::vector< std::pair <ui16, ui32> > guards; //creature ID, amount
  1101. ui32 combatValue; //how hard are guards of this level
  1102. std::vector<si32> resources; //resources given in case of victory
  1103. std::vector< std::pair <ui16, ui32> > creatures; //creatures granted in case of victory (creature ID, amount)
  1104. std::vector<ui16> artifacts; //number of artifacts given in case of victory [0] -> treasure, [1] -> minor [2] -> major [3] -> relic
  1105. ui32 value; //overall value of given things
  1106. ui32 rewardDifficulty; //proportion of reward value to difficulty of guards; how profitable is this creature Bank config
  1107. ui16 easiest; //?!?
  1108. template <typename Handler> void serialize(Handler &h, const int version)
  1109. {
  1110. h & level & chance & upgradeChance & guards & combatValue & resources & creatures & artifacts & value & rewardDifficulty & easiest;
  1111. }
  1112. };
  1113. class DLL_LINKAGE CObjectHandler
  1114. {
  1115. public:
  1116. std::map<si32, si32> cregens; //type 17. dwelling subid -> creature ID
  1117. std::map <ui32, std::vector < ConstTransitivePtr<BankConfig> > > banksInfo; //[index][preset]
  1118. std::map <ui32, std::string> creBanksNames; //[crebank index] -> name of this creature bank
  1119. std::vector<ui32> resVals; //default values of resources in gold
  1120. void loadObjects();
  1121. int bankObjToIndex (const CGObjectInstance * obj);
  1122. template <typename Handler> void serialize(Handler &h, const int version)
  1123. {
  1124. h & cregens & banksInfo & creBanksNames & resVals;
  1125. }
  1126. };