2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2011-12-22 16:05:19 +03:00
|
|
|
#pragma once
|
|
|
|
|
2017-06-24 16:42:05 +02:00
|
|
|
#include "../../lib/battle/BattleHex.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../widgets/Images.h"
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
class CStack;
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
|
|
|
class CBattleInterface;
|
2011-12-22 16:05:19 +03:00
|
|
|
class CCreatureAnimation;
|
2022-11-20 19:11:34 +02:00
|
|
|
class CBattleAnimation;
|
2011-12-22 16:05:19 +03:00
|
|
|
struct CatapultProjectileInfo;
|
|
|
|
struct StackAttackedInfo;
|
|
|
|
|
|
|
|
/// Base class of battle animations
|
|
|
|
class CBattleAnimation
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
CBattleInterface * owner;
|
2022-11-20 19:11:34 +02:00
|
|
|
|
|
|
|
std::list<std::pair<CBattleAnimation *, bool>> & pendingAnimations();
|
|
|
|
std::shared_ptr<CCreatureAnimation> stackAnimation(const CStack * stack);
|
|
|
|
bool stackFacingRight(const CStack * stack);
|
|
|
|
void setStackFacingRight(const CStack * stack, bool facingRight);
|
|
|
|
ui32 maxAnimationID();
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
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:
|
2018-07-25 00:36:48 +02:00
|
|
|
std::shared_ptr<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);
|
2020-01-25 11:21:26 +02:00
|
|
|
|
2020-01-27 02:18:07 +02:00
|
|
|
void shiftColor(const ColorShifter * shifter);
|
2022-11-20 19:11:34 +02:00
|
|
|
void rotateStack(BattleHex hex);
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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
|
2022-11-27 20:01:52 +02:00
|
|
|
|
|
|
|
const CCreature * getCreature();
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
2015-10-12 15:47:10 +02:00
|
|
|
void nextFrame() override;
|
|
|
|
void endAnim() override;
|
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:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
|
|
|
void nextFrame() override;
|
|
|
|
void endAnim() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
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:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
|
|
|
void nextFrame() override;
|
|
|
|
void endAnim() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
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:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
|
|
|
void endAnim() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
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
|
|
|
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
|
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
|
|
|
void nextFrame() override;
|
|
|
|
void endAnim() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
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:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
|
|
|
void endAnim() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
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:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
|
|
|
void endAnim() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
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
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
2013-07-06 19:10:20 +03:00
|
|
|
|
2022-11-20 19:11:34 +02:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
void setupSecondPart();
|
2015-10-12 15:47:10 +02:00
|
|
|
void endAnim() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2017-09-08 13:25:12 +02:00
|
|
|
class CRangedAttackAnimation : public CAttackAnimation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CRangedAttackAnimation(CBattleInterface * owner_, const CStack * attacker, BattleHex dest_, const CStack * defender);
|
|
|
|
protected:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
/// Shooting attack
|
2017-09-08 13:25:12 +02:00
|
|
|
class CShootingAnimation : public CRangedAttackAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
private:
|
2022-11-25 16:32:23 +02:00
|
|
|
bool projectileEmitted;
|
2011-12-22 16:05:19 +03:00
|
|
|
int catapultDamage;
|
2022-11-25 16:32:23 +02:00
|
|
|
|
|
|
|
void setAnimationGroup();
|
|
|
|
void initializeProjectile();
|
|
|
|
void emitProjectile();
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
|
|
|
void nextFrame() override;
|
|
|
|
void endAnim() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
//last two params only for catapult attacks
|
2017-09-05 19:45:29 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2017-09-08 13:25:12 +02:00
|
|
|
class CCastAnimation : public CRangedAttackAnimation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCastAnimation(CBattleInterface * owner_, const CStack * attacker, BattleHex dest_, const CStack * defender);
|
|
|
|
|
|
|
|
bool init() override;
|
|
|
|
void nextFrame() override;
|
|
|
|
void endAnim() override;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-09-05 19:45:29 +02:00
|
|
|
/// This class manages effect animation
|
|
|
|
class CEffectAnimation : public CBattleAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
BattleHex destTile;
|
2017-07-20 06:08:49 +02:00
|
|
|
std::shared_ptr<CAnimation> customAnim;
|
2011-12-22 16:05:19 +03:00
|
|
|
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:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
|
|
|
void nextFrame() override;
|
|
|
|
void endAnim() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2017-09-05 19:45:29 +02:00
|
|
|
CEffectAnimation(CBattleInterface * _owner, std::string _customAnim, int _x, int _y, int _dx = 0, int _dy = 0, bool _Vflip = false, bool _alignToBottom = false);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
CEffectAnimation(CBattleInterface * _owner, std::shared_ptr<CAnimation> _customAnim, int _x, int _y, int _dx = 0, int _dy = 0);
|
|
|
|
|
2017-09-05 19:45:29 +02:00
|
|
|
CEffectAnimation(CBattleInterface * _owner, std::string _customAnim, BattleHex _destTile, bool _Vflip = false, bool _alignToBottom = false);
|
|
|
|
virtual ~CEffectAnimation(){};
|
2012-04-08 13:34:23 +03:00
|
|
|
};
|