CObjectHandler.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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. using boost::logic::tribool;
  26. class IGameCallback;
  27. struct BattleResult;
  28. class CCPPObjectScript;
  29. class CGObjectInstance;
  30. class CScript;
  31. class CObjectScript;
  32. class CGHeroInstance;
  33. class CTown;
  34. class CHero;
  35. class CBuilding;
  36. class CSpell;
  37. class CGTownInstance;
  38. class CArtifact;
  39. class CGDefInfo;
  40. class CSpecObjInfo;
  41. struct TerrainTile;
  42. struct InfoWindow;
  43. class CGBoat;
  44. class DLL_EXPORT CCastleEvent
  45. {
  46. public:
  47. std::string name, message;
  48. std::vector<si32> resources; //gain / loss of resources
  49. ui8 players; //players for whom this event can be applied
  50. ui8 forHuman, forComputer;
  51. ui32 firstShow; //postpone of first encounter time in days
  52. ui32 forEvery; //every n days this event will occure
  53. ui8 bytes[6]; //build specific buildings (raw format, similar to town's)
  54. si32 gen[7]; //additional creatures in i-th level dwelling
  55. bool operator<(const CCastleEvent &drugie) const
  56. {
  57. return firstShow<drugie.firstShow;
  58. }
  59. template <typename Handler> void serialize(Handler &h, const int version)
  60. {
  61. h & name & message & resources & players & forHuman & forComputer & firstShow
  62. & forEvery & bytes & gen;
  63. }
  64. };
  65. class CQuest
  66. {
  67. public:
  68. 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
  69. si32 lastDay; //after this day (first day is 0) mission cannot be completed; if -1 - no limit
  70. ui32 m13489val;
  71. std::vector<ui32> m2stats;
  72. std::vector<ui16> m5arts; //artifacts id
  73. std::vector<std::pair<ui32, ui32> > m6creatures; //pair[cre id, cre count]
  74. std::vector<ui32> m7resources;
  75. std::string firstVisitText, nextVisitText, completedText;
  76. template <typename Handler> void serialize(Handler &h, const int version)
  77. {
  78. h & missionType & lastDay & m13489val & m2stats & m5arts & m6creatures & m7resources
  79. & firstVisitText & nextVisitText & completedText;
  80. }
  81. };
  82. class DLL_EXPORT IObjectInterface
  83. {
  84. public:
  85. static IGameCallback *cb;
  86. IObjectInterface();
  87. virtual ~IObjectInterface();
  88. virtual void onHeroVisit(const CGHeroInstance * h) const;
  89. virtual void onHeroLeave(const CGHeroInstance * h) const;
  90. virtual void newTurn() const;
  91. virtual void initObj(); //synchr
  92. virtual void setProperty(ui8 what, ui32 val);//synchr
  93. };
  94. class DLL_EXPORT CGObjectInstance : protected IObjectInterface
  95. {
  96. protected:
  97. void getNameVis(std::string &hname) const;
  98. void giveDummyBonus(int heroID, ui8 duration = HeroBonus::ONE_DAY) const;
  99. public:
  100. mutable std::string hoverName;
  101. int3 pos; //h3m pos
  102. si32 ID, subID; //normal ID (this one from OH3 maps ;]) - eg. town=98; hero=34
  103. si32 id;//number of object in CObjectHandler's vector
  104. CGDefInfo * defInfo;
  105. CSpecObjInfo * info;
  106. ui8 animPhaseShift;
  107. ui8 tempOwner;
  108. ui8 blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile
  109. virtual int3 getSightCenter() const; //"center" tile from which the sight distance is calculated
  110. virtual int getSightRadious() const; //sight distance (should be used if player-owned structure)
  111. int getOwner() const;
  112. void setOwner(int ow);
  113. int getWidth() const; //returns width of object graphic in tiles
  114. int getHeight() const; //returns height of object graphic in tiles
  115. 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)
  116. int3 getVisitableOffset() const; //returns (x,y,0) offset to first visitable tile from bottom right obj tile (0,0,0) (h3m pos)
  117. 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)
  118. 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)
  119. bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing
  120. CGObjectInstance();
  121. virtual ~CGObjectInstance();
  122. //CGObjectInstance(const CGObjectInstance & right);
  123. //CGObjectInstance& operator=(const CGObjectInstance & right);
  124. virtual const std::string & getHoverText() const;
  125. //////////////////////////////////////////////////////////////////////////
  126. void initObj();
  127. void setProperty(ui8 what, ui32 val);//synchr
  128. virtual void setPropertyDer(ui8 what, ui32 val);//synchr
  129. friend class CGameHandler;
  130. template <typename Handler> void serialize(Handler &h, const int version)
  131. {
  132. h & hoverName & pos & ID & subID & id & animPhaseShift & tempOwner & blockVisit;
  133. //definfo is handled by map serializer
  134. }
  135. };
  136. class DLL_EXPORT CPlayersVisited: public CGObjectInstance
  137. {
  138. public:
  139. std::set<ui8> players; //players that visited this object
  140. bool hasVisited(ui8 player) const;
  141. void setPropertyDer(ui8 what, ui32 val);//synchr
  142. template <typename Handler> void serialize(Handler &h, const int version)
  143. {
  144. h & players;
  145. }
  146. };
  147. class DLL_EXPORT CArmedInstance: public CGObjectInstance
  148. {
  149. public:
  150. CCreatureSet army; //army
  151. virtual bool needsLastStack() const; //true if last stack cannot be taken
  152. int getArmyStrength() const; //sum of AI values of creatures
  153. template <typename Handler> void serialize(Handler &h, const int version)
  154. {
  155. h & static_cast<CGObjectInstance&>(*this);
  156. h & army;
  157. }
  158. };
  159. class DLL_EXPORT CGHeroInstance : public CArmedInstance
  160. {
  161. public:
  162. //////////////////////////////////////////////////////////////////////////
  163. ui8 moveDir; //format: 123
  164. // 8 4
  165. // 765
  166. mutable ui8 isStanding, tacticFormationEnabled;
  167. //////////////////////////////////////////////////////////////////////////
  168. CHero * type;
  169. ui32 exp; //experience point
  170. si32 level; //current level of hero
  171. std::string name; //may be custom
  172. std::string biography; //if custom
  173. si32 portrait; //may be custom
  174. si32 mana; // remaining spell points
  175. std::vector<si32> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
  176. 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
  177. si32 movement; //remaining movement points
  178. si32 identifier; //from the map file
  179. ui8 sex;
  180. ui8 inTownGarrison; // if hero is in town garrison
  181. CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison
  182. CGBoat *boat; //set to CGBoat when sailing
  183. std::vector<ui32> artifacts; //hero's artifacts from bag
  184. 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
  185. std::set<ui32> spells; //known spells (spell IDs)
  186. struct DLL_EXPORT Patrol
  187. {
  188. Patrol(){patrolling=false;patrolRadious=-1;};
  189. ui8 patrolling;
  190. si32 patrolRadious;
  191. template <typename Handler> void serialize(Handler &h, const int version)
  192. {
  193. h & patrolling & patrolRadious;
  194. }
  195. } patrol;
  196. std::list<HeroBonus> bonuses;
  197. //////////////////////////////////////////////////////////////////////////
  198. template <typename Handler> void serialize(Handler &h, const int version)
  199. {
  200. h & static_cast<CArmedInstance&>(*this);
  201. h & exp & level & name & biography & portrait & mana & primSkills & secSkills & movement
  202. & identifier & sex & inTownGarrison & artifacts & artifWorn & spells & patrol & bonuses
  203. & moveDir;
  204. ui8 standardType = (VLC->heroh->heroes[subID] == type);
  205. h & standardType;
  206. if(!standardType)
  207. h & type;
  208. else if(!h.saving)
  209. type = VLC->heroh->heroes[subID];
  210. //visitied town pointer will be restored by map serialization method
  211. }
  212. //////////////////////////////////////////////////////////////////////////
  213. int3 getSightCenter() const; //"center" tile from which the sight distance is calculated
  214. int getSightRadious() const; //sight distance (should be used if player-owned structure)
  215. //////////////////////////////////////////////////////////////////////////
  216. const HeroBonus *getBonus(int from, int id) const;
  217. int valOfBonuses(HeroBonus::BonusType type, int subtype = -1) const; //subtype -> subtype of bonus, if -1 then any
  218. bool hasBonusOfType(HeroBonus::BonusType type, int subtype = -1) const; //determines if hero has a bonus of given type (and optionally subtype)
  219. const std::string &getBiography() const;
  220. bool needsLastStack()const;
  221. 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
  222. unsigned int getLowestCreatureSpeed() const;
  223. int3 getPosition(bool h3m) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
  224. si32 manaLimit() const; //maximum mana value for this hero (basically 10*knowledge)
  225. si32 manaRegain() const; //how many points of mana can hero regain "naturally" in one day
  226. bool canWalkOnSea() const;
  227. int getCurrentLuck(int stack=-1, bool town=false) const;
  228. std::vector<std::pair<int,std::string> > getCurrentLuckModifiers(int stack=-1, bool town=false) const; //args as above
  229. 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
  230. std::vector<std::pair<int,std::string> > getCurrentMoraleModifiers(int stack=-1, bool town=false) const; //args as above
  231. int getPrimSkillLevel(int id) const;
  232. ui8 getSecSkillLevel(const int & ID) const; //0 - no skill
  233. int maxMovePoints(bool onLand) const;
  234. ui32 getArtAtPos(ui16 pos) const; //-1 - no artifact
  235. const CArtifact * getArt(int pos) const;
  236. 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)
  237. 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
  238. static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
  239. double getHeroStrength() const;
  240. int getTotalStrength() const;
  241. ui8 getSpellSchoolLevel(const CSpell * spell) const; //returns level on which given spell would be cast by this hero
  242. 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
  243. //////////////////////////////////////////////////////////////////////////
  244. void initHero();
  245. void initHero(int SUBID);
  246. void recreateArtBonuses();
  247. void initHeroDefInfo();
  248. CGHeroInstance();
  249. virtual ~CGHeroInstance();
  250. //////////////////////////////////////////////////////////////////////////
  251. void setPropertyDer(ui8 what, ui32 val);//synchr
  252. void initObj();
  253. void onHeroVisit(const CGHeroInstance * h) const;
  254. };
  255. class DLL_EXPORT CGDwelling : public CArmedInstance
  256. {
  257. public:
  258. std::vector<std::pair<ui32, std::vector<ui32> > > creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
  259. template <typename Handler> void serialize(Handler &h, const int version)
  260. {
  261. h & static_cast<CArmedInstance&>(*this) & creatures;
  262. }
  263. void initObj();
  264. void onHeroVisit(const CGHeroInstance * h) const;
  265. void newTurn() const;
  266. void heroAcceptsCreatures(const CGHeroInstance *h, ui32 answer) const;
  267. void fightOver(const CGHeroInstance *h, BattleResult *result) const;
  268. void wantsFight(const CGHeroInstance *h, ui32 answer) const;
  269. };
  270. class DLL_EXPORT CGTownInstance : public CGDwelling
  271. {
  272. public:
  273. CTown * town;
  274. std::string name; // name of town
  275. si32 builded; //how many buildings has been built this turn
  276. si32 destroyed; //how many buildings has been destroyed this turn
  277. const CGHeroInstance * garrisonHero, *visitingHero;
  278. ui32 identifier; //special identifier from h3m (only > RoE maps)
  279. si32 alignment;
  280. std::set<si32> forbiddenBuildings, builtBuildings;
  281. std::vector<ui32> possibleSpells, obligatorySpells;
  282. std::vector<std::vector<ui32> > spells; //spells[level] -> vector of spells, first will be available in guild
  283. //struct StrInfo
  284. //{
  285. // std::map<si32,ui32> creatures; //level - available amount
  286. // template <typename Handler> void serialize(Handler &h, const int version)
  287. // {
  288. // h & creatures;
  289. // }
  290. //} strInfo;
  291. std::set<CCastleEvent> events;
  292. //////////////////////////////////////////////////////////////////////////
  293. template <typename Handler> void serialize(Handler &h, const int version)
  294. {
  295. h & static_cast<CGDwelling&>(*this);
  296. h & name & builded & destroyed & identifier & alignment & forbiddenBuildings & builtBuildings
  297. & possibleSpells & obligatorySpells & spells & /*strInfo & */events;
  298. ui8 standardType = (&VLC->townh->towns[subID] == town);
  299. h & standardType;
  300. if(!standardType)
  301. h & town;
  302. else if(!h.saving)
  303. town = &VLC->townh->towns[subID];
  304. //garrison/visiting hero pointers will be restored in the map serialization
  305. }
  306. //////////////////////////////////////////////////////////////////////////
  307. int3 getSightCenter() const; //"center" tile from which the sight distance is calculated
  308. int getSightRadious() const; //returns sight distance
  309. //////////////////////////////////////////////////////////////////////////
  310. bool needsLastStack() const;
  311. int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle
  312. int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  313. int mageGuildLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  314. bool creatureDwelling(const int & level, bool upgraded=false) const;
  315. int getHordeLevel(const int & HID) const; //HID - 0 or 1; returns creature level or -1 if that horde structure is not present
  316. int creatureGrowth(const int & level) const;
  317. bool hasFort() const;
  318. bool hasCapitol() const;
  319. int dailyIncome() const; //calculates daily income of this town
  320. int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
  321. CGTownInstance();
  322. virtual ~CGTownInstance();
  323. //////////////////////////////////////////////////////////////////////////
  324. void onHeroVisit(const CGHeroInstance * h) const;
  325. void onHeroLeave(const CGHeroInstance * h) const;
  326. void initObj();
  327. };
  328. class DLL_EXPORT CGVisitableOPH : public CGObjectInstance //objects visitable only once per hero
  329. {
  330. public:
  331. std::set<si32> visitors; //ids of heroes who have visited this obj
  332. si8 ttype; //tree type - used only by trees of knowledge: 0 - give level for free; 1 - take 2000 gold; 2 - take 10 gems
  333. const std::string & getHoverText() const;
  334. void setPropertyDer(ui8 what, ui32 val);//synchr
  335. void onHeroVisit(const CGHeroInstance * h) const;
  336. void onNAHeroVisit(int heroID, bool alreadyVisited) const;
  337. void initObj();
  338. void treeSelected(int heroID, int resType, int resVal, int expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog
  339. void schoolSelected(int heroID, ui32 which) const;
  340. void arenaSelected(int heroID, int primSkill) const;
  341. template <typename Handler> void serialize(Handler &h, const int version)
  342. {
  343. h & static_cast<CGObjectInstance&>(*this);
  344. h & visitors & ttype;
  345. }
  346. };
  347. class DLL_EXPORT CGEvent : public CArmedInstance //event objects
  348. {
  349. public:
  350. std::string message;
  351. ui32 gainedExp;
  352. si32 manaDiff; //amount of gained / lost mana
  353. si32 moraleDiff; //morale modifier
  354. si32 luckDiff; //luck modifier
  355. std::vector<si32> resources;//gained / lost resources
  356. std::vector<si32> primskills;//gained / lost resources
  357. std::vector<si32> abilities; //gained abilities
  358. std::vector<si32> abilityLevels; //levels of gained abilities
  359. std::vector<si32> artifacts; //gained artifacts
  360. std::vector<si32> spells; //gained spells
  361. CCreatureSet creatures; //gained creatures
  362. ui8 availableFor; //players whom this event is available for
  363. ui8 computerActivate; //true if computre player can activate this event
  364. ui8 humanActivate; //true if human player can activate this event
  365. ui8 removeAfterVisit; //true if event is removed after occurring
  366. template <typename Handler> void serialize(Handler &h, const int version)
  367. {
  368. h & static_cast<CArmedInstance&>(*this);
  369. h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
  370. & abilities & abilityLevels & artifacts & spells & creatures & availableFor
  371. & computerActivate & humanActivate;
  372. }
  373. void activated(const CGHeroInstance * h) const;
  374. void onHeroVisit(const CGHeroInstance * h) const;
  375. void endBattle(const CGHeroInstance *h, BattleResult *result) const;
  376. void giveContents(const CGHeroInstance *h, bool afterBattle) const;
  377. void getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const;
  378. void getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const;
  379. };
  380. class DLL_EXPORT CGCreature : public CArmedInstance //creatures on map
  381. {
  382. public:
  383. ui32 identifier; //unique code for this monster (used in missions)
  384. 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)
  385. std::string message; //message printed for attacking hero
  386. std::vector<ui32> resources; //[res_id], resources given to hero that has won with monsters
  387. si32 gainedArtifact; //ID of artifact gained to hero, -1 if none
  388. ui8 neverFlees; //if true, the troops will never flee
  389. ui8 notGrowingTeam; //if true, number of units won't grow
  390. void fight(const CGHeroInstance *h) const;
  391. void onHeroVisit(const CGHeroInstance * h) const;
  392. void flee( const CGHeroInstance * h ) const;
  393. void endBattle(BattleResult *result) const;
  394. void fleeDecision(const CGHeroInstance *h, ui32 pursue) const;
  395. void joinDecision(const CGHeroInstance *h, int cost, ui32 accept) const;
  396. void initObj();
  397. 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)
  398. template <typename Handler> void serialize(Handler &h, const int version)
  399. {
  400. h & static_cast<CArmedInstance&>(*this);
  401. h & identifier & character & message & resources & gainedArtifact & neverFlees & notGrowingTeam;
  402. }
  403. };
  404. class DLL_EXPORT CGSignBottle : public CGObjectInstance //signs and ocean bottles
  405. {
  406. public:
  407. std::string message;
  408. void onHeroVisit(const CGHeroInstance * h) const;
  409. void initObj();
  410. template <typename Handler> void serialize(Handler &h, const int version)
  411. {
  412. h & static_cast<CGObjectInstance&>(*this);
  413. h & message;
  414. }
  415. };
  416. class DLL_EXPORT CGSeerHut : public CGObjectInstance, public CQuest
  417. {
  418. public:
  419. 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
  420. si32 rID; //reward ID
  421. si32 rVal; //reward value
  422. template <typename Handler> void serialize(Handler &h, const int version)
  423. {
  424. h & static_cast<CGObjectInstance&>(*this) & static_cast<CQuest&>(*this);
  425. h & rewardType & rID & rVal;
  426. }
  427. };
  428. class DLL_EXPORT CGWitchHut : public CPlayersVisited
  429. {
  430. public:
  431. std::vector<si32> allowedAbilities;
  432. ui32 ability;
  433. const std::string & getHoverText() const;
  434. void onHeroVisit(const CGHeroInstance * h) const;
  435. void initObj();
  436. template <typename Handler> void serialize(Handler &h, const int version)
  437. {
  438. h & static_cast<CGObjectInstance&>(*this) & static_cast<CPlayersVisited&>(*this);;
  439. h & allowedAbilities & ability;
  440. }
  441. };
  442. class DLL_EXPORT CGScholar : public CGObjectInstance
  443. {
  444. public:
  445. ui8 bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell
  446. ui16 bonusID; //ID of skill/spell
  447. void giveAnyBonus(const CGHeroInstance * h) const;
  448. void onHeroVisit(const CGHeroInstance * h) const;
  449. void initObj();
  450. template <typename Handler> void serialize(Handler &h, const int version)
  451. {
  452. h & static_cast<CGObjectInstance&>(*this);
  453. h & bonusType & bonusID;
  454. }
  455. };
  456. class DLL_EXPORT CGGarrison : public CArmedInstance
  457. {
  458. public:
  459. ui8 removableUnits;
  460. template <typename Handler> void serialize(Handler &h, const int version)
  461. {
  462. h & static_cast<CArmedInstance&>(*this);
  463. h & removableUnits;
  464. }
  465. };
  466. class DLL_EXPORT CGArtifact : public CArmedInstance
  467. {
  468. public:
  469. std::string message;
  470. ui32 spell; //if it's spell scroll
  471. void onHeroVisit(const CGHeroInstance * h) const;
  472. void fightForArt(ui32 agreed, const CGHeroInstance *h) const;
  473. void endBattle(BattleResult *result, const CGHeroInstance *h) const;
  474. void pick( const CGHeroInstance * h ) const;
  475. void initObj();
  476. template <typename Handler> void serialize(Handler &h, const int version)
  477. {
  478. h & static_cast<CArmedInstance&>(*this);
  479. h & message & spell;
  480. }
  481. };
  482. class DLL_EXPORT CGResource : public CArmedInstance
  483. {
  484. public:
  485. ui32 amount; //0 if random
  486. std::string message;
  487. void onHeroVisit(const CGHeroInstance * h) const;
  488. void collectRes(int player) const;
  489. void initObj();
  490. void fightForRes(ui32 agreed, const CGHeroInstance *h) const;
  491. void endBattle(BattleResult *result, const CGHeroInstance *h) const;
  492. template <typename Handler> void serialize(Handler &h, const int version)
  493. {
  494. h & static_cast<CArmedInstance&>(*this);
  495. h & amount & message;
  496. }
  497. };
  498. class DLL_EXPORT CGPickable : public CGObjectInstance //campfire, treasure chest, Flotsam, Shipwreck Survivor, Sea Chest
  499. {
  500. public:
  501. ui32 type, val1, val2;
  502. void onHeroVisit(const CGHeroInstance * h) const;
  503. void initObj();
  504. void chosen(int which, int heroID) const;
  505. template <typename Handler> void serialize(Handler &h, const int version)
  506. {
  507. h & static_cast<CGObjectInstance&>(*this);
  508. h & type & val1 & val2;
  509. }
  510. };
  511. class DLL_EXPORT CGShrine : public CPlayersVisited
  512. {
  513. public:
  514. ui8 spell; //number of spell or 255 if random
  515. void onHeroVisit(const CGHeroInstance * h) const;
  516. void initObj();
  517. const std::string & getHoverText() const;
  518. template <typename Handler> void serialize(Handler &h, const int version)
  519. {
  520. h & static_cast<CGObjectInstance&>(*this) & static_cast<CPlayersVisited&>(*this);;
  521. h & spell;
  522. }
  523. };
  524. class DLL_EXPORT CGPandoraBox : public CArmedInstance
  525. {
  526. public:
  527. std::string message;
  528. //gained things:
  529. ui32 gainedExp;
  530. si32 manaDiff; //amount of gained / lost mana
  531. si32 moraleDiff; //morale modifier
  532. si32 luckDiff; //luck modifier
  533. std::vector<si32> resources;//gained / lost resources
  534. std::vector<si32> primskills;//gained / lost resources
  535. std::vector<si32> abilities; //gained abilities
  536. std::vector<si32> abilityLevels; //levels of gained abilities
  537. std::vector<si32> artifacts; //gained artifacts
  538. std::vector<si32> spells; //gained spells
  539. CCreatureSet creatures; //gained creatures
  540. template <typename Handler> void serialize(Handler &h, const int version)
  541. {
  542. h & static_cast<CArmedInstance&>(*this);
  543. h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
  544. & abilities & abilityLevels & artifacts & spells & creatures;
  545. }
  546. };
  547. class DLL_EXPORT CGQuestGuard : public CGObjectInstance, public CQuest
  548. {
  549. public:
  550. template <typename Handler> void serialize(Handler &h, const int version)
  551. {
  552. h & static_cast<CQuest&>(*this) & static_cast<CGObjectInstance&>(*this);
  553. }
  554. };
  555. class DLL_EXPORT CGMine : public CArmedInstance
  556. {
  557. public:
  558. void offerLeavingGuards(const CGHeroInstance *h) const;
  559. void onHeroVisit(const CGHeroInstance * h) const;
  560. void newTurn() const;
  561. void initObj();
  562. template <typename Handler> void serialize(Handler &h, const int version)
  563. {
  564. h & static_cast<CArmedInstance&>(*this);
  565. }
  566. };
  567. class DLL_EXPORT CGVisitableOPW : public CGObjectInstance //objects visitable OPW
  568. {
  569. public:
  570. ui8 visited; //true if object has been visited this week
  571. void setPropertyDer(ui8 what, ui32 val);//synchr
  572. void onHeroVisit(const CGHeroInstance * h) const;
  573. void newTurn() const;
  574. template <typename Handler> void serialize(Handler &h, const int version)
  575. {
  576. h & static_cast<CGObjectInstance&>(*this);
  577. h & visited;
  578. }
  579. };
  580. class DLL_EXPORT CGTeleport : public CGObjectInstance //teleports and subterranean gates
  581. {
  582. public:
  583. static std::map<int,std::map<int, std::vector<int> > > objs; //map[ID][subID] => vector of ids
  584. void onHeroVisit(const CGHeroInstance * h) const;
  585. void initObj();
  586. template <typename Handler> void serialize(Handler &h, const int version)
  587. {
  588. h & static_cast<CGObjectInstance&>(*this);
  589. }
  590. };
  591. class DLL_EXPORT CGBonusingObject : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  592. {
  593. public:
  594. void onHeroVisit(const CGHeroInstance * h) const;
  595. const std::string & getHoverText() const;
  596. void initObj();
  597. template <typename Handler> void serialize(Handler &h, const int version)
  598. {
  599. h & static_cast<CGObjectInstance&>(*this);
  600. }
  601. };
  602. class DLL_EXPORT CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  603. {
  604. public:
  605. void onHeroVisit(const CGHeroInstance * h) const;
  606. const std::string & getHoverText() const;
  607. template <typename Handler> void serialize(Handler &h, const int version)
  608. {
  609. h & static_cast<CGObjectInstance&>(*this);
  610. }
  611. };
  612. class DLL_EXPORT CGSirens : public CGObjectInstance
  613. {
  614. public:
  615. void onHeroVisit(const CGHeroInstance * h) const;
  616. const std::string & getHoverText() const;
  617. void initObj();
  618. template <typename Handler> void serialize(Handler &h, const int version)
  619. {
  620. h & static_cast<CGObjectInstance&>(*this);
  621. }
  622. };
  623. class DLL_EXPORT CGObservatory : public CGObjectInstance //Redwood observatory
  624. {
  625. public:
  626. void onHeroVisit(const CGHeroInstance * h) const;
  627. template <typename Handler> void serialize(Handler &h, const int version)
  628. {
  629. h & static_cast<CGObjectInstance&>(*this);
  630. }
  631. };
  632. class DLL_EXPORT CGBoat : public CGObjectInstance
  633. {
  634. public:
  635. ui8 direction;
  636. const CGHeroInstance *hero; //hero on board
  637. void initObj();
  638. CGBoat()
  639. {
  640. direction = 4;
  641. }
  642. template <typename Handler> void serialize(Handler &h, const int version)
  643. {
  644. h & static_cast<CGObjectInstance&>(*this) & direction;
  645. }
  646. };
  647. class DLL_EXPORT CGOnceVisitable : public CPlayersVisited //wagon, corpse, lean to, warriors tomb
  648. {
  649. public:
  650. ui8 artOrRes; //0 - nothing; 1 - artifact; 2 - resource
  651. ui32 bonusType, //id of res or artifact
  652. bonusVal; //resource amount (or not used)
  653. void onHeroVisit(const CGHeroInstance * h) const;
  654. const std::string & getHoverText() const;
  655. void initObj();
  656. void searchTomb(const CGHeroInstance *h, ui32 accept) const;
  657. template <typename Handler> void serialize(Handler &h, const int version)
  658. {
  659. h & static_cast<CGObjectInstance&>(*this) & static_cast<CPlayersVisited&>(*this);;
  660. h & bonusType & bonusVal;
  661. }
  662. };
  663. class DLL_EXPORT CObjectHandler
  664. {
  665. public:
  666. std::vector<si32> cregens; //type 17. dwelling subid -> creature ID
  667. void loadObjects();
  668. template <typename Handler> void serialize(Handler &h, const int version)
  669. {
  670. h & cregens;
  671. }
  672. };
  673. #endif // __COBJECTHANDLER_H__