CObjectHandler.h 47 KB

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