1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Cleaned up BattleAnimationClasses file

This commit is contained in:
Ivan Savenko
2022-12-12 22:04:25 +02:00
parent 776d00d901
commit c172e3c8e0
9 changed files with 285 additions and 315 deletions

View File

@@ -10,9 +10,6 @@
#include "StdInc.h" #include "StdInc.h"
#include "BattleAnimationClasses.h" #include "BattleAnimationClasses.h"
#include <boost/math/constants/constants.hpp>
#include "BattleInterfaceClasses.h"
#include "BattleInterface.h" #include "BattleInterface.h"
#include "BattleProjectileController.h" #include "BattleProjectileController.h"
#include "BattleSiegeController.h" #include "BattleSiegeController.h"
@@ -24,17 +21,13 @@
#include "../CGameInfo.h" #include "../CGameInfo.h"
#include "../CMusicHandler.h" #include "../CMusicHandler.h"
#include "../CPlayerInterface.h" #include "../CPlayerInterface.h"
#include "../Graphics.h"
#include "../gui/CAnimation.h"
#include "../gui/CCursorHandler.h" #include "../gui/CCursorHandler.h"
#include "../gui/CGuiHandler.h" #include "../gui/CGuiHandler.h"
#include "../../CCallback.h" #include "../../CCallback.h"
#include "../../lib/CStack.h" #include "../../lib/CStack.h"
#include "../../lib/CTownHandler.h"
#include "../../lib/mapObjects/CGTownInstance.h"
CBattleAnimation::CBattleAnimation(BattleInterface & owner) BattleAnimation::BattleAnimation(BattleInterface & owner)
: owner(owner), : owner(owner),
ID(owner.stacksController->animIDhelper++), ID(owner.stacksController->animIDhelper++),
initialized(false) initialized(false)
@@ -42,7 +35,7 @@ CBattleAnimation::CBattleAnimation(BattleInterface & owner)
logAnim->trace("Animation #%d created", ID); logAnim->trace("Animation #%d created", ID);
} }
bool CBattleAnimation::tryInitialize() bool BattleAnimation::tryInitialize()
{ {
assert(!initialized); assert(!initialized);
@@ -54,12 +47,12 @@ bool CBattleAnimation::tryInitialize()
return false; return false;
} }
bool CBattleAnimation::isInitialized() bool BattleAnimation::isInitialized()
{ {
return initialized; return initialized;
} }
CBattleAnimation::~CBattleAnimation() BattleAnimation::~BattleAnimation()
{ {
logAnim->trace("Animation #%d ended, type is %s", ID, typeid(this).name()); logAnim->trace("Animation #%d ended, type is %s", ID, typeid(this).name());
for(auto & elem : pendingAnimations()) for(auto & elem : pendingAnimations())
@@ -70,42 +63,37 @@ CBattleAnimation::~CBattleAnimation()
logAnim->trace("Animation #%d deleted", ID); logAnim->trace("Animation #%d deleted", ID);
} }
std::vector<CBattleAnimation *> & CBattleAnimation::pendingAnimations() std::vector<BattleAnimation *> & BattleAnimation::pendingAnimations()
{ {
return owner.stacksController->currentAnimations; return owner.stacksController->currentAnimations;
} }
std::shared_ptr<CreatureAnimation> CBattleAnimation::stackAnimation(const CStack * stack) const std::shared_ptr<CreatureAnimation> BattleAnimation::stackAnimation(const CStack * stack) const
{ {
return owner.stacksController->stackAnimation[stack->ID]; return owner.stacksController->stackAnimation[stack->ID];
} }
bool CBattleAnimation::stackFacingRight(const CStack * stack) bool BattleAnimation::stackFacingRight(const CStack * stack)
{ {
return owner.stacksController->stackFacingRight[stack->ID]; return owner.stacksController->stackFacingRight[stack->ID];
} }
void CBattleAnimation::setStackFacingRight(const CStack * stack, bool facingRight) void BattleAnimation::setStackFacingRight(const CStack * stack, bool facingRight)
{ {
owner.stacksController->stackFacingRight[stack->ID] = facingRight; owner.stacksController->stackFacingRight[stack->ID] = facingRight;
} }
CBattleStackAnimation::CBattleStackAnimation(BattleInterface & owner, const CStack * stack) BattleStackAnimation::BattleStackAnimation(BattleInterface & owner, const CStack * stack)
: CBattleAnimation(owner), : BattleAnimation(owner),
myAnim(stackAnimation(stack)), myAnim(stackAnimation(stack)),
stack(stack) stack(stack)
{ {
assert(myAnim); assert(myAnim);
} }
void CBattleStackAnimation::shiftColor(const ColorShifter * shifter) void AttackAnimation::nextFrame()
{
assert(myAnim);
myAnim->shiftColor(shifter);
}
void CAttackAnimation::nextFrame()
{ {
assert(myAnim->getType() == group);
if(myAnim->getType() != group) if(myAnim->getType() != group)
{ {
myAnim->setType(group); myAnim->setType(group);
@@ -114,20 +102,17 @@ void CAttackAnimation::nextFrame()
if(!soundPlayed) if(!soundPlayed)
{ {
if(shooting) playSound();
CCS->soundh->playSound(battle_sound(getCreature(), shoot));
else
CCS->soundh->playSound(battle_sound(getCreature(), attack));
soundPlayed = true; soundPlayed = true;
} }
} }
CAttackAnimation::~CAttackAnimation() AttackAnimation::~AttackAnimation()
{ {
myAnim->setType(ECreatureAnimType::HOLDING); myAnim->setType(ECreatureAnimType::HOLDING);
} }
const CCreature * CAttackAnimation::getCreature() const const CCreature * AttackAnimation::getCreature() const
{ {
if (attackingStack->getCreature()->idNumber == CreatureID::ARROW_TOWERS) if (attackingStack->getCreature()->idNumber == CreatureID::ARROW_TOWERS)
return owner.siegeController->getTurretCreature(); return owner.siegeController->getTurretCreature();
@@ -135,101 +120,97 @@ const CCreature * CAttackAnimation::getCreature() const
return attackingStack->getCreature(); return attackingStack->getCreature();
} }
CAttackAnimation::CAttackAnimation(BattleInterface & owner, const CStack *attacker, BattleHex _dest, const CStack *defender)
: CBattleStackAnimation(owner, attacker), AttackAnimation::AttackAnimation(BattleInterface & owner, const CStack *attacker, BattleHex _dest, const CStack *defender)
shooting(false), : BattleStackAnimation(owner, attacker),
group(ECreatureAnimType::SHOOT_FRONT), group(ECreatureAnimType::SHOOT_FRONT),
soundPlayed(false), soundPlayed(false),
dest(_dest), dest(_dest),
attackedStack(defender), defendingStack(defender),
attackingStack(attacker) attackingStack(attacker)
{ {
assert(attackingStack && "attackingStack is nullptr in CBattleAttack::CBattleAttack !\n"); assert(attackingStack && "attackingStack is nullptr in CBattleAttack::CBattleAttack !\n");
attackingStackPosBeforeReturn = attackingStack->getPosition(); attackingStackPosBeforeReturn = attackingStack->getPosition();
} }
CDefenceAnimation::CDefenceAnimation(StackAttackedInfo _attackedInfo, BattleInterface & owner) bool HittedAnimation::init()
: CBattleStackAnimation(owner, _attackedInfo.defender),
attacker(_attackedInfo.attacker),
rangedAttack(_attackedInfo.indirectAttack),
killed(_attackedInfo.killed)
{ {
logAnim->debug("Created defence anim for %s", _attackedInfo.defender->getName()); CCS->soundh->playSound(battle_sound(stack->getCreature(), wince));
myAnim->playOnce(ECreatureAnimType::HITTED);
myAnim->onAnimationReset += [&](){ delete this; };
return true;
} }
bool CDefenceAnimation::init() HittedAnimation::HittedAnimation(BattleInterface & owner, const CStack * stack)
: BattleStackAnimation(owner, stack)
{ {
logAnim->info("CDefenceAnimation::init: stack %s", stack->getName()); }
CCS->soundh->playSound(getMySound()); DefenceAnimation::DefenceAnimation(BattleInterface & owner, const CStack * stack)
myAnim->setType(getMyAnimType()); : BattleStackAnimation(owner, stack)
{
}
bool DefenceAnimation::init()
{
CCS->soundh->playSound(battle_sound(stack->getCreature(), defend));
myAnim->playOnce(ECreatureAnimType::DEFENCE);
myAnim->onAnimationReset += [&](){ delete this; }; myAnim->onAnimationReset += [&](){ delete this; };
return true; //initialized successfuly return true; //initialized successfuly
} }
std::string CDefenceAnimation::getMySound() ECreatureAnimType::Type DeathAnimation::getMyAnimType()
{ {
if(killed) if(rangedAttack && myAnim->framesInGroup(ECreatureAnimType::DEATH_RANGED) > 0)
return battle_sound(stack->getCreature(), killed); return ECreatureAnimType::DEATH_RANGED;
else if(stack->defendingAnim)
return battle_sound(stack->getCreature(), defend);
else else
return battle_sound(stack->getCreature(), wince); return ECreatureAnimType::DEATH;
} }
ECreatureAnimType::Type CDefenceAnimation::getMyAnimType() bool DeathAnimation::init()
{ {
if(killed) CCS->soundh->playSound(battle_sound(stack->getCreature(), killed));
{ myAnim->playOnce(getMyAnimType());
if(rangedAttack && myAnim->framesInGroup(ECreatureAnimType::DEATH_RANGED) > 0) myAnim->onAnimationReset += [&](){ delete this; };
return ECreatureAnimType::DEATH_RANGED; return true;
else
return ECreatureAnimType::DEATH;
}
if(stack->defendingAnim)
return ECreatureAnimType::DEFENCE;
else
return ECreatureAnimType::HITTED;
} }
CDefenceAnimation::~CDefenceAnimation() DeathAnimation::DeathAnimation(BattleInterface & owner, const CStack * stack, bool ranged):
BattleStackAnimation(owner, stack),
rangedAttack(ranged)
{ {
if(killed)
{
if(rangedAttack && myAnim->framesInGroup(ECreatureAnimType::DEAD_RANGED) > 0)
myAnim->setType(ECreatureAnimType::DEAD_RANGED);
else
myAnim->setType(ECreatureAnimType::DEAD);
}
else
{
myAnim->setType(ECreatureAnimType::HOLDING);
}
} }
CDummyAnimation::CDummyAnimation(BattleInterface & owner, int howManyFrames) DeathAnimation::~DeathAnimation()
: CBattleAnimation(owner), {
if(rangedAttack && myAnim->framesInGroup(ECreatureAnimType::DEAD_RANGED) > 0)
myAnim->setType(ECreatureAnimType::DEAD_RANGED);
else
myAnim->setType(ECreatureAnimType::DEAD);
}
DummyAnimation::DummyAnimation(BattleInterface & owner, int howManyFrames)
: BattleAnimation(owner),
counter(0), counter(0),
howMany(howManyFrames) howMany(howManyFrames)
{ {
logAnim->debug("Created dummy animation for %d frames", howManyFrames); logAnim->debug("Created dummy animation for %d frames", howManyFrames);
} }
bool CDummyAnimation::init() bool DummyAnimation::init()
{ {
return true; return true;
} }
void CDummyAnimation::nextFrame() void DummyAnimation::nextFrame()
{ {
counter++; counter++;
if(counter > howMany) if(counter > howMany)
delete this; delete this;
} }
bool CMeleeAttackAnimation::init() bool MeleeAttackAnimation::init()
{ {
assert(attackingStack); assert(attackingStack);
assert(!myAnim->isDeadOrDying()); assert(!myAnim->isDeadOrDying());
@@ -240,10 +221,7 @@ bool CMeleeAttackAnimation::init()
return false; return false;
} }
logAnim->info("CMeleeAttackAnimation::init: stack %s -> stack %s", stack->getName(), attackedStack->getName()); logAnim->info("CMeleeAttackAnimation::init: stack %s -> stack %s", stack->getName(), defendingStack->getName());
//reversed
shooting = false;
static const ECreatureAnimType::Type mutPosToGroup[] = static const ECreatureAnimType::Type mutPosToGroup[] =
{ {
@@ -270,15 +248,15 @@ bool CMeleeAttackAnimation::init()
int mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn, dest); int mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn, dest);
if(mutPos == -1 && attackingStack->doubleWide()) if(mutPos == -1 && attackingStack->doubleWide())
{ {
mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->getPosition()); mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, defendingStack->getPosition());
} }
if (mutPos == -1 && attackedStack->doubleWide()) if (mutPos == -1 && defendingStack->doubleWide())
{ {
mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn, attackedStack->occupiedHex()); mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn, defendingStack->occupiedHex());
} }
if (mutPos == -1 && attackedStack->doubleWide() && attackingStack->doubleWide()) if (mutPos == -1 && defendingStack->doubleWide() && attackingStack->doubleWide())
{ {
mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->occupiedHex()); mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, defendingStack->occupiedHex());
} }
@@ -308,7 +286,7 @@ bool CMeleeAttackAnimation::init()
return true; return true;
} }
void CMeleeAttackAnimation::nextFrame() void MeleeAttackAnimation::nextFrame()
{ {
size_t currentFrame = stackAnimation(attackingStack)->getCurrentFrame(); size_t currentFrame = stackAnimation(attackingStack)->getCurrentFrame();
size_t totalFrames = stackAnimation(attackingStack)->framesInGroup(group); size_t totalFrames = stackAnimation(attackingStack)->framesInGroup(group);
@@ -318,24 +296,28 @@ void CMeleeAttackAnimation::nextFrame()
if(owner.getAnimationCondition(EAnimationEvents::HIT) == false) if(owner.getAnimationCondition(EAnimationEvents::HIT) == false)
owner.setAnimationCondition(EAnimationEvents::HIT, true); owner.setAnimationCondition(EAnimationEvents::HIT, true);
} }
AttackAnimation::nextFrame();
CAttackAnimation::nextFrame();
} }
CMeleeAttackAnimation::CMeleeAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked) void MeleeAttackAnimation::playSound()
: CAttackAnimation(owner, attacker, _dest, _attacked) {
CCS->soundh->playSound(battle_sound(getCreature(), attack));
}
MeleeAttackAnimation::MeleeAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked)
: AttackAnimation(owner, attacker, _dest, _attacked)
{ {
logAnim->debug("Created melee attack anim for %s", attacker->getName()); logAnim->debug("Created melee attack anim for %s", attacker->getName());
} }
CStackMoveAnimation::CStackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex _currentHex): StackMoveAnimation::StackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex _currentHex):
CBattleStackAnimation(owner, _stack), BattleStackAnimation(owner, _stack),
currentHex(_currentHex) currentHex(_currentHex)
{ {
} }
bool CMovementAnimation::init() bool MovementAnimation::init()
{ {
assert(stack); assert(stack);
assert(!myAnim->isDeadOrDying()); assert(!myAnim->isDeadOrDying());
@@ -395,7 +377,7 @@ bool CMovementAnimation::init()
return true; return true;
} }
void CMovementAnimation::nextFrame() void MovementAnimation::nextFrame()
{ {
progress += float(GH.mainFPSmng->getElapsedMilliseconds()) / 1000 * timeToMove; progress += float(GH.mainFPSmng->getElapsedMilliseconds()) / 1000 * timeToMove;
@@ -403,7 +385,7 @@ void CMovementAnimation::nextFrame()
myAnim->pos.x = static_cast<Sint16>(begX + distanceX * progress ); myAnim->pos.x = static_cast<Sint16>(begX + distanceX * progress );
myAnim->pos.y = static_cast<Sint16>(begY + distanceY * progress ); myAnim->pos.y = static_cast<Sint16>(begY + distanceY * progress );
CBattleAnimation::nextFrame(); BattleAnimation::nextFrame();
if(progress >= 1.0) if(progress >= 1.0)
{ {
@@ -427,7 +409,7 @@ void CMovementAnimation::nextFrame()
} }
} }
CMovementAnimation::~CMovementAnimation() MovementAnimation::~MovementAnimation()
{ {
assert(stack); assert(stack);
@@ -440,8 +422,8 @@ CMovementAnimation::~CMovementAnimation()
} }
} }
CMovementAnimation::CMovementAnimation(BattleInterface & owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance) MovementAnimation::MovementAnimation(BattleInterface & owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance)
: CStackMoveAnimation(owner, _stack, _destTiles.front()), : StackMoveAnimation(owner, _stack, _destTiles.front()),
destTiles(_destTiles), destTiles(_destTiles),
curentMoveIndex(0), curentMoveIndex(0),
oldPos(stack->getPosition()), oldPos(stack->getPosition()),
@@ -453,13 +435,13 @@ CMovementAnimation::CMovementAnimation(BattleInterface & owner, const CStack *_s
logAnim->debug("Created movement anim for %s", stack->getName()); logAnim->debug("Created movement anim for %s", stack->getName());
} }
CMovementEndAnimation::CMovementEndAnimation(BattleInterface & owner, const CStack * _stack, BattleHex destTile) MovementEndAnimation::MovementEndAnimation(BattleInterface & owner, const CStack * _stack, BattleHex destTile)
: CStackMoveAnimation(owner, _stack, destTile) : StackMoveAnimation(owner, _stack, destTile)
{ {
logAnim->debug("Created movement end anim for %s", stack->getName()); logAnim->debug("Created movement end anim for %s", stack->getName());
} }
bool CMovementEndAnimation::init() bool MovementEndAnimation::init()
{ {
assert(stack); assert(stack);
assert(!myAnim->isDeadOrDying()); assert(!myAnim->isDeadOrDying());
@@ -487,7 +469,7 @@ bool CMovementEndAnimation::init()
return true; return true;
} }
CMovementEndAnimation::~CMovementEndAnimation() MovementEndAnimation::~MovementEndAnimation()
{ {
if(myAnim->getType() != ECreatureAnimType::DEAD) if(myAnim->getType() != ECreatureAnimType::DEAD)
myAnim->setType(ECreatureAnimType::HOLDING); //resetting to default myAnim->setType(ECreatureAnimType::HOLDING); //resetting to default
@@ -495,13 +477,13 @@ CMovementEndAnimation::~CMovementEndAnimation()
CCS->curh->show(); CCS->curh->show();
} }
CMovementStartAnimation::CMovementStartAnimation(BattleInterface & owner, const CStack * _stack) MovementStartAnimation::MovementStartAnimation(BattleInterface & owner, const CStack * _stack)
: CStackMoveAnimation(owner, _stack, _stack->getPosition()) : StackMoveAnimation(owner, _stack, _stack->getPosition())
{ {
logAnim->debug("Created movement start anim for %s", stack->getName()); logAnim->debug("Created movement start anim for %s", stack->getName());
} }
bool CMovementStartAnimation::init() bool MovementStartAnimation::init()
{ {
assert(stack); assert(stack);
assert(!myAnim->isDeadOrDying()); assert(!myAnim->isDeadOrDying());
@@ -526,13 +508,13 @@ bool CMovementStartAnimation::init()
return true; return true;
} }
CReverseAnimation::CReverseAnimation(BattleInterface & owner, const CStack * stack, BattleHex dest) ReverseAnimation::ReverseAnimation(BattleInterface & owner, const CStack * stack, BattleHex dest)
: CStackMoveAnimation(owner, stack, dest) : StackMoveAnimation(owner, stack, dest)
{ {
logAnim->debug("Created reverse anim for %s", stack->getName()); logAnim->debug("Created reverse anim for %s", stack->getName());
} }
bool CReverseAnimation::init() bool ReverseAnimation::init()
{ {
assert(myAnim); assert(myAnim);
assert(!myAnim->isDeadOrDying()); assert(!myAnim->isDeadOrDying());
@@ -547,7 +529,7 @@ bool CReverseAnimation::init()
if(myAnim->framesInGroup(ECreatureAnimType::TURN_L)) if(myAnim->framesInGroup(ECreatureAnimType::TURN_L))
{ {
myAnim->playOnce(ECreatureAnimType::TURN_L); myAnim->playOnce(ECreatureAnimType::TURN_L);
myAnim->onAnimationReset += std::bind(&CReverseAnimation::setupSecondPart, this); myAnim->onAnimationReset += std::bind(&ReverseAnimation::setupSecondPart, this);
} }
else else
{ {
@@ -556,14 +538,14 @@ bool CReverseAnimation::init()
return true; return true;
} }
void CBattleStackAnimation::rotateStack(BattleHex hex) void BattleStackAnimation::rotateStack(BattleHex hex)
{ {
setStackFacingRight(stack, !stackFacingRight(stack)); setStackFacingRight(stack, !stackFacingRight(stack));
stackAnimation(stack)->pos = owner.stacksController->getStackPositionAtHex(hex, stack); stackAnimation(stack)->pos = owner.stacksController->getStackPositionAtHex(hex, stack);
} }
void CReverseAnimation::setupSecondPart() void ReverseAnimation::setupSecondPart()
{ {
assert(stack); assert(stack);
@@ -584,7 +566,7 @@ void CReverseAnimation::setupSecondPart()
delete this; delete this;
} }
bool CResurrectionAnimation::init() bool ResurrectionAnimation::init()
{ {
assert(stack); assert(stack);
@@ -601,19 +583,24 @@ bool CResurrectionAnimation::init()
return true; return true;
} }
CResurrectionAnimation::CResurrectionAnimation(BattleInterface & owner, const CStack * stack): ResurrectionAnimation::ResurrectionAnimation(BattleInterface & owner, const CStack * _stack):
CBattleStackAnimation(owner, stack) BattleStackAnimation(owner, _stack)
{ {
} }
CRangedAttackAnimation::CRangedAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest_, const CStack * defender) RangedAttackAnimation::RangedAttackAnimation(BattleInterface & owner_, const CStack * attacker, BattleHex dest_, const CStack * defender)
: CAttackAnimation(owner, attacker, dest_, defender), : AttackAnimation(owner_, attacker, dest_, defender),
projectileEmitted(false) projectileEmitted(false)
{ {
} }
bool CRangedAttackAnimation::init() void RangedAttackAnimation::playSound()
{
CCS->soundh->playSound(battle_sound(getCreature(), shoot));
}
bool RangedAttackAnimation::init()
{ {
assert(attackingStack); assert(attackingStack);
assert(!myAnim->isDeadOrDying()); assert(!myAnim->isDeadOrDying());
@@ -630,14 +617,13 @@ bool CRangedAttackAnimation::init()
setAnimationGroup(); setAnimationGroup();
initializeProjectile(); initializeProjectile();
shooting = true;
return true; return true;
} }
void CRangedAttackAnimation::setAnimationGroup() void RangedAttackAnimation::setAnimationGroup()
{ {
Point shooterPos = stackAnimation(attackingStack)->pos.topLeft(); Point shooterPos = stackAnimation(attackingStack)->pos.topLeft();
Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, attackedStack); Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, defendingStack);
//maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value) //maximal angle in radians between straight horizontal line and shooting line for which shot is considered to be straight (absoulte value)
static const double straightAngle = 0.2; static const double straightAngle = 0.2;
@@ -653,10 +639,10 @@ void CRangedAttackAnimation::setAnimationGroup()
group = getForwardGroup(); group = getForwardGroup();
} }
void CRangedAttackAnimation::initializeProjectile() void RangedAttackAnimation::initializeProjectile()
{ {
const CCreature *shooterInfo = getCreature(); const CCreature *shooterInfo = getCreature();
Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, attackedStack) + Point(225, 225); Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, defendingStack) + Point(225, 225);
Point shotOrigin = stackAnimation(attackingStack)->pos.topLeft() + Point(222, 265); Point shotOrigin = stackAnimation(attackingStack)->pos.topLeft() + Point(222, 265);
int multiplier = stackFacingRight(attackingStack) ? 1 : -1; int multiplier = stackFacingRight(attackingStack) ? 1 : -1;
@@ -683,14 +669,14 @@ void CRangedAttackAnimation::initializeProjectile()
createProjectile(shotOrigin, shotTarget); createProjectile(shotOrigin, shotTarget);
} }
void CRangedAttackAnimation::emitProjectile() void RangedAttackAnimation::emitProjectile()
{ {
logAnim->info("Ranged attack projectile emitted"); logAnim->info("Ranged attack projectile emitted");
owner.projectilesController->emitStackProjectile(attackingStack); owner.projectilesController->emitStackProjectile(attackingStack);
projectileEmitted = true; projectileEmitted = true;
} }
void CRangedAttackAnimation::nextFrame() void RangedAttackAnimation::nextFrame()
{ {
// animation should be paused if there is an active projectile // animation should be paused if there is an active projectile
if (projectileEmitted) if (projectileEmitted)
@@ -705,7 +691,7 @@ void CRangedAttackAnimation::nextFrame()
} }
} }
CAttackAnimation::nextFrame(); AttackAnimation::nextFrame();
if (!projectileEmitted) if (!projectileEmitted)
{ {
@@ -719,7 +705,7 @@ void CRangedAttackAnimation::nextFrame()
} }
} }
CRangedAttackAnimation::~CRangedAttackAnimation() RangedAttackAnimation::~RangedAttackAnimation()
{ {
//FIXME: this assert triggers under some unclear, rare conditions. Possibly - if game window is inactive and/or in foreground/minimized? //FIXME: this assert triggers under some unclear, rare conditions. Possibly - if game window is inactive and/or in foreground/minimized?
assert(!owner.projectilesController->hasActiveProjectile(attackingStack)); assert(!owner.projectilesController->hasActiveProjectile(attackingStack));
@@ -733,49 +719,49 @@ CRangedAttackAnimation::~CRangedAttackAnimation()
} }
} }
CShootingAnimation::CShootingAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked) ShootingAnimation::ShootingAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked)
: CRangedAttackAnimation(owner, attacker, _dest, _attacked) : RangedAttackAnimation(owner, attacker, _dest, _attacked)
{ {
logAnim->debug("Created shooting anim for %s", stack->getName()); logAnim->debug("Created shooting anim for %s", stack->getName());
} }
void CShootingAnimation::createProjectile(const Point & from, const Point & dest) const void ShootingAnimation::createProjectile(const Point & from, const Point & dest) const
{ {
owner.projectilesController->createProjectile(attackingStack, from, dest); owner.projectilesController->createProjectile(attackingStack, from, dest);
} }
uint32_t CShootingAnimation::getAttackClimaxFrame() const uint32_t ShootingAnimation::getAttackClimaxFrame() const
{ {
const CCreature *shooterInfo = getCreature(); const CCreature *shooterInfo = getCreature();
return shooterInfo->animation.attackClimaxFrame; return shooterInfo->animation.attackClimaxFrame;
} }
ECreatureAnimType::Type CShootingAnimation::getUpwardsGroup() const ECreatureAnimType::Type ShootingAnimation::getUpwardsGroup() const
{ {
return ECreatureAnimType::SHOOT_UP; return ECreatureAnimType::SHOOT_UP;
} }
ECreatureAnimType::Type CShootingAnimation::getForwardGroup() const ECreatureAnimType::Type ShootingAnimation::getForwardGroup() const
{ {
return ECreatureAnimType::SHOOT_FRONT; return ECreatureAnimType::SHOOT_FRONT;
} }
ECreatureAnimType::Type CShootingAnimation::getDownwardsGroup() const ECreatureAnimType::Type ShootingAnimation::getDownwardsGroup() const
{ {
return ECreatureAnimType::SHOOT_DOWN; return ECreatureAnimType::SHOOT_DOWN;
} }
CCatapultAnimation::CCatapultAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked, int _catapultDmg) CatapultAnimation::CatapultAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked, int _catapultDmg)
: CShootingAnimation(owner, attacker, _dest, _attacked), : ShootingAnimation(owner, attacker, _dest, _attacked),
catapultDamage(_catapultDmg), catapultDamage(_catapultDmg),
explosionEmitted(false) explosionEmitted(false)
{ {
logAnim->debug("Created shooting anim for %s", stack->getName()); logAnim->debug("Created shooting anim for %s", stack->getName());
} }
void CCatapultAnimation::nextFrame() void CatapultAnimation::nextFrame()
{ {
CShootingAnimation::nextFrame(); ShootingAnimation::nextFrame();
if ( explosionEmitted) if ( explosionEmitted)
return; return;
@@ -787,21 +773,21 @@ void CCatapultAnimation::nextFrame()
return; return;
explosionEmitted = true; explosionEmitted = true;
Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, attackedStack) + Point(225, 225) - Point(126, 105); Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, defendingStack) + Point(225, 225) - Point(126, 105);
if(catapultDamage > 0) if(catapultDamage > 0)
owner.stacksController->addNewAnim( new CPointEffectAnimation(owner, "WALLHIT", "SGEXPL.DEF", shotTarget)); owner.stacksController->addNewAnim( new PointEffectAnimation(owner, "WALLHIT", "SGEXPL.DEF", shotTarget));
else else
owner.stacksController->addNewAnim( new CPointEffectAnimation(owner, "WALLMISS", "CSGRCK.DEF", shotTarget)); owner.stacksController->addNewAnim( new PointEffectAnimation(owner, "WALLMISS", "CSGRCK.DEF", shotTarget));
} }
void CCatapultAnimation::createProjectile(const Point & from, const Point & dest) const void CatapultAnimation::createProjectile(const Point & from, const Point & dest) const
{ {
owner.projectilesController->createCatapultProjectile(attackingStack, from, dest); owner.projectilesController->createCatapultProjectile(attackingStack, from, dest);
} }
CCastAnimation::CCastAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest_, const CStack * defender, const CSpell * spell) CastAnimation::CastAnimation(BattleInterface & owner_, const CStack * attacker, BattleHex dest_, const CStack * defender, const CSpell * spell)
: CRangedAttackAnimation(owner, attacker, dest_, defender), : RangedAttackAnimation(owner_, attacker, dest_, defender),
spell(spell) spell(spell)
{ {
assert(dest.isValid());// FIXME: when? assert(dest.isValid());// FIXME: when?
@@ -810,7 +796,7 @@ CCastAnimation::CCastAnimation(BattleInterface & owner, const CStack * attacker,
dest = defender->getPosition(); dest = defender->getPosition();
} }
ECreatureAnimType::Type CCastAnimation::findValidGroup( const std::vector<ECreatureAnimType::Type> candidates ) const ECreatureAnimType::Type CastAnimation::findValidGroup( const std::vector<ECreatureAnimType::Type> candidates ) const
{ {
for ( auto group : candidates) for ( auto group : candidates)
{ {
@@ -822,7 +808,7 @@ ECreatureAnimType::Type CCastAnimation::findValidGroup( const std::vector<ECreat
return ECreatureAnimType::HOLDING; return ECreatureAnimType::HOLDING;
} }
ECreatureAnimType::Type CCastAnimation::getUpwardsGroup() const ECreatureAnimType::Type CastAnimation::getUpwardsGroup() const
{ {
return findValidGroup({ return findValidGroup({
ECreatureAnimType::VCMI_CAST_UP, ECreatureAnimType::VCMI_CAST_UP,
@@ -832,7 +818,7 @@ ECreatureAnimType::Type CCastAnimation::getUpwardsGroup() const
}); });
} }
ECreatureAnimType::Type CCastAnimation::getForwardGroup() const ECreatureAnimType::Type CastAnimation::getForwardGroup() const
{ {
return findValidGroup({ return findValidGroup({
ECreatureAnimType::VCMI_CAST_FRONT, ECreatureAnimType::VCMI_CAST_FRONT,
@@ -842,7 +828,7 @@ ECreatureAnimType::Type CCastAnimation::getForwardGroup() const
}); });
} }
ECreatureAnimType::Type CCastAnimation::getDownwardsGroup() const ECreatureAnimType::Type CastAnimation::getDownwardsGroup() const
{ {
return findValidGroup({ return findValidGroup({
ECreatureAnimType::VCMI_CAST_DOWN, ECreatureAnimType::VCMI_CAST_DOWN,
@@ -852,13 +838,13 @@ ECreatureAnimType::Type CCastAnimation::getDownwardsGroup() const
}); });
} }
void CCastAnimation::createProjectile(const Point & from, const Point & dest) const void CastAnimation::createProjectile(const Point & from, const Point & dest) const
{ {
if (!spell->animationInfo.projectile.empty()) if (!spell->animationInfo.projectile.empty())
owner.projectilesController->createSpellProjectile(attackingStack, from, dest, spell); owner.projectilesController->createSpellProjectile(attackingStack, from, dest, spell);
} }
uint32_t CCastAnimation::getAttackClimaxFrame() const uint32_t CastAnimation::getAttackClimaxFrame() const
{ {
//FIXME: allow defining this parameter in config file, separately from attackClimaxFrame of missile attacks //FIXME: allow defining this parameter in config file, separately from attackClimaxFrame of missile attacks
uint32_t maxFrames = stackAnimation(attackingStack)->framesInGroup(group); uint32_t maxFrames = stackAnimation(attackingStack)->framesInGroup(group);
@@ -868,8 +854,8 @@ uint32_t CCastAnimation::getAttackClimaxFrame() const
return 0; return 0;
} }
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, int effects): PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, int effects):
CBattleAnimation(owner), BattleAnimation(owner),
animation(std::make_shared<CAnimation>(animationName)), animation(std::make_shared<CAnimation>(animationName)),
soundName(soundName), soundName(soundName),
effectFlags(effects), effectFlags(effects),
@@ -880,40 +866,40 @@ CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, std::strin
logAnim->info("CPointEffectAnimation::init: effect %s", animationName); logAnim->info("CPointEffectAnimation::init: effect %s", animationName);
} }
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<BattleHex> hex, int effects): PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<BattleHex> hex, int effects):
CPointEffectAnimation(owner, soundName, animationName, effects) PointEffectAnimation(owner, soundName, animationName, effects)
{ {
battlehexes = hex; battlehexes = hex;
} }
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, BattleHex hex, int effects): PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, BattleHex hex, int effects):
CPointEffectAnimation(owner, soundName, animationName, effects) PointEffectAnimation(owner, soundName, animationName, effects)
{ {
assert(hex.isValid()); assert(hex.isValid());
battlehexes.push_back(hex); battlehexes.push_back(hex);
} }
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<Point> pos, int effects): PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<Point> pos, int effects):
CPointEffectAnimation(owner, soundName, animationName, effects) PointEffectAnimation(owner, soundName, animationName, effects)
{ {
positions = pos; positions = pos;
} }
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, int effects): PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, int effects):
CPointEffectAnimation(owner, soundName, animationName, effects) PointEffectAnimation(owner, soundName, animationName, effects)
{ {
positions.push_back(pos); positions.push_back(pos);
} }
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, BattleHex hex, int effects): PointEffectAnimation::PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, BattleHex hex, int effects):
CPointEffectAnimation(owner, soundName, animationName, effects) PointEffectAnimation(owner, soundName, animationName, effects)
{ {
assert(hex.isValid()); assert(hex.isValid());
battlehexes.push_back(hex); battlehexes.push_back(hex);
positions.push_back(pos); positions.push_back(pos);
} }
bool CPointEffectAnimation::init() bool PointEffectAnimation::init()
{ {
animation->preload(); animation->preload();
@@ -971,7 +957,7 @@ bool CPointEffectAnimation::init()
return true; return true;
} }
void CPointEffectAnimation::nextFrame() void PointEffectAnimation::nextFrame()
{ {
playSound(); playSound();
playEffect(); playEffect();
@@ -984,37 +970,37 @@ void CPointEffectAnimation::nextFrame()
} }
} }
bool CPointEffectAnimation::alignToBottom() const bool PointEffectAnimation::alignToBottom() const
{ {
return effectFlags & ALIGN_TO_BOTTOM; return effectFlags & ALIGN_TO_BOTTOM;
} }
bool CPointEffectAnimation::waitForSound() const bool PointEffectAnimation::waitForSound() const
{ {
return effectFlags & WAIT_FOR_SOUND; return effectFlags & WAIT_FOR_SOUND;
} }
bool CPointEffectAnimation::forceOnTop() const bool PointEffectAnimation::forceOnTop() const
{ {
return effectFlags & FORCE_ON_TOP; return effectFlags & FORCE_ON_TOP;
} }
bool CPointEffectAnimation::screenFill() const bool PointEffectAnimation::screenFill() const
{ {
return effectFlags & SCREEN_FILL; return effectFlags & SCREEN_FILL;
} }
void CPointEffectAnimation::onEffectFinished() void PointEffectAnimation::onEffectFinished()
{ {
effectFinished = true; effectFinished = true;
} }
void CPointEffectAnimation::onSoundFinished() void PointEffectAnimation::onSoundFinished()
{ {
soundFinished = true; soundFinished = true;
} }
void CPointEffectAnimation::playSound() void PointEffectAnimation::playSound()
{ {
if (soundPlayed) if (soundPlayed)
return; return;
@@ -1034,7 +1020,7 @@ void CPointEffectAnimation::playSound()
CCS->soundh->setCallback(channel, [&](){ onSoundFinished(); }); CCS->soundh->setCallback(channel, [&](){ onSoundFinished(); });
} }
void CPointEffectAnimation::playEffect() void PointEffectAnimation::playEffect()
{ {
if ( effectFinished ) if ( effectFinished )
return; return;
@@ -1055,7 +1041,7 @@ void CPointEffectAnimation::playEffect()
} }
} }
void CPointEffectAnimation::clearEffect() void PointEffectAnimation::clearEffect()
{ {
auto & effects = owner.effectsController->battleEffects; auto & effects = owner.effectsController->battleEffects;
@@ -1064,17 +1050,13 @@ void CPointEffectAnimation::clearEffect()
}); });
} }
CPointEffectAnimation::~CPointEffectAnimation() PointEffectAnimation::~PointEffectAnimation()
{ {
assert(effectFinished); assert(effectFinished);
assert(soundFinished); assert(soundFinished);
} }
CWaitingAnimation::CWaitingAnimation(BattleInterface & owner): void WaitingProjectileAnimation::nextFrame()
CBattleAnimation(owner)
{}
void CWaitingAnimation::nextFrame()
{ {
// initialization conditions fulfilled, delay is over // initialization conditions fulfilled, delay is over
if(owner.getAnimationCondition(EAnimationEvents::HIT) == false) if(owner.getAnimationCondition(EAnimationEvents::HIT) == false)
@@ -1083,16 +1065,16 @@ void CWaitingAnimation::nextFrame()
delete this; delete this;
} }
CWaitingProjectileAnimation::CWaitingProjectileAnimation(BattleInterface & owner, const CStack * shooter): WaitingProjectileAnimation::WaitingProjectileAnimation(BattleInterface & owner_, const CStack * shooter):
CWaitingAnimation(owner), BattleAnimation(owner_),
shooter(shooter) shooter(shooter)
{} {}
bool CWaitingProjectileAnimation::init() bool WaitingProjectileAnimation::init()
{ {
for(auto & elem : pendingAnimations()) for(auto & elem : pendingAnimations())
{ {
auto * attackAnim = dynamic_cast<CRangedAttackAnimation *>(elem); auto * attackAnim = dynamic_cast<RangedAttackAnimation *>(elem);
if( attackAnim && shooter && attackAnim->stack->ID == shooter->ID && !attackAnim->isInitialized() ) if( attackAnim && shooter && attackAnim->stack->ID == shooter->ID && !attackAnim->isInitialized() )
{ {

View File

@@ -10,7 +10,6 @@
#pragma once #pragma once
#include "../../lib/battle/BattleHex.h" #include "../../lib/battle/BattleHex.h"
#include "../../lib/CSoundBase.h"
#include "BattleConstants.h" #include "BattleConstants.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
@@ -24,21 +23,17 @@ VCMI_LIB_NAMESPACE_END
class CAnimation; class CAnimation;
class BattleInterface; class BattleInterface;
class CreatureAnimation; class CreatureAnimation;
class CBattleAnimation;
struct CatapultProjectileInfo;
struct StackAttackedInfo; struct StackAttackedInfo;
struct Point; struct Point;
class ColorShifter;
/// Base class of battle animations /// Base class of battle animations
class CBattleAnimation class BattleAnimation
{ {
protected: protected:
BattleInterface & owner; BattleInterface & owner;
bool initialized; bool initialized;
std::vector<CBattleAnimation *> & pendingAnimations(); std::vector<BattleAnimation *> & pendingAnimations();
std::shared_ptr<CreatureAnimation> stackAnimation(const CStack * stack) const; std::shared_ptr<CreatureAnimation> stackAnimation(const CStack * stack) const;
bool stackFacingRight(const CStack * stack); bool stackFacingRight(const CStack * stack);
void setStackFacingRight(const CStack * stack, bool facingRight); void setStackFacingRight(const CStack * stack, bool facingRight);
@@ -51,63 +46,71 @@ public:
bool isInitialized(); bool isInitialized();
bool tryInitialize(); bool tryInitialize();
virtual void nextFrame() {} //call every new frame virtual void nextFrame() {} //call every new frame
virtual ~CBattleAnimation(); virtual ~BattleAnimation();
CBattleAnimation(BattleInterface & owner); BattleAnimation(BattleInterface & owner);
}; };
/// Sub-class which is responsible for managing the battle stack animation. /// Sub-class which is responsible for managing the battle stack animation.
class CBattleStackAnimation : public CBattleAnimation class BattleStackAnimation : public BattleAnimation
{ {
public: public:
std::shared_ptr<CreatureAnimation> myAnim; //animation for our stack, managed by BattleInterface std::shared_ptr<CreatureAnimation> myAnim; //animation for our stack, managed by BattleInterface
const CStack * stack; //id of stack whose animation it is const CStack * stack; //id of stack whose animation it is
CBattleStackAnimation(BattleInterface & owner, const CStack * _stack); BattleStackAnimation(BattleInterface & owner, const CStack * _stack);
void shiftColor(const ColorShifter * shifter);
void rotateStack(BattleHex hex); void rotateStack(BattleHex hex);
}; };
/// This class is responsible for managing the battle attack animation /// This class is responsible for managing the battle attack animation
class CAttackAnimation : public CBattleStackAnimation class AttackAnimation : public BattleStackAnimation
{ {
bool soundPlayed; bool soundPlayed;
protected: protected:
BattleHex dest; //attacked hex BattleHex dest; //attacked hex
bool shooting; ECreatureAnimType::Type group;
ECreatureAnimType::Type group; //if shooting is true, print this animation group const CStack *defendingStack;
const CStack *attackedStack;
const CStack *attackingStack; const CStack *attackingStack;
int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
const CCreature * getCreature() const; const CCreature * getCreature() const;
public: public:
void nextFrame() override; virtual void playSound() = 0;
CAttackAnimation(BattleInterface & owner, const CStack *attacker, BattleHex _dest, const CStack *defender); void nextFrame() override;
~CAttackAnimation(); AttackAnimation(BattleInterface & owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
~AttackAnimation();
}; };
/// Animation of a defending unit /// Animation of a defending unit
class CDefenceAnimation : public CBattleStackAnimation class DefenceAnimation : public BattleStackAnimation
{ {
ECreatureAnimType::Type getMyAnimType();
std::string getMySound();
const CStack * attacker; //attacking stack
bool rangedAttack; //if true, stack has been attacked by shooting
bool killed; //if true, stack has been killed
public: public:
bool init() override; bool init() override;
DefenceAnimation(BattleInterface & owner, const CStack * stack);
CDefenceAnimation(StackAttackedInfo _attackedInfo, BattleInterface & owner);
~CDefenceAnimation();
}; };
class CDummyAnimation : public CBattleAnimation /// Animation of a hit unit
class HittedAnimation : public BattleStackAnimation
{
public:
HittedAnimation(BattleInterface & owner, const CStack * stack);
bool init() override;
};
/// 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();
};
class DummyAnimation : public BattleAnimation
{ {
private: private:
int counter; int counter;
@@ -116,31 +119,32 @@ public:
bool init() override; bool init() override;
void nextFrame() override; void nextFrame() override;
CDummyAnimation(BattleInterface & owner, int howManyFrames); DummyAnimation(BattleInterface & owner, int howManyFrames);
}; };
/// Hand-to-hand attack /// Hand-to-hand attack
class CMeleeAttackAnimation : public CAttackAnimation class MeleeAttackAnimation : public AttackAnimation
{ {
public: public:
bool init() override; bool init() override;
void nextFrame() override; void nextFrame() override;
void playSound() override;
CMeleeAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked); MeleeAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked);
}; };
/// Base class for all animations that play during stack movement /// Base class for all animations that play during stack movement
class CStackMoveAnimation : public CBattleStackAnimation class StackMoveAnimation : public BattleStackAnimation
{ {
public: public:
BattleHex currentHex; BattleHex currentHex;
protected: protected:
CStackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex _currentHex); StackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex _currentHex);
}; };
/// Move animation of a creature /// Move animation of a creature
class CMovementAnimation : public CStackMoveAnimation class MovementAnimation : public StackMoveAnimation
{ {
private: private:
std::vector<BattleHex> destTiles; //full path, includes already passed hexes std::vector<BattleHex> destTiles; //full path, includes already passed hexes
@@ -158,49 +162,49 @@ public:
bool init() override; bool init() override;
void nextFrame() override; void nextFrame() override;
CMovementAnimation(BattleInterface & owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance); MovementAnimation(BattleInterface & owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance);
~CMovementAnimation(); ~MovementAnimation();
}; };
/// Move end animation of a creature /// Move end animation of a creature
class CMovementEndAnimation : public CStackMoveAnimation class MovementEndAnimation : public StackMoveAnimation
{ {
public: public:
bool init() override; bool init() override;
CMovementEndAnimation(BattleInterface & owner, const CStack * _stack, BattleHex destTile); MovementEndAnimation(BattleInterface & owner, const CStack * _stack, BattleHex destTile);
~CMovementEndAnimation(); ~MovementEndAnimation();
}; };
/// Move start animation of a creature /// Move start animation of a creature
class CMovementStartAnimation : public CStackMoveAnimation class MovementStartAnimation : public StackMoveAnimation
{ {
public: public:
bool init() override; bool init() override;
CMovementStartAnimation(BattleInterface & owner, const CStack * _stack); MovementStartAnimation(BattleInterface & owner, const CStack * _stack);
}; };
/// Class responsible for animation of stack chaning direction (left <-> right) /// Class responsible for animation of stack chaning direction (left <-> right)
class CReverseAnimation : public CStackMoveAnimation class ReverseAnimation : public StackMoveAnimation
{ {
void setupSecondPart(); void setupSecondPart();
public: public:
bool init() override; bool init() override;
CReverseAnimation(BattleInterface & owner, const CStack * stack, BattleHex dest); ReverseAnimation(BattleInterface & owner, const CStack * stack, BattleHex dest);
}; };
/// Resurrects stack from dead state /// Resurrects stack from dead state
class CResurrectionAnimation : public CBattleStackAnimation class ResurrectionAnimation : public BattleStackAnimation
{ {
public: public:
bool init() override; bool init() override;
CResurrectionAnimation(BattleInterface & owner, const CStack * _stack); ResurrectionAnimation(BattleInterface & owner, const CStack * _stack);
}; };
class CRangedAttackAnimation : public CAttackAnimation class RangedAttackAnimation : public AttackAnimation
{ {
void setAnimationGroup(); void setAnimationGroup();
@@ -219,15 +223,16 @@ protected:
virtual uint32_t getAttackClimaxFrame() const = 0; virtual uint32_t getAttackClimaxFrame() const = 0;
public: public:
CRangedAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender); RangedAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender);
~CRangedAttackAnimation(); ~RangedAttackAnimation();
bool init() override; bool init() override;
void nextFrame() override; void nextFrame() override;
void playSound() override;
}; };
/// Shooting attack /// Shooting attack
class CShootingAnimation : public CRangedAttackAnimation class ShootingAnimation : public RangedAttackAnimation
{ {
ECreatureAnimType::Type getUpwardsGroup() const override; ECreatureAnimType::Type getUpwardsGroup() const override;
ECreatureAnimType::Type getForwardGroup() const override; ECreatureAnimType::Type getForwardGroup() const override;
@@ -237,25 +242,25 @@ class CShootingAnimation : public CRangedAttackAnimation
uint32_t getAttackClimaxFrame() const override; uint32_t getAttackClimaxFrame() const override;
public: public:
CShootingAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender); ShootingAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender);
}; };
/// Catapult attack /// Catapult attack
class CCatapultAnimation : public CShootingAnimation class CatapultAnimation : public ShootingAnimation
{ {
private: private:
bool explosionEmitted; bool explosionEmitted;
int catapultDamage; int catapultDamage;
public: public:
CCatapultAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender, int _catapultDmg = 0); 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 createProjectile(const Point & from, const Point & dest) const override;
void nextFrame() override; void nextFrame() override;
}; };
class CCastAnimation : public CRangedAttackAnimation class CastAnimation : public RangedAttackAnimation
{ {
const CSpell * spell; const CSpell * spell;
@@ -268,24 +273,11 @@ class CCastAnimation : public CRangedAttackAnimation
uint32_t getAttackClimaxFrame() const override; uint32_t getAttackClimaxFrame() const override;
public: public:
CCastAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest_, const CStack * defender, const CSpell * spell); CastAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest_, const CStack * defender, const CSpell * spell);
};
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;
}; };
/// Class that plays effect at one or more positions along with (single) sound effect /// Class that plays effect at one or more positions along with (single) sound effect
class CPointEffectAnimation : public CBattleAnimation class PointEffectAnimation : public BattleAnimation
{ {
std::string soundName; std::string soundName;
bool soundPlayed; bool soundPlayed;
@@ -313,44 +305,36 @@ public:
enum EEffectFlags enum EEffectFlags
{ {
ALIGN_TO_BOTTOM = 1, ALIGN_TO_BOTTOM = 1,
WAIT_FOR_SOUND = 2, WAIT_FOR_SOUND = 2, // Unused, can be removed
FORCE_ON_TOP = 4, FORCE_ON_TOP = 4,
SCREEN_FILL = 8, SCREEN_FILL = 8,
}; };
/// Create animation with screen-wide effect /// Create animation with screen-wide effect
CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, int effects = 0); PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, int effects = 0);
/// Create animation positioned at point(s). Note that positions must be are absolute, including battleint position offset /// Create animation positioned at point(s). Note that positions must be are absolute, including battleint position offset
CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos , int effects = 0); PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos , int effects = 0);
CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<Point> pos , int effects = 0); PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<Point> pos , int effects = 0);
/// Create animation positioned at certain hex(es) /// Create animation positioned at certain hex(es)
CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, BattleHex hex , int effects = 0); PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, BattleHex hex , int effects = 0);
CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<BattleHex> hex, int effects = 0); PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, std::vector<BattleHex> hex, int effects = 0);
CPointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, BattleHex hex, int effects = 0); PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, BattleHex hex, int effects = 0);
~CPointEffectAnimation(); ~PointEffectAnimation();
bool init() override; bool init() override;
void nextFrame() override; void nextFrame() override;
}; };
/// Base class (e.g. for use in dynamic_cast's) for "animations" that wait for certain event
class CWaitingAnimation : public CBattleAnimation
{
protected:
CWaitingAnimation(BattleInterface & owner);
public:
void nextFrame() override;
};
/// Class that waits till projectile of certain shooter hits a target /// Class that waits till projectile of certain shooter hits a target
class CWaitingProjectileAnimation : public CWaitingAnimation class WaitingProjectileAnimation : public BattleAnimation
{ {
const CStack * shooter; const CStack * shooter;
public: public:
CWaitingProjectileAnimation(BattleInterface & owner, const CStack * shooter); WaitingProjectileAnimation(BattleInterface & owner, const CStack * shooter);
void nextFrame() override;
bool init() override; bool init() override;
}; };

