2
0

CObjectHandler.h 47 KB

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