2011-12-22 16:05:19 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../../lib/BattleHex.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../widgets/Images.h"
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
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:
|
2013-07-06 19:10:20 +03:00
|
|
|
virtual bool init() = 0; //to be called - if returned false, call again until returns true
|
|
|
|
virtual void nextFrame() {} //call every new frame
|
2011-12-22 16:05:19 +03:00
|
|
|
virtual void endAnim(); //to be called mostly internally; in this class it removes animation from pendingAnims list
|
2013-07-16 21:12:47 +03:00
|
|
|
virtual ~CBattleAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
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:
|
2013-07-06 19:10:20 +03:00
|
|
|
CCreatureAnimation * myAnim; //animation for our stack, managed by CBattleInterface
|
2011-12-22 16:05:19 +03:00
|
|
|
const CStack * stack; //id of stack whose animation it is
|
|
|
|
|
|
|
|
CBattleStackAnimation(CBattleInterface * _owner, const CStack * _stack);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// This class is responsible for managing the battle attack animation
|
|
|
|
class CAttackAnimation : public CBattleStackAnimation
|
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
bool soundPlayed;
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
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();
|
2013-07-06 19:10:20 +03:00
|
|
|
void endAnim();
|
2011-12-22 16:05:19 +03:00
|
|
|
bool checkInitialConditions();
|
|
|
|
|
|
|
|
CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Animation of a defending unit
|
|
|
|
class CDefenceAnimation : public CBattleStackAnimation
|
|
|
|
{
|
2013-07-16 21:12:47 +03:00
|
|
|
CCreatureAnim::EAnimType getMyAnimType();
|
|
|
|
std::string getMySound();
|
|
|
|
|
|
|
|
void startAnimation();
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
const CStack * attacker; //attacking stack
|
2013-07-16 21:12:47 +03:00
|
|
|
bool rangedAttack; //if true, stack has been attacked by shooting
|
2011-12-22 16:05:19 +03:00
|
|
|
bool killed; //if true, stack has been killed
|
2013-07-16 21:12:47 +03:00
|
|
|
|
|
|
|
float timeToWait; // for how long this animation should be paused
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
|
|
|
bool init();
|
|
|
|
void nextFrame();
|
|
|
|
void endAnim();
|
|
|
|
|
|
|
|
CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner);
|
2012-04-08 13:34:23 +03:00
|
|
|
virtual ~CDefenceAnimation(){};
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CDummyAnimation : public CBattleAnimation
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int counter;
|
|
|
|
int howMany;
|
|
|
|
public:
|
|
|
|
bool init();
|
|
|
|
void nextFrame();
|
|
|
|
void endAnim();
|
|
|
|
|
|
|
|
CDummyAnimation(CBattleInterface * _owner, int howManyFrames);
|
2012-04-08 13:34:23 +03:00
|
|
|
virtual ~CDummyAnimation(){}
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Hand-to-hand attack
|
|
|
|
class CMeleeAttackAnimation : public CAttackAnimation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool init();
|
|
|
|
void endAnim();
|
|
|
|
|
|
|
|
CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked);
|
2012-04-08 13:34:23 +03:00
|
|
|
virtual ~CMeleeAttackAnimation(){};
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Move animation of a creature
|
|
|
|
class CMovementAnimation : public CBattleStackAnimation
|
|
|
|
{
|
|
|
|
private:
|
2013-07-06 19:10:20 +03:00
|
|
|
bool shouldRotate();
|
|
|
|
|
|
|
|
std::vector<BattleHex> destTiles; //full path, includes already passed hexes
|
|
|
|
ui32 curentMoveIndex; // index of nextHex in destTiles
|
|
|
|
|
|
|
|
BattleHex oldPos; //position of stack before move
|
|
|
|
|
|
|
|
double begX, begY; // starting position
|
|
|
|
double distanceX, distanceY; // full movement distance, may be negative if creture moves topleft
|
|
|
|
|
|
|
|
double timeToMove; // full length of movement animation
|
|
|
|
double progress; // range 0 -> 1, indicates move progrees. 0 = movement starts, 1 = move ends
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
2013-07-19 19:35:16 +03:00
|
|
|
BattleHex nextHex; // next hex, to which creature move right now
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
bool init();
|
|
|
|
void nextFrame();
|
|
|
|
void endAnim();
|
|
|
|
|
|
|
|
CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance);
|
2012-04-08 13:34:23 +03:00
|
|
|
virtual ~CMovementAnimation(){};
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Move end animation of a creature
|
|
|
|
class CMovementEndAnimation : public CBattleStackAnimation
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
BattleHex destinationTile;
|
|
|
|
public:
|
|
|
|
bool init();
|
|
|
|
void endAnim();
|
|
|
|
|
|
|
|
CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile);
|
2012-04-08 13:34:23 +03:00
|
|
|
virtual ~CMovementEndAnimation(){};
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Move start animation of a creature
|
|
|
|
class CMovementStartAnimation : public CBattleStackAnimation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool init();
|
|
|
|
void endAnim();
|
|
|
|
|
|
|
|
CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack);
|
2012-04-08 13:34:23 +03:00
|
|
|
virtual ~CMovementStartAnimation(){};
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Class responsible for animation of stack chaning direction (left <-> right)
|
|
|
|
class CReverseAnimation : public CBattleStackAnimation
|
|
|
|
{
|
|
|
|
BattleHex hex;
|
|
|
|
public:
|
|
|
|
bool priority; //true - high, false - low
|
|
|
|
bool init();
|
2013-07-06 19:10:20 +03:00
|
|
|
|
|
|
|
static void rotateStack(CBattleInterface * owner, const CStack * stack, BattleHex hex);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
void setupSecondPart();
|
|
|
|
void endAnim();
|
|
|
|
|
|
|
|
CReverseAnimation(CBattleInterface * _owner, const CStack * stack, BattleHex dest, bool _priority);
|
2012-04-08 13:34:23 +03:00
|
|
|
virtual ~CReverseAnimation(){};
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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
|
2013-04-04 16:18:38 +03:00
|
|
|
//bool spin; //if true, frameNum will be increased
|
2013-07-06 19:10:20 +03:00
|
|
|
int animStartDelay; //frame of shooter animation when projectile should appear
|
|
|
|
bool shotDone; // actual shot already done, projectile is flying
|
2011-12-22 16:05:19 +03:00
|
|
|
bool reverse; //if true, projectile will be flipped by vertical asix
|
2013-04-04 21:20:25 +03:00
|
|
|
std::shared_ptr<CatapultProjectileInfo> catapultInfo; // holds info about the parabolic trajectory of the cannon
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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);
|
2012-04-08 13:34:23 +03:00
|
|
|
virtual ~CShootingAnimation(){};
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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;
|
2014-11-27 15:51:16 +02:00
|
|
|
bool alignToBottom;
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
|
|
|
bool init();
|
|
|
|
void nextFrame();
|
|
|
|
void endAnim();
|
|
|
|
|
2014-11-27 15:51:16 +02:00
|
|
|
CSpellEffectAnimation(CBattleInterface * _owner, ui32 _effect, BattleHex _destTile, int _dx = 0, int _dy = 0, bool _Vflip = false, bool _alignToBottom = false);
|
|
|
|
CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false, bool _alignToBottom = false);
|
|
|
|
CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, BattleHex _destTile, bool _Vflip = false, bool _alignToBottom = false);
|
2012-04-08 13:34:23 +03:00
|
|
|
virtual ~CSpellEffectAnimation(){};
|
|
|
|
};
|