CBattleAnimations.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. bool isEarliest(bool perStackConcurrency); //determines if this animation is earliest of all
  28. ui32 ID; //unique identifier
  29. CBattleAnimation(CBattleInterface * _owner);
  30. };
  31. /// Sub-class which is responsible for managing the battle stack animation.
  32. class CBattleStackAnimation : public CBattleAnimation
  33. {
  34. public:
  35. const CStack * stack; //id of stack whose animation it is
  36. CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack);
  37. static bool isToReverseHlp(BattleHex hexFrom, BattleHex hexTo, bool curDir); //helper for isToReverse
  38. 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)
  39. CCreatureAnimation * myAnim(); //animation for our stack
  40. };
  41. /// This class is responsible for managing the battle attack animation
  42. class CAttackAnimation : public CBattleStackAnimation
  43. {
  44. protected:
  45. BattleHex dest; //attacked hex
  46. bool shooting;
  47. CCreatureAnim::EAnimType group; //if shooting is true, print this animation group
  48. const CStack *attackedStack;
  49. const CStack *attackingStack;
  50. int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
  51. public:
  52. void nextFrame();
  53. bool checkInitialConditions();
  54. CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
  55. };
  56. /// Animation of a defending unit
  57. class CDefenceAnimation : public CBattleStackAnimation
  58. {
  59. private:
  60. //std::vector<StackAttackedInfo> attackedInfos;
  61. int dmg; //damage dealt
  62. int amountKilled; //how many creatures in stack has been killed
  63. const CStack * attacker; //attacking stack
  64. bool byShooting; //if true, stack has been attacked by shooting
  65. bool killed; //if true, stack has been killed
  66. public:
  67. bool init();
  68. void nextFrame();
  69. void endAnim();
  70. CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner);
  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. };
  83. /// Hand-to-hand attack
  84. class CMeleeAttackAnimation : public CAttackAnimation
  85. {
  86. public:
  87. bool init();
  88. void nextFrame();
  89. void endAnim();
  90. CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked);
  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. };
  110. /// Move end animation of a creature
  111. class CMovementEndAnimation : public CBattleStackAnimation
  112. {
  113. private:
  114. BattleHex destinationTile;
  115. public:
  116. bool init();
  117. void nextFrame();
  118. void endAnim();
  119. CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile);
  120. };
  121. /// Move start animation of a creature
  122. class CMovementStartAnimation : public CBattleStackAnimation
  123. {
  124. public:
  125. bool init();
  126. void nextFrame();
  127. void endAnim();
  128. CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack);
  129. };
  130. /// Class responsible for animation of stack chaning direction (left <-> right)
  131. class CReverseAnimation : public CBattleStackAnimation
  132. {
  133. private:
  134. int partOfAnim; //1 - first, 2 - second
  135. bool secondPartSetup;
  136. BattleHex hex;
  137. public:
  138. bool priority; //true - high, false - low
  139. bool init();
  140. void nextFrame();
  141. void setupSecondPart();
  142. void endAnim();
  143. CReverseAnimation(CBattleInterface * _owner, const CStack * stack, BattleHex dest, bool _priority);
  144. };
  145. /// Small struct which contains information about the position and the velocity of a projectile
  146. struct ProjectileInfo
  147. {
  148. double x, y; //position on the screen
  149. double dx, dy; //change in position in one step
  150. int step, lastStep; //to know when finish showing this projectile
  151. int creID; //ID of creature that shot this projectile
  152. int stackID; //ID of stack
  153. int frameNum; //frame to display form projectile animation
  154. bool spin; //if true, frameNum will be increased
  155. int animStartDelay; //how many times projectile must be attempted to be shown till it's really show (decremented after hit)
  156. bool reverse; //if true, projectile will be flipped by vertical asix
  157. CatapultProjectileInfo * catapultInfo; // holds info about the parabolic trajectory of the cannon
  158. };
  159. /// Shooting attack
  160. class CShootingAnimation : public CAttackAnimation
  161. {
  162. private:
  163. int catapultDamage;
  164. bool catapult;
  165. public:
  166. bool init();
  167. void nextFrame();
  168. void endAnim();
  169. //last two params only for catapult attacks
  170. CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest,
  171. const CStack * _attacked, bool _catapult = false, int _catapultDmg = 0);
  172. };
  173. /// This class manages a spell effect animation
  174. class CSpellEffectAnimation : public CBattleAnimation
  175. {
  176. private:
  177. ui32 effect;
  178. BattleHex destTile;
  179. std::string customAnim;
  180. int x, y, dx, dy;
  181. bool Vflip;
  182. public:
  183. bool init();
  184. void nextFrame();
  185. void endAnim();
  186. CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, BattleHex _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false);
  187. CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false);
  188. };