CHeroHandler.h 6.8 KB

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