CObjectHandler.h 22 KB

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