CBattleAnimations.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * CBattleAnimations.h, 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. #pragma once
  11. #include "../../lib/battle/BattleHex.h"
  12. #include "../widgets/Images.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CStack;
  15. VCMI_LIB_NAMESPACE_END
  16. class CBattleInterface;
  17. class CCreatureAnimation;
  18. struct CatapultProjectileInfo;
  19. struct StackAttackedInfo;
  20. /// Base class of battle animations
  21. class CBattleAnimation
  22. {
  23. protected:
  24. CBattleInterface * owner;
  25. public:
  26. virtual bool init() = 0; //to be called - if returned false, call again until returns true
  27. virtual void nextFrame() {} //call every new frame
  28. virtual void endAnim(); //to be called mostly internally; in this class it removes animation from pendingAnims list
  29. virtual ~CBattleAnimation();
  30. bool isEarliest(bool perStackConcurrency); //determines if this animation is earliest of all
  31. ui32 ID; //unique identifier
  32. CBattleAnimation(CBattleInterface * _owner);
  33. };
  34. /// Sub-class which is responsible for managing the battle stack animation.
  35. class CBattleStackAnimation : public CBattleAnimation
  36. {
  37. public:
  38. std::shared_ptr<CCreatureAnimation> myAnim; //animation for our stack, managed by CBattleInterface
  39. const CStack * stack; //id of stack whose animation it is
  40. CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack);
  41. void shiftColor(const ColorShifter * shifter);
  42. };
  43. /// This class is responsible for managing the battle attack animation
  44. class CAttackAnimation : public CBattleStackAnimation
  45. {
  46. bool soundPlayed;
  47. protected:
  48. BattleHex dest; //attacked hex
  49. bool shooting;
  50. CCreatureAnim::EAnimType group; //if shooting is true, print this animation group
  51. const CStack *attackedStack;
  52. const CStack *attackingStack;
  53. int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
  54. public:
  55. void nextFrame() override;
  56. void endAnim() override;
  57. bool checkInitialConditions();
  58. CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
  59. };
  60. /// Animation of a defending unit
  61. class CDefenceAnimation : public CBattleStackAnimation
  62. {
  63. CCreatureAnim::EAnimType getMyAnimType();
  64. std::string getMySound();
  65. void startAnimation();
  66. const CStack * attacker; //attacking stack
  67. bool rangedAttack; //if true, stack has been attacked by shooting
  68. bool killed; //if true, stack has been killed
  69. float timeToWait; // for how long this animation should be paused
  70. public:
  71. bool init() override;
  72. void nextFrame() override;
  73. void endAnim() override;
  74. CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner);
  75. virtual ~CDefenceAnimation(){};
  76. };
  77. class CDummyAnimation : public CBattleAnimation
  78. {
  79. private:
  80. int counter;
  81. int howMany;
  82. public:
  83. bool init() override;
  84. void nextFrame() override;
  85. void endAnim() override;
  86. CDummyAnimation(CBattleInterface * _owner, int howManyFrames);
  87. virtual ~CDummyAnimation(){}
  88. };
  89. /// Hand-to-hand attack
  90. class CMeleeAttackAnimation : public CAttackAnimation
  91. {
  92. public:
  93. bool init() override;
  94. void endAnim() override;
  95. CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked);
  96. virtual ~CMeleeAttackAnimation(){};
  97. };
  98. /// Move animation of a creature
  99. class CMovementAnimation : public CBattleStackAnimation
  100. {
  101. private:
  102. std::vector<BattleHex> destTiles; //full path, includes already passed hexes
  103. ui32 curentMoveIndex; // index of nextHex in destTiles
  104. BattleHex oldPos; //position of stack before move
  105. double begX, begY; // starting position
  106. double distanceX, distanceY; // full movement distance, may be negative if creture moves topleft
  107. double timeToMove; // full length of movement animation
  108. double progress; // range 0 -> 1, indicates move progrees. 0 = movement starts, 1 = move ends
  109. public:
  110. BattleHex nextHex; // next hex, to which creature move right now
  111. bool init() override;
  112. void nextFrame() override;
  113. void endAnim() override;
  114. CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance);
  115. virtual ~CMovementAnimation(){};
  116. };
  117. /// Move end animation of a creature
  118. class CMovementEndAnimation : public CBattleStackAnimation
  119. {
  120. private:
  121. BattleHex destinationTile;
  122. public:
  123. bool init() override;
  124. void endAnim() override;
  125. CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile);
  126. virtual ~CMovementEndAnimation(){};
  127. };
  128. /// Move start animation of a creature
  129. class CMovementStartAnimation : public CBattleStackAnimation
  130. {
  131. public:
  132. bool init() override;
  133. void endAnim() override;
  134. CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack);
  135. virtual ~CMovementStartAnimation(){};
  136. };
  137. /// Class responsible for animation of stack chaning direction (left <-> right)
  138. class CReverseAnimation : public CBattleStackAnimation
  139. {
  140. BattleHex hex;
  141. public:
  142. bool priority; //true - high, false - low
  143. bool init() override;
  144. static void rotateStack(CBattleInterface * owner, const CStack * stack, BattleHex hex);
  145. void setupSecondPart();
  146. void endAnim() override;
  147. CReverseAnimation(CBattleInterface * _owner, const CStack * stack, BattleHex dest, bool _priority);
  148. virtual ~CReverseAnimation(){};
  149. };
  150. class CRangedAttackAnimation : public CAttackAnimation
  151. {
  152. public:
  153. CRangedAttackAnimation(CBattleInterface * owner_, const CStack * attacker, BattleHex dest_, const CStack * defender);
  154. protected:
  155. };
  156. /// Shooting attack
  157. class CShootingAnimation : public CRangedAttackAnimation
  158. {
  159. private:
  160. int catapultDamage;
  161. public:
  162. bool init() override;
  163. void nextFrame() override;
  164. void endAnim() override;
  165. //last two params only for catapult attacks
  166. CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest,
  167. const CStack * _attacked, bool _catapult = false, int _catapultDmg = 0);
  168. virtual ~CShootingAnimation(){};
  169. };
  170. class CCastAnimation : public CRangedAttackAnimation
  171. {
  172. public:
  173. CCastAnimation(CBattleInterface * owner_, const CStack * attacker, BattleHex dest_, const CStack * defender);
  174. bool init() override;
  175. void nextFrame() override;
  176. void endAnim() override;
  177. };
  178. /// This class manages effect animation
  179. class CEffectAnimation : public CBattleAnimation
  180. {
  181. private:
  182. BattleHex destTile;
  183. std::shared_ptr<CAnimation> customAnim;
  184. int x, y, dx, dy;
  185. bool Vflip;
  186. bool alignToBottom;
  187. public:
  188. bool init() override;
  189. void nextFrame() override;
  190. void endAnim() override;
  191. CEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false, bool _alignToBottom = false);
  192. CEffectAnimation(CBattleInterface * _owner, std::shared_ptr<CAnimation> _customAnim, int _x, int _y, int _dx = 0, int _dy = 0);
  193. CEffectAnimation(CBattleInterface * _owner, std::string _customAnim, BattleHex _destTile, bool _Vflip = false, bool _alignToBottom = false);
  194. virtual ~CEffectAnimation(){};
  195. };