2
0

CCommanderInstance.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * CCommanderInstance.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CCommanderInstance.h"
  12. #include "../../GameLibrary.h"
  13. #include "../../entities/hero/CHeroHandler.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. CCommanderInstance::CCommanderInstance(IGameInfoCallback *cb)
  16. :CStackInstance(cb)
  17. {}
  18. CCommanderInstance::CCommanderInstance(IGameInfoCallback *cb, const CreatureID & id)
  19. : CStackInstance(cb, BonusNodeType::COMMANDER, false)
  20. , name("Commando")
  21. {
  22. alive = true;
  23. level = 1;
  24. setCount(1);
  25. setType(nullptr);
  26. secondarySkills.resize (ECommander::SPELL_POWER + 1);
  27. setType(id);
  28. //TODO - parse them
  29. }
  30. void CCommanderInstance::setAlive (bool Alive)
  31. {
  32. //TODO: helm of immortality
  33. alive = Alive;
  34. if (!alive)
  35. {
  36. removeBonusesRecursive(Bonus::UntilCommanderKilled);
  37. }
  38. }
  39. bool CCommanderInstance::canGainExperience() const
  40. {
  41. return alive;
  42. }
  43. int CCommanderInstance::getExpRank() const
  44. {
  45. return LIBRARY->heroh->level (getTotalExperience());
  46. }
  47. int CCommanderInstance::getLevel() const
  48. {
  49. return std::max (1, getExpRank());
  50. }
  51. void CCommanderInstance::levelUp ()
  52. {
  53. level++;
  54. for(const auto & bonus : LIBRARY->creh->commanderLevelPremy)
  55. { //grant all regular level-up bonuses
  56. accumulateBonus(bonus);
  57. }
  58. }
  59. ArtBearer CCommanderInstance::bearerType() const
  60. {
  61. return ArtBearer::COMMANDER;
  62. }
  63. bool CCommanderInstance::gainsLevel() const
  64. {
  65. return getTotalExperience() >= LIBRARY->heroh->reqExp(level + 1);
  66. }
  67. VCMI_LIB_NAMESPACE_END