unit.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #pragma once
  2. #include "abstractfactory.h"
  3. #include <QObject>
  4. #include <QString>
  5. #include <QImage>
  6. #include <iostream>
  7. #include <vector>
  8. class Effect;
  9. class Cell;
  10. class Unit : public QObject {
  11. Q_OBJECT
  12. public:
  13. explicit Unit(QString parameters);
  14. virtual ~Unit() {}
  15. //---------------------------------------------//
  16. //---------Basic traits getters section--------//
  17. //---------------------------------------------//
  18. double getExperience();
  19. int getLevel();
  20. int getMovementSpeed();
  21. int getInitiative();
  22. int getIntelligence();
  23. int getStrength();
  24. int getAgility();
  25. int getActivityPoints();
  26. int getAttackPoints();
  27. int getAttackCost();
  28. int getAttackRange();
  29. int getStartingActivityPoints();
  30. int getHealthPoints();
  31. void setHealthPoints(int);
  32. int getMaxHealthPoints();
  33. int getMagicDefence();
  34. int getPhysicDefence();
  35. int getCost();
  36. void setCost(int value);
  37. virtual bool isCharacter();
  38. std::vector<QString> getParentSpecs();
  39. std::vector<QString> getUpgradeSpecs();
  40. //---------------------------------------------//
  41. //------------Unit location section------------//
  42. //---------------------------------------------//
  43. Cell* getLocation();
  44. void setLocation(Cell* to);
  45. double getRealX();
  46. void setRealX(double x);
  47. double getRealY();
  48. void setRealY(double y);
  49. //---------------------------------------------//
  50. //--------Damage checkers & calculators--------//
  51. //---------------------------------------------//
  52. virtual int reduceIncomingDamage(std::string damageType, int value);
  53. virtual bool canAttackForDistance(std::string, int) {return false;}
  54. virtual bool canAttackToCell(Cell* ) {return false;}
  55. virtual bool canAttackUnit(Unit* ) {return false;}
  56. //---------------------------------------------//
  57. //--------Effect processing & calling----------//
  58. //---------------------------------------------//
  59. void operateEffectList();
  60. void add(Effect*);
  61. void remove(std::vector<Effect*>::iterator);
  62. void remove(Effect*);
  63. std::vector<Effect*>::iterator beginIteratorEffectsList();
  64. std::vector<Effect*>::iterator endIteratorEffectsList();
  65. //---------------------------------------------//
  66. //-------Movement checkers & calculators-------//
  67. //---------------------------------------------//
  68. int lenOfActualPath(Cell* destination);
  69. virtual bool canMoveForDistance(int distance);
  70. virtual bool canMoveToCell(Cell* destination);
  71. virtual void moveToCell(Cell* destination);
  72. virtual int theSameNear();
  73. //---------------------------------------------//
  74. //----------------GUI section------------------//
  75. //---------------------------------------------//
  76. QString getUnitId() const;
  77. QString getUnitName() const;
  78. QString getUnitDescr() const;
  79. QString getUnitBaseClassId() const;
  80. std::vector<QString> getUnitTraits() const;
  81. QImage getUnitIcon() const;
  82. //---------------------------------------------//
  83. //-----------Parameters load section-----------//
  84. //---------------------------------------------//
  85. private:
  86. void loadUnitName(QString unit_folder);
  87. void loadUnitDescr(QString unit_folder);
  88. void loadUnitBaseClass(QString unit_folder);
  89. void loadUnitTraits(QString unit_folder);
  90. void loadUnitIcon(QString unit_folder);
  91. void loadUnitPrevSpecs(QString unit_folder);
  92. void loadUnitUpgradeSpecs(QString unit_folder);
  93. public:
  94. bool operator <(const Unit &b) {
  95. if (base_class_id_ != b.base_class_id_)
  96. return base_class_id_ < b.base_class_id_;
  97. return unit_id_ < b.unit_id_;
  98. }
  99. protected:
  100. std::vector <Effect*> effects_;
  101. //personal information
  102. int cost_;
  103. std::vector<QString> parent_specs_;
  104. std::vector<QString> upgrade_specs_;
  105. double experience_;
  106. int level_;
  107. std::string race_; //lower case
  108. //actions and events
  109. double initiative_;
  110. int activity_points_;
  111. //movement
  112. Cell* location_;
  113. int movement_speed_; //how many cells can move for one activity point
  114. double real_x_;
  115. double real_y_;
  116. //attack action
  117. int agility_;
  118. int attack_range_;
  119. int intelligence_;
  120. int strength_;
  121. int attack_cost_; //how many activity points does attack cost
  122. int starting_activity_points_;
  123. //durability
  124. int health_points_;
  125. int max_health_points_;
  126. int magic_defence_; //less or equal 40
  127. int physic_defence_; //less or equal 40
  128. // GUI values
  129. QString race_id_;
  130. QString unit_id_;
  131. QString unit_name_;
  132. QString unit_descr_;
  133. QString base_class_id_;
  134. QImage unit_icon_;
  135. };