2
0

CHeroHandler.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #ifndef __CHEROHANDLER_H__
  2. #define __CHEROHANDLER_H__
  3. #include "../global.h"
  4. #include <string>
  5. #include <vector>
  6. #include <set>
  7. #include "../lib/ConstTransitivePtr.h"
  8. /*
  9. * CHeroHandler.h, part of VCMI engine
  10. *
  11. * Authors: listed in file AUTHORS in main folder
  12. *
  13. * License: GNU General Public License v2.0 or later
  14. * Full text of license available in license.txt file, in main folder
  15. *
  16. */
  17. class CHeroClass;
  18. class CDefHandler;
  19. class CGameInfo;
  20. class CGHeroInstance;
  21. struct SSpecialtyInfo
  22. { si32 type;
  23. si32 val;
  24. si32 subtype;
  25. si32 additionalinfo;
  26. template <typename Handler> void serialize(Handler &h, const int version)
  27. {
  28. h & type & val & subtype & additionalinfo;
  29. }
  30. };
  31. class DLL_EXPORT CHero
  32. {
  33. public:
  34. enum EHeroClasses {KNIGHT, CLERIC, RANGER, DRUID, ALCHEMIST, WIZARD,
  35. DEMONIAC, HERETIC, DEATHKNIGHT, NECROMANCER, WARLOCK, OVERLORD,
  36. BARBARIAN, BATTLEMAGE, BEASTMASTER, WITCH, PLANESWALKER, ELEMENTALIST};
  37. std::string name; //name of hero
  38. si32 ID;
  39. ui32 lowStack[3], highStack[3]; //amount of units; described below
  40. std::string refTypeStack[3]; //reference names of units appearing in hero's army if he is recruited in tavern
  41. CHeroClass * heroClass;
  42. EHeroClasses heroType; //hero class
  43. std::vector<std::pair<ui8,ui8> > secSkillsInit; //initial secondary skills; first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert)
  44. std::vector<SSpecialtyInfo> spec;
  45. si32 startingSpell; //-1 if none
  46. ui8 sex; // default sex: 0=male, 1=female
  47. //bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;}
  48. CHero();
  49. ~CHero();
  50. template <typename Handler> void serialize(Handler &h, const int version)
  51. {
  52. h & name & ID & lowStack & highStack & refTypeStack & heroClass & heroType & secSkillsInit & spec & startingSpell & sex;
  53. }
  54. };
  55. class DLL_EXPORT CHeroClass
  56. {
  57. public:
  58. ui8 alignment;
  59. ui32 skillLimit; //how many secondary skills can hero learn
  60. std::string name;
  61. float aggression;
  62. int initialAttack, initialDefence, initialPower, initialKnowledge; //initial values of primary skills
  63. std::vector<std::pair<int,int> > primChance;//primChance[PRIMARY_SKILL_ID] - first is for levels 2 - 9, second for 10+;;; probability (%) of getting point of primary skill when getting new level
  64. std::vector<int> proSec; //probabilities of gaining secondary skills (out of 112), in id order
  65. int selectionProbability[9]; //probability of selection in towns
  66. std::vector<int> terrCosts; //default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock; -1 means terrain is imapassable
  67. int chooseSecSkill(const std::set<int> & possibles) const; //picks secondary skill out from given possibilities
  68. CHeroClass(); //c-tor
  69. ~CHeroClass(); //d-tor
  70. template <typename Handler> void serialize(Handler &h, const int version)
  71. {
  72. h & skillLimit & name & aggression & initialAttack & initialDefence & initialPower & initialKnowledge & primChance
  73. & proSec & selectionProbability & terrCosts & alignment;
  74. }
  75. EAlignment getAlignment();
  76. };
  77. struct DLL_EXPORT CObstacleInfo
  78. {
  79. int ID;
  80. std::string defName,
  81. blockmap, //blockmap: X - blocked, N - not blocked, L - description goes to the next line, staring with the left bottom hex
  82. allowedTerrains; /*terrains[i]: 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills
  83. 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees
  84. 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field
  85. 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough
  86. 24. ship to ship 25. ship*/
  87. std::pair<si16, si16> posShift; //shift of obstacle's position in the battlefield <x shift, y shift>, eg. if it's <-1, 2> obstacle will be printed one pixel to the left and two to the bottom
  88. int getWidth() const; //returns width of obstacle in hexes
  89. int getHeight() const; //returns height of obstacle in hexes
  90. std::vector<THex> getBlocked(THex hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex'
  91. THex getMaxBlocked(THex hex) const; //returns maximal hex (max number) covered by this obstacle
  92. template <typename Handler> void serialize(Handler &h, const int version)
  93. {
  94. h & ID & defName & blockmap & allowedTerrains & posShift;
  95. }
  96. };
  97. struct DLL_EXPORT SPuzzleInfo
  98. {
  99. ui16 number; //type of puzzle
  100. si16 x, y; //position
  101. ui16 whenUncovered; //determines the sequnce of discovering (the lesser it is the sooner puzzle will be discovered)
  102. std::string filename; //file with graphic of this puzzle
  103. template <typename Handler> void serialize(Handler &h, const int version)
  104. {
  105. h & number & x & y & whenUncovered & filename;
  106. }
  107. };
  108. const int PUZZLES_PER_FACTION = 48;
  109. class DLL_EXPORT CHeroHandler
  110. {
  111. public:
  112. std::vector< ConstTransitivePtr<CHero> > heroes; //changed from nodrze
  113. std::vector<CHeroClass *> heroClasses;
  114. std::vector<ui64> expPerLevel; //expPerLEvel[i] is amount of exp needed to reach level i; if it is not in this vector, multiplicate last value by 1,2 to get next value
  115. struct SBallisticsLevelInfo
  116. {
  117. ui8 keep, tower, gate, wall; //chance to hit in percent (eg. 87 is 87%)
  118. ui8 shots; //how many shots we have
  119. ui8 noDmg, oneDmg, twoDmg; //chances for shot dealing certain dmg in percent (eg. 87 is 87%); must sum to 100
  120. ui8 sum; //I don't know if it is useful for anything, but it's in config file
  121. template <typename Handler> void serialize(Handler &h, const int version)
  122. {
  123. h & keep & tower & gate & wall & shots & noDmg & oneDmg & twoDmg & sum;
  124. }
  125. };
  126. std::vector<SBallisticsLevelInfo> ballistics; //info about ballistics ability per level; [0] - none; [1] - basic; [2] - adv; [3] - expert
  127. std::map<int, CObstacleInfo> obstacles; //info about obstacles that may be placed on battlefield
  128. std::vector<int> nativeTerrains; //info about native terrains of different factions
  129. void loadObstacles(); //loads info about obstacles
  130. std::vector<SPuzzleInfo> puzzleInfo[F_NUMBER]; //descriptions of puzzles
  131. void loadPuzzleInfo();
  132. unsigned int level(ui64 experience) const; //calculates level corresponding to given experience amount
  133. ui64 reqExp(unsigned int level) const; //calculates experience required for given level
  134. void loadHeroes();
  135. void loadHeroClasses();
  136. void initHeroClasses();
  137. void loadTerrains();
  138. CHeroHandler(); //c-tor
  139. ~CHeroHandler(); //d-tor
  140. template <typename Handler> void serialize(Handler &h, const int version)
  141. {
  142. h & heroClasses & heroes & expPerLevel & ballistics & obstacles & nativeTerrains & puzzleInfo;
  143. if(!h.saving)
  144. {
  145. //restore class pointers
  146. for (int i=0; i<heroes.size(); i++)
  147. {
  148. heroes[i]->heroClass = heroClasses[heroes[i]->heroType];
  149. }
  150. }
  151. }
  152. };
  153. #endif // __CHEROHANDLER_H__