View File

@@ -44,7 +44,7 @@ void BattleEffectsController::displayEffect(EBattleEffect::EBattleEffect effect,
{ {
std::string customAnim = graphics->battleACToDef[effect][0]; std::string customAnim = graphics->battleACToDef[effect][0];
owner.stacksController->addNewAnim(new CPointEffectAnimation(owner, soundBase::stringsList()[soundID], customAnim, destTile)); owner.stacksController->addNewAnim(new PointEffectAnimation(owner, soundBase::stringsList()[soundID], customAnim, destTile));
} }
void BattleEffectsController::displayCustomEffects(const std::vector<CustomEffectInfo> & customEffects) void BattleEffectsController::displayCustomEffects(const std::vector<CustomEffectInfo> & customEffects)

View File

@@ -24,7 +24,7 @@ class CAnimation;
class Canvas; class Canvas;
class BattleInterface; class BattleInterface;
class BattleRenderer; class BattleRenderer;
class CPointEffectAnimation; class PointEffectAnimation;
/// Struct for battle effect animation e.g. morale, prayer, armageddon, bless,... /// Struct for battle effect animation e.g. morale, prayer, armageddon, bless,...
struct BattleEffect struct BattleEffect
@@ -59,5 +59,5 @@ public:
void collectRenderableObjects(BattleRenderer & renderer); void collectRenderableObjects(BattleRenderer & renderer);
friend class CPointEffectAnimation; friend class PointEffectAnimation;
}; };

