2
0

CHeroHandler.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. CDefHandler * moveAnim; //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
  40. int chooseSecSkill(const std::set<int> & possibles) const; //picks secondary skill out from given possibilities
  41. CHeroClass();
  42. ~CHeroClass();
  43. template <typename Handler> void serialize(Handler &h, const int version)
  44. {
  45. h & skillLimit & name & aggression & initialAttack & initialDefence & initialPower & initialKnowledge & primChance
  46. & proSec & selectionProbability & terrCosts;
  47. }
  48. };
  49. class DLL_EXPORT CHeroHandler
  50. {
  51. public:
  52. std::vector<CHero*> heroes; //by³o nodrze
  53. std::vector<CHeroClass *> heroClasses;
  54. 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
  55. unsigned int level(unsigned int experience);
  56. unsigned int reqExp(unsigned int level);
  57. void loadHeroes();
  58. void loadHeroClasses();
  59. void initHeroClasses();
  60. ~CHeroHandler();
  61. void initTerrainCosts();
  62. template <typename Handler> void serialize(Handler &h, const int version)
  63. {
  64. h & heroClasses & heroes & expPerLevel;
  65. if(!h.saving)
  66. {
  67. //restore class pointers
  68. for (int i=0; i<heroes.size(); i++)
  69. {
  70. heroes[i]->heroClass = heroClasses[heroes[i]->heroType];
  71. }
  72. }
  73. }
  74. };
  75. #endif // __CHEROHANDLER_H__