CObjectHandler.h 37 KB

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