View File

@@ -514,7 +514,7 @@ void BattleInterface::spellCast(const BattleSpellCast * sc)
{ {
executeOnAnimationCondition(EAnimationEvents::BEFORE_HIT, true, [=]() executeOnAnimationCondition(EAnimationEvents::BEFORE_HIT, true, [=]()
{ {
stacksController->addNewAnim(new CCastAnimation(*this, casterStack, targetedTile, curInt->cb->battleGetStackByPos(targetedTile), spell)); stacksController->addNewAnim(new CastAnimation(*this, casterStack, targetedTile, curInt->cb->battleGetStackByPos(targetedTile), spell));
displaySpellCast(spellID, casterStack->getPosition()); displaySpellCast(spellID, casterStack->getPosition());
}); });
} }
@@ -533,7 +533,7 @@ void BattleInterface::spellCast(const BattleSpellCast * sc)
{ {
projectilesController->createSpellProjectile( nullptr, srccoord, destcoord, spell); projectilesController->createSpellProjectile( nullptr, srccoord, destcoord, spell);
projectilesController->emitStackProjectile( nullptr ); projectilesController->emitStackProjectile( nullptr );
stacksController->addNewAnim(new CWaitingProjectileAnimation(*this, nullptr)); stacksController->addNewAnim(new WaitingProjectileAnimation(*this, nullptr));
}); });
} }
} }
@@ -576,8 +576,8 @@ void BattleInterface::spellCast(const BattleSpellCast * sc)
bool side = sc->side; bool side = sc->side;
executeOnAnimationCondition(EAnimationEvents::AFTER_HIT, true, [=](){ executeOnAnimationCondition(EAnimationEvents::AFTER_HIT, true, [=](){
stacksController->addNewAnim(new CPointEffectAnimation(*this, "", side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero)); stacksController->addNewAnim(new PointEffectAnimation(*this, "", side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero));
stacksController->addNewAnim(new CPointEffectAnimation(*this, "", side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero)); stacksController->addNewAnim(new PointEffectAnimation(*this, "", side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero));
}); });
} }
} }
@@ -618,24 +618,24 @@ void BattleInterface::displaySpellAnimationQueue(const CSpell::TAnimationQueue &
for(const CSpell::TAnimation & animation : q) for(const CSpell::TAnimation & animation : q)
{ {
if(animation.pause > 0) if(animation.pause > 0)
stacksController->addNewAnim(new CDummyAnimation(*this, animation.pause)); stacksController->addNewAnim(new DummyAnimation(*this, animation.pause));
else else
{ {
int flags = 0; int flags = 0;
if (isHit) if (isHit)
flags |= CPointEffectAnimation::FORCE_ON_TOP; flags |= PointEffectAnimation::FORCE_ON_TOP;
if (animation.verticalPosition == VerticalPosition::BOTTOM) if (animation.verticalPosition == VerticalPosition::BOTTOM)
flags |= CPointEffectAnimation::ALIGN_TO_BOTTOM; flags |= PointEffectAnimation::ALIGN_TO_BOTTOM;
if (!destinationTile.isValid()) if (!destinationTile.isValid())
flags |= CPointEffectAnimation::SCREEN_FILL; flags |= PointEffectAnimation::SCREEN_FILL;
if (!destinationTile.isValid()) if (!destinationTile.isValid())
stacksController->addNewAnim(new CPointEffectAnimation(*this, "", animation.resourceName, flags)); stacksController->addNewAnim(new PointEffectAnimation(*this, "", animation.resourceName, flags));
else else
stacksController->addNewAnim(new CPointEffectAnimation(*this, "", animation.resourceName, destinationTile, flags)); stacksController->addNewAnim(new PointEffectAnimation(*this, "", animation.resourceName, destinationTile, flags));
} }
} }
} }

