Unit.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. int getMagicDefence();
  32. int getPhysicDefence();
  33. int getCost();
  34. void setCost(int value);
  35. virtual bool isCharacter();
  36. std::vector<QString> getParentSpecs();
  37. std::vector<QString> getUpgradeSpecs();
  38. //---------------------------------------------//
  39. //------------Unit location section------------//
  40. //---------------------------------------------//
  41. Cell* getLocation();
  42. void setLocation(Cell* to);
  43. double getRealX();
  44. void setRealX(double x);
  45. double getRealY();
  46. void setRealY(double y);
  47. //---------------------------------------------//
  48. //--------Damage checkers & calculators--------//
  49. //---------------------------------------------//
  50. virtual int reduceIncomingDamage(std::string damageType, int value);
  51. virtual bool canAttackForDistance(std::string, int) {return false;}
  52. virtual bool canAttackToCell(Cell* ) {return false;}
  53. virtual bool canAttackUnit(Unit* ) {return false;}
  54. //---------------------------------------------//
  55. //--------Effect processing & calling----------//
  56. //---------------------------------------------//
  57. void operateEffectList();
  58. void add(Effect*);
  59. void remove(std::vector<Effect*>::iterator);
  60. void remove(Effect*);
  61. std::vector<Effect*>::iterator beginIteratorEffectsList();
  62. std::vector<Effect*>::iterator endIteratorEffectsList();
  63. //---------------------------------------------//
  64. //-------Movement checkers & calculators-------//
  65. //---------------------------------------------//
  66. int lenOfActualPath(Cell* destination);
  67. virtual bool canMoveForDistance(int distance);
  68. virtual bool canMoveToCell(Cell* destination);
  69. virtual void moveToCell(Cell* destination);
  70. virtual int theSameNear();
  71. //---------------------------------------------//
  72. //----------------GUI section------------------//
  73. //---------------------------------------------//
  74. QString getUnitId() const;
  75. QString getUnitName() const;
  76. QString getUnitDescr() const;
  77. QString getUnitBaseClassId() const;
  78. std::vector<QString> getUnitTraits() const;
  79. QImage getUnitIcon() const;
  80. //---------------------------------------------//
  81. //-----------Parameters load section-----------//
  82. //---------------------------------------------//
  83. private:
  84. void loadUnitName(QString unit_folder);
  85. void loadUnitDescr(QString unit_folder);
  86. void loadUnitBaseClass(QString unit_folder);
  87. void loadUnitTraits(QString unit_folder);
  88. void loadUnitIcon(QString unit_folder);
  89. void loadUnitPrevSpecs(QString unit_folder);
  90. void loadUnitUpgradeSpecs(QString unit_folder);
  91. public:
  92. bool operator <(const Unit &b) {
  93. if (base_class_id_ != b.base_class_id_)
  94. return base_class_id_ < b.base_class_id_;
  95. return unit_id_ < b.unit_id_;
  96. }
  97. protected:
  98. std::vector <Effect*> effects_;
  99. //personal information
  100. int cost_;
  101. std::vector<QString> parent_specs_;
  102. std::vector<QString> upgrade_specs_;
  103. double experience_;
  104. int level_;
  105. std::string race_; //lower case
  106. //actions and events
  107. double initiative_;
  108. int activity_points_;
  109. //movement
  110. Cell* location_;
  111. int movement_speed_; //how many cells can move for one activity point
  112. double real_x_;
  113. double real_y_;
  114. //attack action
  115. int agility_;
  116. int attack_range_;
  117. int intelligence_;
  118. int strength_;
  119. int attack_cost_; //how many activity points does attack cost
  120. int starting_activity_points_;
  121. //durability
  122. int health_points_;
  123. int magic_defence_; //less or equal 40
  124. int physic_defence_; //less or equal 40
  125. // GUI values
  126. QString race_id_;
  127. QString unit_id_;
  128. QString unit_name_;
  129. QString unit_descr_;
  130. QString base_class_id_;
  131. QImage unit_icon_;
  132. };