CObjectHandler.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 "CCreatureHandler.h"
  9. using boost::logic::tribool;
  10. class CCPPObjectScript;
  11. class CGObjectInstance;
  12. class CScript;
  13. class CObjectScript;
  14. class CGHeroInstance;
  15. class CTown;
  16. class CHero;
  17. class CBuilding;
  18. class CSpell;
  19. class CGTownInstance;
  20. class CArtifact;
  21. class CGDefInfo;
  22. class CSpecObjInfo;
  23. class DLL_EXPORT CCastleEvent
  24. {
  25. public:
  26. std::string name, message;
  27. int wood, mercury, ore, sulfur, crystal, gems, gold; //gain / loss of resources
  28. unsigned char players; //players for whom this event can be applied
  29. bool forHuman, forComputer;
  30. int firstShow; //postpone of first encounter time in days
  31. int forEvery; //every n days this event will occure
  32. unsigned char bytes[6]; //build specific buildings (raw format, similar to town's)
  33. int gen[7]; //additional creatures in i-th level dwelling
  34. bool operator<(const CCastleEvent &drugie) const
  35. {
  36. return firstShow<drugie.firstShow;
  37. }
  38. };
  39. class DLL_EXPORT CGObjectInstance
  40. {
  41. public:
  42. int3 pos; //h3m pos
  43. int ID, subID; //normal ID (this one from OH3 maps ;]) - eg. town=98; hero=34
  44. si32 id;//number of object in CObjectHandler's vector
  45. CGDefInfo * defInfo;
  46. CCPPObjectScript * state;
  47. CSpecObjInfo * info;
  48. unsigned char animPhaseShift;
  49. std::string hoverName;
  50. ui8 tempOwner; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna
  51. ui8 blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile
  52. virtual bool isHero() const;
  53. int getOwner() const;
  54. void setOwner(int ow);
  55. int getWidth() const; //returns width of object graphic in tiles
  56. int getHeight() const; //returns height of object graphic in tiles
  57. 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)
  58. 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)
  59. bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing
  60. CGObjectInstance();
  61. virtual ~CGObjectInstance();
  62. CGObjectInstance(const CGObjectInstance & right);
  63. CGObjectInstance& operator=(const CGObjectInstance & right);
  64. };
  65. class DLL_EXPORT CArmedInstance: public CGObjectInstance
  66. {
  67. public:
  68. CCreatureSet army; //army
  69. };
  70. class DLL_EXPORT CGHeroInstance : public CArmedInstance
  71. {
  72. public:
  73. mutable int moveDir; //format: 123
  74. // 8 4
  75. // 765
  76. mutable ui8 isStanding, tacticFormationEnabled;
  77. CHero * type;
  78. ui32 exp; //experience point
  79. int level; //current level of hero
  80. std::string name; //may be custom
  81. std::string biography; //may be custom
  82. int portrait; //may be custom
  83. int mana; // remaining spell points
  84. std::vector<int> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
  85. std::vector<std::pair<int,int> > 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
  86. int movement; //remaining movement points
  87. int identifier; //from the map file
  88. bool sex;
  89. struct DLL_EXPORT Patrol
  90. {
  91. Patrol(){patrolling=false;patrolRadious=-1;};
  92. bool patrolling;
  93. int patrolRadious;
  94. } patrol;
  95. bool inTownGarrison; // if hero is in town garrison
  96. CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison
  97. std::vector<ui32> artifacts; //hero's artifacts from bag
  98. 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
  99. std::set<ui32> spells; //known spells (spell IDs)
  100. virtual bool isHero() const;
  101. unsigned int getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype) const;
  102. unsigned int getLowestCreatureSpeed();
  103. unsigned int getAdditiveMoveBonus() const;
  104. float getMultiplicativeMoveBonus() const;
  105. static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
  106. int3 getPosition(bool h3m) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
  107. int getSightDistance() const; //returns sight distance of this hero
  108. int manaLimit() const; //maximum mana value for this hero (basically 10*knowledge)
  109. //void setPosition(int3 Pos, bool h3m); //as above, but sets position
  110. bool canWalkOnSea() const;
  111. int getCurrentLuck() const;
  112. int getCurrentMorale() const;
  113. int getPrimSkillLevel(int id) const;
  114. int getSecSkillLevel(const int & ID) const; //0 - no skill
  115. int maxMovePoints(bool onLand) const;
  116. ui32 getArtAtPos(ui16 pos) const; //-1 - no artifact
  117. void setArtAtPos(ui16 pos, int art);
  118. const CArtifact * getArt(int pos) const;
  119. 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
  120. void initHero();
  121. void initHero(int SUBID);
  122. CGHeroInstance();
  123. virtual ~CGHeroInstance();
  124. };
  125. class DLL_EXPORT CGTownInstance : public CArmedInstance
  126. {
  127. public:
  128. CTown * town;
  129. std::string name; // name of town
  130. int builded; //how many buildings has been built this turn
  131. int destroyed; //how many buildings has been destroyed this turn
  132. const CGHeroInstance * garrisonHero, *visitingHero;
  133. int identifier; //special identifier from h3m (only > RoE maps)
  134. int alignment;
  135. std::set<si32> forbiddenBuildings, builtBuildings;
  136. std::vector<int> possibleSpells, obligatorySpells;
  137. std::vector<std::vector<ui32> > spells; //spells[level] -> vector of spells, first will be available in guild
  138. struct StrInfo
  139. {
  140. std::map<si32,ui32> creatures; //level - available amount
  141. template <typename Handler> void serialize(Handler &h, const int version)
  142. {
  143. h & creatures;
  144. }
  145. } strInfo;
  146. std::set<CCastleEvent> events;
  147. int getSightDistance() const; //returns sight distance
  148. int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle
  149. int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  150. int mageGuildLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  151. bool creatureDwelling(const int & level, bool upgraded=false) const;
  152. int getHordeLevel(const int & HID) const; //HID - 0 or 1; returns creature level or -1 if that horde structure is not present
  153. int creatureGrowth(const int & level) const;
  154. bool hasFort() const;
  155. bool hasCapitol() const;
  156. int dailyIncome() const;
  157. int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
  158. CGTownInstance();
  159. virtual ~CGTownInstance();
  160. };
  161. class DLL_EXPORT CObjectHandler
  162. {
  163. public:
  164. std::vector<std::string> names; //vector of objects; i-th object in vector has subnumber i
  165. std::vector<int> cregens; //type 17. dwelling subid -> creature ID
  166. void loadObjects();
  167. std::vector<std::string> creGens; //names of creatures' generators
  168. std::vector<std::string> advobtxt;
  169. std::vector<std::string> xtrainfo;
  170. std::vector<std::string> restypes;
  171. std::vector<std::pair<std::string,std::string> > mines; //first - name; second - event description
  172. };
  173. #endif //COBJECTHANDLER_H