CObjectHandler.h 47 KB

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