View File

@@ -100,7 +100,7 @@ void BattleObstacleController::obstaclePlaced(const std::vector<std::shared_ptr<
//we assume here that effect graphics have the same size as the usual obstacle image //we assume here that effect graphics have the same size as the usual obstacle image
// -> if we know how to blit obstacle, let's blit the effect in the same place // -> if we know how to blit obstacle, let's blit the effect in the same place
Point whereTo = getObstaclePosition(first, *oi); Point whereTo = getObstaclePosition(first, *oi);
owner.stacksController->addNewAnim(new CPointEffectAnimation(owner, spellObstacle->appearSound, spellObstacle->appearAnimation, whereTo, oi->pos)); owner.stacksController->addNewAnim(new PointEffectAnimation(owner, spellObstacle->appearSound, spellObstacle->appearAnimation, whereTo, oi->pos));
//so when multiple obstacles are added, they show up one after another //so when multiple obstacles are added, they show up one after another
owner.waitForAnimationCondition(EAnimationEvents::ACTION, false); owner.waitForAnimationCondition(EAnimationEvents::ACTION, false);

View File

@@ -336,7 +336,7 @@ void BattleSiegeController::stackIsCatapulting(const CatapultAttack & ca)
const CStack *stack = owner.curInt->cb->battleGetStackByID(ca.attacker); const CStack *stack = owner.curInt->cb->battleGetStackByID(ca.attacker);
for (auto attackInfo : ca.attackedParts) for (auto attackInfo : ca.attackedParts)
{ {
owner.stacksController->addNewAnim(new CCatapultAnimation(owner, stack, attackInfo.destinationTile, nullptr, attackInfo.damageDealt)); owner.stacksController->addNewAnim(new CatapultAnimation(owner, stack, attackInfo.destinationTile, nullptr, attackInfo.damageDealt));
} }
} }
else else
@@ -347,7 +347,7 @@ void BattleSiegeController::stackIsCatapulting(const CatapultAttack & ca)
for (auto attackInfo : ca.attackedParts) for (auto attackInfo : ca.attackedParts)
positions.push_back(owner.stacksController->getStackPositionAtHex(attackInfo.destinationTile, nullptr) + Point(99, 120)); positions.push_back(owner.stacksController->getStackPositionAtHex(attackInfo.destinationTile, nullptr) + Point(99, 120));
owner.stacksController->addNewAnim(new CPointEffectAnimation(owner, "WALLHIT", "SGEXPL.DEF", positions)); owner.stacksController->addNewAnim(new PointEffectAnimation(owner, "WALLHIT", "SGEXPL.DEF", positions));
} }
owner.waitForAnimationCondition(EAnimationEvents::ACTION, false); owner.waitForAnimationCondition(EAnimationEvents::ACTION, false);

