CObjectHandler.h 46 KB

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