CBattleAnimations.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #pragma once
  2. #include "../CAnimation.h"
  3. #include "../../lib/BattleHex.h"
  4. class CBattleInterface;
  5. class CStack;
  6. class CCreatureAnimation;
  7. struct CatapultProjectileInfo;
  8. struct StackAttackedInfo;
  9. /*
  10. * CBattleAnimations.h, part of VCMI engine
  11. *
  12. * Authors: listed in file AUTHORS in main folder
  13. *
  14. * License: GNU General Public License v2.0 or later
  15. * Full text of license available in license.txt file, in main folder
  16. *
  17. */
  18. /// Base class of battle animations
  19. class CBattleAnimation
  20. {
  21. protected:
  22. CBattleInterface * owner;
  23. public:
  24. virtual bool init()=0; //to be called - if returned false, call again until returns true
  25. virtual void nextFrame()=0; //call every new frame
  26. virtual void endAnim(); //to be called mostly internally; in this class it removes animation from pendingAnims list
  27. virtual ~CBattleAnimation(){};
  28. bool isEarliest(bool perStackConcurrency); //determines if this animation is earliest of all
  29. ui32 ID; //unique identifier
  30. CBattleAnimation(CBattleInterface * _owner);
  31. };
  32. /// Sub-class which is responsible for managing the battle stack animation.
  33. class CBattleStackAnimation : public CBattleAnimation
  34. {
  35. public:
  36. const CStack * stack; //id of stack whose animation it is
  37. CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack);
  38. CCreatureAnimation * myAnim(); //animation for our stack
  39. };
  40. /// This class is responsible for managing the battle attack animation
  41. class CAttackAnimation : public CBattleStackAnimation
  42. {
  43. protected:
  44. BattleHex dest; //attacked hex
  45. bool shooting;
  46. CCreatureAnim::EAnimType group; //if shooting is true, print this animation group
  47. const CStack *attackedStack;
  48. const CStack *attackingStack;
  49. int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
  50. public:
  51. void nextFrame();
  52. bool checkInitialConditions();
  53. CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
  54. };
  55. /// Animation of a defending unit
  56. class CDefenceAnimation : public CBattleStackAnimation
  57. {
  58. private:
  59. //std::vector<StackAttackedInfo> attackedInfos;
  60. const CStack * attacker; //attacking stack
  61. bool byShooting; //if true, stack has been attacked by shooting
  62. bool killed; //if true, stack has been killed
  63. public:
  64. bool init();
  65. void nextFrame();
  66. void endAnim();
  67. CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner);
  68. virtual ~CDefenceAnimation(){};
  69. };
  70. class CDummyAnimation : public CBattleAnimation
  71. {
  72. private:
  73. int counter;
  74. int howMany;
  75. public:
  76. bool init();
  77. void nextFrame();
  78. void endAnim();
  79. CDummyAnimation(CBattleInterface * _owner, int howManyFrames);
  80. virtual ~CDummyAnimation(){}
  81. };
  82. /// Hand-to-hand attack
  83. class CMeleeAttackAnimation : public CAttackAnimation
  84. {
  85. public:
  86. bool init();
  87. void nextFrame();
  88. void endAnim();
  89. CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked);
  90. virtual ~CMeleeAttackAnimation(){};
  91. };
  92. /// Move animation of a creature
  93. class CMovementAnimation : public CBattleStackAnimation
  94. {
  95. private:
  96. std::vector<BattleHex> destTiles; //destination
  97. BattleHex nextHex;
  98. ui32 nextPos;
  99. int distance;
  100. double stepX, stepY; //how far stack is moved in one frame
  101. double posX, posY;
  102. int steps, whichStep;
  103. int curStackPos; //position of stack before move
  104. public:
  105. bool init();
  106. void nextFrame();
  107. void endAnim();
  108. CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance);
  109. virtual ~CMovementAnimation(){};
  110. };
  111. /// Move end animation of a creature
  112. class CMovementEndAnimation : public CBattleStackAnimation
  113. {
  114. private:
  115. BattleHex destinationTile;
  116. public:
  117. bool init();
  118. void nextFrame();
  119. void endAnim();
  120. CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile);
  121. virtual ~CMovementEndAnimation(){};
  122. };
  123. /// Move start animation of a creature
  124. class CMovementStartAnimation : public CBattleStackAnimation
  125. {
  126. public:
  127. bool init();
  128. void nextFrame();
  129. void endAnim();
  130. CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack);
  131. virtual ~CMovementStartAnimation(){};
  132. };
  133. /// Class responsible for animation of stack chaning direction (left <-> right)
  134. class CReverseAnimation : public CBattleStackAnimation
  135. {
  136. private:
  137. int partOfAnim; //1 - first, 2 - second
  138. bool secondPartSetup;
  139. BattleHex hex;
  140. public:
  141. bool priority; //true - high, false - low
  142. bool init();
  143. void nextFrame();
  144. void setupSecondPart();
  145. void endAnim();
  146. CReverseAnimation(CBattleInterface * _owner, const CStack * stack, BattleHex dest, bool _priority);
  147. virtual ~CReverseAnimation(){};
  148. };
  149. /// Small struct which contains information about the position and the velocity of a projectile
  150. struct ProjectileInfo
  151. {
  152. double x, y; //position on the screen
  153. double dx, dy; //change in position in one step
  154. int step, lastStep; //to know when finish showing this projectile
  155. int creID; //ID of creature that shot this projectile
  156. int stackID; //ID of stack
  157. int frameNum; //frame to display form projectile animation
  158. bool spin; //if true, frameNum will be increased
  159. int animStartDelay; //how many times projectile must be attempted to be shown till it's really show (decremented after hit)
  160. bool reverse; //if true, projectile will be flipped by vertical asix
  161. CatapultProjectileInfo * catapultInfo; // holds info about the parabolic trajectory of the cannon
  162. };
  163. /// Shooting attack
  164. class CShootingAnimation : public CAttackAnimation
  165. {
  166. private:
  167. int catapultDamage;
  168. public:
  169. bool init();
  170. void nextFrame();
  171. void endAnim();
  172. //last two params only for catapult attacks
  173. CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest,
  174. const CStack * _attacked, bool _catapult = false, int _catapultDmg = 0);
  175. virtual ~CShootingAnimation(){};
  176. };
  177. /// This class manages a spell effect animation
  178. class CSpellEffectAnimation : public CBattleAnimation
  179. {
  180. private:
  181. ui32 effect;
  182. BattleHex destTile;
  183. std::string customAnim;
  184. int x, y, dx, dy;
  185. bool Vflip;
  186. public:
  187. bool init();
  188. void nextFrame();
  189. void endAnim();
  190. CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, BattleHex _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false);
  191. CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false);
  192. virtual ~CSpellEffectAnimation(){};
  193. };