View File

@@ -107,7 +107,7 @@ BattleHex BattleStacksController::getStackCurrentPosition(const CStack * stack)
// stack position will be updated only *after* movement is finished // stack position will be updated only *after* movement is finished
// before this - stack is always at its initial position. Thus we need to find // before this - stack is always at its initial position. Thus we need to find
// its current position. Which can be found only in this class // its current position. Which can be found only in this class
if (CStackMoveAnimation *move = dynamic_cast<CStackMoveAnimation*>(anim)) if (StackMoveAnimation *move = dynamic_cast<StackMoveAnimation*>(anim))
{ {
if (move->stack == stack) if (move->stack == stack)
return move->currentHex; return move->currentHex;
@@ -168,7 +168,7 @@ void BattleStacksController::stackReset(const CStack * stack)
{ {
owner.executeOnAnimationCondition(EAnimationEvents::HIT, true, [=]() owner.executeOnAnimationCondition(EAnimationEvents::HIT, true, [=]()
{ {
addNewAnim(new CResurrectionAnimation(owner, stack)); addNewAnim(new ResurrectionAnimation(owner, stack));
}); });
} }
@@ -275,7 +275,7 @@ bool BattleStacksController::stackNeedsAmountBox(const CStack * stack) const
for(auto anim : currentAnimations) //no matter what other conditions below are, hide box when creature is playing hit animation for(auto anim : currentAnimations) //no matter what other conditions below are, hide box when creature is playing hit animation
{ {
auto hitAnimation = dynamic_cast<CDefenceAnimation*>(anim); auto hitAnimation = dynamic_cast<DefenceAnimation*>(anim);
if(hitAnimation && (hitAnimation->stack->ID == stack->ID)) if(hitAnimation && (hitAnimation->stack->ID == stack->ID))
return false; return false;
} }
@@ -372,7 +372,7 @@ void BattleStacksController::updateBattleAnimations()
} }
} }
void BattleStacksController::addNewAnim(CBattleAnimation *anim) void BattleStacksController::addNewAnim(BattleAnimation *anim)
{ {
currentAnimations.push_back(anim); currentAnimations.push_back(anim);
owner.setAnimationCondition(EAnimationEvents::ACTION, true); owner.setAnimationCondition(EAnimationEvents::ACTION, true);
@@ -418,20 +418,26 @@ void BattleStacksController::stacksAreAttacked(std::vector<StackAttackedInfo> at
{ {
owner.executeOnAnimationCondition(EAnimationEvents::MOVEMENT, true, [=]() owner.executeOnAnimationCondition(EAnimationEvents::MOVEMENT, true, [=]()
{ {
addNewAnim(new CReverseAnimation(owner, attackedInfo.defender, attackedInfo.defender->getPosition())); addNewAnim(new ReverseAnimation(owner, attackedInfo.defender, attackedInfo.defender->getPosition()));
}); });
} }
} }
for(auto & attackedInfo : attackedInfos) for(auto & attackedInfo : attackedInfos)
{ {
bool useDeathAnim = attackedInfo.killed;
bool useDefenceAnim = attackedInfo.defender->defendingAnim && !attackedInfo.indirectAttack && !attackedInfo.killed; bool useDefenceAnim = attackedInfo.defender->defendingAnim && !attackedInfo.indirectAttack && !attackedInfo.killed;
EAnimationEvents usedEvent = useDefenceAnim ? EAnimationEvents::ATTACK : EAnimationEvents::HIT; EAnimationEvents usedEvent = useDefenceAnim ? EAnimationEvents::ATTACK : EAnimationEvents::HIT;
owner.executeOnAnimationCondition(usedEvent, true, [=]() owner.executeOnAnimationCondition(usedEvent, true, [=]()
{ {
addNewAnim(new CDefenceAnimation(attackedInfo, owner)); if (useDeathAnim)
addNewAnim(new DeathAnimation(owner, attackedInfo.defender, attackedInfo.indirectAttack));
else if(useDefenceAnim)
addNewAnim(new DefenceAnimation(owner, attackedInfo.defender));
else
addNewAnim(new HittedAnimation(owner, attackedInfo.defender));
if (attackedInfo.battleEffect != EBattleEffect::INVALID) if (attackedInfo.battleEffect != EBattleEffect::INVALID)
owner.effectsController->displayEffect(EBattleEffect::EBattleEffect(attackedInfo.battleEffect), attackedInfo.defender->getPosition()); owner.effectsController->displayEffect(EBattleEffect::EBattleEffect(attackedInfo.battleEffect), attackedInfo.defender->getPosition());
@@ -447,7 +453,7 @@ void BattleStacksController::stacksAreAttacked(std::vector<StackAttackedInfo> at
{ {
owner.executeOnAnimationCondition(EAnimationEvents::AFTER_HIT, true, [=](){ owner.executeOnAnimationCondition(EAnimationEvents::AFTER_HIT, true, [=](){
owner.effectsController->displayEffect(EBattleEffect::RESURRECT, soundBase::RESURECT, attackedInfo.defender->getPosition()); owner.effectsController->displayEffect(EBattleEffect::RESURRECT, soundBase::RESURECT, attackedInfo.defender->getPosition());
addNewAnim(new CResurrectionAnimation(owner, attackedInfo.defender)); addNewAnim(new ResurrectionAnimation(owner, attackedInfo.defender));
}); });
} }
@@ -469,16 +475,15 @@ void BattleStacksController::stackMoved(const CStack *stack, std::vector<BattleH
assert(owner.getAnimationCondition(EAnimationEvents::ACTION) == false); assert(owner.getAnimationCondition(EAnimationEvents::ACTION) == false);
if(shouldRotate(stack, stack->getPosition(), destHex[0])) if(shouldRotate(stack, stack->getPosition(), destHex[0]))
addNewAnim(new CReverseAnimation(owner, stack, destHex[0])); addNewAnim(new ReverseAnimation(owner, stack, destHex[0]));
addNewAnim(new CMovementStartAnimation(owner, stack));
addNewAnim(new MovementStartAnimation(owner, stack));
owner.waitForAnimationCondition(EAnimationEvents::ACTION, false); owner.waitForAnimationCondition(EAnimationEvents::ACTION, false);
addNewAnim(new CMovementAnimation(owner, stack, destHex, distance)); addNewAnim(new MovementAnimation(owner, stack, destHex, distance));
owner.waitForAnimationCondition(EAnimationEvents::ACTION, false); owner.waitForAnimationCondition(EAnimationEvents::ACTION, false);
addNewAnim(new CMovementEndAnimation(owner, stack, destHex.back())); addNewAnim(new MovementEndAnimation(owner, stack, destHex.back()));
owner.waitForAnimationCondition(EAnimationEvents::ACTION, false); owner.waitForAnimationCondition(EAnimationEvents::ACTION, false);
} }
@@ -504,7 +509,7 @@ void BattleStacksController::stackAttacking( const StackAttackInfo & info )
{ {
owner.executeOnAnimationCondition(EAnimationEvents::MOVEMENT, true, [=]() owner.executeOnAnimationCondition(EAnimationEvents::MOVEMENT, true, [=]()
{ {
addNewAnim(new CReverseAnimation(owner, attacker, attacker->getPosition())); addNewAnim(new ReverseAnimation(owner, attacker, attacker->getPosition()));
}); });
} }
@@ -543,11 +548,11 @@ void BattleStacksController::stackAttacking( const StackAttackInfo & info )
{ {
if (info.indirectAttack) if (info.indirectAttack)
{ {
addNewAnim(new CShootingAnimation(owner, attacker, tile, defender)); addNewAnim(new ShootingAnimation(owner, attacker, tile, defender));
} }
else else
{ {
addNewAnim(new CMeleeAttackAnimation(owner, attacker, tile, defender)); addNewAnim(new MeleeAttackAnimation(owner, attacker, tile, defender));
} }
}); });
@@ -609,7 +614,6 @@ bool BattleStacksController::shouldRotate(const CStack * stack, const BattleHex
return false; return false;
} }
void BattleStacksController::endAction(const BattleAction* action) void BattleStacksController::endAction(const BattleAction* action)
{ {
//FIXME: there should be no more ongoing animations. If not - then some other method created animations but did not wait for them to end //FIXME: there should be no more ongoing animations. If not - then some other method created animations but did not wait for them to end
@@ -625,7 +629,7 @@ void BattleStacksController::endAction(const BattleAction* action)
if (s && facingRight(s) != shouldFaceRight && s->alive() && stackAnimation[s->ID]->isIdle()) if (s && facingRight(s) != shouldFaceRight && s->alive() && stackAnimation[s->ID]->isIdle())
{ {
addNewAnim(new CReverseAnimation(owner, s, s->getPosition())); addNewAnim(new ReverseAnimation(owner, s, s->getPosition()));
} }
} }
owner.waitForAnimationCondition(EAnimationEvents::ACTION, false); owner.waitForAnimationCondition(EAnimationEvents::ACTION, false);

View File

@@ -25,9 +25,9 @@ struct StackAttackInfo;
class Canvas; class Canvas;
class BattleInterface; class BattleInterface;
class CBattleAnimation; class BattleAnimation;
class CreatureAnimation; class CreatureAnimation;
class CBattleAnimation; class BattleAnimation;
class BattleRenderer; class BattleRenderer;
class IImage; class IImage;
@@ -45,7 +45,7 @@ class BattleStacksController
std::shared_ptr<IImage> amountEffNeutral; std::shared_ptr<IImage> amountEffNeutral;
/// currently displayed animations <anim, initialized> /// currently displayed animations <anim, initialized>
std::vector<CBattleAnimation *> currentAnimations; std::vector<BattleAnimation *> currentAnimations;
/// animations of creatures from fighting armies (order by BattleInfo's stacks' ID) /// animations of creatures from fighting armies (order by BattleInfo's stacks' ID)
std::map<int32_t, std::shared_ptr<CreatureAnimation>> stackAnimation; std::map<int32_t, std::shared_ptr<CreatureAnimation>> stackAnimation;
@@ -110,7 +110,7 @@ public:
void collectRenderableObjects(BattleRenderer & renderer); void collectRenderableObjects(BattleRenderer & renderer);
void addNewAnim(CBattleAnimation *anim); //adds new anim to pendingAnims void addNewAnim(BattleAnimation *anim); //adds new anim to pendingAnims
void updateBattleAnimations(); void updateBattleAnimations();
const CStack* getActiveStack() const; const CStack* getActiveStack() const;
@@ -119,5 +119,5 @@ public:
/// returns position of animation needed to place stack in specific hex /// returns position of animation needed to place stack in specific hex
Point getStackPositionAtHex(BattleHex hexNum, const CStack * creature) const; Point getStackPositionAtHex(BattleHex hexNum, const CStack * creature) const;
friend class CBattleAnimation; // for exposing pendingAnims/creAnims/creDir to animations friend class BattleAnimation; // for exposing pendingAnims/creAnims/creDir to animations
}; };