CObjectHandler.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  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. #include "CCreatureHandler.h"
  10. #include "../lib/HeroBonus.h"
  11. #ifndef _MSC_VER
  12. #include "CHeroHandler.h"
  13. #include "CTownHandler.h"
  14. #include "../lib/VCMI_Lib.h"
  15. #endif
  16. /*
  17. * CObjectHandler.h, part of VCMI engine
  18. *
  19. * Authors: listed in file AUTHORS in main folder
  20. *
  21. * License: GNU General Public License v2.0 or later
  22. * Full text of license available in license.txt file, in main folder
  23. *
  24. */
  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. struct TerrainTile;
  42. struct InfoWindow;
  43. struct Component;
  44. struct BankConfig;
  45. class CGBoat;
  46. class DLL_EXPORT CCastleEvent
  47. {
  48. public:
  49. std::string name, message;
  50. std::vector<si32> resources; //gain / loss of resources
  51. ui8 players; //players for whom this event can be applied
  52. ui8 forHuman, forComputer;
  53. ui32 firstShow; //postpone of first encounter time in days
  54. ui32 forEvery; //every n days this event will occure
  55. ui8 bytes[6]; //build specific buildings (raw format, similar to town's)
  56. si32 gen[7]; //additional creatures in i-th level dwelling
  57. bool operator<(const CCastleEvent &drugie) const
  58. {
  59. return firstShow<drugie.firstShow;
  60. }
  61. template <typename Handler> void serialize(Handler &h, const int version)
  62. {
  63. h & name & message & resources & players & forHuman & forComputer & firstShow
  64. & forEvery & bytes & gen;
  65. }
  66. };
  67. class CQuest
  68. {
  69. public:
  70. ui8 missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain playe
  71. si32 lastDay; //after this day (first day is 0) mission cannot be completed; if -1 - no limit
  72. ui32 m13489val;
  73. std::vector<ui32> m2stats;
  74. std::vector<ui16> m5arts; //artifacts id
  75. std::vector<std::pair<ui32, ui32> > m6creatures; //pair[cre id, cre count]
  76. std::vector<ui32> m7resources;
  77. std::string firstVisitText, nextVisitText, completedText;
  78. template <typename Handler> void serialize(Handler &h, const int version)
  79. {
  80. h & missionType & lastDay & m13489val & m2stats & m5arts & m6creatures & m7resources
  81. & firstVisitText & nextVisitText & completedText;
  82. }
  83. };
  84. class DLL_EXPORT IObjectInterface
  85. {
  86. public:
  87. static IGameCallback *cb;
  88. IObjectInterface();
  89. virtual ~IObjectInterface();
  90. virtual void onHeroVisit(const CGHeroInstance * h) const;
  91. virtual void onHeroLeave(const CGHeroInstance * h) const;
  92. virtual void newTurn() const;
  93. virtual void initObj(); //synchr
  94. virtual void setProperty(ui8 what, ui32 val);//synchr
  95. static void preInit(); //called before objs receive their initObj
  96. static void postInit();//caleed after objs receive their initObj
  97. };
  98. class DLL_EXPORT IShipyard
  99. {
  100. public:
  101. const CGObjectInstance *o;
  102. IShipyard(const CGObjectInstance *O);
  103. void getBoatCost(std::vector<si32> &cost) const;
  104. virtual void getOutOffsets(std::vector<int3> &offsets) const =0; //offsets to obj pos when we boat can be placed
  105. //virtual bool validLocation() const; //returns true if there is a water tile near where boat can be placed
  106. int3 bestLocation() const; //returns location when the boat should be placed
  107. int state() const; //0 - can buid, 1 - there is already a boat at dest tile, 2 - dest tile is blocked, 3 - no water
  108. static const IShipyard *castFrom(const CGObjectInstance *obj);
  109. static IShipyard *castFrom(CGObjectInstance *obj);
  110. };
  111. class DLL_EXPORT CGObjectInstance : public IObjectInterface
  112. {
  113. protected:
  114. void getNameVis(std::string &hname) const;
  115. void giveDummyBonus(int heroID, ui8 duration = HeroBonus::ONE_DAY) const;
  116. public:
  117. mutable std::string hoverName;
  118. int3 pos; //h3m pos
  119. si32 ID, subID; //normal ID (this one from OH3 maps ;]) - eg. town=98; hero=34
  120. si32 id;//number of object in CObjectHandler's vector
  121. CGDefInfo * defInfo;
  122. CSpecObjInfo * info;
  123. ui8 animPhaseShift;
  124. ui8 tempOwner;
  125. ui8 blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile
  126. virtual int3 getSightCenter() const; //"center" tile from which the sight distance is calculated
  127. virtual int getSightRadious() const; //sight distance (should be used if player-owned structure)
  128. int getOwner() const;
  129. void setOwner(int ow);
  130. int getWidth() const; //returns width of object graphic in tiles
  131. int getHeight() const; //returns height of object graphic in tiles
  132. 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)
  133. int3 getVisitableOffset() const; //returns (x,y,0) offset to first visitable tile from bottom right obj tile (0,0,0) (h3m pos)
  134. 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)
  135. 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)
  136. std::set<int3> getBlockedPos() const; //returns set of positions blocked by this object
  137. bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing
  138. CGObjectInstance();
  139. virtual ~CGObjectInstance();
  140. //CGObjectInstance(const CGObjectInstance & right);
  141. //CGObjectInstance& operator=(const CGObjectInstance & right);
  142. virtual const std::string & getHoverText() const;
  143. //////////////////////////////////////////////////////////////////////////
  144. void initObj();
  145. void onHeroVisit(const CGHeroInstance * h) const;
  146. void setProperty(ui8 what, ui32 val);//synchr
  147. virtual void setPropertyDer(ui8 what, ui32 val);//synchr
  148. friend class CGameHandler;
  149. template <typename Handler> void serialize(Handler &h, const int version)
  150. {
  151. h & hoverName & pos & ID & subID & id & animPhaseShift & tempOwner & blockVisit;
  152. //definfo is handled by map serializer
  153. }
  154. };
  155. class DLL_EXPORT CPlayersVisited: public CGObjectInstance
  156. {
  157. public:
  158. std::set<ui8> players; //players that visited this object
  159. bool hasVisited(ui8 player) const;
  160. virtual void setPropertyDer( ui8 what, ui32 val );
  161. template <typename Handler> void serialize(Handler &h, const int version)
  162. {
  163. h & players;
  164. }
  165. };
  166. class DLL_EXPORT CArmedInstance: public CGObjectInstance
  167. {
  168. public:
  169. CCreatureSet army; //army
  170. virtual bool needsLastStack() const; //true if last stack cannot be taken
  171. int getArmyStrength() const; //sum of AI values of creatures
  172. ui64 getPower (TSlot slot) const; //value of specific stack
  173. std::string getRoughAmount (TSlot slot) const; //rought size of specific stack
  174. template <typename Handler> void serialize(Handler &h, const int version)
  175. {
  176. h & static_cast<CGObjectInstance&>(*this);
  177. h & army;
  178. }
  179. };
  180. class DLL_EXPORT CGHeroInstance : public CArmedInstance
  181. {
  182. public:
  183. //////////////////////////////////////////////////////////////////////////
  184. ui8 moveDir; //format: 123
  185. // 8 4
  186. // 765
  187. mutable ui8 isStanding, tacticFormationEnabled;
  188. //////////////////////////////////////////////////////////////////////////
  189. CHero * type;
  190. ui64 exp; //experience point
  191. si32 level; //current level of hero
  192. std::string name; //may be custom
  193. std::string biography; //if custom
  194. si32 portrait; //may be custom
  195. si32 mana; // remaining spell points
  196. std::vector<si32> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
  197. 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
  198. si32 movement; //remaining movement points
  199. si32 identifier; //from the map file
  200. ui8 sex;
  201. ui8 inTownGarrison; // if hero is in town garrison
  202. CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison
  203. CGBoat *boat; //set to CGBoat when sailing
  204. std::vector<ui32> artifacts; //hero's artifacts from bag
  205. std::map<ui16,ui32> 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
  206. std::set<ui32> spells; //known spells (spell IDs)
  207. struct DLL_EXPORT Patrol
  208. {
  209. Patrol(){patrolling=false;patrolRadious=-1;};
  210. ui8 patrolling;
  211. si32 patrolRadious;
  212. template <typename Handler> void serialize(Handler &h, const int version)
  213. {
  214. h & patrolling & patrolRadious;
  215. }
  216. } patrol;
  217. std::list<HeroBonus> bonuses;
  218. //////////////////////////////////////////////////////////////////////////
  219. template <typename Handler> void serialize(Handler &h, const int version)
  220. {
  221. h & static_cast<CArmedInstance&>(*this);
  222. h & exp & level & name & biography & portrait & mana & primSkills & secSkills & movement
  223. & identifier & sex & inTownGarrison & artifacts & artifWorn & spells & patrol & bonuses
  224. & moveDir;
  225. ui8 standardType = (VLC->heroh->heroes[subID] == type);
  226. h & standardType;
  227. if(!standardType)
  228. h & type;
  229. else if(!h.saving)
  230. type = VLC->heroh->heroes[subID];
  231. //visitied town pointer will be restored by map serialization method
  232. }
  233. //////////////////////////////////////////////////////////////////////////
  234. int3 getSightCenter() const; //"center" tile from which the sight distance is calculated
  235. int getSightRadious() const; //sight distance (should be used if player-owned structure)
  236. //////////////////////////////////////////////////////////////////////////
  237. const HeroBonus *getBonus(int from, int id) const;
  238. int valOfBonuses(HeroBonus::BonusType type, int subtype = -1) const; //subtype -> subtype of bonus, if -1 then any
  239. bool hasBonusOfType(HeroBonus::BonusType type, int subtype = -1) const; //determines if hero has a bonus of given type (and optionally subtype)
  240. const std::string &getBiography() const;
  241. bool needsLastStack()const;
  242. 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
  243. unsigned int getLowestCreatureSpeed() const;
  244. int3 getPosition(bool h3m) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
  245. si32 manaLimit() const; //maximum mana value for this hero (basically 10*knowledge)
  246. si32 manaRegain() const; //how many points of mana can hero regain "naturally" in one day
  247. bool canWalkOnSea() const;
  248. int getCurrentLuck(int stack=-1, bool town=false) const;
  249. std::vector<std::pair<int,std::string> > getCurrentLuckModifiers(int stack=-1, bool town=false) const; //args as above
  250. int getCurrentMorale(int stack=-1, bool town=false) const; //if stack - position of creature, if -1 then morale for hero is calculated; town - if bonuses from town (tavern) should be considered
  251. std::vector<std::pair<int,std::string> > getCurrentMoraleModifiers(int stack=-1, bool town=false) const; //args as above
  252. int getPrimSkillLevel(int id) const;
  253. ui8 getSecSkillLevel(const int & ID) const; //0 - no skill
  254. int maxMovePoints(bool onLand) const;
  255. ui32 getArtAtPos(ui16 pos) const; //-1 - no artifact
  256. const CArtifact * getArt(int pos) const;
  257. 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)
  258. 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
  259. static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
  260. double getHeroStrength() const;
  261. int getTotalStrength() const;
  262. ui8 getSpellSchoolLevel(const CSpell * spell) const; //returns level on which given spell would be cast by this hero
  263. 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
  264. std::pair<ui32, si32> calculateNecromancy (const BattleResult &battleResult) const;
  265. void showNecromancyDialog (std::pair<ui32, si32> raisedStack) const;
  266. //////////////////////////////////////////////////////////////////////////
  267. void initHero();
  268. void initHero(int SUBID);
  269. void recreateArtBonuses();
  270. void initHeroDefInfo();
  271. CGHeroInstance();
  272. virtual ~CGHeroInstance();
  273. //////////////////////////////////////////////////////////////////////////
  274. void setPropertyDer(ui8 what, ui32 val);//synchr
  275. void initObj();
  276. void onHeroVisit(const CGHeroInstance * h) const;
  277. };
  278. class DLL_EXPORT CGDwelling : public CArmedInstance
  279. {
  280. public:
  281. std::vector<std::pair<ui32, std::vector<ui32> > > creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
  282. template <typename Handler> void serialize(Handler &h, const int version)
  283. {
  284. h & static_cast<CArmedInstance&>(*this) & creatures;
  285. }
  286. void initObj();
  287. void onHeroVisit(const CGHeroInstance * h) const;
  288. void newTurn() const;
  289. void heroAcceptsCreatures(const CGHeroInstance *h, ui32 answer) const;
  290. void fightOver(const CGHeroInstance *h, BattleResult *result) const;
  291. void wantsFight(const CGHeroInstance *h, ui32 answer) const;
  292. };
  293. class DLL_EXPORT CGVisitableOPH : public CGObjectInstance //objects visitable only once per hero
  294. {
  295. public:
  296. std::set<si32> visitors; //ids of heroes who have visited this obj
  297. si8 ttype; //tree type - used only by trees of knowledge: 0 - give level for free; 1 - take 2000 gold; 2 - take 10 gems
  298. const std::string & getHoverText() const;
  299. void setPropertyDer(ui8 what, ui32 val);//synchr
  300. void onHeroVisit(const CGHeroInstance * h) const;
  301. void onNAHeroVisit(int heroID, bool alreadyVisited) const;
  302. void initObj();
  303. void treeSelected(int heroID, int resType, int resVal, ui64 expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog
  304. void schoolSelected(int heroID, ui32 which) const;
  305. void arenaSelected(int heroID, int primSkill) const;
  306. template <typename Handler> void serialize(Handler &h, const int version)
  307. {
  308. h & static_cast<CGObjectInstance&>(*this);
  309. h & visitors & ttype;
  310. }
  311. };
  312. class DLL_EXPORT CGTownBuilding : public IObjectInterface
  313. {
  314. ///basic class for town structures handled as map objects
  315. public:
  316. si32 ID; //from buildig list
  317. si32 id; //identifies its index on towns vector
  318. CGTownInstance *town;
  319. template <typename Handler> void serialize(Handler &h, const int version)
  320. {
  321. h & ID & id;
  322. }
  323. };
  324. class DLL_EXPORT COPWBonus : public CGTownBuilding
  325. {///used for OPW bonusing structures
  326. public:
  327. std::set<si32> visitors;
  328. void setProperty(ui8 what, ui32 val);
  329. void onHeroVisit (const CGHeroInstance * h) const;
  330. COPWBonus (int index, CGTownInstance *TOWN);
  331. COPWBonus (){ID = 0; town = NULL;};
  332. template <typename Handler> void serialize(Handler &h, const int version)
  333. {
  334. h & static_cast<CGTownBuilding&>(*this);
  335. h & visitors;
  336. }
  337. };
  338. class DLL_EXPORT CTownBonus : public CGTownBuilding
  339. {
  340. ///used for one-time bonusing structures
  341. ///feel free to merge inheritance tree
  342. public:
  343. std::set<si32> visitors;
  344. void setProperty(ui8 what, ui32 val);
  345. void onHeroVisit (const CGHeroInstance * h) const;
  346. CTownBonus (int index, CGTownInstance *TOWN);
  347. CTownBonus (){ID = 0; town = NULL;};
  348. template <typename Handler> void serialize(Handler &h, const int version)
  349. {
  350. h & static_cast<CGTownBuilding&>(*this);
  351. h & visitors;
  352. }
  353. };
  354. class DLL_EXPORT CGTownInstance : public CGDwelling, public IShipyard
  355. {
  356. public:
  357. CTown * town;
  358. std::string name; // name of town
  359. si32 builded; //how many buildings has been built this turn
  360. si32 destroyed; //how many buildings has been destroyed this turn
  361. const CGHeroInstance * garrisonHero, *visitingHero;
  362. ui32 identifier; //special identifier from h3m (only > RoE maps)
  363. si32 alignment;
  364. std::set<si32> forbiddenBuildings, builtBuildings;
  365. std::vector<CGTownBuilding*> bonusingBuildings;
  366. std::vector<ui32> possibleSpells, obligatorySpells;
  367. std::vector<std::vector<ui32> > spells; //spells[level] -> vector of spells, first will be available in guild
  368. std::set<CCastleEvent> events;
  369. //////////////////////////////////////////////////////////////////////////
  370. template <typename Handler> void serialize(Handler &h, const int version)
  371. {
  372. h & static_cast<CGDwelling&>(*this);
  373. h & name & builded & destroyed & identifier & alignment & forbiddenBuildings & builtBuildings
  374. & possibleSpells & obligatorySpells & spells & /*strInfo & */events;
  375. ui8 standardType = (&VLC->townh->towns[subID] == town);
  376. h & standardType;
  377. if(!standardType)
  378. h & town;
  379. else if(!h.saving)
  380. town = &VLC->townh->towns[subID];
  381. //garrison/visiting hero pointers will be restored in the map serialization
  382. }
  383. //////////////////////////////////////////////////////////////////////////
  384. int3 getSightCenter() const; //"center" tile from which the sight distance is calculated
  385. int getSightRadious() const; //returns sight distance
  386. void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
  387. void setPropertyDer(ui8 what, ui32 val);
  388. void newTurn() const;
  389. //////////////////////////////////////////////////////////////////////////
  390. bool needsLastStack() const;
  391. int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle
  392. int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  393. int mageGuildLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  394. bool creatureDwelling(const int & level, bool upgraded=false) const;
  395. int getHordeLevel(const int & HID) const; //HID - 0 or 1; returns creature level or -1 if that horde structure is not present
  396. int creatureGrowth(const int & level) const;
  397. bool hasFort() const;
  398. bool hasCapitol() const;
  399. int dailyIncome() const; //calculates daily income of this town
  400. int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
  401. void removeCapitols (ui8 owner, bool me) const;
  402. CGTownInstance();
  403. virtual ~CGTownInstance();
  404. //////////////////////////////////////////////////////////////////////////
  405. void fightOver(const CGHeroInstance *h, BattleResult *result) const;
  406. void onHeroVisit(const CGHeroInstance * h) const;
  407. void onHeroLeave(const CGHeroInstance * h) const;
  408. void initObj();
  409. };
  410. class DLL_EXPORT CGPandoraBox : public CArmedInstance
  411. {
  412. public:
  413. std::string message;
  414. ui8 removeAfterVisit; //true if event is removed after occurring
  415. //gained things:
  416. ui32 gainedExp;
  417. si32 manaDiff; //amount of gained / lost mana
  418. si32 moraleDiff; //morale modifier
  419. si32 luckDiff; //luck modifier
  420. std::vector<si32> resources;//gained / lost resources
  421. std::vector<si32> primskills;//gained / lost resources
  422. std::vector<si32> abilities; //gained abilities
  423. std::vector<si32> abilityLevels; //levels of gained abilities
  424. std::vector<si32> artifacts; //gained artifacts
  425. std::vector<si32> spells; //gained spells
  426. CCreatureSet creatures; //gained creatures
  427. void initObj();
  428. void onHeroVisit(const CGHeroInstance * h) const;
  429. void open (const CGHeroInstance * h, ui32 accept) const;
  430. void endBattle(const CGHeroInstance *h, BattleResult *result) const;
  431. void giveContents(const CGHeroInstance *h, bool afterBattle) const;
  432. void getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const;
  433. void getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const;
  434. template <typename Handler> void serialize(Handler &h, const int version)
  435. {
  436. h & static_cast<CArmedInstance&>(*this);
  437. h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
  438. & abilities & abilityLevels & artifacts & spells & creatures & army;
  439. }
  440. };
  441. class DLL_EXPORT CGEvent : public CGPandoraBox //event objects
  442. {
  443. public:
  444. ui8 availableFor; //players whom this event is available for
  445. ui8 computerActivate; //true if computre player can activate this event
  446. ui8 humanActivate; //true if human player can activate this event
  447. template <typename Handler> void serialize(Handler &h, const int version)
  448. {
  449. h & static_cast<CArmedInstance&>(*this);
  450. h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
  451. & abilities & abilityLevels & artifacts & spells & creatures & availableFor
  452. & computerActivate & humanActivate & army;
  453. }
  454. void onHeroVisit(const CGHeroInstance * h) const;
  455. void activated(const CGHeroInstance * h) const;
  456. };
  457. class DLL_EXPORT CGCreature : public CArmedInstance //creatures on map
  458. {
  459. public:
  460. ui32 identifier; //unique code for this monster (used in missions)
  461. si8 character; //chracter of this set of creatures (0 - the most friendly, 4 - the most hostile) => on init changed to 0 (compliant) - 10 value (savage)
  462. std::string message; //message printed for attacking hero
  463. std::vector<ui32> resources; //[res_id], resources given to hero that has won with monsters
  464. si32 gainedArtifact; //ID of artifact gained to hero, -1 if none
  465. ui8 neverFlees; //if true, the troops will never flee
  466. ui8 notGrowingTeam; //if true, number of units won't grow
  467. void fight(const CGHeroInstance *h) const;
  468. void onHeroVisit(const CGHeroInstance * h) const;
  469. //const std::string & getHoverText() const;
  470. void flee( const CGHeroInstance * h ) const;
  471. void endBattle(BattleResult *result) const;
  472. void fleeDecision(const CGHeroInstance *h, ui32 pursue) const;
  473. void joinDecision(const CGHeroInstance *h, int cost, ui32 accept) const;
  474. void initObj();
  475. 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)
  476. template <typename Handler> void serialize(Handler &h, const int version)
  477. {
  478. h & static_cast<CArmedInstance&>(*this);
  479. h & identifier & character & message & resources & gainedArtifact & neverFlees & notGrowingTeam;
  480. }
  481. };
  482. class DLL_EXPORT CGSignBottle : public CGObjectInstance //signs and ocean bottles
  483. {
  484. public:
  485. std::string message;
  486. void onHeroVisit(const CGHeroInstance * h) const;
  487. void initObj();
  488. template <typename Handler> void serialize(Handler &h, const int version)
  489. {
  490. h & static_cast<CGObjectInstance&>(*this);
  491. h & message;
  492. }
  493. };
  494. class DLL_EXPORT CGSeerHut : public CGObjectInstance, public CQuest
  495. {
  496. public:
  497. 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
  498. si32 rID; //reward ID
  499. si32 rVal; //reward value
  500. template <typename Handler> void serialize(Handler &h, const int version)
  501. {
  502. h & static_cast<CGObjectInstance&>(*this) & static_cast<CQuest&>(*this);
  503. h & rewardType & rID & rVal;
  504. }
  505. };
  506. class DLL_EXPORT CGWitchHut : public CPlayersVisited
  507. {
  508. public:
  509. std::vector<si32> allowedAbilities;
  510. ui32 ability;
  511. const std::string & getHoverText() const;
  512. void onHeroVisit(const CGHeroInstance * h) const;
  513. void initObj();
  514. template <typename Handler> void serialize(Handler &h, const int version)
  515. {
  516. h & static_cast<CGObjectInstance&>(*this) & static_cast<CPlayersVisited&>(*this);;
  517. h & allowedAbilities & ability;
  518. }
  519. };
  520. class DLL_EXPORT CGScholar : public CGObjectInstance
  521. {
  522. public:
  523. ui8 bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell
  524. ui16 bonusID; //ID of skill/spell
  525. void giveAnyBonus(const CGHeroInstance * h) const;
  526. void onHeroVisit(const CGHeroInstance * h) const;
  527. void initObj();
  528. template <typename Handler> void serialize(Handler &h, const int version)
  529. {
  530. h & static_cast<CGObjectInstance&>(*this);
  531. h & bonusType & bonusID;
  532. }
  533. };
  534. class DLL_EXPORT CGGarrison : public CArmedInstance
  535. {
  536. public:
  537. ui8 removableUnits;
  538. void onHeroVisit (const CGHeroInstance *h) const;
  539. void fightOver (const CGHeroInstance *h, BattleResult *result) const;
  540. template <typename Handler> void serialize(Handler &h, const int version)
  541. {
  542. h & static_cast<CArmedInstance&>(*this);
  543. h & removableUnits;
  544. }
  545. };
  546. class DLL_EXPORT CGArtifact : public CArmedInstance
  547. {
  548. public:
  549. std::string message;
  550. ui32 spell; //if it's spell scroll
  551. void onHeroVisit(const CGHeroInstance * h) const;
  552. void fightForArt(ui32 agreed, const CGHeroInstance *h) const;
  553. void endBattle(BattleResult *result, const CGHeroInstance *h) const;
  554. void pick( const CGHeroInstance * h ) const;
  555. void initObj();
  556. template <typename Handler> void serialize(Handler &h, const int version)
  557. {
  558. h & static_cast<CArmedInstance&>(*this);
  559. h & message & spell;
  560. }
  561. };
  562. class DLL_EXPORT CGResource : public CArmedInstance
  563. {
  564. public:
  565. ui32 amount; //0 if random
  566. std::string message;
  567. void onHeroVisit(const CGHeroInstance * h) const;
  568. void collectRes(int player) const;
  569. void initObj();
  570. void fightForRes(ui32 agreed, const CGHeroInstance *h) const;
  571. void endBattle(BattleResult *result, const CGHeroInstance *h) const;
  572. template <typename Handler> void serialize(Handler &h, const int version)
  573. {
  574. h & static_cast<CArmedInstance&>(*this);
  575. h & amount & message;
  576. }
  577. };
  578. class DLL_EXPORT CGPickable : public CGObjectInstance //campfire, treasure chest, Flotsam, Shipwreck Survivor, Sea Chest
  579. {
  580. public:
  581. ui32 type, val1, val2;
  582. void onHeroVisit(const CGHeroInstance * h) const;
  583. void initObj();
  584. void chosen(int which, int heroID) const;
  585. template <typename Handler> void serialize(Handler &h, const int version)
  586. {
  587. h & static_cast<CGObjectInstance&>(*this);
  588. h & type & val1 & val2;
  589. }
  590. };
  591. class DLL_EXPORT CGShrine : public CPlayersVisited
  592. {
  593. public:
  594. ui8 spell; //number of spell or 255 if random
  595. void onHeroVisit(const CGHeroInstance * h) const;
  596. void initObj();
  597. const std::string & getHoverText() const;
  598. template <typename Handler> void serialize(Handler &h, const int version)
  599. {
  600. h & static_cast<CGObjectInstance&>(*this) & static_cast<CPlayersVisited&>(*this);;
  601. h & spell;
  602. }
  603. };
  604. class DLL_EXPORT CGQuestGuard : public CGObjectInstance, public CQuest
  605. {
  606. public:
  607. template <typename Handler> void serialize(Handler &h, const int version)
  608. {
  609. h & static_cast<CQuest&>(*this) & static_cast<CGObjectInstance&>(*this);
  610. }
  611. };
  612. class DLL_EXPORT CGMine : public CArmedInstance
  613. {
  614. public:
  615. void offerLeavingGuards(const CGHeroInstance *h) const;
  616. void onHeroVisit(const CGHeroInstance * h) const;
  617. void newTurn() const;
  618. void initObj();
  619. template <typename Handler> void serialize(Handler &h, const int version)
  620. {
  621. h & static_cast<CArmedInstance&>(*this);
  622. }
  623. };
  624. class DLL_EXPORT CGVisitableOPW : public CGObjectInstance //objects visitable OPW
  625. {
  626. public:
  627. ui8 visited; //true if object has been visited this week
  628. void setPropertyDer(ui8 what, ui32 val);//synchr
  629. void onHeroVisit(const CGHeroInstance * h) const;
  630. void newTurn() const;
  631. template <typename Handler> void serialize(Handler &h, const int version)
  632. {
  633. h & static_cast<CGObjectInstance&>(*this);
  634. h & visited;
  635. }
  636. };
  637. class DLL_EXPORT CGTeleport : public CGObjectInstance //teleports and subterranean gates
  638. {
  639. public:
  640. static std::map<int,std::map<int, std::vector<int> > > objs; //teleports: map[ID][subID] => vector of ids
  641. static std::vector<std::pair<int, int> > gates; //subterranean gates: pairs of ids
  642. void onHeroVisit(const CGHeroInstance * h) const;
  643. void initObj();
  644. static void postInit();
  645. template <typename Handler> void serialize(Handler &h, const int version)
  646. {
  647. h & static_cast<CGObjectInstance&>(*this);
  648. }
  649. };
  650. class DLL_EXPORT CGBonusingObject : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  651. {
  652. public:
  653. void onHeroVisit(const CGHeroInstance * h) const;
  654. const std::string & getHoverText() const;
  655. void initObj();
  656. template <typename Handler> void serialize(Handler &h, const int version)
  657. {
  658. h & static_cast<CGObjectInstance&>(*this);
  659. }
  660. };
  661. class DLL_EXPORT CGMagicSpring : public CGVisitableOPW
  662. {///unfortunatelly, this one is quite different than others
  663. public:
  664. void onHeroVisit(const CGHeroInstance * h) const;
  665. const std::string & getHoverText() const;
  666. template <typename Handler> void serialize(Handler &h, const int version)
  667. {
  668. h & static_cast<CGObjectInstance&>(*this);
  669. h & visited;
  670. }
  671. };
  672. class DLL_EXPORT CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  673. {
  674. public:
  675. void onHeroVisit(const CGHeroInstance * h) const;
  676. const std::string & getHoverText() const;
  677. template <typename Handler> void serialize(Handler &h, const int version)
  678. {
  679. h & static_cast<CGObjectInstance&>(*this);
  680. }
  681. };
  682. class DLL_EXPORT CGSirens : public CGObjectInstance
  683. {
  684. public:
  685. void onHeroVisit(const CGHeroInstance * h) const;
  686. const std::string & getHoverText() const;
  687. void initObj();
  688. template <typename Handler> void serialize(Handler &h, const int version)
  689. {
  690. h & static_cast<CGObjectInstance&>(*this);
  691. }
  692. };
  693. class DLL_EXPORT CGObservatory : public CGObjectInstance //Redwood observatory
  694. {
  695. public:
  696. void onHeroVisit(const CGHeroInstance * h) const;
  697. template <typename Handler> void serialize(Handler &h, const int version)
  698. {
  699. h & static_cast<CGObjectInstance&>(*this);
  700. }
  701. };
  702. class DLL_EXPORT CGKeys : public CGObjectInstance //Base class for Keymaster and guards, ToDo Border Gate
  703. {
  704. public:
  705. static std::map <ui8, std::set <ui8> > playerKeyMap; //[players][keysowned]
  706. //SubID 0 - lightblue, 1 - green, 2 - red, 3 - darkblue, 4 - brown, 5 - purple, 6 - white, 7 - black
  707. void setPropertyDer (ui8 what, ui32 val);
  708. bool wasMyColorVisited (int player) const;
  709. template <typename Handler> void serialize(Handler &h, const int version)
  710. {
  711. h & static_cast<CGObjectInstance&>(*this);
  712. }
  713. };
  714. class DLL_EXPORT CGKeymasterTent : public CGKeys
  715. {
  716. public:
  717. void onHeroVisit(const CGHeroInstance * h) const;
  718. const std::string & getHoverText() const;
  719. template <typename Handler> void serialize(Handler &h, const int version)
  720. {
  721. h & static_cast<CGObjectInstance&>(*this);
  722. }
  723. };
  724. class DLL_EXPORT CGBorderGuard : public CGKeys
  725. {
  726. public:
  727. void initObj();
  728. const std::string & getHoverText() const;
  729. void onHeroVisit(const CGHeroInstance * h) const;
  730. void openGate(const CGHeroInstance *h, ui32 accept) const;
  731. template <typename Handler> void serialize(Handler &h, const int version)
  732. {
  733. h & static_cast<CGObjectInstance&>(*this);
  734. h & blockVisit;
  735. }
  736. };
  737. class DLL_EXPORT CGBorderGate : public CGBorderGuard //not fully imlemented, waiting for garrison
  738. {
  739. public:
  740. void onHeroVisit(const CGHeroInstance * h) const;
  741. };
  742. class DLL_EXPORT CGBoat : public CGObjectInstance
  743. {
  744. public:
  745. ui8 direction;
  746. const CGHeroInstance *hero; //hero on board
  747. void initObj();
  748. CGBoat()
  749. {
  750. hero = NULL;
  751. direction = 4;
  752. }
  753. template <typename Handler> void serialize(Handler &h, const int version)
  754. {
  755. h & static_cast<CGObjectInstance&>(*this) & direction;
  756. }
  757. };
  758. class DLL_EXPORT CGOnceVisitable : public CPlayersVisited
  759. ///wagon, corpse, lean to, warriors tomb
  760. {
  761. public:
  762. ui8 artOrRes; //0 - nothing; 1 - artifact; 2 - resource
  763. ui32 bonusType, //id of res or artifact
  764. bonusVal; //resource amount (or not used)
  765. void onHeroVisit(const CGHeroInstance * h) const;
  766. const std::string & getHoverText() const;
  767. void initObj();
  768. void searchTomb(const CGHeroInstance *h, ui32 accept) const;
  769. template <typename Handler> void serialize(Handler &h, const int version)
  770. {
  771. h & static_cast<CGObjectInstance&>(*this) & static_cast<CPlayersVisited&>(*this);;
  772. h & bonusType & bonusVal;
  773. }
  774. };
  775. class DLL_EXPORT CBank : public CArmedInstance
  776. {
  777. public:
  778. int index; //banks have unusal numbering - see ZCRBANK.txt and initObj()
  779. BankConfig *bc;
  780. float multiplier; //for improved banks script
  781. std::vector<ui32> artifacts; //fixed and deterministic
  782. ui32 daycounter;
  783. void initObj();
  784. const std::string & getHoverText() const;
  785. void setPropertyDer (ui8 what, ui32 val);
  786. void initialize() const;
  787. void reset(ui16 var1);
  788. void newTurn() const;
  789. virtual void onHeroVisit (const CGHeroInstance * h) const;
  790. virtual void fightGuards (const CGHeroInstance *h, ui32 accept) const;
  791. virtual void endBattle (const CGHeroInstance *h, const BattleResult *result) const;
  792. template <typename Handler> void serialize(Handler &h, const int version)
  793. {
  794. h & static_cast<CGObjectInstance&>(*this);
  795. h & index & multiplier & artifacts & daycounter;
  796. }
  797. };
  798. class DLL_EXPORT CGPyramid : public CBank
  799. {
  800. public:
  801. static BankConfig pyramidConfig;
  802. ui16 spell;
  803. void initObj();
  804. const std::string & getHoverText() const;
  805. void newTurn() const {}; //empty, no reset
  806. void onHeroVisit (const CGHeroInstance * h) const;
  807. void endBattle (const CGHeroInstance *h, const BattleResult *result) const;
  808. template <typename Handler> void serialize(Handler &h, const int version)
  809. {
  810. h & static_cast<CGObjectInstance&>(*this);
  811. h & spell;
  812. }
  813. };
  814. class CGShipyard : public CGObjectInstance, public IShipyard
  815. {
  816. public:
  817. void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
  818. CGShipyard();
  819. void onHeroVisit(const CGHeroInstance * h) const;
  820. };
  821. class DLL_EXPORT CGMagi : public CGObjectInstance
  822. {
  823. public:
  824. static std::map <si32, std::vector<si32> > eyelist; //[subID][id], supports multiple sets as in H5
  825. void initObj();
  826. void onHeroVisit(const CGHeroInstance * h) const;
  827. template <typename Handler> void serialize(Handler &h, const int version)
  828. {
  829. h & static_cast<CGObjectInstance&>(*this);
  830. }
  831. };
  832. class DLL_EXPORT CCartographer : public CPlayersVisited
  833. {
  834. ///behaviour varies depending on surface and floor
  835. public:
  836. void onHeroVisit( const CGHeroInstance * h ) const;
  837. void buyMap (const CGHeroInstance *h, ui32 accept) const;
  838. template <typename Handler> void serialize(Handler &h, const int version)
  839. {
  840. h & players;
  841. }
  842. };
  843. class DLL_EXPORT CShop : public CGObjectInstance
  844. {
  845. ///base class for university, art merchant, slave market etc.
  846. public:
  847. std::map<ui16, Component*> available;
  848. std::map<ui16, Component*> chosen, bought; //redundant?
  849. //keys are unique for all three maps
  850. std::map<ui16, ui32> price;
  851. void initObj() {};
  852. void setPropertyDer (ui8 what, ui32 val);
  853. void newTurn() const;
  854. virtual void reset (ui32 val) {}; //get new items for Black Market, Tavern, Refugee Camp
  855. virtual void onHeroVisit (const CGHeroInstance * h) const {};
  856. virtual void trade (const CGHeroInstance * h) const {};
  857. template <typename Handler> void serialize(Handler &h, const int version)
  858. {
  859. h & available & chosen & bought & price;
  860. }
  861. };
  862. class DLL_EXPORT CGArtMerchant : public CShop
  863. {
  864. public:
  865. void reset (ui32 val);
  866. void onHeroVisit (const CGHeroInstance * h) const {};
  867. };
  868. class DLL_EXPORT CGRefugeeCamp : public CShop
  869. {
  870. public:
  871. void reset (ui32 val);
  872. void onHeroVisit (const CGHeroInstance * h) const {};
  873. };
  874. struct BankConfig
  875. {
  876. BankConfig() {level = chance = upgradeChance = combatValue = value = rewardDifficulty = easiest = 0; };
  877. ui8 level; //1 - 4, how hard the battle will be
  878. ui8 chance; //chance for this level being chosen
  879. ui8 upgradeChance; //chance for creatures to be in upgraded versions
  880. std::vector< std::pair <ui16, ui32> > guards; //creature ID, amount
  881. ui32 combatValue; //how hard are guards of this level
  882. std::vector<si32> resources; //resources given in case of victory
  883. std::vector< std::pair <ui16, ui32> > creatures; //creatures granted in case of victory (creature ID, amount)
  884. std::vector<ui16> artifacts; //number of artifacts given in case of victory [0] -> treasure, [1] -> minor [2] -> major [3] -> relic
  885. ui32 value; //overall value of given things
  886. ui32 rewardDifficulty; //proportion of reward value to difficulty of guards; how profitable is this creature Bank config
  887. ui16 easiest; //?!?
  888. template <typename Handler> void serialize(Handler &h, const int version)
  889. {
  890. h & level & chance & upgradeChance & guards & combatValue & resources & creatures & artifacts & value & rewardDifficulty & easiest;
  891. }
  892. };
  893. class DLL_EXPORT CObjectHandler
  894. {
  895. public:
  896. std::vector<si32> cregens; //type 17. dwelling subid -> creature ID
  897. std::map <ui32, std::vector <BankConfig> > banksInfo; //[index][preset]
  898. std::map <ui32, std::string> creBanksNames; //[crebank index] -> name of this creature bank
  899. void loadObjects();
  900. template <typename Handler> void serialize(Handler &h, const int version)
  901. {
  902. h & cregens & banksInfo;
  903. }
  904. };
  905. #endif // __COBJECTHANDLER_H__