CObjectHandler.h 46 KB

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