CBattleAnimations.h 6.9 KB

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