CHeroHandler.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #pragma once
  2. #include "../lib/ConstTransitivePtr.h"
  3. #include "GameConstants.h"
  4. /*
  5. * CHeroHandler.h, part of VCMI engine
  6. *
  7. * Authors: listed in file AUTHORS in main folder
  8. *
  9. * License: GNU General Public License v2.0 or later
  10. * Full text of license available in license.txt file, in main folder
  11. *
  12. */
  13. class CHeroClass;
  14. class CDefHandler;
  15. class CGameInfo;
  16. class CGHeroInstance;
  17. struct BattleHex;
  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. si32 ID;
  77. std::string defName;
  78. std::vector<ui8> allowedTerrains;
  79. std::vector<ui8> allowedSpecialBfields;
  80. ui8 isAbsoluteObstacle; //there may only one such obstacle in battle and its position is always the same
  81. si32 width, height; //how much space to the right and up is needed to place obstacle (affects only placement algorithm)
  82. std::vector<si16> blockedTiles; //offsets relative to obstacle position (that is its left bottom corner)
  83. std::vector<BattleHex> getBlocked(BattleHex hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex'
  84. bool isAppropriate(int terrainType, int specialBattlefield = -1) const;
  85. template <typename Handler> void serialize(Handler &h, const int version)
  86. {
  87. h & ID & defName & allowedTerrains & allowedSpecialBfields & isAbsoluteObstacle & width & height & blockedTiles;
  88. }
  89. };
  90. struct DLL_LINKAGE SPuzzleInfo
  91. {
  92. ui16 number; //type of puzzle
  93. si16 x, y; //position
  94. ui16 whenUncovered; //determines the sequnce of discovering (the lesser it is the sooner puzzle will be discovered)
  95. std::string filename; //file with graphic of this puzzle
  96. template <typename Handler> void serialize(Handler &h, const int version)
  97. {
  98. h & number & x & y & whenUncovered & filename;
  99. }
  100. };
  101. const int PUZZLES_PER_FACTION = 48;
  102. class DLL_LINKAGE CHeroHandler
  103. {
  104. public:
  105. std::vector< ConstTransitivePtr<CHero> > heroes; //changed from nodrze
  106. std::vector<CHeroClass *> heroClasses;
  107. 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
  108. struct SBallisticsLevelInfo
  109. {
  110. ui8 keep, tower, gate, wall; //chance to hit in percent (eg. 87 is 87%)
  111. ui8 shots; //how many shots we have
  112. ui8 noDmg, oneDmg, twoDmg; //chances for shot dealing certain dmg in percent (eg. 87 is 87%); must sum to 100
  113. ui8 sum; //I don't know if it is useful for anything, but it's in config file
  114. template <typename Handler> void serialize(Handler &h, const int version)
  115. {
  116. h & keep & tower & gate & wall & shots & noDmg & oneDmg & twoDmg & sum;
  117. }
  118. };
  119. std::vector<SBallisticsLevelInfo> ballistics; //info about ballistics ability per level; [0] - none; [1] - basic; [2] - adv; [3] - expert
  120. std::map<int, CObstacleInfo> obstacles; //info about obstacles that may be placed on battlefield
  121. std::map<int, CObstacleInfo> absoluteObstacles; //info about obstacles that may be placed on battlefield
  122. std::vector<int> nativeTerrains; //info about native terrains of different factions
  123. void loadObstacles(); //loads info about obstacles
  124. std::vector<SPuzzleInfo> puzzleInfo[GameConstants::F_NUMBER]; //descriptions of puzzles
  125. void loadPuzzleInfo();
  126. ui32 level(ui64 experience) const; //calculates level corresponding to given experience amount
  127. ui64 reqExp(ui32 level) const; //calculates experience required for given level
  128. void loadHeroes();
  129. void loadHeroClasses();
  130. void initHeroClasses();
  131. void loadTerrains();
  132. CHeroHandler(); //c-tor
  133. ~CHeroHandler(); //d-tor
  134. template <typename Handler> void serialize(Handler &h, const int version)
  135. {
  136. h & heroClasses & heroes & expPerLevel & ballistics & nativeTerrains & puzzleInfo;
  137. h & obstacles & absoluteObstacles;
  138. if(!h.saving)
  139. {
  140. //restore class pointers
  141. for (int i=0; i<heroes.size(); i++)
  142. {
  143. heroes[i]->heroClass = heroClasses[heroes[i]->heroType];
  144. }
  145. }
  146. }
  147. };