unit.h 4.6 KB

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