CBattleAnimations.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. int dmg; //damage dealt
  61. int amountKilled; //how many creatures in stack has been killed
  62. const CStack * attacker; //attacking stack
  63. bool byShooting; //if true, stack has been attacked by shooting
  64. bool killed; //if true, stack has been killed
  65. public:
  66. bool init();
  67. void nextFrame();
  68. void endAnim();
  69. CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner);
  70. virtual ~CDefenceAnimation(){};
  71. };
  72. class CDummyAnimation : public CBattleAnimation
  73. {
  74. private:
  75. int counter;
  76. int howMany;
  77. public:
  78. bool init();
  79. void nextFrame();
  80. void endAnim();
  81. CDummyAnimation(CBattleInterface * _owner, int howManyFrames);
  82. virtual ~CDummyAnimation(){}
  83. };
  84. /// Hand-to-hand attack
  85. class CMeleeAttackAnimation : public CAttackAnimation
  86. {
  87. public:
  88. bool init();
  89. void nextFrame();
  90. void endAnim();
  91. CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked);
  92. virtual ~CMeleeAttackAnimation(){};
  93. };
  94. /// Move animation of a creature
  95. class CMovementAnimation : public CBattleStackAnimation
  96. {
  97. private:
  98. std::vector<BattleHex> destTiles; //destination
  99. BattleHex nextHex;
  100. ui32 nextPos;
  101. int distance;
  102. double stepX, stepY; //how far stack is moved in one frame
  103. double posX, posY;
  104. int steps, whichStep;
  105. int curStackPos; //position of stack before move
  106. public:
  107. bool init();
  108. void nextFrame();
  109. void endAnim();
  110. CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance);
  111. virtual ~CMovementAnimation(){};
  112. };
  113. /// Move end animation of a creature
  114. class CMovementEndAnimation : public CBattleStackAnimation
  115. {
  116. private:
  117. BattleHex destinationTile;
  118. public:
  119. bool init();
  120. void nextFrame();
  121. void endAnim();
  122. CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile);
  123. virtual ~CMovementEndAnimation(){};
  124. };
  125. /// Move start animation of a creature
  126. class CMovementStartAnimation : public CBattleStackAnimation
  127. {
  128. public:
  129. bool init();
  130. void nextFrame();
  131. void endAnim();
  132. CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack);
  133. virtual ~CMovementStartAnimation(){};
  134. };
  135. /// Class responsible for animation of stack chaning direction (left <-> right)
  136. class CReverseAnimation : public CBattleStackAnimation
  137. {
  138. private:
  139. int partOfAnim; //1 - first, 2 - second
  140. bool secondPartSetup;
  141. BattleHex hex;
  142. public:
  143. bool priority; //true - high, false - low
  144. bool init();
  145. void nextFrame();
  146. void setupSecondPart();
  147. void endAnim();
  148. CReverseAnimation(CBattleInterface * _owner, const CStack * stack, BattleHex dest, bool _priority);
  149. virtual ~CReverseAnimation(){};
  150. };
  151. /// Small struct which contains information about the position and the velocity of a projectile
  152. struct ProjectileInfo
  153. {
  154. double x, y; //position on the screen
  155. double dx, dy; //change in position in one step
  156. int step, lastStep; //to know when finish showing this projectile
  157. int creID; //ID of creature that shot this projectile
  158. int stackID; //ID of stack
  159. int frameNum; //frame to display form projectile animation
  160. bool spin; //if true, frameNum will be increased
  161. int animStartDelay; //how many times projectile must be attempted to be shown till it's really show (decremented after hit)
  162. bool reverse; //if true, projectile will be flipped by vertical asix
  163. CatapultProjectileInfo * catapultInfo; // holds info about the parabolic trajectory of the cannon
  164. };
  165. /// Shooting attack
  166. class CShootingAnimation : public CAttackAnimation
  167. {
  168. private:
  169. int catapultDamage;
  170. bool catapult;
  171. public:
  172. bool init();
  173. void nextFrame();
  174. void endAnim();
  175. //last two params only for catapult attacks
  176. CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest,
  177. const CStack * _attacked, bool _catapult = false, int _catapultDmg = 0);
  178. virtual ~CShootingAnimation(){};
  179. };
  180. /// This class manages a spell effect animation
  181. class CSpellEffectAnimation : public CBattleAnimation
  182. {
  183. private:
  184. ui32 effect;
  185. BattleHex destTile;
  186. std::string customAnim;
  187. int x, y, dx, dy;
  188. bool Vflip;
  189. public:
  190. bool init();
  191. void nextFrame();
  192. void endAnim();
  193. CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, BattleHex _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false);
  194. CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false);
  195. virtual ~CSpellEffectAnimation(){};
  196. };