CHeroHandler.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef __CHEROHANDLER_H__
  2. #define __CHEROHANDLER_H__
  3. #include "../global.h"
  4. #include <string>
  5. #include <vector>
  6. #include <set>
  7. class CHeroClass;
  8. class CDefHandler;
  9. class CGameInfo;
  10. class CGHeroInstance;
  11. class DLL_EXPORT CHero
  12. {
  13. public:
  14. std::string name;
  15. int ID;
  16. int lowStack[3], highStack[3]; //amount of units; described below
  17. std::string refTypeStack[3]; //reference names of units appearing in hero's army if he is recruited in tavern
  18. CHeroClass * heroClass;
  19. EHeroClasses heroType; //hero class
  20. std::vector<std::pair<ui8,ui8> > secSkillsInit; //initial secondary skills; first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert)
  21. //bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;}
  22. template <typename Handler> void serialize(Handler &h, const int version)
  23. {
  24. h & name & ID & lowStack & highStack & refTypeStack & heroType & ID;
  25. //hero class pointer is restored by herohandler
  26. }
  27. };
  28. class DLL_EXPORT CHeroClass
  29. {
  30. public:
  31. ui32 skillLimit; //how many secondary skills can hero learn
  32. std::string name;
  33. float aggression;
  34. int initialAttack, initialDefence, initialPower, initialKnowledge;
  35. 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
  36. std::vector<int> proSec; //probabilities of gaining secondary skills (out of 112), in id order
  37. int selectionProbability[9]; //probability of selection in towns
  38. 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
  39. int chooseSecSkill(const std::set<int> & possibles) const; //picks secondary skill out from given possibilities
  40. CHeroClass();
  41. ~CHeroClass();
  42. template <typename Handler> void serialize(Handler &h, const int version)
  43. {
  44. h & skillLimit & name & aggression & initialAttack & initialDefence & initialPower & initialKnowledge & primChance
  45. & proSec & selectionProbability & terrCosts;
  46. }
  47. };
  48. class DLL_EXPORT CHeroHandler
  49. {
  50. public:
  51. std::vector<CHero*> heroes; //by³o nodrze
  52. std::vector<CHeroClass *> heroClasses;
  53. std::vector<int> 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
  54. struct SBallisticsLevelInfo
  55. {
  56. ui8 keep, tower, gate, wall; //chance to hit in percent (eg. 87 is 87%)
  57. ui8 shots; //how many shots we have
  58. ui8 noDmg, oneDmg, twoDmg; //chances for shot dealing certain dmg in percent (eg. 87 is 87%); must sum to 100
  59. ui8 sum; //I don't know if it is useful for anything, but it's in config file
  60. template <typename Handler> void serialize(Handler &h, const int version)
  61. {
  62. h & keep & tower & gate & wall & shots & noDmg & oneDmg & twoDmg & sum;
  63. }
  64. };
  65. std::vector<SBallisticsLevelInfo> ballistics; //info about ballistics ability per level; [0] - none; [1] - basic; [2] - adv; [3] - expert
  66. unsigned int level(unsigned int experience);
  67. unsigned int reqExp(unsigned int level);
  68. void loadHeroes();
  69. void loadHeroClasses();
  70. void initHeroClasses();
  71. void initTerrainCosts();
  72. CHeroHandler();
  73. ~CHeroHandler();
  74. template <typename Handler> void serialize(Handler &h, const int version)
  75. {
  76. h & heroClasses & heroes & expPerLevel & ballistics;
  77. if(!h.saving)
  78. {
  79. //restore class pointers
  80. for (int i=0; i<heroes.size(); i++)
  81. {
  82. heroes[i]->heroClass = heroClasses[heroes[i]->heroType];
  83. }
  84. }
  85. }
  86. };
  87. #endif // __CHEROHANDLER_H__