123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- #pragma once
- #include "../CAnimation.h"
- #include "../../lib/BattleHex.h"
- class CBattleInterface;
- class CStack;
- class CCreatureAnimation;
- struct CatapultProjectileInfo;
- struct StackAttackedInfo;
- /*
- * CBattleAnimations.h, part of VCMI engine
- *
- * Authors: listed in file AUTHORS in main folder
- *
- * License: GNU General Public License v2.0 or later
- * Full text of license available in license.txt file, in main folder
- *
- */
- /// Base class of battle animations
- class CBattleAnimation
- {
- protected:
- CBattleInterface * owner;
- public:
- virtual bool init()=0; //to be called - if returned false, call again until returns true
- virtual void nextFrame()=0; //call every new frame
- virtual void endAnim(); //to be called mostly internally; in this class it removes animation from pendingAnims list
- virtual ~CBattleAnimation(){};
- bool isEarliest(bool perStackConcurrency); //determines if this animation is earliest of all
- ui32 ID; //unique identifier
- CBattleAnimation(CBattleInterface * _owner);
- };
- /// Sub-class which is responsible for managing the battle stack animation.
- class CBattleStackAnimation : public CBattleAnimation
- {
- public:
- const CStack * stack; //id of stack whose animation it is
- CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack);
- CCreatureAnimation * myAnim(); //animation for our stack
- };
- /// This class is responsible for managing the battle attack animation
- class CAttackAnimation : public CBattleStackAnimation
- {
- protected:
- BattleHex dest; //attacked hex
- bool shooting;
- CCreatureAnim::EAnimType group; //if shooting is true, print this animation group
- const CStack *attackedStack;
- const CStack *attackingStack;
- int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
- public:
- void nextFrame();
- bool checkInitialConditions();
- CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
- };
- /// Animation of a defending unit
- class CDefenceAnimation : public CBattleStackAnimation
- {
- private:
- //std::vector<StackAttackedInfo> attackedInfos;
- const CStack * attacker; //attacking stack
- bool byShooting; //if true, stack has been attacked by shooting
- bool killed; //if true, stack has been killed
- public:
- bool init();
- void nextFrame();
- void endAnim();
- CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner);
- virtual ~CDefenceAnimation(){};
- };
- class CDummyAnimation : public CBattleAnimation
- {
- private:
- int counter;
- int howMany;
- public:
- bool init();
- void nextFrame();
- void endAnim();
- CDummyAnimation(CBattleInterface * _owner, int howManyFrames);
- virtual ~CDummyAnimation(){}
- };
- /// Hand-to-hand attack
- class CMeleeAttackAnimation : public CAttackAnimation
- {
- public:
- bool init();
- void nextFrame();
- void endAnim();
- CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked);
- virtual ~CMeleeAttackAnimation(){};
- };
- /// Move animation of a creature
- class CMovementAnimation : public CBattleStackAnimation
- {
- private:
- std::vector<BattleHex> destTiles; //destination
- BattleHex nextHex;
- ui32 nextPos;
- int distance;
- double stepX, stepY; //how far stack is moved in one frame
- double posX, posY;
- int steps, whichStep;
- int curStackPos; //position of stack before move
- public:
- bool init();
- void nextFrame();
- void endAnim();
- CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance);
- virtual ~CMovementAnimation(){};
- };
- /// Move end animation of a creature
- class CMovementEndAnimation : public CBattleStackAnimation
- {
- private:
- BattleHex destinationTile;
- public:
- bool init();
- void nextFrame();
- void endAnim();
- CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile);
- virtual ~CMovementEndAnimation(){};
- };
- /// Move start animation of a creature
- class CMovementStartAnimation : public CBattleStackAnimation
- {
- public:
- bool init();
- void nextFrame();
- void endAnim();
- CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack);
- virtual ~CMovementStartAnimation(){};
- };
- /// Class responsible for animation of stack chaning direction (left <-> right)
- class CReverseAnimation : public CBattleStackAnimation
- {
- private:
- int partOfAnim; //1 - first, 2 - second
- bool secondPartSetup;
- BattleHex hex;
- public:
- bool priority; //true - high, false - low
- bool init();
- void nextFrame();
- void setupSecondPart();
- void endAnim();
- CReverseAnimation(CBattleInterface * _owner, const CStack * stack, BattleHex dest, bool _priority);
- virtual ~CReverseAnimation(){};
- };
- /// Small struct which contains information about the position and the velocity of a projectile
- struct ProjectileInfo
- {
- double x, y; //position on the screen
- double dx, dy; //change in position in one step
- int step, lastStep; //to know when finish showing this projectile
- int creID; //ID of creature that shot this projectile
- int stackID; //ID of stack
- int frameNum; //frame to display form projectile animation
- bool spin; //if true, frameNum will be increased
- int animStartDelay; //how many times projectile must be attempted to be shown till it's really show (decremented after hit)
- bool reverse; //if true, projectile will be flipped by vertical asix
- CatapultProjectileInfo * catapultInfo; // holds info about the parabolic trajectory of the cannon
- };
- /// Shooting attack
- class CShootingAnimation : public CAttackAnimation
- {
- private:
- int catapultDamage;
- public:
- bool init();
- void nextFrame();
- void endAnim();
- //last two params only for catapult attacks
- CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest,
- const CStack * _attacked, bool _catapult = false, int _catapultDmg = 0);
- virtual ~CShootingAnimation(){};
- };
- /// This class manages a spell effect animation
- class CSpellEffectAnimation : public CBattleAnimation
- {
- private:
- ui32 effect;
- BattleHex destTile;
- std::string customAnim;
- int x, y, dx, dy;
- bool Vflip;
- public:
- bool init();
- void nextFrame();
- void endAnim();
- CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, BattleHex _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false);
- CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false);
- virtual ~CSpellEffectAnimation(){};
- };
|