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

View File

@ -10,7 +10,6 @@
#pragma once
#include "../../lib/battle/BattleHex.h"
#include "../../lib/CSoundBase.h"
#include "BattleConstants.h"
VCMI_LIB_NAMESPACE_BEGIN
@ -24,21 +23,17 @@ VCMI_LIB_NAMESPACE_END
class CAnimation;
class BattleInterface;
class CreatureAnimation;
class CBattleAnimation;
struct CatapultProjectileInfo;
struct StackAttackedInfo;
struct Point;
class ColorShifter;
/// Base class of battle animations
class CBattleAnimation
class BattleAnimation
{
protected:
BattleInterface & owner;
bool initialized;
std::vector<CBattleAnimation *> & pendingAnimations();
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);
@ -51,63 +46,71 @@ public:
bool isInitialized();
bool tryInitialize();
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.
class CBattleStackAnimation : public CBattleAnimation
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
CBattleStackAnimation(BattleInterface & owner, const CStack * _stack);
BattleStackAnimation(BattleInterface & owner, const CStack * _stack);
void shiftColor(const ColorShifter * shifter);
void rotateStack(BattleHex hex);
};
/// This class is responsible for managing the battle attack animation
class CAttackAnimation : public CBattleStackAnimation
class AttackAnimation : public BattleStackAnimation
{
bool soundPlayed;
protected:
BattleHex dest; //attacked hex
bool shooting;
ECreatureAnimType::Type group; //if shooting is true, print this animation group
const CStack *attackedStack;
ECreatureAnimType::Type group;
const CStack *defendingStack;
const CStack *attackingStack;
int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature
const CCreature * getCreature() const;
public:
void nextFrame() override;
virtual void playSound() = 0;
CAttackAnimation(BattleInterface & owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
~CAttackAnimation();
void nextFrame() override;
AttackAnimation(BattleInterface & owner, const CStack *attacker, BattleHex _dest, const CStack *defender);
~AttackAnimation();
};
/// 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:
bool init() override;
CDefenceAnimation(StackAttackedInfo _attackedInfo, BattleInterface & owner);
~CDefenceAnimation();
DefenceAnimation(BattleInterface & owner, const CStack * stack);
};
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:
int counter;
@ -116,31 +119,32 @@ public:
bool init() override;
void nextFrame() override;
CDummyAnimation(BattleInterface & owner, int howManyFrames);
DummyAnimation(BattleInterface & owner, int howManyFrames);
};
/// Hand-to-hand attack
class CMeleeAttackAnimation : public CAttackAnimation
class MeleeAttackAnimation : public AttackAnimation
{
public:
bool init() 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
class CStackMoveAnimation : public CBattleStackAnimation
class StackMoveAnimation : public BattleStackAnimation
{
public:
BattleHex currentHex;
protected:
CStackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex _currentHex);
StackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex _currentHex);
};
/// Move animation of a creature
class CMovementAnimation : public CStackMoveAnimation
class MovementAnimation : public StackMoveAnimation
{
private:
std::vector<BattleHex> destTiles; //full path, includes already passed hexes
@ -158,49 +162,49 @@ public:
bool init() override;
void nextFrame() override;
CMovementAnimation(BattleInterface & owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance);
~CMovementAnimation();
MovementAnimation(BattleInterface & owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance);
~MovementAnimation();
};
/// Move end animation of a creature
class CMovementEndAnimation : public CStackMoveAnimation
class MovementEndAnimation : public StackMoveAnimation
{
public:
bool init() override;
CMovementEndAnimation(BattleInterface & owner, const CStack * _stack, BattleHex destTile);
~CMovementEndAnimation();
MovementEndAnimation(BattleInterface & owner, const CStack * _stack, BattleHex destTile);
~MovementEndAnimation();
};
/// Move start animation of a creature
class CMovementStartAnimation : public CStackMoveAnimation
class MovementStartAnimation : public StackMoveAnimation
{
public:
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 CReverseAnimation : public CStackMoveAnimation
class ReverseAnimation : public StackMoveAnimation
{
void setupSecondPart();
public:
bool init() override;
CReverseAnimation(BattleInterface & owner, const CStack * stack, BattleHex dest);
ReverseAnimation(BattleInterface & owner, const CStack * stack, BattleHex dest);
};
/// Resurrects stack from dead state
class CResurrectionAnimation : public CBattleStackAnimation
class ResurrectionAnimation : public BattleStackAnimation
{
public:
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();
@ -219,15 +223,16 @@ protected:
virtual uint32_t getAttackClimaxFrame() const = 0;
public:
CRangedAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender);
~CRangedAttackAnimation();
RangedAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest, const CStack * defender);
~RangedAttackAnimation();
bool init() override;
void nextFrame() override;
void playSound() override;
};
/// Shooting attack
class CShootingAnimation : public CRangedAttackAnimation
class ShootingAnimation : public RangedAttackAnimation
{
ECreatureAnimType::Type getUpwardsGroup() const override;
ECreatureAnimType::Type getForwardGroup() const override;
@ -237,25 +242,25 @@ class CShootingAnimation : public CRangedAttackAnimation
uint32_t getAttackClimaxFrame() const override;
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
class CCatapultAnimation : public CShootingAnimation
class CatapultAnimation : public ShootingAnimation
{
private:
bool explosionEmitted;
int catapultDamage;
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 nextFrame() override;
};
class CCastAnimation : public CRangedAttackAnimation
class CastAnimation : public RangedAttackAnimation
{
const CSpell * spell;
@ -268,24 +273,11 @@ class CCastAnimation : public CRangedAttackAnimation
uint32_t getAttackClimaxFrame() const override;
public:
CCastAnimation(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;
CastAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest_, const CStack * defender, const CSpell * spell);
};
/// 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;
bool soundPlayed;
@ -313,44 +305,36 @@ public:
enum EEffectFlags
{
ALIGN_TO_BOTTOM = 1,
WAIT_FOR_SOUND = 2,
WAIT_FOR_SOUND = 2, // Unused, can be removed
FORCE_ON_TOP = 4,
SCREEN_FILL = 8,
};
/// 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
CPointEffectAnimation(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, 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)
CPointEffectAnimation(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, 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);
~CPointEffectAnimation();
PointEffectAnimation(BattleInterface & owner, std::string soundName, std::string animationName, Point pos, BattleHex hex, int effects = 0);
~PointEffectAnimation();
bool init() 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 CWaitingProjectileAnimation : public CWaitingAnimation
class WaitingProjectileAnimation : public BattleAnimation
{
const CStack * shooter;
public:
CWaitingProjectileAnimation(BattleInterface & owner, const CStack * shooter);
WaitingProjectileAnimation(BattleInterface & owner, const CStack * shooter);
void nextFrame() override;
bool init() override;
};

View File

@ -44,7 +44,7 @@ void BattleEffectsController::displayEffect(EBattleEffect::EBattleEffect effect,
{
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)

View File

@ -24,7 +24,7 @@ class CAnimation;
class Canvas;
class BattleInterface;
class BattleRenderer;
class CPointEffectAnimation;
class PointEffectAnimation;
/// Struct for battle effect animation e.g. morale, prayer, armageddon, bless,...
struct BattleEffect
@ -59,5 +59,5 @@ public:
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, [=]()
{
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());
});
}
@ -533,7 +533,7 @@ void BattleInterface::spellCast(const BattleSpellCast * sc)
{
projectilesController->createSpellProjectile( nullptr, srccoord, destcoord, spell);
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;
executeOnAnimationCondition(EAnimationEvents::AFTER_HIT, true, [=](){
stacksController->addNewAnim(new CPointEffectAnimation(*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_A.DEF" : "SP07_B.DEF", leftHero));
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)
{
if(animation.pause > 0)
stacksController->addNewAnim(new CDummyAnimation(*this, animation.pause));
stacksController->addNewAnim(new DummyAnimation(*this, animation.pause));
else
{
int flags = 0;
if (isHit)
flags |= CPointEffectAnimation::FORCE_ON_TOP;
flags |= PointEffectAnimation::FORCE_ON_TOP;
if (animation.verticalPosition == VerticalPosition::BOTTOM)
flags |= CPointEffectAnimation::ALIGN_TO_BOTTOM;
flags |= PointEffectAnimation::ALIGN_TO_BOTTOM;
if (!destinationTile.isValid())
flags |= CPointEffectAnimation::SCREEN_FILL;
flags |= PointEffectAnimation::SCREEN_FILL;
if (!destinationTile.isValid())
stacksController->addNewAnim(new CPointEffectAnimation(*this, "", animation.resourceName, flags));
stacksController->addNewAnim(new PointEffectAnimation(*this, "", animation.resourceName, flags));
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
// -> if we know how to blit obstacle, let's blit the effect in the same place
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
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);
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
@ -347,7 +347,7 @@ void BattleSiegeController::stackIsCatapulting(const CatapultAttack & ca)
for (auto attackInfo : ca.attackedParts)
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);

View File

@ -107,7 +107,7 @@ BattleHex BattleStacksController::getStackCurrentPosition(const CStack * stack)
// stack position will be updated only *after* movement is finished
// 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
if (CStackMoveAnimation *move = dynamic_cast<CStackMoveAnimation*>(anim))
if (StackMoveAnimation *move = dynamic_cast<StackMoveAnimation*>(anim))
{
if (move->stack == stack)
return move->currentHex;
@ -168,7 +168,7 @@ void BattleStacksController::stackReset(const CStack * stack)
{
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
{
auto hitAnimation = dynamic_cast<CDefenceAnimation*>(anim);
auto hitAnimation = dynamic_cast<DefenceAnimation*>(anim);
if(hitAnimation && (hitAnimation->stack->ID == stack->ID))
return false;
}
@ -372,7 +372,7 @@ void BattleStacksController::updateBattleAnimations()
}
}
void BattleStacksController::addNewAnim(CBattleAnimation *anim)
void BattleStacksController::addNewAnim(BattleAnimation *anim)
{
currentAnimations.push_back(anim);
owner.setAnimationCondition(EAnimationEvents::ACTION, true);
@ -418,20 +418,26 @@ void BattleStacksController::stacksAreAttacked(std::vector<StackAttackedInfo> at
{
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)
{
bool useDeathAnim = attackedInfo.killed;
bool useDefenceAnim = attackedInfo.defender->defendingAnim && !attackedInfo.indirectAttack && !attackedInfo.killed;
EAnimationEvents usedEvent = useDefenceAnim ? EAnimationEvents::ATTACK : EAnimationEvents::HIT;
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)
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.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);
if(shouldRotate(stack, stack->getPosition(), destHex[0]))
addNewAnim(new CReverseAnimation(owner, stack, destHex[0]));
addNewAnim(new CMovementStartAnimation(owner, stack));
addNewAnim(new ReverseAnimation(owner, stack, destHex[0]));
addNewAnim(new MovementStartAnimation(owner, stack));
owner.waitForAnimationCondition(EAnimationEvents::ACTION, false);
addNewAnim(new CMovementAnimation(owner, stack, destHex, distance));
addNewAnim(new MovementAnimation(owner, stack, destHex, distance));
owner.waitForAnimationCondition(EAnimationEvents::ACTION, false);
addNewAnim(new CMovementEndAnimation(owner, stack, destHex.back()));
addNewAnim(new MovementEndAnimation(owner, stack, destHex.back()));
owner.waitForAnimationCondition(EAnimationEvents::ACTION, false);
}
@ -504,7 +509,7 @@ void BattleStacksController::stackAttacking( const StackAttackInfo & info )
{
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)
{
addNewAnim(new CShootingAnimation(owner, attacker, tile, defender));
addNewAnim(new ShootingAnimation(owner, attacker, tile, defender));
}
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;
}
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
@ -625,7 +629,7 @@ void BattleStacksController::endAction(const BattleAction* action)
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);

View File

@ -25,9 +25,9 @@ struct StackAttackInfo;
class Canvas;
class BattleInterface;
class CBattleAnimation;
class BattleAnimation;
class CreatureAnimation;
class CBattleAnimation;
class BattleAnimation;
class BattleRenderer;
class IImage;
@ -45,7 +45,7 @@ class BattleStacksController
std::shared_ptr<IImage> amountEffNeutral;
/// 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)
std::map<int32_t, std::shared_ptr<CreatureAnimation>> stackAnimation;
@ -110,7 +110,7 @@ public:
void collectRenderableObjects(BattleRenderer & renderer);
void addNewAnim(CBattleAnimation *anim); //adds new anim to pendingAnims
void addNewAnim(BattleAnimation *anim); //adds new anim to pendingAnims
void updateBattleAnimations();
const CStack* getActiveStack() const;
@ -119,5 +119,5 @@ public:
/// returns position of animation needed to place stack in specific hex
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
};