CHeroHandler.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 initialPrimSkills[GameConstants::PRIMARY_SKILLS]; //initial values of primary skills, uses PrimarySkill enum
  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[GameConstants::F_NUMBER]; //probability of selection in towns
  63. int chooseSecSkill(const std::set<int> & possibles) const; //picks secondary skill out from given possibilities
  64. CHeroClass(); //c-tor
  65. ~CHeroClass(); //d-tor
  66. template <typename Handler> void serialize(Handler &h, const int version)
  67. {
  68. h & skillLimit & name & aggression & initialPrimSkills & primChance
  69. & proSec & selectionProbability & alignment;
  70. }
  71. EAlignment::EAlignment getAlignment() const;
  72. };
  73. struct DLL_LINKAGE CObstacleInfo
  74. {
  75. si32 ID;
  76. std::string defName;
  77. std::vector<ui8> allowedTerrains;
  78. std::vector<ui8> allowedSpecialBfields;
  79. ui8 isAbsoluteObstacle; //there may only one such obstacle in battle and its position is always the same
  80. si32 width, height; //how much space to the right and up is needed to place obstacle (affects only placement algorithm)
  81. std::vector<si16> blockedTiles; //offsets relative to obstacle position (that is its left bottom corner)
  82. std::vector<BattleHex> getBlocked(BattleHex hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex'
  83. bool isAppropriate(int terrainType, int specialBattlefield = -1) const;
  84. template <typename Handler> void serialize(Handler &h, const int version)
  85. {
  86. h & ID & defName & allowedTerrains & allowedSpecialBfields & isAbsoluteObstacle & width & height & blockedTiles;
  87. }
  88. };
  89. class DLL_LINKAGE CHeroHandler
  90. {
  91. public:
  92. std::vector< ConstTransitivePtr<CHero> > heroes; //changed from nodrze
  93. std::vector<CHeroClass *> heroClasses;
  94. 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
  95. //default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock; -1 means terrain is imapassable
  96. std::vector<int> terrCosts;
  97. struct SBallisticsLevelInfo
  98. {
  99. ui8 keep, tower, gate, wall; //chance to hit in percent (eg. 87 is 87%)
  100. ui8 shots; //how many shots we have
  101. ui8 noDmg, oneDmg, twoDmg; //chances for shot dealing certain dmg in percent (eg. 87 is 87%); must sum to 100
  102. ui8 sum; //I don't know if it is useful for anything, but it's in config file
  103. template <typename Handler> void serialize(Handler &h, const int version)
  104. {
  105. h & keep & tower & gate & wall & shots & noDmg & oneDmg & twoDmg & sum;
  106. }
  107. };
  108. std::vector<SBallisticsLevelInfo> ballistics; //info about ballistics ability per level; [0] - none; [1] - basic; [2] - adv; [3] - expert
  109. std::map<int, CObstacleInfo> obstacles; //info about obstacles that may be placed on battlefield
  110. std::map<int, CObstacleInfo> absoluteObstacles; //info about obstacles that may be placed on battlefield
  111. void loadObstacles(); //loads info about obstacles
  112. ui32 level(ui64 experience) const; //calculates level corresponding to given experience amount
  113. ui64 reqExp(ui32 level) const; //calculates experience required for given level
  114. void loadHeroes();
  115. void loadHeroClasses();
  116. void initHeroClasses();
  117. void loadTerrains();
  118. CHeroHandler(); //c-tor
  119. ~CHeroHandler(); //d-tor
  120. template <typename Handler> void serialize(Handler &h, const int version)
  121. {
  122. h & heroClasses & heroes & expPerLevel & ballistics & terrCosts;
  123. h & obstacles & absoluteObstacles;
  124. if(!h.saving)
  125. {
  126. //restore class pointers
  127. for (int i=0; i<heroes.size(); i++)
  128. {
  129. heroes[i]->heroClass = heroClasses[heroes[i]->heroType];
  130. }
  131. }
  132. }
  133. };