CObjectHandler.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  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. typedef std::vector<std::pair<ui32, std::vector<ui32> > > TCreaturesSet;
  370. CSpecObjInfo * info; //h3m info about dewlling
  371. TCreaturesSet creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
  372. template <typename Handler> void serialize(Handler &h, const int version)
  373. {
  374. h & static_cast<CArmedInstance&>(*this) & creatures;
  375. }
  376. void initObj();
  377. void setProperty(ui8 what, ui32 val);
  378. void onHeroVisit(const CGHeroInstance * h) const;
  379. void newTurn() const;
  380. void heroAcceptsCreatures(const CGHeroInstance *h, ui32 answer) const;
  381. void fightOver(const CGHeroInstance *h, BattleResult *result) const;
  382. void wantsFight(const CGHeroInstance *h, ui32 answer) const;
  383. };
  384. class DLL_LINKAGE CGVisitableOPH : public CGObjectInstance //objects visitable only once per hero
  385. {
  386. public:
  387. std::set<si32> visitors; //ids of heroes who have visited this obj
  388. si8 ttype; //tree type - used only by trees of knowledge: 0 - give level for free; 1 - take 2000 gold; 2 - take 10 gems
  389. const std::string & getHoverText() const;
  390. void setPropertyDer(ui8 what, ui32 val);//synchr
  391. void onHeroVisit(const CGHeroInstance * h) const;
  392. void onNAHeroVisit(int heroID, bool alreadyVisited) const;
  393. void initObj();
  394. void treeSelected(int heroID, int resType, int resVal, expType expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog
  395. void schoolSelected(int heroID, ui32 which) const;
  396. void arenaSelected(int heroID, int primSkill) const;
  397. template <typename Handler> void serialize(Handler &h, const int version)
  398. {
  399. h & static_cast<CGObjectInstance&>(*this);
  400. h & visitors & ttype;
  401. }
  402. };
  403. class DLL_LINKAGE CGTownBuilding : public IObjectInterface
  404. {
  405. ///basic class for town structures handled as map objects
  406. public:
  407. si32 ID; //from buildig list
  408. si32 id; //identifies its index on towns vector
  409. CGTownInstance *town;
  410. template <typename Handler> void serialize(Handler &h, const int version)
  411. {
  412. h & ID & id;
  413. }
  414. };
  415. class DLL_LINKAGE COPWBonus : public CGTownBuilding
  416. {///used for OPW bonusing structures
  417. public:
  418. std::set<si32> visitors;
  419. void setProperty(ui8 what, ui32 val);
  420. void onHeroVisit (const CGHeroInstance * h) const;
  421. COPWBonus (int index, CGTownInstance *TOWN);
  422. COPWBonus (){ID = 0; town = NULL;};
  423. template <typename Handler> void serialize(Handler &h, const int version)
  424. {
  425. h & static_cast<CGTownBuilding&>(*this);
  426. h & visitors;
  427. }
  428. };
  429. class DLL_LINKAGE CTownBonus : public CGTownBuilding
  430. {
  431. ///used for one-time bonusing structures
  432. ///feel free to merge inheritance tree
  433. public:
  434. std::set<si32> visitors;
  435. void setProperty(ui8 what, ui32 val);
  436. void onHeroVisit (const CGHeroInstance * h) const;
  437. CTownBonus (int index, CGTownInstance *TOWN);
  438. CTownBonus (){ID = 0; town = NULL;};
  439. template <typename Handler> void serialize(Handler &h, const int version)
  440. {
  441. h & static_cast<CGTownBuilding&>(*this);
  442. h & visitors;
  443. }
  444. };
  445. class DLL_LINKAGE CTownAndVisitingHero : public CBonusSystemNode
  446. {
  447. public:
  448. CTownAndVisitingHero();
  449. };
  450. struct DLL_LINKAGE GrowthInfo
  451. {
  452. struct Entry
  453. {
  454. int count;
  455. std::string description;
  456. Entry(const std::string &format, int _count);
  457. Entry(int subID, EBuilding::EBuilding building, int _count);
  458. };
  459. std::vector<Entry> entries;
  460. int totalGrowth() const;
  461. };
  462. class DLL_LINKAGE CGTownInstance : public CGDwelling, public IShipyard, public IMarket
  463. {
  464. public:
  465. CTownAndVisitingHero townAndVis;
  466. CTown * town;
  467. std::string name; // name of town
  468. si32 builded; //how many buildings has been built this turn
  469. si32 destroyed; //how many buildings has been destroyed this turn
  470. ConstTransitivePtr<CGHeroInstance> garrisonHero, visitingHero;
  471. ui32 identifier; //special identifier from h3m (only > RoE maps)
  472. si32 alignment;
  473. std::set<si32> forbiddenBuildings, builtBuildings;
  474. std::vector<CGTownBuilding*> bonusingBuildings;
  475. std::vector<ui32> possibleSpells, obligatorySpells;
  476. std::vector<std::vector<ui32> > spells; //spells[level] -> vector of spells, first will be available in guild
  477. std::list<CCastleEvent*> events;
  478. std::pair<si32, si32> bonusValue;//var to store town bonuses (rampart = resources from mystic pond);
  479. //////////////////////////////////////////////////////////////////////////
  480. static std::vector<const CArtifact *> merchantArtifacts; //vector of artifacts available at Artifact merchant, NULLs possible (for making empty space when artifact is bought)
  481. static std::vector<int> universitySkills;//skills for university of magic
  482. template <typename Handler> void serialize(Handler &h, const int version)
  483. {
  484. h & static_cast<CGDwelling&>(*this);
  485. h & name & builded & destroyed & identifier & alignment & forbiddenBuildings & builtBuildings & bonusValue
  486. & possibleSpells & obligatorySpells & spells & /*strInfo & */events & bonusingBuildings;
  487. for (std::vector<CGTownBuilding*>::iterator i = bonusingBuildings.begin(); i!=bonusingBuildings.end(); i++)
  488. (*i)->town = this;
  489. h & town & townAndVis;
  490. BONUS_TREE_DESERIALIZATION_FIX
  491. //garrison/visiting hero pointers will be restored in the map serialization
  492. }
  493. //////////////////////////////////////////////////////////////////////////
  494. virtual CBonusSystemNode *whatShouldBeAttached() OVERRIDE;
  495. std::string nodeName() const OVERRIDE;
  496. void deserializationFix();
  497. void recreateBuildingsBonuses();
  498. bool addBonusIfBuilt(int building, int type, int val, IPropagator *prop, int subtype = -1); //returns true if building is built and bonus has been added
  499. bool addBonusIfBuilt(int building, int type, int val, int subtype = -1); //convienence version of above
  500. void setVisitingHero(CGHeroInstance *h);
  501. void setGarrisonedHero(CGHeroInstance *h);
  502. const CArmedInstance *getUpperArmy() const; //garrisoned hero if present or the town itself
  503. // void getParents(TCNodes &out, const CBonusSystemNode *root = NULL) const;
  504. // void getBonuses(BonusList &out, const CSelector &selector, const CBonusSystemNode *root = NULL) const;
  505. //////////////////////////////////////////////////////////////////////////
  506. 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
  507. int3 getSightCenter() const; //"center" tile from which the sight distance is calculated
  508. int getSightRadious() const; //returns sight distance
  509. int getBoatType() const; //0 - evil (if a ship can be evil...?), 1 - good, 2 - neutral
  510. void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
  511. int getMarketEfficiency() const; //=market count
  512. bool allowsTrade(EMarketMode::EMarketMode mode) const;
  513. std::vector<int> availableItemsIds(EMarketMode::EMarketMode mode) const;
  514. void setPropertyDer(ui8 what, ui32 val);
  515. void newTurn() const;
  516. //////////////////////////////////////////////////////////////////////////
  517. bool needsLastStack() const;
  518. int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle
  519. int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  520. int mageGuildLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  521. bool creatureDwelling(const int & level, bool upgraded=false) const;
  522. int getHordeLevel(const int & HID) const; //HID - 0 or 1; returns creature level or -1 if that horde structure is not present
  523. int creatureGrowth(const int & level) const;
  524. GrowthInfo getGrowthInfo(int level) const;
  525. bool hasFort() const;
  526. bool hasCapitol() const;
  527. bool hasBuilt(int buildingID) const;
  528. int dailyIncome() const; //calculates daily income of this town
  529. int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
  530. void removeCapitols (ui8 owner) const;
  531. bool armedGarrison() const; //true if town has creatures in garrison or garrisoned hero
  532. CGTownInstance();
  533. virtual ~CGTownInstance();
  534. //////////////////////////////////////////////////////////////////////////
  535. void fightOver(const CGHeroInstance *h, BattleResult *result) const;
  536. void onHeroVisit(const CGHeroInstance * h) const;
  537. void onHeroLeave(const CGHeroInstance * h) const;
  538. void initObj();
  539. };
  540. class DLL_LINKAGE CGPandoraBox : public CArmedInstance
  541. {
  542. public:
  543. std::string message;
  544. //gained things:
  545. ui32 gainedExp;
  546. si32 manaDiff; //amount of gained / lost mana
  547. si32 moraleDiff; //morale modifier
  548. si32 luckDiff; //luck modifier
  549. std::vector<si32> resources;//gained / lost resources
  550. std::vector<si32> primskills;//gained / lost resources
  551. std::vector<si32> abilities; //gained abilities
  552. std::vector<si32> abilityLevels; //levels of gained abilities
  553. std::vector<si32> artifacts; //gained artifacts
  554. std::vector<si32> spells; //gained spells
  555. CCreatureSet creatures; //gained creatures
  556. void initObj();
  557. void onHeroVisit(const CGHeroInstance * h) const;
  558. void open (const CGHeroInstance * h, ui32 accept) const;
  559. void endBattle(const CGHeroInstance *h, BattleResult *result) const;
  560. void giveContents(const CGHeroInstance *h, bool afterBattle) const;
  561. void getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const;
  562. void getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const;
  563. template <typename Handler> void serialize(Handler &h, const int version)
  564. {
  565. h & static_cast<CArmedInstance&>(*this);
  566. h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
  567. & abilities & abilityLevels & artifacts & spells & creatures;
  568. }
  569. };
  570. class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects
  571. {
  572. public:
  573. ui8 removeAfterVisit; //true if event is removed after occurring
  574. ui8 availableFor; //players whom this event is available for
  575. ui8 computerActivate; //true if computre player can activate this event
  576. ui8 humanActivate; //true if human player can activate this event
  577. template <typename Handler> void serialize(Handler &h, const int version)
  578. {
  579. h & static_cast<CGPandoraBox &>(*this);
  580. h & removeAfterVisit & availableFor & computerActivate & humanActivate;
  581. }
  582. void onHeroVisit(const CGHeroInstance * h) const;
  583. void activated(const CGHeroInstance * h) const;
  584. };
  585. class DLL_LINKAGE CGCreature : public CArmedInstance //creatures on map
  586. {
  587. public:
  588. ui32 identifier; //unique code for this monster (used in missions)
  589. si8 character; //character of this set of creatures (0 - the most friendly, 4 - the most hostile) => on init changed to -4 (compliant) ... 10 value (savage)
  590. std::string message; //message printed for attacking hero
  591. std::vector<ui32> resources; //[res_id], resources given to hero that has won with monsters
  592. si32 gainedArtifact; //ID of artifact gained to hero, -1 if none
  593. ui8 neverFlees; //if true, the troops will never flee
  594. ui8 notGrowingTeam; //if true, number of units won't grow
  595. ui64 temppower; //used to handle fractional stack growth for tiny stacks
  596. void fight(const CGHeroInstance *h) const;
  597. void onHeroVisit(const CGHeroInstance * h) const;
  598. const std::string & getHoverText() const;
  599. void flee( const CGHeroInstance * h ) const;
  600. void endBattle(BattleResult *result) const;
  601. void fleeDecision(const CGHeroInstance *h, ui32 pursue) const;
  602. void joinDecision(const CGHeroInstance *h, int cost, ui32 accept) const;
  603. void initObj();
  604. void newTurn() const;
  605. void setPropertyDer(ui8 what, ui32 val);
  606. 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)
  607. struct DLL_LINKAGE RestoredCreature // info about merging stacks after battle back into one
  608. {
  609. si32 basicType;
  610. template <typename Handler> void serialize(Handler &h, const int version)
  611. {
  612. h & basicType;
  613. }
  614. } restore;
  615. template <typename Handler> void serialize(Handler &h, const int version)
  616. {
  617. h & static_cast<CArmedInstance&>(*this);
  618. h & identifier & character & message & resources & gainedArtifact & neverFlees & notGrowingTeam & temppower & restore;
  619. }
  620. };
  621. class DLL_LINKAGE CGSignBottle : public CGObjectInstance //signs and ocean bottles
  622. {
  623. public:
  624. std::string message;
  625. void onHeroVisit(const CGHeroInstance * h) const;
  626. void initObj();
  627. template <typename Handler> void serialize(Handler &h, const int version)
  628. {
  629. h & static_cast<CGObjectInstance&>(*this);
  630. h & message;
  631. }
  632. };
  633. class DLL_LINKAGE CGSeerHut : public CArmedInstance, public CQuest //army is used when giving reward
  634. {
  635. public:
  636. 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
  637. si32 rID; //reward ID
  638. si32 rVal; //reward value
  639. ui8 textOption; //store randomized mission write-ups rather than entire string (?)
  640. std::string seerName;
  641. //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
  642. //TODO? organize
  643. CStackBasicDescriptor stackToKill;
  644. ui8 stackDirection;
  645. std::string heroName; //backup of hero name
  646. si32 heroPortrait;
  647. void initObj();
  648. const std::string & getHoverText() const;
  649. void setPropertyDer (ui8 what, ui32 val);
  650. int checkDirection() const; //calculates the region of map where monster is placed
  651. void newTurn() const;
  652. void onHeroVisit (const CGHeroInstance * h) const;
  653. void finishQuest (const CGHeroInstance * h, ui32 accept) const; //common for both objects
  654. void completeQuest (const CGHeroInstance * h) const;
  655. const CGHeroInstance *getHeroToKill(bool allowNull = false) const;
  656. const CGCreature *getCreatureToKill(bool allowNull = false) const;
  657. void addReplacements(MetaString &out, const std::string &base) const;
  658. template <typename Handler> void serialize(Handler &h, const int version)
  659. {
  660. h & static_cast<CGObjectInstance&>(*this) & static_cast<CQuest&>(*this);
  661. h & rewardType & rID & rVal & textOption & seerName;
  662. h & stackToKill & stackDirection & heroName & heroPortrait;
  663. }
  664. };
  665. class DLL_LINKAGE CGQuestGuard : public CGSeerHut
  666. {
  667. public:
  668. void initObj();
  669. void completeQuest (const CGHeroInstance * h) const;
  670. template <typename Handler> void serialize(Handler &h, const int version)
  671. {
  672. h & static_cast<CGSeerHut&>(*this);
  673. }
  674. };
  675. class DLL_LINKAGE CGWitchHut : public CPlayersVisited
  676. {
  677. public:
  678. std::vector<si32> allowedAbilities;
  679. ui32 ability;
  680. const std::string & getHoverText() const;
  681. void onHeroVisit(const CGHeroInstance * h) const;
  682. void initObj();
  683. template <typename Handler> void serialize(Handler &h, const int version)
  684. {
  685. h & static_cast<CPlayersVisited&>(*this);
  686. h & allowedAbilities & ability;
  687. }
  688. };
  689. class DLL_LINKAGE CGScholar : public CGObjectInstance
  690. {
  691. public:
  692. ui8 bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell
  693. ui16 bonusID; //ID of skill/spell
  694. void giveAnyBonus(const CGHeroInstance * h) const;
  695. void onHeroVisit(const CGHeroInstance * h) const;
  696. void initObj();
  697. template <typename Handler> void serialize(Handler &h, const int version)
  698. {
  699. h & static_cast<CGObjectInstance&>(*this);
  700. h & bonusType & bonusID;
  701. }
  702. };
  703. class DLL_LINKAGE CGGarrison : public CArmedInstance
  704. {
  705. public:
  706. ui8 removableUnits;
  707. ui8 getPassableness() const;
  708. void onHeroVisit (const CGHeroInstance *h) const;
  709. void fightOver (const CGHeroInstance *h, BattleResult *result) const;
  710. template <typename Handler> void serialize(Handler &h, const int version)
  711. {
  712. h & static_cast<CArmedInstance&>(*this);
  713. h & removableUnits;
  714. }
  715. };
  716. class DLL_LINKAGE CGArtifact : public CArmedInstance
  717. {
  718. public:
  719. CArtifactInstance *storedArtifact;
  720. std::string message;
  721. void onHeroVisit(const CGHeroInstance * h) const;
  722. void fightForArt(ui32 agreed, const CGHeroInstance *h) const;
  723. void endBattle(BattleResult *result, const CGHeroInstance *h) const;
  724. void pick( const CGHeroInstance * h ) const;
  725. void initObj();
  726. template <typename Handler> void serialize(Handler &h, const int version)
  727. {
  728. h & static_cast<CArmedInstance&>(*this);
  729. h & message & storedArtifact;
  730. }
  731. };
  732. class DLL_LINKAGE CGResource : public CArmedInstance
  733. {
  734. public:
  735. ui32 amount; //0 if random
  736. std::string message;
  737. void onHeroVisit(const CGHeroInstance * h) const;
  738. void collectRes(int player) const;
  739. void initObj();
  740. void fightForRes(ui32 agreed, const CGHeroInstance *h) const;
  741. void endBattle(BattleResult *result, const CGHeroInstance *h) const;
  742. template <typename Handler> void serialize(Handler &h, const int version)
  743. {
  744. h & static_cast<CArmedInstance&>(*this);
  745. h & amount & message;
  746. }
  747. };
  748. class DLL_LINKAGE CGPickable : public CGObjectInstance //campfire, treasure chest, Flotsam, Shipwreck Survivor, Sea Chest
  749. {
  750. public:
  751. ui32 type, val1, val2;
  752. void onHeroVisit(const CGHeroInstance * h) const;
  753. void initObj();
  754. void chosen(int which, int heroID) const;
  755. template <typename Handler> void serialize(Handler &h, const int version)
  756. {
  757. h & static_cast<CGObjectInstance&>(*this);
  758. h & type & val1 & val2;
  759. }
  760. };
  761. class DLL_LINKAGE CGShrine : public CPlayersVisited
  762. {
  763. public:
  764. ui8 spell; //number of spell or 255 if random
  765. void onHeroVisit(const CGHeroInstance * h) const;
  766. void initObj();
  767. const std::string & getHoverText() const;
  768. template <typename Handler> void serialize(Handler &h, const int version)
  769. {
  770. h & static_cast<CPlayersVisited&>(*this);;
  771. h & spell;
  772. }
  773. };
  774. class DLL_LINKAGE CGMine : public CArmedInstance
  775. {
  776. public:
  777. ui8 producedResource;
  778. ui32 producedQuantity;
  779. void offerLeavingGuards(const CGHeroInstance *h) const;
  780. void endBattle(BattleResult *result, ui8 attackingPlayer) const;
  781. void fight(ui32 agreed, const CGHeroInstance *h) const;
  782. void onHeroVisit(const CGHeroInstance * h) const;
  783. void flagMine(ui8 player) const;
  784. void newTurn() const;
  785. void initObj();
  786. template <typename Handler> void serialize(Handler &h, const int version)
  787. {
  788. h & static_cast<CArmedInstance&>(*this);
  789. h & producedResource & producedQuantity;
  790. }
  791. ui32 defaultResProduction();
  792. };
  793. class DLL_LINKAGE CGVisitableOPW : public CGObjectInstance //objects visitable OPW
  794. {
  795. public:
  796. ui8 visited; //true if object has been visited this week
  797. void setPropertyDer(ui8 what, ui32 val);//synchr
  798. void onHeroVisit(const CGHeroInstance * h) const;
  799. void newTurn() const;
  800. template <typename Handler> void serialize(Handler &h, const int version)
  801. {
  802. h & static_cast<CGObjectInstance&>(*this);
  803. h & visited;
  804. }
  805. };
  806. class DLL_LINKAGE CGTeleport : public CGObjectInstance //teleports and subterranean gates
  807. {
  808. public:
  809. static std::map<int,std::map<int, std::vector<int> > > objs; //teleports: map[ID][subID] => vector of ids
  810. static std::vector<std::pair<int, int> > gates; //subterranean gates: pairs of ids
  811. void onHeroVisit(const CGHeroInstance * h) const;
  812. void initObj();
  813. static void postInit();
  814. static int getMatchingGate(int id); //receives id of one subterranean gate and returns id of the paired one, -1 if none
  815. template <typename Handler> void serialize(Handler &h, const int version)
  816. {
  817. h & static_cast<CGObjectInstance&>(*this);
  818. }
  819. };
  820. class DLL_LINKAGE CGBonusingObject : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  821. {
  822. public:
  823. void onHeroVisit(const CGHeroInstance * h) const;
  824. const std::string & getHoverText() const;
  825. void initObj();
  826. template <typename Handler> void serialize(Handler &h, const int version)
  827. {
  828. h & static_cast<CGObjectInstance&>(*this);
  829. }
  830. };
  831. class DLL_LINKAGE CGMagicSpring : public CGVisitableOPW
  832. {///unfortunatelly, this one is quite different than others
  833. public:
  834. void onHeroVisit(const CGHeroInstance * h) const;
  835. const std::string & getHoverText() const;
  836. template <typename Handler> void serialize(Handler &h, const int version)
  837. {
  838. h & static_cast<CGObjectInstance&>(*this);
  839. h & visited;
  840. }
  841. };
  842. class DLL_LINKAGE CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  843. {
  844. public:
  845. void onHeroVisit(const CGHeroInstance * h) const;
  846. const std::string & getHoverText() const;
  847. template <typename Handler> void serialize(Handler &h, const int version)
  848. {
  849. h & static_cast<CGObjectInstance&>(*this);
  850. }
  851. };
  852. class DLL_LINKAGE CGSirens : public CGObjectInstance
  853. {
  854. public:
  855. void onHeroVisit(const CGHeroInstance * h) const;
  856. const std::string & getHoverText() const;
  857. void initObj();
  858. template <typename Handler> void serialize(Handler &h, const int version)
  859. {
  860. h & static_cast<CGObjectInstance&>(*this);
  861. }
  862. };
  863. class DLL_LINKAGE CGObservatory : public CGObjectInstance //Redwood observatory
  864. {
  865. public:
  866. void onHeroVisit(const CGHeroInstance * h) const;
  867. template <typename Handler> void serialize(Handler &h, const int version)
  868. {
  869. h & static_cast<CGObjectInstance&>(*this);
  870. }
  871. };
  872. class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards
  873. {
  874. public:
  875. static std::map <ui8, std::set <ui8> > playerKeyMap; //[players][keysowned]
  876. //SubID 0 - lightblue, 1 - green, 2 - red, 3 - darkblue, 4 - brown, 5 - purple, 6 - white, 7 - black
  877. void setPropertyDer (ui8 what, ui32 val);
  878. bool wasMyColorVisited (int player) const;
  879. template <typename Handler> void serialize(Handler &h, const int version)
  880. {
  881. h & static_cast<CGObjectInstance&>(*this);
  882. }
  883. };
  884. class DLL_LINKAGE CGKeymasterTent : public CGKeys
  885. {
  886. public:
  887. void onHeroVisit(const CGHeroInstance * h) const;
  888. const std::string & getHoverText() const;
  889. template <typename Handler> void serialize(Handler &h, const int version)
  890. {
  891. h & static_cast<CGObjectInstance&>(*this);
  892. }
  893. };
  894. class DLL_LINKAGE CGBorderGuard : public CGKeys
  895. {
  896. public:
  897. void initObj();
  898. const std::string & getHoverText() const;
  899. void onHeroVisit(const CGHeroInstance * h) const;
  900. void openGate(const CGHeroInstance *h, ui32 accept) const;
  901. template <typename Handler> void serialize(Handler &h, const int version)
  902. {
  903. h & static_cast<CGObjectInstance&>(*this);
  904. h & blockVisit;
  905. }
  906. };
  907. class DLL_LINKAGE CGBorderGate : public CGBorderGuard //not fully imlemented, waiting for garrison
  908. {
  909. public:
  910. void onHeroVisit(const CGHeroInstance * h) const;
  911. ui8 getPassableness() const;
  912. };
  913. class DLL_LINKAGE CGBoat : public CGObjectInstance
  914. {
  915. public:
  916. ui8 direction;
  917. const CGHeroInstance *hero; //hero on board
  918. void initObj();
  919. CGBoat()
  920. {
  921. hero = NULL;
  922. direction = 4;
  923. }
  924. template <typename Handler> void serialize(Handler &h, const int version)
  925. {
  926. h & static_cast<CGObjectInstance&>(*this) & direction;
  927. }
  928. };
  929. class DLL_LINKAGE CGOnceVisitable : public CPlayersVisited
  930. ///wagon, corpse, lean to, warriors tomb
  931. {
  932. public:
  933. ui8 artOrRes; //0 - nothing; 1 - artifact; 2 - resource
  934. ui32 bonusType, //id of res or artifact
  935. bonusVal; //resource amount (or not used)
  936. void onHeroVisit(const CGHeroInstance * h) const;
  937. const std::string & getHoverText() const;
  938. void initObj();
  939. void searchTomb(const CGHeroInstance *h, ui32 accept) const;
  940. template <typename Handler> void serialize(Handler &h, const int version)
  941. {
  942. h & static_cast<CPlayersVisited&>(*this);;
  943. h & artOrRes & bonusType & bonusVal;
  944. }
  945. };
  946. class DLL_LINKAGE CBank : public CArmedInstance
  947. {
  948. public:
  949. int index; //banks have unusal numbering - see ZCRBANK.txt and initObj()
  950. BankConfig *bc;
  951. double multiplier; //for improved banks script
  952. std::vector<ui32> artifacts; //fixed and deterministic
  953. ui32 daycounter;
  954. void initObj();
  955. const std::string & getHoverText() const;
  956. void setPropertyDer (ui8 what, ui32 val);
  957. void initialize() const;
  958. void reset(ui16 var1);
  959. void newTurn() const;
  960. virtual void onHeroVisit (const CGHeroInstance * h) const;
  961. virtual void fightGuards (const CGHeroInstance *h, ui32 accept) const;
  962. virtual void endBattle (const CGHeroInstance *h, const BattleResult *result) const;
  963. template <typename Handler> void serialize(Handler &h, const int version)
  964. {
  965. h & static_cast<CArmedInstance&>(*this);
  966. h & index & multiplier & artifacts & daycounter & bc;
  967. }
  968. };
  969. class DLL_LINKAGE CGPyramid : public CBank
  970. {
  971. public:
  972. ui16 spell;
  973. void initObj();
  974. const std::string & getHoverText() const;
  975. void newTurn() const {}; //empty, no reset
  976. void onHeroVisit (const CGHeroInstance * h) const;
  977. void endBattle (const CGHeroInstance *h, const BattleResult *result) const;
  978. template <typename Handler> void serialize(Handler &h, const int version)
  979. {
  980. h & static_cast<CBank&>(*this);
  981. h & spell;
  982. }
  983. };
  984. class CGShipyard : public CGObjectInstance, public IShipyard
  985. {
  986. public:
  987. void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
  988. CGShipyard();
  989. void onHeroVisit(const CGHeroInstance * h) const;
  990. };
  991. class DLL_LINKAGE CGMagi : public CGObjectInstance
  992. {
  993. public:
  994. static std::map <si32, std::vector<si32> > eyelist; //[subID][id], supports multiple sets as in H5
  995. void initObj();
  996. void onHeroVisit(const CGHeroInstance * h) const;
  997. template <typename Handler> void serialize(Handler &h, const int version)
  998. {
  999. h & static_cast<CGObjectInstance&>(*this);
  1000. }
  1001. };
  1002. class DLL_LINKAGE CCartographer : public CPlayersVisited
  1003. {
  1004. ///behaviour varies depending on surface and floor
  1005. public:
  1006. void onHeroVisit( const CGHeroInstance * h ) const;
  1007. void buyMap (const CGHeroInstance *h, ui32 accept) const;
  1008. template <typename Handler> void serialize(Handler &h, const int version)
  1009. {
  1010. h & static_cast<CPlayersVisited&>(*this);
  1011. }
  1012. };
  1013. class DLL_LINKAGE CGDenOfthieves : public CGObjectInstance
  1014. {
  1015. void onHeroVisit (const CGHeroInstance * h) const;
  1016. };
  1017. class DLL_LINKAGE CGObelisk : public CPlayersVisited
  1018. {
  1019. public:
  1020. static ui8 obeliskCount; //how many obelisks are on map
  1021. static std::map<ui8, ui8> visited; //map: team_id => how many obelisks has been visited
  1022. void setPropertyDer (ui8 what, ui32 val);
  1023. void onHeroVisit(const CGHeroInstance * h) const;
  1024. void initObj();
  1025. const std::string & getHoverText() const;
  1026. template <typename Handler> void serialize(Handler &h, const int version)
  1027. {
  1028. h & static_cast<CPlayersVisited&>(*this);
  1029. }
  1030. };
  1031. class DLL_LINKAGE CGLighthouse : public CGObjectInstance
  1032. {
  1033. public:
  1034. void onHeroVisit(const CGHeroInstance * h) const;
  1035. void initObj();
  1036. const std::string & getHoverText() const;
  1037. template <typename Handler> void serialize(Handler &h, const int version)
  1038. {
  1039. h & static_cast<CGObjectInstance&>(*this);
  1040. }
  1041. void giveBonusTo( ui8 player ) const;
  1042. };
  1043. class DLL_LINKAGE CGMarket : public CGObjectInstance, public IMarket
  1044. {
  1045. public:
  1046. CGMarket();
  1047. void onHeroVisit(const CGHeroInstance * h) const; //open trading window
  1048. int getMarketEfficiency() const;
  1049. bool allowsTrade(EMarketMode::EMarketMode mode) const;
  1050. int availableUnits(EMarketMode::EMarketMode mode, int marketItemSerial) const; //-1 if unlimited
  1051. std::vector<int> availableItemsIds(EMarketMode::EMarketMode mode) const;
  1052. template <typename Handler> void serialize(Handler &h, const int version)
  1053. {
  1054. h & static_cast<CGObjectInstance&>(*this);
  1055. }
  1056. };
  1057. class DLL_LINKAGE CGBlackMarket : public CGMarket
  1058. {
  1059. public:
  1060. std::vector<const CArtifact *> artifacts; //available artifacts
  1061. void newTurn() const; //reset artifacts for black market every month
  1062. std::vector<int> availableItemsIds(EMarketMode::EMarketMode mode) const;
  1063. template <typename Handler> void serialize(Handler &h, const int version)
  1064. {
  1065. h & static_cast<CGMarket&>(*this);
  1066. h & artifacts;
  1067. }
  1068. };
  1069. class DLL_LINKAGE CGUniversity : public CGMarket
  1070. {
  1071. public:
  1072. std::vector<int> skills; //available skills
  1073. std::vector<int> availableItemsIds(EMarketMode::EMarketMode mode) const;
  1074. void initObj();//set skills for trade
  1075. void onHeroVisit(const CGHeroInstance * h) const; //open window
  1076. template <typename Handler> void serialize(Handler &h, const int version)
  1077. {
  1078. h & static_cast<CGMarket&>(*this);
  1079. h & skills;
  1080. }
  1081. };
  1082. struct BankConfig
  1083. {
  1084. BankConfig() {level = chance = upgradeChance = combatValue = value = rewardDifficulty = easiest = 0; };
  1085. ui8 level; //1 - 4, how hard the battle will be
  1086. ui8 chance; //chance for this level being chosen
  1087. ui8 upgradeChance; //chance for creatures to be in upgraded versions
  1088. std::vector< std::pair <ui16, ui32> > guards; //creature ID, amount
  1089. ui32 combatValue; //how hard are guards of this level
  1090. std::vector<si32> resources; //resources given in case of victory
  1091. std::vector< std::pair <ui16, ui32> > creatures; //creatures granted in case of victory (creature ID, amount)
  1092. std::vector<ui16> artifacts; //number of artifacts given in case of victory [0] -> treasure, [1] -> minor [2] -> major [3] -> relic
  1093. ui32 value; //overall value of given things
  1094. ui32 rewardDifficulty; //proportion of reward value to difficulty of guards; how profitable is this creature Bank config
  1095. ui16 easiest; //?!?
  1096. template <typename Handler> void serialize(Handler &h, const int version)
  1097. {
  1098. h & level & chance & upgradeChance & guards & combatValue & resources & creatures & artifacts & value & rewardDifficulty & easiest;
  1099. }
  1100. };
  1101. class DLL_LINKAGE CObjectHandler
  1102. {
  1103. public:
  1104. std::vector<si32> cregens; //type 17. dwelling subid -> creature ID
  1105. std::map <ui32, std::vector < ConstTransitivePtr<BankConfig> > > banksInfo; //[index][preset]
  1106. std::map <ui32, std::string> creBanksNames; //[crebank index] -> name of this creature bank
  1107. std::vector<ui32> resVals; //default values of resources in gold
  1108. void loadObjects();
  1109. template <typename Handler> void serialize(Handler &h, const int version)
  1110. {
  1111. h & cregens & banksInfo & creBanksNames & resVals;
  1112. }
  1113. };