CObjectHandler.h 27 KB

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