From 2442d38b9aa9763be0adf6df77f8891f9162f155 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 1 Dec 2022 23:40:03 +0200 Subject: [PATCH] Fix ranged attack animations --- client/battle/CBattleAnimations.cpp | 13 ++++++------- client/battle/CBattleProjectileController.cpp | 10 +++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/client/battle/CBattleAnimations.cpp b/client/battle/CBattleAnimations.cpp index f816cdd3f..7e3926a44 100644 --- a/client/battle/CBattleAnimations.cpp +++ b/client/battle/CBattleAnimations.cpp @@ -738,7 +738,7 @@ bool CRangedAttackAnimation::init() void CRangedAttackAnimation::setAnimationGroup() { Point shooterPos = stackAnimation(attackingStack)->pos.topLeft(); - Point shotTarget = owner->stacksController->getStackPositionAtHex(dest, attackedStack) + Point(225, 225); + Point shotTarget = owner->stacksController->getStackPositionAtHex(dest, attackedStack); //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; @@ -761,17 +761,17 @@ void CRangedAttackAnimation::initializeProjectile() Point shotOrigin = stackAnimation(attackingStack)->pos.topLeft() + Point(222, 265); int multiplier = stackFacingRight(attackingStack) ? 1 : -1; - if (group == CCreatureAnim::SHOOT_UP) + if (group == getUpwardsGroup()) { shotOrigin.x += ( -25 + shooterInfo->animation.upperRightMissleOffsetX ) * multiplier; shotOrigin.y += shooterInfo->animation.upperRightMissleOffsetY; } - else if (group == CCreatureAnim::SHOOT_DOWN) + else if (group == getDownwardsGroup()) { shotOrigin.x += ( -25 + shooterInfo->animation.lowerRightMissleOffsetX ) * multiplier; shotOrigin.y += shooterInfo->animation.lowerRightMissleOffsetY; } - else if (group == CCreatureAnim::SHOOT_FRONT) + else if (group == getForwardGroup()) { shotOrigin.x += ( -25 + shooterInfo->animation.rightMissleOffsetX ) * multiplier; shotOrigin.y += shooterInfo->animation.rightMissleOffsetY; @@ -819,8 +819,6 @@ void CRangedAttackAnimation::nextFrame() { const CCreature *shooterInfo = getCreature(); - assert(stackAnimation(attackingStack)->isShooting()); - logAnim->info("Ranged attack executing, %d / %d / %d", stackAnimation(attackingStack)->getCurrentFrame(), shooterInfo->animation.attackClimaxFrame, @@ -967,7 +965,8 @@ CCreatureAnim::EAnimType CCastAnimation::getDownwardsGroup() const void CCastAnimation::createProjectile(const Point & from, const Point & dest) const { - owner->projectilesController->createSpellProjectile(attackingStack, attackedStack, from, dest, spell); + if (!spell->animationInfo.projectile.empty()) + owner->projectilesController->createSpellProjectile(attackingStack, attackedStack, from, dest, spell); } CPointEffectAnimation::CPointEffectAnimation(CBattleInterface * _owner, soundBase::soundID sound, std::string animationName, int effects): diff --git a/client/battle/CBattleProjectileController.cpp b/client/battle/CBattleProjectileController.cpp index 0c1e114fb..826dbf172 100644 --- a/client/battle/CBattleProjectileController.cpp +++ b/client/battle/CBattleProjectileController.cpp @@ -343,14 +343,14 @@ void CBattleProjectileController::createProjectile(const CStack * shooter, const missileProjectile->animation = getProjectileImage(shooter); missileProjectile->reverse = !owner->stacksController->facingRight(shooter); missileProjectile->frameNum = computeProjectileFrameID(from, dest, shooter); - missileProjectile->steps = computeProjectileFlightTime(from, dest, AnimationControls::getProjectileSpeed()); } - projectile->from = from; - projectile->dest = dest; + projectile->steps = computeProjectileFlightTime(from, dest, AnimationControls::getProjectileSpeed()); + projectile->from = from; + projectile->dest = dest; projectile->shooterID = shooter->ID; - projectile->step = 0; - projectile->playing = false; + projectile->step = 0; + projectile->playing = false; projectiles.push_back(projectile); }