unit.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #pragma once
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cassert>
  5. #include <string>
  6. #include "unit.h"
  7. Unit::Unit(){}
  8. double Unit::getExperience() {
  9. return experience_;
  10. }
  11. void Unit::setExperience(double value) {
  12. experience_ = value;
  13. }
  14. double Unit::getLevel() {
  15. return level_;
  16. };
  17. void Unit::setLevel(double value) {
  18. level_ = value;
  19. }
  20. double Unit::getHealthPoints() {
  21. return health_points_;
  22. };
  23. void Unit::setHealthPoints(double value) {
  24. health_points_ = value;
  25. }
  26. double Unit::getManaPoints() {
  27. return mana_points_;
  28. }
  29. void Unit::setManaPoints(double value) {
  30. mana_points_ = value;
  31. }
  32. double Unit::getEnergyPoints() {
  33. return energy_points_;
  34. }
  35. void Unit::setEnergyPoints(double value) {
  36. energy_points_ = value;
  37. }
  38. double Unit::getActivePoints() {
  39. return active_points_;
  40. }
  41. void Unit::setActivePoints(double value) {
  42. active_points_ = value;
  43. }
  44. double Unit::getAttackRange() {
  45. return attack_range_;
  46. }
  47. void Unit::setAttackRange(double value) {
  48. attack_range_ = value;
  49. }
  50. std::pair<int, int> Unit::getLocation() {
  51. return location_;
  52. }
  53. void Unit::setLocation(double x, double y) {
  54. location_ = std::make_pair(x, y);
  55. }
  56. double Unit::getMovementSpeed() {
  57. return movement_speed_;
  58. }
  59. void Unit::setMovementSpeed(double value) {
  60. movement_speed_ = value;
  61. }
  62. double Unit::getInitiative_() {
  63. return initiative_;
  64. }
  65. void Unit::setInitiative_(double value) {
  66. initiative_ = value;
  67. }
  68. double Unit::getDamagePerHit() {
  69. return damage_per_hit_;
  70. }
  71. void Unit::setDamagePerHit(double value) {
  72. damage_per_hit_ = value;
  73. }
  74. double Unit::getIntelligence() {
  75. return intelligence_;
  76. }
  77. void Unit::setIntelligence(double value) {
  78. intelligence_ = value;
  79. }
  80. double Unit::getStrength() {
  81. return strength_;
  82. }
  83. void Unit::setStrength(double value) {
  84. strength_ = value;
  85. }
  86. double Unit::getAgility() {
  87. return agility_;
  88. }
  89. void Unit::setAgility(double value) {
  90. agility_ = value;
  91. }
  92. double Unit::getMagicDefence() {
  93. return magic_defence_;
  94. }
  95. void Unit::setMagicDefence(double value) {
  96. magic_defence_ = value;
  97. }
  98. double Unit::getPhysicDefence() {
  99. return physic_defence_;
  100. }
  101. void Unit::setPhysicDefence(double value) {
  102. physic_defence_ = value;
  103. }
  104. void Unit::calculateDamagePerHit() {
  105. damage_per_hit_ = 0.5 * std::max(getAgility(), std::max(getStrength(), getIntelligence()));
  106. }
  107. double Unit::reduceIncomingDamage(std::string damageType, int damage) { //returns damage after reducing by defence
  108. assert("Incorrect damage type in call reduceIncomingDamage(), expected" &&
  109. damageType[0] == 'p' || damageType[0] == 'P' || damageType[0] == 'm' || damageType[0] == 'M');
  110. assert("Magic defence of unit is incorrectly high (>40), but must be" && magic_defence_ <= 40);
  111. assert("Physic defence of unit is incorrectly high (>40), but must be" && physic_defence_ <= 40);
  112. if (damageType[0] == 'p' || damageType[0] == 'P') {
  113. return (1 - 2.5 * physic_defence_ / 100) * damage;
  114. }
  115. else if (damageType[0] == 'm' || damageType[0] == 'M') {
  116. return (1 - 2.5 * magic_defence_ / 100) * damage;
  117. }
  118. }