2017-07-13 10:26:03 +02:00
|
|
|
/*
|
2022-12-11 23:16:23 +02:00
|
|
|
* BattleAnimations.h, part of VCMI engine
|
2017-07-13 10:26:03 +02:00
|
|
|
*
|
|
|
|
* 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-08 19:41:02 +02:00
|
|
|
#include "BattleConstants.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-12-08 19:41:02 +02:00
|
|
|
class CCreature;
|
|
|
|
class CSpell;
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2022-12-08 19:41:02 +02:00
|
|
|
class CAnimation;
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleInterface;
|
|
|
|
class CreatureAnimation;
|
2011-12-22 16:05:19 +03:00
|
|
|
struct StackAttackedInfo;
|
2022-12-08 19:41:02 +02:00
|
|
|
struct Point;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
/// Base class of battle animations
|
2022-12-12 22:04:25 +02:00
|
|
|
class BattleAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
protected:
|
2022-12-13 13:58:16 +02:00
|
|
|
BattleInterface & owner;
|
2022-11-28 16:02:46 +02:00
|
|
|
bool initialized;
|
2022-11-20 19:11:34 +02:00
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
std::vector<BattleAnimation *> & pendingAnimations();
|
2022-12-09 13:26:17 +02:00
|
|
|
std::shared_ptr<CreatureAnimation> stackAnimation(const CStack * stack) const;
|
2022-11-20 19:11:34 +02:00
|
|
|
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
|
|
|
|
|
|
|
public:
|
|
|
|
ui32 ID; //unique identifier
|
|
|
|
|
|
|
|
bool isInitialized();
|
|
|
|
bool tryInitialize();
|
2013-07-06 19:10:20 +03:00
|
|
|
virtual void nextFrame() {} //call every new frame
|
2022-12-12 22:04:25 +02:00
|
|
|
virtual ~BattleAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
BattleAnimation(BattleInterface & owner);
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Sub-class which is responsible for managing the battle stack animation.
|
2022-12-12 22:04:25 +02:00
|
|
|
class BattleStackAnimation : public BattleAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
public:
|
2022-12-09 13:10:35 +02:00
|
|
|
std::shared_ptr<CreatureAnimation> myAnim; //animation for our stack, managed by BattleInterface
|
2011-12-22 16:05:19 +03:00
|
|
|
const CStack * stack; //id of stack whose animation it is
|
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
BattleStackAnimation(BattleInterface & owner, const CStack * _stack);
|
2020-01-25 11:21:26 +02:00
|
|
|
|
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
|
2022-12-12 22:04:25 +02:00
|
|
|
class AttackAnimation : public BattleStackAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
bool soundPlayed;
|
2011-12-22 16:05:19 +03:00
|
|
|
protected:
|
|
|
|
BattleHex dest; //attacked hex
|
2022-12-12 22:04:25 +02:00
|
|
|
ECreatureAnimType::Type group;
|
|
|
|
const CStack *defendingStack;
|
2011-12-22 16:05:19 +03:00
|
|
|
const CStack *attackingStack;
|
|
|
|
int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
|
2022-11-27 20:01:52 +02:00
|
|
|
|
2022-12-06 14:12:13 +02:00
|
|
|
const CCreature * getCreature() const;
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
2022-12-12 22:04:25 +02:00
|
|
|
virtual void playSound() = 0;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
void nextFrame() override;
|
|
|
|
AttackAnimation(BattleInterface & owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
|
|
|
|
~AttackAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Animation of a defending unit
|
2022-12-12 22:04:25 +02:00
|
|
|
class DefenceAnimation : public BattleStackAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-12 22:04:25 +02:00
|
|
|
public:
|
|
|
|
bool init() override;
|
|
|
|
DefenceAnimation(BattleInterface & owner, const CStack * stack);
|
|
|
|
};
|
2013-07-16 21:12:47 +03:00
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
/// Animation of a hit unit
|
|
|
|
class HittedAnimation : public BattleStackAnimation
|
|
|
|
{
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
2022-12-12 22:04:25 +02:00
|
|
|
HittedAnimation(BattleInterface & owner, const CStack * stack);
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
2022-12-12 22:04:25 +02:00
|
|
|
};
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
/// Animation of a dying unit
|
|
|
|
class DeathAnimation : public BattleStackAnimation
|
|
|
|
{
|
|
|
|
bool rangedAttack;
|
|
|
|
ECreatureAnimType::Type getMyAnimType();
|
|
|
|
public:
|
|
|
|
bool init() override;
|
|
|
|
DeathAnimation(BattleInterface & owner, const CStack * stack, bool ranged);
|
|
|
|
~DeathAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
class DummyAnimation : public BattleAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
DummyAnimation(BattleInterface & owner, int howManyFrames);
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Hand-to-hand attack
|
2022-12-12 22:04:25 +02:00
|
|
|
class MeleeAttackAnimation : public AttackAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
2022-12-10 00:25:11 +02:00
|
|
|
void nextFrame() override;
|
2022-12-12 22:04:25 +02:00
|
|
|
void playSound() override;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
MeleeAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked);
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
/// Base class for all animations that play during stack movement
|
2022-12-12 22:04:25 +02:00
|
|
|
class StackMoveAnimation : public BattleStackAnimation
|
2022-11-28 22:35:38 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
BattleHex currentHex;
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
protected:
|
2022-12-12 22:04:25 +02:00
|
|
|
StackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex _currentHex);
|
2022-11-28 22:35:38 +02:00
|
|
|
};
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
/// Move animation of a creature
|
2022-12-12 22:04:25 +02:00
|
|
|
class MovementAnimation : public StackMoveAnimation
|
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
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
MovementAnimation(BattleInterface & owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance);
|
|
|
|
~MovementAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Move end animation of a creature
|
2022-12-12 22:04:25 +02:00
|
|
|
class MovementEndAnimation : public StackMoveAnimation
|
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
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
MovementEndAnimation(BattleInterface & owner, const CStack * _stack, BattleHex destTile);
|
|
|
|
~MovementEndAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Move start animation of a creature
|
2022-12-12 22:04:25 +02:00
|
|
|
class MovementStartAnimation : public StackMoveAnimation
|
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
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
MovementStartAnimation(BattleInterface & owner, const CStack * _stack);
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Class responsible for animation of stack chaning direction (left <-> right)
|
2022-12-12 22:04:25 +02:00
|
|
|
class ReverseAnimation : public StackMoveAnimation
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-10 00:25:11 +02:00
|
|
|
void setupSecondPart();
|
2011-12-22 16:05:19 +03:00
|
|
|
public:
|
2015-10-12 15:47:10 +02:00
|
|
|
bool init() override;
|
2013-07-06 19:10:20 +03:00
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
ReverseAnimation(BattleInterface & owner, const CStack * stack, BattleHex dest);
|
2011-12-22 16:05:19 +03:00
|
|
|
};
|
|
|
|
|
2022-12-08 20:43:51 +02:00
|
|
|
/// Resurrects stack from dead state
|
2022-12-12 22:04:25 +02:00
|
|
|
class ResurrectionAnimation : public BattleStackAnimation
|
2022-12-08 20:43:51 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool init() override;
|
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
ResurrectionAnimation(BattleInterface & owner, const CStack * _stack);
|
2022-12-08 20:43:51 +02:00
|
|
|
};
|
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
class RangedAttackAnimation : public AttackAnimation
|
2017-09-08 13:25:12 +02:00
|
|
|
{
|
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;
|
|
|
|
|
2022-12-08 19:41:02 +02:00
|
|
|
virtual ECreatureAnimType::Type getUpwardsGroup() const = 0;
|
|
|
|
virtual ECreatureAnimType::Type getForwardGroup() const = 0;
|
|
|
|
virtual ECreatureAnimType::Type getDownwardsGroup() const = 0;
|
2022-12-01 22:06:42 +02:00
|
|
|
|
|
|
|
virtual void createProjectile(const Point & from, const Point & dest) const = 0;
|
2022-12-06 14:12:13 +02:00
|
|
|
virtual uint32_t getAttackClimaxFrame() const = 0;
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
public:
|
2022-12-12 22:04:25 +02:00
|
|
|
RangedAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender);
|
|
|
|
~RangedAttackAnimation();
|
2022-12-01 22:06:42 +02:00
|
|
|
|
|
|
|
bool init() override;
|
|
|
|
void nextFrame() override;
|
2022-12-12 22:04:25 +02:00
|
|
|
void playSound() override;
|
2017-09-08 13:25:12 +02:00
|
|
|
};
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
/// Shooting attack
|
2022-12-12 22:04:25 +02:00
|
|
|
class ShootingAnimation : public RangedAttackAnimation
|
2022-12-01 22:06:42 +02:00
|
|
|
{
|
2022-12-08 19:41:02 +02:00
|
|
|
ECreatureAnimType::Type getUpwardsGroup() const override;
|
|
|
|
ECreatureAnimType::Type getForwardGroup() const override;
|
|
|
|
ECreatureAnimType::Type getDownwardsGroup() const override;
|
2022-12-01 22:06:42 +02:00
|
|
|
|
|
|
|
void createProjectile(const Point & from, const Point & dest) const override;
|
2022-12-06 14:12:13 +02:00
|
|
|
uint32_t getAttackClimaxFrame() const override;
|
2022-12-01 22:06:42 +02:00
|
|
|
|
|
|
|
public:
|
2022-12-12 22:04:25 +02:00
|
|
|
ShootingAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender);
|
2022-12-01 22:06:42 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Catapult attack
|
2022-12-12 22:04:25 +02:00
|
|
|
class CatapultAnimation : public ShootingAnimation
|
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-12 22:04:25 +02:00
|
|
|
CatapultAnimation(BattleInterface & 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
|
|
|
};
|
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
class CastAnimation : public RangedAttackAnimation
|
2017-09-08 13:25:12 +02:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
const CSpell * spell;
|
|
|
|
|
2022-12-08 19:41:02 +02:00
|
|
|
ECreatureAnimType::Type findValidGroup( const std::vector<ECreatureAnimType::Type> candidates ) const;
|
|
|
|
ECreatureAnimType::Type getUpwardsGroup() const override;
|
|
|
|
ECreatureAnimType::Type getForwardGroup() const override;
|
|
|
|
ECreatureAnimType::Type getDownwardsGroup() const override;
|
2022-12-01 22:06:42 +02:00
|
|
|
|
|
|
|
void createProjectile(const Point & from, const Point & dest) const override;
|
2022-12-06 14:12:13 +02:00
|
|
|
uint32_t getAttackClimaxFrame() const override;
|
2022-12-01 22:06:42 +02:00
|
|
|
|
2017-09-08 13:25:12 +02:00
|
|
|
public:
|
2022-12-12 22:04:25 +02:00
|
|
|
CastAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest_, const CStack * defender, const CSpell * spell);
|
2022-12-02 01:55:09 +02:00
|
|
|
};
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
/// Class that plays effect at one or more positions along with (single) sound effect
|
2022-12-12 22:04:25 +02:00
|
|
|
class PointEffectAnimation : public BattleAnimation
|
2022-12-01 22:06:42 +02:00
|
|
|
{
|
2022-12-12 21:17:15 +02:00
|
|
|
std::string soundName;
|
2022-12-01 22:06:42 +02:00
|
|
|
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-12 22:04:25 +02:00
|
|
|
WAIT_FOR_SOUND = 2, // Unused, can be removed
|
2022-12-02 01:55:09 +02:00
|
|
|
FORCE_ON_TOP = 4,
|
|
|
|
SCREEN_FILL = 8,
|
2022-12-01 22:06:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Create animation with screen-wide effect
|
2022-12-12 22:04:25 +02:00
|
|
|
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, int effects = 0);
|
2022-12-01 22:06:42 +02:00
|
|
|
|
|
|
|
/// Create animation positioned at point(s). Note that positions must be are absolute, including battleint position offset
|
2022-12-12 22:04:25 +02:00
|
|
|
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos , int effects = 0);
|
|
|
|
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<Point> pos , int effects = 0);
|
2022-12-01 22:06:42 +02:00
|
|
|
|
|
|
|
/// Create animation positioned at certain hex(es)
|
2022-12-12 22:04:25 +02:00
|
|
|
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, BattleHex hex , int effects = 0);
|
|
|
|
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<BattleHex> hex, int effects = 0);
|
2022-12-02 01:55:09 +02:00
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, BattleHex hex, int effects = 0);
|
|
|
|
~PointEffectAnimation();
|
2017-09-08 13:25:12 +02:00
|
|
|
|
|
|
|
bool init() override;
|
|
|
|
void nextFrame() override;
|
|
|
|
};
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
/// Class that waits till projectile of certain shooter hits a target
|
2022-12-12 22:04:25 +02:00
|
|
|
class WaitingProjectileAnimation : public BattleAnimation
|
2022-12-01 22:06:42 +02:00
|
|
|
{
|
|
|
|
const CStack * shooter;
|
|
|
|
public:
|
2022-12-12 22:04:25 +02:00
|
|
|
WaitingProjectileAnimation(BattleInterface & owner, const CStack * shooter);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2022-12-12 22:04:25 +02:00
|
|
|
void nextFrame() override;
|
2022-12-01 22:06:42 +02:00
|
|
|
bool init() override;
|
2012-04-08 13:34:23 +03:00
|
|
|
};
|