CObjectHandler.h 47 KB

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