CCommanderInstance.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. }
  19. CCommanderInstance::CCommanderInstance(IGameInfoCallback * cb, const CreatureID & id)
  20. : CStackInstance(cb, BonusNodeType::COMMANDER, false)
  21. , name("Commando")
  22. {
  23. alive = true;
  24. level = 1;
  25. setCount(1);
  26. setType(nullptr);
  27. secondarySkills.resize(ECommander::SPELL_POWER + 1);
  28. setType(id);
  29. //TODO - parse them
  30. }
  31. void CCommanderInstance::setAlive(bool Alive)
  32. {
  33. //TODO: helm of immortality
  34. alive = Alive;
  35. if(!alive)
  36. {
  37. removeBonusesRecursive(Bonus::UntilCommanderKilled);
  38. }
  39. }
  40. bool CCommanderInstance::canGainExperience() const
  41. {
  42. return alive;
  43. }
  44. int CCommanderInstance::getExpRank() const
  45. {
  46. return LIBRARY->heroh->level(getTotalExperience());
  47. }
  48. int CCommanderInstance::getLevel() const
  49. {
  50. return std::max(1, getExpRank());
  51. }
  52. void CCommanderInstance::levelUp()
  53. {
  54. level++;
  55. for(const auto & bonus : LIBRARY->creh->commanderLevelPremy)
  56. { //grant all regular level-up bonuses
  57. accumulateBonus(bonus);
  58. }
  59. }
  60. ArtBearer CCommanderInstance::bearerType() const
  61. {
  62. return ArtBearer::COMMANDER;
  63. }
  64. bool CCommanderInstance::gainsLevel() const
  65. {
  66. return getTotalExperience() >= LIBRARY->heroh->reqExp(level + 1);
  67. }
  68. VCMI_LIB_NAMESPACE_END