CHeroHandler.h 6.8 KB

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