CObjectHandler.h 24 KB

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