CObjectHandler.h 25 KB

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