1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
/*
* BattleAnimations.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
*
*/
#pragma once
#include "../../lib/battle/BattleHexArray.h"
#include "../../lib/filesystem/ResourcePath.h"
#include "BattleConstants.h"
VCMI_LIB_NAMESPACE_BEGIN
class CStack;
class CCreature;
class CSpell;
class Point;
VCMI_LIB_NAMESPACE_END
class ColorFilter;
class BattleHero;
class CAnimation;
class BattleInterface;
class CreatureAnimation;
struct StackAttackedInfo;
/// Base class of battle animations
class BattleAnimation
{
protected:
BattleInterface & owner;
bool initialized;
std::vector<BattleAnimation *> & pendingAnimations();
std::shared_ptr<CreatureAnimation> stackAnimation(const CStack * stack) const;
bool stackFacingRight(const CStack * stack);
void setStackFacingRight(const CStack * stack, bool facingRight);
virtual bool init() = 0; //to be called - if returned false, call again until returns true
public:
ui32 ID; //unique identifier
bool isInitialized();
bool tryInitialize();
virtual void tick(uint32_t msPassed) {} //call every new frame
virtual ~BattleAnimation();
BattleAnimation(BattleInterface & owner);
};
/// Sub-class which is responsible for managing the battle stack animation.
class BattleStackAnimation : public BattleAnimation
{
public:
std::shared_ptr<CreatureAnimation> myAnim; //animation for our stack, managed by BattleInterface
const CStack * stack; //id of stack whose animation it is
BattleStackAnimation(BattleInterface & owner, const CStack * _stack);
void rotateStack(BattleHex hex);
};
class StackActionAnimation : public BattleStackAnimation
{
ECreatureAnimType nextGroup;
ECreatureAnimType currGroup;
AudioPath sound;
public:
void setNextGroup( ECreatureAnimType group );
void setGroup( ECreatureAnimType group );
void setSound( const AudioPath & sound );
ECreatureAnimType getGroup() const;
StackActionAnimation(BattleInterface & owner, const CStack * _stack);
~StackActionAnimation();
bool init() override;
};
/// Animation of a defending unit
class DefenceAnimation : public StackActionAnimation
{
public:
DefenceAnimation(BattleInterface & owner, const CStack * stack);
};
/// Animation of a hit unit
class HittedAnimation : public StackActionAnimation
{
public:
HittedAnimation(BattleInterface & owner, const CStack * stack);
};
/// Animation of a dying unit
class DeathAnimation : public StackActionAnimation
{
public:
DeathAnimation(BattleInterface & owner, const CStack * stack, bool ranged);
};
/// Resurrects stack from dead state
class ResurrectionAnimation : public StackActionAnimation
{
public:
ResurrectionAnimation(BattleInterface & owner, const CStack * _stack);
};
class ColorTransformAnimation : public BattleStackAnimation
{
std::vector<ColorFilter> steps;
std::vector<float> timePoints;
const CSpell * spell;
float totalProgress;
bool init() override;
void tick(uint32_t msPassed) override;
public:
ColorTransformAnimation(BattleInterface & owner, const CStack * _stack, const std::string & colorFilterName, const CSpell * spell);
};
/// Base class for all animations that play during stack movement
class StackMoveAnimation : public BattleStackAnimation
{
public:
BattleHex nextHex;
BattleHex prevHex;
protected:
StackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex prevHex, BattleHex nextHex);
};
/// Move animation of a creature
class MovementAnimation : public StackMoveAnimation
{
private:
int moveSoundHandler; // sound handler used when moving a unit
const BattleHexArray & destTiles; //full path, includes already passed hexes
ui32 currentMoveIndex; // index of nextHex in destTiles
double begX, begY; // starting position
double distanceX, distanceY; // full movement distance, may be negative if creture moves topleft
/// progress gain per second
double progressPerSecond;
/// range 0 -> 1, indicates move progrees. 0 = movement starts, 1 = move ends
double progress;
public:
bool init() override;
void tick(uint32_t msPassed) override;
MovementAnimation(BattleInterface & owner, const CStack *_stack, const BattleHexArray & _destTiles, int _distance);
~MovementAnimation();
};
/// Move end animation of a creature
class MovementEndAnimation : public StackMoveAnimation
{
public:
bool init() override;
MovementEndAnimation(BattleInterface & owner, const CStack * _stack, BattleHex destTile);
~MovementEndAnimation();
};
/// Move start animation of a creature
class MovementStartAnimation : public StackMoveAnimation
{
public:
bool init() override;
MovementStartAnimation(BattleInterface & owner, const CStack * _stack);
};
/// Class responsible for animation of stack chaning direction (left <-> right)
class ReverseAnimation : public StackMoveAnimation
{
void setupSecondPart();
public:
bool init() override;
ReverseAnimation(BattleInterface & owner, const CStack * stack, BattleHex dest);
};
/// This class is responsible for managing the battle attack animation
class AttackAnimation : public StackActionAnimation
{
protected:
BattleHex dest; //attacked hex
const CStack *defendingStack;
const CStack *attackingStack;
int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
const CCreature * getCreature() const;
ECreatureAnimType findValidGroup( const std::vector<ECreatureAnimType> candidates ) const;
public:
AttackAnimation(BattleInterface & owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
};
/// Hand-to-hand attack
class MeleeAttackAnimation : public AttackAnimation
{
ECreatureAnimType getUpwardsGroup(bool multiAttack) const;
ECreatureAnimType getForwardGroup(bool multiAttack) const;
ECreatureAnimType getDownwardsGroup(bool multiAttack) const;
ECreatureAnimType selectGroup(bool multiAttack);
public:
MeleeAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked, bool multiAttack);
void tick(uint32_t msPassed) override;
};
class RangedAttackAnimation : public AttackAnimation
{
void setAnimationGroup();
void initializeProjectile();
void emitProjectile();
void emitExplosion();
protected:
bool projectileEmitted;
virtual ECreatureAnimType getUpwardsGroup() const = 0;
virtual ECreatureAnimType getForwardGroup() const = 0;
virtual ECreatureAnimType getDownwardsGroup() const = 0;
virtual void createProjectile(const Point & from, const Point & dest) const = 0;
virtual uint32_t getAttackClimaxFrame() const = 0;
public:
RangedAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender);
~RangedAttackAnimation();
bool init() override;
void tick(uint32_t msPassed) override;
};
/// Shooting attack
class ShootingAnimation : public RangedAttackAnimation
{
ECreatureAnimType getUpwardsGroup() const override;
ECreatureAnimType getForwardGroup() const override;
ECreatureAnimType getDownwardsGroup() const override;
void createProjectile(const Point & from, const Point & dest) const override;
uint32_t getAttackClimaxFrame() const override;
public:
ShootingAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender);
};
/// Catapult attack
class CatapultAnimation : public ShootingAnimation
{
private:
bool explosionEmitted;
int catapultDamage;
public:
CatapultAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender, int _catapultDmg = 0);
void createProjectile(const Point & from, const Point & dest) const override;
void tick(uint32_t msPassed) override;
};
class CastAnimation : public RangedAttackAnimation
{
const CSpell * spell;
ECreatureAnimType getUpwardsGroup() const override;
ECreatureAnimType getForwardGroup() const override;
ECreatureAnimType getDownwardsGroup() const override;
void createProjectile(const Point & from, const Point & dest) const override;
uint32_t getAttackClimaxFrame() const override;
public:
CastAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest_, const CStack * defender, const CSpell * spell);
};
class DummyAnimation : public BattleAnimation
{
private:
int counter;
int howMany;
public:
bool init() override;
void tick(uint32_t msPassed) override;
DummyAnimation(BattleInterface & owner, int howManyFrames);
};
/// Class that plays effect at one or more positions along with (single) sound effect
class EffectAnimation : public BattleAnimation
{
std::string soundName;
int effectFlags;
float transparencyFactor;
bool effectFinished;
bool reversed;
std::shared_ptr<CAnimation> animation;
std::vector<Point> positions;
BattleHexArray battlehexes;
bool alignToBottom() const;
bool waitForSound() const;
bool forceOnTop() const;
bool screenFill() const;
void onEffectFinished();
void clearEffect();
void playEffect(uint32_t msPassed);
public:
enum EEffectFlags
{
ALIGN_TO_BOTTOM = 1,
FORCE_ON_TOP = 2,
SCREEN_FILL = 4,
};
/// Create animation with screen-wide effect
EffectAnimation(BattleInterface & owner, const AnimationPath & animationName, int effects = 0, float transparencyFactor = 1.f, bool reversed = false);
/// Create animation positioned at point(s). Note that positions must be are absolute, including battleint position offset
EffectAnimation(BattleInterface & owner, const AnimationPath & animationName, Point pos , int effects = 0, bool reversed = false);
EffectAnimation(BattleInterface & owner, const AnimationPath & animationName, std::vector<Point> pos , int effects = 0, bool reversed = false);
/// Create animation positioned at certain hex(es)
EffectAnimation(BattleInterface & owner, const AnimationPath & animationName, BattleHex hex , int effects = 0, float transparencyFactor = 1.0f, bool reversed = false);
EffectAnimation(BattleInterface & owner, const AnimationPath & animationName, const BattleHexArray & hexes, int effects = 0, bool reversed = false);
EffectAnimation(BattleInterface & owner, const AnimationPath & animationName, Point pos, BattleHex hex, int effects = 0, bool reversed = false);
~EffectAnimation();
bool init() override;
void tick(uint32_t msPassed) override;
};
class HeroCastAnimation : public BattleAnimation
{
std::shared_ptr<BattleHero> hero;
const CStack * target;
const CSpell * spell;
BattleHex tile;
bool projectileEmitted;
void initializeProjectile();
void emitProjectile();
void emitAnimationEvent();
public:
HeroCastAnimation(BattleInterface & owner, std::shared_ptr<BattleHero> hero, BattleHex dest, const CStack * defender, const CSpell * spell);
void tick(uint32_t msPassed) override;
bool init() override;
};
|