CObjectHandler.h 34 KB

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