CHeroHandler.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. struct DLL_EXPORT CObstacleInfo
  49. {
  50. int ID;
  51. std::string defName,
  52. blockmap, //blockmap: X - blocked, N - not blocked, L - description goes to the next line, staring with the left bottom hex
  53. allowedTerrains; /*terrains[i]: 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills
  54. 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees
  55. 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field
  56. 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough
  57. 24. ship to ship 25. ship*/
  58. int getWidth(); //returns width of obstacle in hexes
  59. int getHeight(); //returns height of obstacle in hexes
  60. std::vector<int> getBlocked(int hex); //returns vector of hexes blocked by obstacle when it's placed on hex 'hex'
  61. template <typename Handler> void serialize(Handler &h, const int version)
  62. {
  63. h & ID & defName & blockmap & allowedTerrains;
  64. }
  65. };
  66. class DLL_EXPORT CHeroHandler
  67. {
  68. public:
  69. std::vector<CHero*> heroes; //by³o nodrze
  70. std::vector<CHeroClass *> heroClasses;
  71. 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
  72. struct SBallisticsLevelInfo
  73. {
  74. ui8 keep, tower, gate, wall; //chance to hit in percent (eg. 87 is 87%)
  75. ui8 shots; //how many shots we have
  76. ui8 noDmg, oneDmg, twoDmg; //chances for shot dealing certain dmg in percent (eg. 87 is 87%); must sum to 100
  77. ui8 sum; //I don't know if it is useful for anything, but it's in config file
  78. template <typename Handler> void serialize(Handler &h, const int version)
  79. {
  80. h & keep & tower & gate & wall & shots & noDmg & oneDmg & twoDmg & sum;
  81. }
  82. };
  83. std::vector<SBallisticsLevelInfo> ballistics; //info about ballistics ability per level; [0] - none; [1] - basic; [2] - adv; [3] - expert
  84. std::map<int, CObstacleInfo> obstacles; //info about obstacles that may be placed on battlefield
  85. void loadObstacles();
  86. unsigned int level(unsigned int experience);
  87. unsigned int reqExp(unsigned int level);
  88. void loadHeroes();
  89. void loadHeroClasses();
  90. void initHeroClasses();
  91. void initTerrainCosts();
  92. CHeroHandler();
  93. ~CHeroHandler();
  94. template <typename Handler> void serialize(Handler &h, const int version)
  95. {
  96. h & heroClasses & heroes & expPerLevel & ballistics & obstacles;
  97. if(!h.saving)
  98. {
  99. //restore class pointers
  100. for (int i=0; i<heroes.size(); i++)
  101. {
  102. heroes[i]->heroClass = heroClasses[heroes[i]->heroType];
  103. }
  104. }
  105. }
  106. };
  107. #endif // __CHEROHANDLER_H__