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"
|
2022-12-01 22:06:42 +02:00
|
|
|
#include "../../lib/CSoundBase.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
|
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
protected:
|
|
|
|
CBattleInterface * owner;
|
2022-11-28 16:02:46 +02:00
|
|
|
bool initialized;
|
2022-11-20 19:11:34 +02:00
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
std::vector<CBattleAnimation *> & pendingAnimations();
|
2022-11-20 19:11:34 +02:00
|
|
|
std::shared_ptr<CCreatureAnimation> stackAnimation(const CStack * stack);
|
|
|
|
bool stackFacingRight(const CStack * stack);
|
|
|
|
void setStackFacingRight(const CStack * stack, bool facingRight);
|
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
virtual bool init() = 0; //to be called - if returned false, call again until returns true
|
2022-11-28 16:02:46 +02:00
|
|
|
bool checkInitialConditions(); //determines if this animation is earliest of all
|
|
|
|
|
|
|
|
public:
|
|
|
|
ui32 ID; //unique identifier
|
|
|
|
|
|
|
|
bool isInitialized();
|
|
|
|
bool tryInitialize();
|
2013-07-06 19:10:20 +03:00
|
|
|
virtual void nextFrame() {} //call every new frame
|
2013-07-16 21:12:47 +03:00
|
|
|
virtual ~CBattleAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
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;
|
2011-12-22 16:05:19 +03:00
|
|
|
bool checkInitialConditions();
|
|
|
|
|
|
|
|
CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
|
2022-11-28 16:02:46 +02:00
|
|
|
~CAttackAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner);
|
2022-11-28 16:02:46 +02:00
|
|
|
~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;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
CDummyAnimation(CBattleInterface * _owner, int howManyFrames);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Hand-to-hand attack
|
|
|
|
class CMeleeAttackAnimation : public CAttackAnimation
|
|
|
|
{
|
|
|
|
public:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked);
|
|
|
|
};
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
/// Base class for all animations that play during stack movement
|
2022-11-28 22:35:38 +02:00
|
|
|
class CStackMoveAnimation : public CBattleStackAnimation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BattleHex currentHex;
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
protected:
|
2022-11-28 22:35:38 +02:00
|
|
|
CStackMoveAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex _currentHex);
|
|
|
|
};
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
/// Move animation of a creature
|
2022-11-28 22:35:38 +02:00
|
|
|
class CMovementAnimation : public CStackMoveAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
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:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
|
|
|
void nextFrame() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
CMovementAnimation(CBattleInterface *_owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance);
|
2022-11-28 16:02:46 +02:00
|
|
|
~CMovementAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Move end animation of a creature
|
2022-11-28 22:35:38 +02:00
|
|
|
class CMovementEndAnimation : public CStackMoveAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile);
|
2022-11-28 16:02:46 +02:00
|
|
|
~CMovementEndAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Move start animation of a creature
|
2022-11-28 22:35:38 +02:00
|
|
|
class CMovementStartAnimation : public CStackMoveAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Class responsible for animation of stack chaning direction (left <-> right)
|
2022-11-28 22:35:38 +02:00
|
|
|
class CReverseAnimation : public CStackMoveAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void setupSecondPart();
|
|
|
|
|
|
|
|
CReverseAnimation(CBattleInterface * _owner, const CStack * stack, BattleHex dest, bool _priority);
|
2022-11-28 16:02:46 +02:00
|
|
|
~CReverseAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
2017-09-08 13:25:12 +02:00
|
|
|
class CRangedAttackAnimation : public CAttackAnimation
|
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
|
|
|
|
void setAnimationGroup();
|
|
|
|
void initializeProjectile();
|
|
|
|
void emitProjectile();
|
|
|
|
void emitExplosion();
|
|
|
|
|
2017-09-08 13:25:12 +02:00
|
|
|
protected:
|
2022-12-01 22:06:42 +02:00
|
|
|
bool projectileEmitted;
|
|
|
|
|
|
|
|
virtual CCreatureAnim::EAnimType getUpwardsGroup() const = 0;
|
|
|
|
virtual CCreatureAnim::EAnimType getForwardGroup() const = 0;
|
|
|
|
virtual CCreatureAnim::EAnimType getDownwardsGroup() const = 0;
|
|
|
|
|
|
|
|
virtual void createProjectile(const Point & from, const Point & dest) const = 0;
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
public:
|
|
|
|
CRangedAttackAnimation(CBattleInterface * owner_, const CStack * attacker, BattleHex dest, const CStack * defender);
|
|
|
|
~CRangedAttackAnimation();
|
|
|
|
|
|
|
|
bool init() override;
|
|
|
|
void nextFrame() override;
|
2017-09-08 13:25:12 +02:00
|
|
|
};
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
/// Shooting attack
|
2017-09-08 13:25:12 +02:00
|
|
|
class CShootingAnimation : public CRangedAttackAnimation
|
2022-12-01 22:06:42 +02:00
|
|
|
{
|
|
|
|
CCreatureAnim::EAnimType getUpwardsGroup() const override;
|
|
|
|
CCreatureAnim::EAnimType getForwardGroup() const override;
|
|
|
|
CCreatureAnim::EAnimType getDownwardsGroup() const override;
|
|
|
|
|
|
|
|
void createProjectile(const Point & from, const Point & dest) const override;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CShootingAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex dest, const CStack * defender);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Catapult attack
|
|
|
|
class CCatapultAnimation : public CShootingAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
private:
|
2022-11-27 23:26:28 +02:00
|
|
|
bool explosionEmitted;
|
2011-12-22 16:05:19 +03:00
|
|
|
int catapultDamage;
|
2022-11-25 16:32:23 +02:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
2022-12-01 22:06:42 +02:00
|
|
|
CCatapultAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex dest, const CStack * defender, int _catapultDmg = 0);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void createProjectile(const Point & from, const Point & dest) const override;
|
|
|
|
void nextFrame() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
2017-09-08 13:25:12 +02:00
|
|
|
class CCastAnimation : public CRangedAttackAnimation
|
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
const CSpell * spell;
|
|
|
|
|
|
|
|
CCreatureAnim::EAnimType findValidGroup( const std::vector<CCreatureAnim::EAnimType> candidates ) const;
|
|
|
|
CCreatureAnim::EAnimType getUpwardsGroup() const override;
|
|
|
|
CCreatureAnim::EAnimType getForwardGroup() const override;
|
|
|
|
CCreatureAnim::EAnimType getDownwardsGroup() const override;
|
|
|
|
|
|
|
|
void createProjectile(const Point & from, const Point & dest) const override;
|
|
|
|
|
2017-09-08 13:25:12 +02:00
|
|
|
public:
|
2022-12-01 22:06:42 +02:00
|
|
|
CCastAnimation(CBattleInterface * owner_, const CStack * attacker, BattleHex dest_, const CStack * defender, const CSpell * spell);
|
|
|
|
};
|
|
|
|
|
2022-12-02 01:55:09 +02:00
|
|
|
struct CPointEffectParameters
|
|
|
|
{
|
|
|
|
std::vector<Point> positions;
|
|
|
|
std::vector<BattleHex> tiles;
|
|
|
|
std::string animation;
|
|
|
|
|
|
|
|
soundBase::soundID sound = soundBase::invalid;
|
|
|
|
BattleHex boundHex = BattleHex::INVALID;
|
|
|
|
bool aligntoBottom = false;
|
|
|
|
bool waitForSound = false;
|
|
|
|
bool screenFill = false;
|
|
|
|
};
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
/// Class that plays effect at one or more positions along with (single) sound effect
|
|
|
|
class CPointEffectAnimation : public CBattleAnimation
|
|
|
|
{
|
|
|
|
soundBase::soundID sound;
|
|
|
|
bool soundPlayed;
|
|
|
|
bool soundFinished;
|
|
|
|
bool effectFinished;
|
|
|
|
int effectFlags;
|
|
|
|
|
|
|
|
std::shared_ptr<CAnimation> animation;
|
|
|
|
std::vector<Point> positions;
|
|
|
|
std::vector<BattleHex> battlehexes;
|
|
|
|
|
|
|
|
bool alignToBottom() const;
|
|
|
|
bool waitForSound() const;
|
2022-12-02 01:55:09 +02:00
|
|
|
bool forceOnTop() const;
|
|
|
|
bool screenFill() const;
|
2022-12-01 22:06:42 +02:00
|
|
|
|
|
|
|
void onEffectFinished();
|
|
|
|
void onSoundFinished();
|
|
|
|
void clearEffect();
|
|
|
|
|
|
|
|
void playSound();
|
|
|
|
void playEffect();
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum EEffectFlags
|
|
|
|
{
|
|
|
|
ALIGN_TO_BOTTOM = 1,
|
2022-12-02 01:55:09 +02:00
|
|
|
WAIT_FOR_SOUND = 2,
|
|
|
|
FORCE_ON_TOP = 4,
|
|
|
|
SCREEN_FILL = 8,
|
2022-12-01 22:06:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Create animation with screen-wide effect
|
|
|
|
CPointEffectAnimation(CBattleInterface * _owner, soundBase::soundID sound, std::string animationName, int effects = 0);
|
|
|
|
|
|
|
|
/// Create animation positioned at point(s). Note that positions must be are absolute, including battleint position offset
|
|
|
|
CPointEffectAnimation(CBattleInterface * _owner, soundBase::soundID sound, std::string animationName, Point pos , int effects = 0);
|
|
|
|
CPointEffectAnimation(CBattleInterface * _owner, soundBase::soundID sound, std::string animationName, std::vector<Point> pos , int effects = 0);
|
|
|
|
|
|
|
|
/// Create animation positioned at certain hex(es)
|
2022-12-02 01:55:09 +02:00
|
|
|
CPointEffectAnimation(CBattleInterface * _owner, soundBase::soundID sound, std::string animationName, BattleHex hex , int effects = 0);
|
|
|
|
CPointEffectAnimation(CBattleInterface * _owner, soundBase::soundID sound, std::string animationName, std::vector<BattleHex> hex, int effects = 0);
|
|
|
|
|
|
|
|
CPointEffectAnimation(CBattleInterface * _owner, soundBase::soundID sound, std::string animationName, Point pos, BattleHex hex, int effects = 0);
|
2022-12-01 22:06:42 +02:00
|
|
|
~CPointEffectAnimation();
|
2017-09-08 13:25:12 +02:00
|
|
|
|
|
|
|
bool init() override;
|
|
|
|
void nextFrame() override;
|
|
|
|
};
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
/// Base class (e.g. for use in dynamic_cast's) for "animations" that wait for certain event
|
|
|
|
class CWaitingAnimation : public CBattleAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
protected:
|
|
|
|
CWaitingAnimation(CBattleInterface * owner_);
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
2015-10-12 15:47:10 +02:00
|
|
|
void nextFrame() override;
|
2022-12-01 22:06:42 +02:00
|
|
|
};
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
/// Class that waits till projectile of certain shooter hits a target
|
|
|
|
class CWaitingProjectileAnimation : public CWaitingAnimation
|
|
|
|
{
|
|
|
|
const CStack * shooter;
|
|
|
|
public:
|
|
|
|
CWaitingProjectileAnimation(CBattleInterface * owner_, const CStack * shooter);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
bool init() override;
|
2012-04-08 13:34:23 +03:00
|
|
|
};
|