CObjectHandler.h 46 KB

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