CObjectHandler.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 ibject is visitable at location (x, y) form left top tile of image (x, y in tiles)
  58. bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing
  59. CGObjectInstance();
  60. virtual ~CGObjectInstance();
  61. CGObjectInstance(const CGObjectInstance & right);
  62. CGObjectInstance& operator=(const CGObjectInstance & right);
  63. };
  64. class DLL_EXPORT CArmedInstance: public CGObjectInstance
  65. {
  66. public:
  67. CCreatureSet army; //army
  68. };
  69. class DLL_EXPORT CGHeroInstance : public CArmedInstance
  70. {
  71. public:
  72. mutable int moveDir; //format: 123
  73. // 8 4
  74. // 765
  75. mutable ui8 isStanding, tacticFormationEnabled, looseFormation;
  76. CHero * type;
  77. ui32 exp; //experience point
  78. int level; //current level of hero
  79. std::string name; //may be custom
  80. std::string biography; //may be custom
  81. int portrait; //may be custom
  82. int mana; // remaining spell points
  83. std::vector<int> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
  84. std::vector<std::pair<int,int> > secSkills; //first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert)
  85. int movement; //remaining movement points
  86. int identifier; //from the map file
  87. bool sex;
  88. struct DLL_EXPORT Patrol
  89. {
  90. Patrol(){patrolling=false;patrolRadious=-1;};
  91. bool patrolling;
  92. int patrolRadious;
  93. } patrol;
  94. bool inTownGarrison; // if hero is in town garrison
  95. CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison
  96. std::vector<ui32> artifacts; //hero's artifacts from bag
  97. 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
  98. std::set<ui32> spells; //known spells (spell IDs)
  99. virtual bool isHero() const;
  100. unsigned int getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype) const;
  101. unsigned int getLowestCreatureSpeed();
  102. unsigned int getAdditiveMoveBonus() const;
  103. float getMultiplicativeMoveBonus() const;
  104. static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
  105. int3 getPosition(bool h3m) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
  106. int getSightDistance() const; //returns sight distance of this hero
  107. void setPosition(int3 Pos, bool h3m); //as above, but sets position
  108. bool canWalkOnSea() const;
  109. int getCurrentLuck() const;
  110. int getCurrentMorale() const;
  111. int getSecSkillLevel(const int & ID) const; //-1 - no skill
  112. ui32 getArtAtPos(ui16 pos) const; //-1 - no artifact
  113. void setArtAtPos(ui16 pos, int art);
  114. const CArtifact * getArt(int pos);
  115. CGHeroInstance();
  116. virtual ~CGHeroInstance();
  117. };
  118. class DLL_EXPORT CGTownInstance : public CArmedInstance
  119. {
  120. public:
  121. CTown * town;
  122. std::string name; // name of town
  123. int builded; //how many buildings has been built this turn
  124. int destroyed; //how many buildings has been destroyed this turn
  125. const CGHeroInstance * garrisonHero, *visitingHero;
  126. int identifier; //special identifier from h3m (only > RoE maps)
  127. int alignment;
  128. std::set<si32> forbiddenBuildings, builtBuildings;
  129. std::vector<int> possibleSpells, obligatorySpells;
  130. std::vector<std::vector<ui32> > spells; //spells[level] -> vector of spells, first will be available in guild
  131. struct StrInfo
  132. {
  133. std::map<si32,ui32> creatures; //level - available amount
  134. template <typename Handler> void serialize(Handler &h, const int version)
  135. {
  136. h & creatures;
  137. }
  138. } strInfo;
  139. std::set<CCastleEvent> events;
  140. int getSightDistance() const; //returns sight distance
  141. int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle
  142. int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  143. int mageGuildLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  144. bool creatureDwelling(const int & level, bool upgraded=false) const;
  145. int getHordeLevel(const int & HID) const; //HID - 0 or 1; returns creature level or -1 if that horde structure is not present
  146. int creatureGrowth(const int & level) const;
  147. bool hasFort() const;
  148. bool hasCapitol() const;
  149. int dailyIncome() const;
  150. int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
  151. CGTownInstance();
  152. virtual ~CGTownInstance();
  153. };
  154. class DLL_EXPORT CObjectHandler
  155. {
  156. public:
  157. std::vector<std::string> names; //vector of objects; i-th object in vector has subnumber i
  158. std::vector<int> cregens; //type 17. dwelling subid -> creature ID
  159. void loadObjects();
  160. std::vector<std::string> creGens; //names of creatures' generators
  161. std::vector<std::string> advobtxt;
  162. std::vector<std::string> xtrainfo;
  163. std::vector<std::string> restypes;
  164. std::vector<std::pair<std::string,std::string> > mines; //first - name; second - event description
  165. };
  166. #endif //COBJECTHANDLER_H