CObjectHandler.h 31 KB

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