2017-07-13 10:26:03 +02:00
|
|
|
/*
|
2022-12-11 23:16:23 +02:00
|
|
|
* BattleAnimationClasses.cpp, part of VCMI engine
|
2017-07-13 10:26:03 +02:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2011-12-22 16:05:19 +03:00
|
|
|
#include "StdInc.h"
|
2022-12-09 13:38:46 +02:00
|
|
|
#include "BattleAnimationClasses.h"
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
#include <boost/math/constants/constants.hpp>
|
2013-07-06 19:10:20 +03:00
|
|
|
|
2022-12-09 13:38:46 +02:00
|
|
|
#include "BattleInterfaceClasses.h"
|
|
|
|
#include "BattleInterface.h"
|
|
|
|
#include "BattleProjectileController.h"
|
|
|
|
#include "BattleSiegeController.h"
|
|
|
|
#include "BattleFieldController.h"
|
|
|
|
#include "BattleEffectsController.h"
|
|
|
|
#include "BattleStacksController.h"
|
|
|
|
#include "CreatureAnimation.h"
|
2013-07-06 19:10:20 +03:00
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CMusicHandler.h"
|
2011-12-22 16:05:19 +03:00
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
#include "../Graphics.h"
|
2017-09-05 16:21:44 +02:00
|
|
|
#include "../gui/CAnimation.h"
|
2013-04-07 14:52:07 +03:00
|
|
|
#include "../gui/CCursorHandler.h"
|
2013-07-06 19:10:20 +03:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
#include "../../CCallback.h"
|
2017-03-17 17:48:44 +02:00
|
|
|
#include "../../lib/CStack.h"
|
2013-07-06 19:10:20 +03:00
|
|
|
#include "../../lib/CTownHandler.h"
|
2014-07-15 10:14:49 +03:00
|
|
|
#include "../../lib/mapObjects/CGTownInstance.h"
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CBattleAnimation::CBattleAnimation(BattleInterface & owner)
|
|
|
|
: owner(owner),
|
|
|
|
ID(owner.stacksController->animIDhelper++),
|
2022-11-28 16:02:46 +02:00
|
|
|
initialized(false)
|
2013-07-16 21:12:47 +03:00
|
|
|
{
|
2017-08-10 22:47:58 +02:00
|
|
|
logAnim->trace("Animation #%d created", ID);
|
2013-07-16 21:12:47 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
bool CBattleAnimation::tryInitialize()
|
2013-07-16 21:12:47 +03:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
assert(!initialized);
|
|
|
|
|
|
|
|
if ( init() )
|
|
|
|
{
|
|
|
|
initialized = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-07-16 21:12:47 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
bool CBattleAnimation::isInitialized()
|
2022-11-20 19:11:34 +02:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
return initialized;
|
2022-11-20 19:11:34 +02:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
CBattleAnimation::~CBattleAnimation()
|
2022-11-20 19:11:34 +02:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
logAnim->trace("Animation #%d ended, type is %s", ID, typeid(this).name());
|
|
|
|
for(auto & elem : pendingAnimations())
|
|
|
|
{
|
|
|
|
if(elem == this)
|
|
|
|
elem = nullptr;
|
|
|
|
}
|
|
|
|
logAnim->trace("Animation #%d deleted", ID);
|
2022-11-20 19:11:34 +02:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
std::vector<CBattleAnimation *> & CBattleAnimation::pendingAnimations()
|
2022-11-20 19:11:34 +02:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
return owner.stacksController->currentAnimations;
|
2022-11-20 19:11:34 +02:00
|
|
|
}
|
|
|
|
|
2022-12-09 13:26:17 +02:00
|
|
|
std::shared_ptr<CreatureAnimation> CBattleAnimation::stackAnimation(const CStack * stack) const
|
2022-11-20 19:11:34 +02:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
return owner.stacksController->stackAnimation[stack->ID];
|
2022-11-20 19:11:34 +02:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
bool CBattleAnimation::stackFacingRight(const CStack * stack)
|
2022-11-20 19:11:34 +02:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
return owner.stacksController->stackFacingRight[stack->ID];
|
2022-11-20 19:11:34 +02:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
void CBattleAnimation::setStackFacingRight(const CStack * stack, bool facingRight)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.stacksController->stackFacingRight[stack->ID] = facingRight;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
bool CBattleAnimation::checkInitialConditions()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
int lowestMoveID = ID;
|
2022-12-01 22:06:42 +02:00
|
|
|
auto * thAnim = dynamic_cast<CBattleStackAnimation *>(this);
|
|
|
|
auto * thSen = dynamic_cast<CPointEffectAnimation *>(this);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-11-20 19:11:34 +02:00
|
|
|
for(auto & elem : pendingAnimations())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
auto * sen = dynamic_cast<CPointEffectAnimation *>(elem);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
// all effect animations can play concurrently with each other
|
|
|
|
if(sen && thSen && sen != thSen)
|
2011-12-22 16:05:19 +03:00
|
|
|
continue;
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
auto * revAnim = dynamic_cast<CReverseAnimation *>(elem);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
// if there is high-priority reverse animation affecting our stack then this animation will wait
|
|
|
|
if(revAnim && thAnim && revAnim && revAnim->stack->ID == thAnim->stack->ID && revAnim->priority)
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
if(elem)
|
|
|
|
vstd::amin(lowestMoveID, elem->ID);
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
2022-11-28 16:02:46 +02:00
|
|
|
return ID == lowestMoveID;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CBattleStackAnimation::CBattleStackAnimation(BattleInterface & owner, const CStack * stack)
|
2020-10-06 01:27:04 +02:00
|
|
|
: CBattleAnimation(owner),
|
2022-11-20 19:11:34 +02:00
|
|
|
myAnim(stackAnimation(stack)),
|
2020-10-06 01:27:04 +02:00
|
|
|
stack(stack)
|
2013-09-27 22:42:17 +03:00
|
|
|
{
|
|
|
|
assert(myAnim);
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2020-01-27 02:18:07 +02:00
|
|
|
void CBattleStackAnimation::shiftColor(const ColorShifter * shifter)
|
2020-01-25 11:21:26 +02:00
|
|
|
{
|
|
|
|
assert(myAnim);
|
|
|
|
myAnim->shiftColor(shifter);
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void CAttackAnimation::nextFrame()
|
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
if(myAnim->getType() != group)
|
|
|
|
{
|
|
|
|
myAnim->setType(group);
|
2022-11-28 16:02:46 +02:00
|
|
|
myAnim->onAnimationReset += [&](){ delete this; };
|
2013-07-06 19:10:20 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
if(!soundPlayed)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
if(shooting)
|
2022-11-27 20:01:52 +02:00
|
|
|
CCS->soundh->playSound(battle_sound(getCreature(), shoot));
|
2011-12-22 16:05:19 +03:00
|
|
|
else
|
2022-11-27 20:01:52 +02:00
|
|
|
CCS->soundh->playSound(battle_sound(getCreature(), attack));
|
2013-07-06 19:10:20 +03:00
|
|
|
soundPlayed = true;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
2013-07-06 19:10:20 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
CAttackAnimation::~CAttackAnimation()
|
2013-07-06 19:10:20 +03:00
|
|
|
{
|
|
|
|
myAnim->setType(CCreatureAnim::HOLDING);
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CAttackAnimation::checkInitialConditions()
|
|
|
|
{
|
2022-11-20 19:11:34 +02:00
|
|
|
for(auto & elem : pendingAnimations())
|
2013-07-16 21:12:47 +03:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
CBattleStackAnimation * stAnim = dynamic_cast<CBattleStackAnimation *>(elem);
|
2013-07-16 21:12:47 +03:00
|
|
|
CReverseAnimation * revAnim = dynamic_cast<CReverseAnimation *>(stAnim);
|
|
|
|
|
2017-05-28 13:39:36 +02:00
|
|
|
if(revAnim && attackedStack) // enemy must be fully reversed
|
2013-07-16 21:12:47 +03:00
|
|
|
{
|
|
|
|
if (revAnim->stack->ID == attackedStack->ID)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2022-11-28 16:02:46 +02:00
|
|
|
return CBattleAnimation::checkInitialConditions();
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-12-06 14:12:13 +02:00
|
|
|
const CCreature * CAttackAnimation::getCreature() const
|
2022-11-27 20:01:52 +02:00
|
|
|
{
|
|
|
|
if (attackingStack->getCreature()->idNumber == CreatureID::ARROW_TOWERS)
|
2022-12-13 13:58:16 +02:00
|
|
|
return owner.siegeController->getTurretCreature();
|
2022-11-27 20:01:52 +02:00
|
|
|
else
|
|
|
|
return attackingStack->getCreature();
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CAttackAnimation::CAttackAnimation(BattleInterface & owner, const CStack *attacker, BattleHex _dest, const CStack *defender)
|
|
|
|
: CBattleStackAnimation(owner, attacker),
|
2022-11-28 16:43:38 +02:00
|
|
|
shooting(false),
|
|
|
|
group(CCreatureAnim::SHOOT_FRONT),
|
|
|
|
soundPlayed(false),
|
|
|
|
dest(_dest),
|
|
|
|
attackedStack(defender),
|
|
|
|
attackingStack(attacker)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-06-26 14:18:27 +03:00
|
|
|
assert(attackingStack && "attackingStack is nullptr in CBattleAttack::CBattleAttack !\n");
|
2017-07-20 06:08:49 +02:00
|
|
|
attackingStackPosBeforeReturn = attackingStack->getPosition();
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CDefenceAnimation::CDefenceAnimation(StackAttackedInfo _attackedInfo, BattleInterface & owner)
|
|
|
|
: CBattleStackAnimation(owner, _attackedInfo.defender),
|
2022-11-28 16:43:38 +02:00
|
|
|
attacker(_attackedInfo.attacker),
|
|
|
|
rangedAttack(_attackedInfo.indirectAttack),
|
|
|
|
killed(_attackedInfo.killed),
|
|
|
|
timeToWait(0)
|
2014-09-23 16:02:30 +03:00
|
|
|
{
|
2017-08-10 22:47:58 +02:00
|
|
|
logAnim->debug("Created defence anim for %s", _attackedInfo.defender->getName());
|
2014-09-23 16:02:30 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
bool CDefenceAnimation::init()
|
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
ui32 lowestMoveID = ID;
|
2022-11-20 19:11:34 +02:00
|
|
|
for(auto & elem : pendingAnimations())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-08-06 18:25:51 +03:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
auto * defAnim = dynamic_cast<CDefenceAnimation *>(elem);
|
2011-12-22 16:05:19 +03:00
|
|
|
if(defAnim && defAnim->stack->ID != stack->ID)
|
|
|
|
continue;
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
auto * attAnim = dynamic_cast<CAttackAnimation *>(elem);
|
2011-12-22 16:05:19 +03:00
|
|
|
if(attAnim && attAnim->stack->ID != stack->ID)
|
|
|
|
continue;
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
auto * sen = dynamic_cast<CPointEffectAnimation *>(elem);
|
2022-11-24 16:30:04 +02:00
|
|
|
if (sen && attacker == nullptr)
|
|
|
|
return false;
|
|
|
|
|
2013-08-09 20:37:41 +03:00
|
|
|
if (sen)
|
|
|
|
continue;
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
CReverseAnimation * animAsRev = dynamic_cast<CReverseAnimation *>(elem);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2013-08-06 18:25:51 +03:00
|
|
|
if(animAsRev)
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
if(elem)
|
|
|
|
vstd::amin(lowestMoveID, elem->ID);
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
2013-07-16 21:12:47 +03:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
if(ID > lowestMoveID)
|
|
|
|
return false;
|
|
|
|
|
2013-08-06 18:25:51 +03:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
//reverse unit if necessary
|
2022-12-13 13:58:16 +02:00
|
|
|
if(attacker && owner.getCurrentPlayerInterface()->cb->isToReverse(stack->getPosition(), attacker->getPosition(), stackFacingRight(stack), attacker->doubleWide(), stackFacingRight(attacker)))
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.stacksController->addNewAnim(new CReverseAnimation(owner, stack, stack->getPosition(), true));
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//unit reversed
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
if(rangedAttack && attacker != nullptr && owner.projectilesController->hasActiveProjectile(attacker)) //delay hit animation
|
2016-11-27 16:48:18 +02:00
|
|
|
{
|
2022-11-17 13:21:03 +02:00
|
|
|
return false;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2013-07-16 21:12:47 +03:00
|
|
|
// synchronize animation with attacker, unless defending or attacked by shooter:
|
|
|
|
// wait for 1/2 of attack animation
|
|
|
|
if (!rangedAttack && getMyAnimType() != CCreatureAnim::DEFENCE)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-07-17 01:59:39 +03:00
|
|
|
float frameLength = AnimationControls::getCreatureAnimationSpeed(
|
2022-11-20 19:11:34 +02:00
|
|
|
stack->getCreature(), stackAnimation(stack).get(), getMyAnimType());
|
2013-07-16 21:12:47 +03:00
|
|
|
|
2013-07-17 01:59:39 +03:00
|
|
|
timeToWait = myAnim->framesInGroup(getMyAnimType()) * frameLength / 2;
|
2013-07-16 21:12:47 +03:00
|
|
|
|
|
|
|
myAnim->setType(CCreatureAnim::HOLDING);
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-16 21:12:47 +03:00
|
|
|
timeToWait = 0;
|
|
|
|
startAnimation();
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true; //initialized successfuly
|
|
|
|
}
|
|
|
|
|
2013-07-16 21:12:47 +03:00
|
|
|
std::string CDefenceAnimation::getMySound()
|
|
|
|
{
|
|
|
|
if(killed)
|
|
|
|
return battle_sound(stack->getCreature(), killed);
|
2017-07-20 06:08:49 +02:00
|
|
|
else if(stack->defendingAnim)
|
2013-07-16 21:12:47 +03:00
|
|
|
return battle_sound(stack->getCreature(), defend);
|
2017-07-20 06:08:49 +02:00
|
|
|
else
|
|
|
|
return battle_sound(stack->getCreature(), wince);
|
2013-07-16 21:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CCreatureAnim::EAnimType CDefenceAnimation::getMyAnimType()
|
|
|
|
{
|
|
|
|
if(killed)
|
2017-09-08 13:25:12 +02:00
|
|
|
{
|
|
|
|
if(rangedAttack && myAnim->framesInGroup(CCreatureAnim::DEATH_RANGED) > 0)
|
|
|
|
return CCreatureAnim::DEATH_RANGED;
|
|
|
|
else
|
|
|
|
return CCreatureAnim::DEATH;
|
|
|
|
}
|
2016-11-27 16:48:18 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(stack->defendingAnim)
|
2013-07-16 21:12:47 +03:00
|
|
|
return CCreatureAnim::DEFENCE;
|
2017-07-20 06:08:49 +02:00
|
|
|
else
|
|
|
|
return CCreatureAnim::HITTED;
|
2013-07-16 21:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDefenceAnimation::startAnimation()
|
|
|
|
{
|
|
|
|
CCS->soundh->playSound(getMySound());
|
|
|
|
myAnim->setType(getMyAnimType());
|
2022-11-28 16:02:46 +02:00
|
|
|
myAnim->onAnimationReset += [&](){ delete this; };
|
2013-07-16 21:12:47 +03:00
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void CDefenceAnimation::nextFrame()
|
|
|
|
{
|
2013-07-16 21:12:47 +03:00
|
|
|
if (timeToWait > 0)
|
|
|
|
{
|
|
|
|
timeToWait -= float(GH.mainFPSmng->getElapsedMilliseconds()) / 1000;
|
|
|
|
if (timeToWait <= 0)
|
|
|
|
startAnimation();
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
CBattleAnimation::nextFrame();
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
CDefenceAnimation::~CDefenceAnimation()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2017-09-05 19:45:29 +02:00
|
|
|
if(killed)
|
|
|
|
{
|
2017-09-08 13:25:12 +02:00
|
|
|
if(rangedAttack && myAnim->framesInGroup(CCreatureAnim::DEAD_RANGED) > 0)
|
|
|
|
myAnim->setType(CCreatureAnim::DEAD_RANGED);
|
|
|
|
else
|
|
|
|
myAnim->setType(CCreatureAnim::DEAD);
|
2017-09-05 19:45:29 +02:00
|
|
|
}
|
2013-07-06 19:10:20 +03:00
|
|
|
else
|
2017-09-05 19:45:29 +02:00
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
myAnim->setType(CCreatureAnim::HOLDING);
|
2017-09-05 19:45:29 +02:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CDummyAnimation::CDummyAnimation(BattleInterface & owner, int howManyFrames)
|
|
|
|
: CBattleAnimation(owner),
|
2022-11-28 16:43:38 +02:00
|
|
|
counter(0),
|
|
|
|
howMany(howManyFrames)
|
2015-09-12 23:01:36 +02:00
|
|
|
{
|
2017-08-11 13:38:10 +02:00
|
|
|
logAnim->debug("Created dummy animation for %d frames", howManyFrames);
|
2015-09-12 23:01:36 +02:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
bool CDummyAnimation::init()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDummyAnimation::nextFrame()
|
|
|
|
{
|
|
|
|
counter++;
|
|
|
|
if(counter > howMany)
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CMeleeAttackAnimation::init()
|
|
|
|
{
|
2017-09-08 13:25:12 +02:00
|
|
|
if(!CAttackAnimation::checkInitialConditions())
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
|
2022-11-28 22:35:38 +02:00
|
|
|
if(!attackingStack || myAnim->isDeadOrDying())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
bool toReverse = owner.getCurrentPlayerInterface()->cb->isToReverse(attackingStackPosBeforeReturn, attackedStack->getPosition(), stackFacingRight(stack), attackedStack->doubleWide(), stackFacingRight(attackedStack));
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2017-09-08 13:25:12 +02:00
|
|
|
if(toReverse)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.stacksController->addNewAnim(new CReverseAnimation(owner, stack, attackingStackPosBeforeReturn, true));
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
2013-07-16 21:12:47 +03:00
|
|
|
|
|
|
|
// opponent must face attacker ( = different directions) before he can be attacked
|
2017-09-08 13:25:12 +02:00
|
|
|
if(attackingStack && attackedStack &&
|
2022-11-20 19:11:34 +02:00
|
|
|
stackFacingRight(attackingStack) == stackFacingRight(attackedStack))
|
2013-07-16 21:12:47 +03:00
|
|
|
return false;
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
//reversed
|
|
|
|
|
|
|
|
shooting = false;
|
|
|
|
|
2017-09-08 13:25:12 +02:00
|
|
|
static const CCreatureAnim::EAnimType mutPosToGroup[] =
|
|
|
|
{
|
|
|
|
CCreatureAnim::ATTACK_UP,
|
|
|
|
CCreatureAnim::ATTACK_UP,
|
|
|
|
CCreatureAnim::ATTACK_FRONT,
|
|
|
|
CCreatureAnim::ATTACK_DOWN,
|
|
|
|
CCreatureAnim::ATTACK_DOWN,
|
|
|
|
CCreatureAnim::ATTACK_FRONT
|
|
|
|
};
|
|
|
|
|
|
|
|
static const CCreatureAnim::EAnimType mutPosToGroup2H[] =
|
|
|
|
{
|
|
|
|
CCreatureAnim::VCMI_2HEX_UP,
|
|
|
|
CCreatureAnim::VCMI_2HEX_UP,
|
|
|
|
CCreatureAnim::VCMI_2HEX_FRONT,
|
|
|
|
CCreatureAnim::VCMI_2HEX_DOWN,
|
|
|
|
CCreatureAnim::VCMI_2HEX_DOWN,
|
|
|
|
CCreatureAnim::VCMI_2HEX_FRONT
|
|
|
|
};
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2017-07-01 10:34:00 +02:00
|
|
|
int revShiftattacker = (attackingStack->side == BattleSide::ATTACKER ? -1 : 1);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
int mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn, dest);
|
|
|
|
if(mutPos == -1 && attackingStack->doubleWide())
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->getPosition());
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
if (mutPos == -1 && attackedStack->doubleWide())
|
|
|
|
{
|
|
|
|
mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn, attackedStack->occupiedHex());
|
|
|
|
}
|
|
|
|
if (mutPos == -1 && attackedStack->doubleWide() && attackingStack->doubleWide())
|
|
|
|
{
|
|
|
|
mutPos = BattleHex::mutualPosition(attackingStackPosBeforeReturn + revShiftattacker, attackedStack->occupiedHex());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch(mutPos) //attack direction
|
|
|
|
{
|
2017-09-08 13:25:12 +02:00
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
2011-12-22 16:05:19 +03:00
|
|
|
group = mutPosToGroup[mutPos];
|
2020-10-06 01:27:04 +02:00
|
|
|
if(attackingStack->hasBonusOfType(Bonus::TWO_HEX_ATTACK_BREATH))
|
2017-09-08 13:25:12 +02:00
|
|
|
{
|
|
|
|
CCreatureAnim::EAnimType group2H = mutPosToGroup2H[mutPos];
|
|
|
|
if(myAnim->framesInGroup(group2H)>0)
|
|
|
|
group = group2H;
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
break;
|
|
|
|
default:
|
2017-08-11 13:38:10 +02:00
|
|
|
logGlobal->error("Critical Error! Wrong dest in stackAttacking! dest: %d; attacking stack pos: %d; mutual pos: %d", dest.hex, attackingStackPosBeforeReturn, mutPos);
|
2011-12-22 16:05:19 +03:00
|
|
|
group = CCreatureAnim::ATTACK_FRONT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CMeleeAttackAnimation::CMeleeAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked)
|
|
|
|
: CAttackAnimation(owner, attacker, _dest, _attacked)
|
2014-09-23 16:02:30 +03:00
|
|
|
{
|
2017-08-10 20:59:55 +02:00
|
|
|
logAnim->debug("Created melee attack anim for %s", attacker->getName());
|
2014-09-23 16:02:30 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CStackMoveAnimation::CStackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex _currentHex):
|
|
|
|
CBattleStackAnimation(owner, _stack),
|
2022-11-28 22:35:38 +02:00
|
|
|
currentHex(_currentHex)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
bool CMovementAnimation::init()
|
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
if( !CBattleAnimation::checkInitialConditions() )
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
|
2022-11-28 22:35:38 +02:00
|
|
|
if(!stack || myAnim->isDeadOrDying())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-20 19:11:34 +02:00
|
|
|
if(stackAnimation(stack)->framesInGroup(CCreatureAnim::MOVING) == 0 ||
|
2013-07-06 19:10:20 +03:00
|
|
|
stack->hasBonus(Selector::typeSubtype(Bonus::FLYING, 1)))
|
2012-09-29 11:35:31 +03:00
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
//no movement or teleport, end immediately
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2012-09-29 11:35:31 +03:00
|
|
|
return false;
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
//reverse unit if necessary
|
2022-12-13 13:58:16 +02:00
|
|
|
if(owner.stacksController->shouldRotate(stack, oldPos, currentHex))
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
// it seems that H3 does NOT plays full rotation animation here in most situations
|
|
|
|
// Logical since it takes quite a lot of time
|
|
|
|
if (curentMoveIndex == 0) // full rotation only for moving towards first tile.
|
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.stacksController->addNewAnim(new CReverseAnimation(owner, stack, oldPos, true));
|
2013-07-06 19:10:20 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-20 19:11:34 +02:00
|
|
|
rotateStack(oldPos);
|
2013-07-06 19:10:20 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
if(myAnim->getType() != CCreatureAnim::MOVING)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
myAnim->setType(CCreatureAnim::MOVING);
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
if (owner.moveSoundHander == -1)
|
2012-05-15 19:29:40 +03:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.moveSoundHander = CCS->soundh->playSound(battle_sound(stack->getCreature(), move), -1);
|
2012-05-15 19:29:40 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
Point begPosition = owner.stacksController->getStackPositionAtHex(oldPos, stack);
|
|
|
|
Point endPosition = owner.stacksController->getStackPositionAtHex(currentHex, stack);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
timeToMove = AnimationControls::getMovementDuration(stack->getCreature());
|
|
|
|
|
|
|
|
begX = begPosition.x;
|
|
|
|
begY = begPosition.y;
|
|
|
|
progress = 0;
|
|
|
|
distanceX = endPosition.x - begPosition.x;
|
|
|
|
distanceY = endPosition.y - begPosition.y;
|
|
|
|
|
2020-11-11 21:43:40 +02:00
|
|
|
if (stack->hasBonus(Selector::type()(Bonus::FLYING)))
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
float distance = static_cast<float>(sqrt(distanceX * distanceX + distanceY * distanceY));
|
2013-07-06 19:10:20 +03:00
|
|
|
|
2013-07-16 21:12:47 +03:00
|
|
|
timeToMove *= AnimationControls::getFlightDistance(stack->getCreature()) / distance;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMovementAnimation::nextFrame()
|
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
progress += float(GH.mainFPSmng->getElapsedMilliseconds()) / 1000 * timeToMove;
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
//moving instructions
|
2013-07-06 19:10:20 +03:00
|
|
|
myAnim->pos.x = static_cast<Sint16>(begX + distanceX * progress );
|
|
|
|
myAnim->pos.y = static_cast<Sint16>(begY + distanceY * progress );
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
CBattleAnimation::nextFrame();
|
|
|
|
|
|
|
|
if(progress >= 1.0)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
// Sets the position of the creature animation sprites
|
2022-12-13 13:58:16 +02:00
|
|
|
Point coords = owner.stacksController->getStackPositionAtHex(currentHex, stack);
|
2013-07-06 19:10:20 +03:00
|
|
|
myAnim->pos = coords;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
// true if creature haven't reached the final destination hex
|
2013-07-06 19:10:20 +03:00
|
|
|
if ((curentMoveIndex + 1) < destTiles.size())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
// update the next hex field which has to be reached by the stack
|
2013-07-06 19:10:20 +03:00
|
|
|
curentMoveIndex++;
|
2022-11-28 22:35:38 +02:00
|
|
|
oldPos = currentHex;
|
|
|
|
currentHex = destTiles[curentMoveIndex];
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
// request re-initialization
|
|
|
|
initialized = false;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
else
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
CMovementAnimation::~CMovementAnimation()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
assert(stack);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
myAnim->pos = owner.stacksController->getStackPositionAtHex(currentHex, stack);
|
|
|
|
owner.stacksController->addNewAnim(new CMovementEndAnimation(owner, stack, currentHex));
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
if(owner.moveSoundHander != -1)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
CCS->soundh->stopSound(owner.moveSoundHander);
|
|
|
|
owner.moveSoundHander = -1;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CMovementAnimation::CMovementAnimation(BattleInterface & owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance)
|
|
|
|
: CStackMoveAnimation(owner, _stack, _destTiles.front()),
|
2020-10-06 01:27:04 +02:00
|
|
|
destTiles(_destTiles),
|
|
|
|
curentMoveIndex(0),
|
|
|
|
oldPos(stack->getPosition()),
|
|
|
|
begX(0), begY(0),
|
|
|
|
distanceX(0), distanceY(0),
|
|
|
|
timeToMove(0.0),
|
2022-11-28 22:35:38 +02:00
|
|
|
progress(0.0)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2017-08-10 20:59:55 +02:00
|
|
|
logAnim->debug("Created movement anim for %s", stack->getName());
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CMovementEndAnimation::CMovementEndAnimation(BattleInterface & owner, const CStack * _stack, BattleHex destTile)
|
|
|
|
: CStackMoveAnimation(owner, _stack, destTile)
|
2014-09-23 16:02:30 +03:00
|
|
|
{
|
2017-08-10 20:59:55 +02:00
|
|
|
logAnim->debug("Created movement end anim for %s", stack->getName());
|
2014-09-23 16:02:30 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
bool CMovementEndAnimation::init()
|
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
//if( !isEarliest(true) )
|
|
|
|
// return false;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
if(!stack || myAnim->framesInGroup(CCreatureAnim::MOVE_END) == 0 ||
|
2022-11-28 22:35:38 +02:00
|
|
|
myAnim->isDeadOrDying())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCS->soundh->playSound(battle_sound(stack->getCreature(), endMoving));
|
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
myAnim->setType(CCreatureAnim::MOVE_END);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
myAnim->onAnimationReset += [&](){ delete this; };
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
return true;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
CMovementEndAnimation::~CMovementEndAnimation()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
if(myAnim->getType() != CCreatureAnim::DEAD)
|
|
|
|
myAnim->setType(CCreatureAnim::HOLDING); //resetting to default
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
CCS->curh->show();
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CMovementStartAnimation::CMovementStartAnimation(BattleInterface & owner, const CStack * _stack)
|
|
|
|
: CStackMoveAnimation(owner, _stack, _stack->getPosition())
|
2014-09-23 16:02:30 +03:00
|
|
|
{
|
2017-08-10 20:59:55 +02:00
|
|
|
logAnim->debug("Created movement start anim for %s", stack->getName());
|
2014-09-23 16:02:30 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
bool CMovementStartAnimation::init()
|
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
if( !CBattleAnimation::checkInitialConditions() )
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
2022-11-28 22:35:38 +02:00
|
|
|
if(!stack || myAnim->isDeadOrDying())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCS->soundh->playSound(battle_sound(stack->getCreature(), startMoving));
|
2013-07-06 19:10:20 +03:00
|
|
|
myAnim->setType(CCreatureAnim::MOVE_START);
|
2022-11-28 16:02:46 +02:00
|
|
|
myAnim->onAnimationReset += [&](){ delete this; };
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CReverseAnimation::CReverseAnimation(BattleInterface & owner, const CStack * stack, BattleHex dest, bool _priority)
|
|
|
|
: CStackMoveAnimation(owner, stack, dest),
|
2022-11-28 16:43:38 +02:00
|
|
|
priority(_priority)
|
2014-09-23 16:02:30 +03:00
|
|
|
{
|
2017-08-10 20:59:55 +02:00
|
|
|
logAnim->debug("Created reverse anim for %s", stack->getName());
|
2014-09-23 16:02:30 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
|
|
|
bool CReverseAnimation::init()
|
|
|
|
{
|
2022-11-28 22:35:38 +02:00
|
|
|
if(myAnim == nullptr || myAnim->isDeadOrDying())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2011-12-22 16:05:19 +03:00
|
|
|
return false; //there is no such creature
|
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
if(!priority && !CBattleAnimation::checkInitialConditions())
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
if(myAnim->framesInGroup(CCreatureAnim::TURN_L))
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
myAnim->setType(CCreatureAnim::TURN_L);
|
|
|
|
myAnim->onAnimationReset += std::bind(&CReverseAnimation::setupSecondPart, this);
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
2013-07-06 19:10:20 +03:00
|
|
|
else
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
setupSecondPart();
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
2013-07-06 19:10:20 +03:00
|
|
|
return true;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
CReverseAnimation::~CReverseAnimation()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
if( stack && stack->alive() )//don't do that if stack is dead
|
2013-07-06 19:10:20 +03:00
|
|
|
myAnim->setType(CCreatureAnim::HOLDING);
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-11-20 19:11:34 +02:00
|
|
|
void CBattleStackAnimation::rotateStack(BattleHex hex)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-11-20 19:11:34 +02:00
|
|
|
setStackFacingRight(stack, !stackFacingRight(stack));
|
2012-09-16 17:36:31 +03:00
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
stackAnimation(stack)->pos = owner.stacksController->getStackPositionAtHex(hex, stack);
|
2013-07-06 19:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CReverseAnimation::setupSecondPart()
|
|
|
|
{
|
|
|
|
if(!stack)
|
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2013-07-06 19:10:20 +03:00
|
|
|
return;
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-11-28 22:35:38 +02:00
|
|
|
rotateStack(currentHex);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
if(myAnim->framesInGroup(CCreatureAnim::TURN_R))
|
|
|
|
{
|
|
|
|
myAnim->setType(CCreatureAnim::TURN_R);
|
2022-11-28 16:02:46 +02:00
|
|
|
myAnim->onAnimationReset += [&](){ delete this; };
|
2013-07-06 19:10:20 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
else
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CRangedAttackAnimation::CRangedAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest_, const CStack * defender)
|
|
|
|
: CAttackAnimation(owner, attacker, dest_, defender),
|
2022-12-01 22:06:42 +02:00
|
|
|
projectileEmitted(false)
|
2017-09-08 13:25:12 +02:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
logAnim->info("Ranged attack animation created");
|
2014-09-23 16:02:30 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
bool CRangedAttackAnimation::init()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
|
|
|
if( !CAttackAnimation::checkInitialConditions() )
|
|
|
|
return false;
|
|
|
|
|
2022-11-28 16:02:46 +02:00
|
|
|
assert(attackingStack);
|
2022-11-28 22:35:38 +02:00
|
|
|
assert(!myAnim->isDeadOrDying());
|
2022-11-28 16:02:46 +02:00
|
|
|
|
2022-11-28 22:35:38 +02:00
|
|
|
if(!attackingStack || myAnim->isDeadOrDying())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-11-25 16:32:23 +02:00
|
|
|
//FIXME: how is this possible?
|
2022-11-27 17:24:45 +02:00
|
|
|
logAnim->warn("Shooting animation has not started yet but attacker is dead! Aborting...");
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-31 20:52:10 +03:00
|
|
|
//reverse unit if necessary
|
2022-12-13 13:58:16 +02:00
|
|
|
if (attackingStack && attackedStack && owner.getCurrentPlayerInterface()->cb->isToReverse(attackingStack->getPosition(), attackedStack->getPosition(), stackFacingRight(attackingStack), attackingStack->doubleWide(), stackFacingRight(attackedStack)))
|
2013-01-31 20:52:10 +03:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.stacksController->addNewAnim(new CReverseAnimation(owner, attackingStack, attackingStack->getPosition(), true));
|
2013-01-31 20:52:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
logAnim->info("Ranged attack animation initialized");
|
2022-11-25 16:32:23 +02:00
|
|
|
setAnimationGroup();
|
2022-11-27 17:24:45 +02:00
|
|
|
initializeProjectile();
|
2022-11-25 16:32:23 +02:00
|
|
|
shooting = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void CRangedAttackAnimation::setAnimationGroup()
|
2022-11-25 16:32:23 +02:00
|
|
|
{
|
|
|
|
Point shooterPos = stackAnimation(attackingStack)->pos.topLeft();
|
2022-12-13 13:58:16 +02:00
|
|
|
Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, attackedStack);
|
2022-11-25 16:32:23 +02:00
|
|
|
|
2013-04-04 21:20:25 +03:00
|
|
|
//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;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-11-27 20:01:52 +02:00
|
|
|
double projectileAngle = -atan2(shotTarget.y - shooterPos.y, std::abs(shotTarget.x - shooterPos.x));
|
2021-01-17 14:02:58 +02:00
|
|
|
|
2022-11-25 16:32:23 +02:00
|
|
|
// Calculate projectile start position. Offsets are read out of the CRANIM.TXT.
|
|
|
|
if (projectileAngle > straightAngle)
|
2022-12-01 22:06:42 +02:00
|
|
|
group = getUpwardsGroup();
|
2022-11-25 16:32:23 +02:00
|
|
|
else if (projectileAngle < -straightAngle)
|
2022-12-01 22:06:42 +02:00
|
|
|
group = getDownwardsGroup();
|
2022-11-25 16:32:23 +02:00
|
|
|
else
|
2022-12-01 22:06:42 +02:00
|
|
|
group = getForwardGroup();
|
2022-11-25 16:32:23 +02:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void CRangedAttackAnimation::initializeProjectile()
|
2022-11-25 16:32:23 +02:00
|
|
|
{
|
2022-11-27 20:01:52 +02:00
|
|
|
const CCreature *shooterInfo = getCreature();
|
2022-12-13 13:58:16 +02:00
|
|
|
Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, attackedStack) + Point(225, 225);
|
2022-11-25 16:32:23 +02:00
|
|
|
Point shotOrigin = stackAnimation(attackingStack)->pos.topLeft() + Point(222, 265);
|
|
|
|
int multiplier = stackFacingRight(attackingStack) ? 1 : -1;
|
2013-04-04 16:18:38 +03:00
|
|
|
|
2022-12-01 23:40:03 +02:00
|
|
|
if (group == getUpwardsGroup())
|
2022-11-17 13:21:03 +02:00
|
|
|
{
|
2022-11-25 16:32:23 +02:00
|
|
|
shotOrigin.x += ( -25 + shooterInfo->animation.upperRightMissleOffsetX ) * multiplier;
|
|
|
|
shotOrigin.y += shooterInfo->animation.upperRightMissleOffsetY;
|
2022-11-17 13:21:03 +02:00
|
|
|
}
|
2022-12-01 23:40:03 +02:00
|
|
|
else if (group == getDownwardsGroup())
|
2013-04-04 21:20:25 +03:00
|
|
|
{
|
2022-11-25 16:32:23 +02:00
|
|
|
shotOrigin.x += ( -25 + shooterInfo->animation.lowerRightMissleOffsetX ) * multiplier;
|
|
|
|
shotOrigin.y += shooterInfo->animation.lowerRightMissleOffsetY;
|
2013-04-04 21:20:25 +03:00
|
|
|
}
|
2022-12-01 23:40:03 +02:00
|
|
|
else if (group == getForwardGroup())
|
2013-04-04 21:20:25 +03:00
|
|
|
{
|
2022-11-25 16:32:23 +02:00
|
|
|
shotOrigin.x += ( -25 + shooterInfo->animation.rightMissleOffsetX ) * multiplier;
|
|
|
|
shotOrigin.y += shooterInfo->animation.rightMissleOffsetY;
|
2013-04-04 21:20:25 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-25 16:32:23 +02:00
|
|
|
assert(0);
|
2022-11-15 21:42:16 +02:00
|
|
|
}
|
2013-04-04 16:18:38 +03:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
createProjectile(shotOrigin, shotTarget);
|
2022-11-25 16:32:23 +02:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void CRangedAttackAnimation::emitProjectile()
|
2022-11-25 16:32:23 +02:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
logAnim->info("Ranged attack projectile emitted");
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.projectilesController->emitStackProjectile(attackingStack);
|
2022-11-25 16:32:23 +02:00
|
|
|
projectileEmitted = true;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void CRangedAttackAnimation::nextFrame()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-11-25 16:32:23 +02:00
|
|
|
for(auto & it : pendingAnimations())
|
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
CMovementStartAnimation * anim = dynamic_cast<CMovementStartAnimation *>(it);
|
|
|
|
CReverseAnimation * anim2 = dynamic_cast<CReverseAnimation *>(it);
|
2022-11-25 16:32:23 +02:00
|
|
|
if( (anim && anim->stack->ID == stack->ID) || (anim2 && anim2->stack->ID == stack->ID && anim2->priority ) )
|
2022-12-01 22:06:42 +02:00
|
|
|
{
|
|
|
|
assert(0); // FIXME: our stack started to move even though we are playing shooting animation? How?
|
2022-11-25 16:32:23 +02:00
|
|
|
return;
|
2022-12-01 22:06:42 +02:00
|
|
|
}
|
2022-11-25 16:32:23 +02:00
|
|
|
}
|
|
|
|
|
2022-11-27 20:01:52 +02:00
|
|
|
// animation should be paused if there is an active projectile
|
|
|
|
if (projectileEmitted)
|
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
if (owner.projectilesController->hasActiveProjectile(attackingStack))
|
2022-11-27 20:01:52 +02:00
|
|
|
stackAnimation(attackingStack)->pause();
|
|
|
|
else
|
|
|
|
stackAnimation(attackingStack)->play();
|
|
|
|
}
|
|
|
|
|
|
|
|
CAttackAnimation::nextFrame();
|
|
|
|
|
2022-11-25 16:32:23 +02:00
|
|
|
if (!projectileEmitted)
|
2022-11-20 19:11:34 +02:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
logAnim->info("Ranged attack executing, %d / %d / %d",
|
|
|
|
stackAnimation(attackingStack)->getCurrentFrame(),
|
2022-12-06 14:12:13 +02:00
|
|
|
getAttackClimaxFrame(),
|
2022-12-01 22:06:42 +02:00
|
|
|
stackAnimation(attackingStack)->framesInGroup(group));
|
|
|
|
|
2022-11-27 17:24:45 +02:00
|
|
|
// emit projectile once animation playback reached "climax" frame
|
2022-12-06 14:12:13 +02:00
|
|
|
if ( stackAnimation(attackingStack)->getCurrentFrame() >= getAttackClimaxFrame() )
|
2022-11-20 19:11:34 +02:00
|
|
|
{
|
2022-11-25 16:32:23 +02:00
|
|
|
emitProjectile();
|
2022-12-01 22:06:42 +02:00
|
|
|
stackAnimation(attackingStack)->pause();
|
2022-11-20 19:11:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
CRangedAttackAnimation::~CRangedAttackAnimation()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
logAnim->info("Ranged attack animation is over");
|
|
|
|
//FIXME: this assert triggers under some unclear, rare conditions. Possibly - if game window is inactive and/or in foreground/minimized?
|
2022-12-13 13:58:16 +02:00
|
|
|
assert(!owner.projectilesController->hasActiveProjectile(attackingStack));
|
2022-11-27 20:01:52 +02:00
|
|
|
assert(projectileEmitted);
|
|
|
|
|
2022-11-20 19:11:34 +02:00
|
|
|
// FIXME: is this possible? Animation is over but we're yet to fire projectile?
|
2022-11-25 16:32:23 +02:00
|
|
|
if (!projectileEmitted)
|
|
|
|
{
|
2022-11-27 17:24:45 +02:00
|
|
|
logAnim->warn("Shooting animation has finished but projectile was not emitted! Emitting it now...");
|
2022-11-25 16:32:23 +02:00
|
|
|
emitProjectile();
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CShootingAnimation::CShootingAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked)
|
|
|
|
: CRangedAttackAnimation(owner, attacker, _dest, _attacked)
|
2017-09-08 13:25:12 +02:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
logAnim->debug("Created shooting anim for %s", stack->getName());
|
2017-09-08 13:25:12 +02:00
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void CShootingAnimation::createProjectile(const Point & from, const Point & dest) const
|
2017-09-08 13:25:12 +02:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.projectilesController->createProjectile(attackingStack, from, dest);
|
2022-12-01 22:06:42 +02:00
|
|
|
}
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-06 14:12:13 +02:00
|
|
|
uint32_t CShootingAnimation::getAttackClimaxFrame() const
|
|
|
|
{
|
|
|
|
const CCreature *shooterInfo = getCreature();
|
|
|
|
return shooterInfo->animation.attackClimaxFrame;
|
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
CCreatureAnim::EAnimType CShootingAnimation::getUpwardsGroup() const
|
|
|
|
{
|
|
|
|
return CCreatureAnim::SHOOT_UP;
|
|
|
|
}
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
CCreatureAnim::EAnimType CShootingAnimation::getForwardGroup() const
|
|
|
|
{
|
|
|
|
return CCreatureAnim::SHOOT_FRONT;
|
|
|
|
}
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
CCreatureAnim::EAnimType CShootingAnimation::getDownwardsGroup() const
|
|
|
|
{
|
|
|
|
return CCreatureAnim::SHOOT_DOWN;
|
|
|
|
}
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CCatapultAnimation::CCatapultAnimation(BattleInterface & owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked, int _catapultDmg)
|
|
|
|
: CShootingAnimation(owner, attacker, _dest, _attacked),
|
2022-12-01 22:06:42 +02:00
|
|
|
catapultDamage(_catapultDmg),
|
|
|
|
explosionEmitted(false)
|
|
|
|
{
|
|
|
|
logAnim->debug("Created shooting anim for %s", stack->getName());
|
|
|
|
}
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void CCatapultAnimation::nextFrame()
|
|
|
|
{
|
|
|
|
CShootingAnimation::nextFrame();
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
if ( explosionEmitted)
|
|
|
|
return;
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
if ( !projectileEmitted)
|
|
|
|
return;
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
if (owner.projectilesController->hasActiveProjectile(attackingStack))
|
2022-12-01 22:06:42 +02:00
|
|
|
return;
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
explosionEmitted = true;
|
2022-12-13 13:58:16 +02:00
|
|
|
Point shotTarget = owner.stacksController->getStackPositionAtHex(dest, attackedStack) + Point(225, 225) - Point(126, 105);
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
if(catapultDamage > 0)
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.stacksController->addNewAnim( new CPointEffectAnimation(owner, soundBase::WALLHIT, "SGEXPL.DEF", shotTarget));
|
2022-12-01 22:06:42 +02:00
|
|
|
else
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.stacksController->addNewAnim( new CPointEffectAnimation(owner, soundBase::WALLMISS, "CSGRCK.DEF", shotTarget));
|
2022-12-01 22:06:42 +02:00
|
|
|
}
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void CCatapultAnimation::createProjectile(const Point & from, const Point & dest) const
|
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.projectilesController->createCatapultProjectile(attackingStack, from, dest);
|
2022-12-01 22:06:42 +02:00
|
|
|
}
|
2017-09-08 13:25:12 +02:00
|
|
|
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CCastAnimation::CCastAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest_, const CStack * defender, const CSpell * spell)
|
|
|
|
: CRangedAttackAnimation(owner, attacker, dest_, defender),
|
2022-12-01 22:06:42 +02:00
|
|
|
spell(spell)
|
|
|
|
{
|
|
|
|
assert(dest.isValid());// FIXME: when?
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
if(!dest_.isValid() && defender)
|
|
|
|
dest = defender->getPosition();
|
|
|
|
}
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
CCreatureAnim::EAnimType CCastAnimation::findValidGroup( const std::vector<CCreatureAnim::EAnimType> candidates ) const
|
|
|
|
{
|
|
|
|
for ( auto group : candidates)
|
2017-09-08 13:25:12 +02:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
if(myAnim->framesInGroup(group) > 0)
|
|
|
|
return group;
|
2017-09-08 13:25:12 +02:00
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
assert(0);
|
|
|
|
return CCreatureAnim::HOLDING;
|
2017-09-08 13:25:12 +02:00
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
CCreatureAnim::EAnimType CCastAnimation::getUpwardsGroup() const
|
2017-09-08 13:25:12 +02:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
return findValidGroup({
|
|
|
|
CCreatureAnim::VCMI_CAST_UP,
|
|
|
|
CCreatureAnim::CAST_UP,
|
|
|
|
CCreatureAnim::SHOOT_UP,
|
|
|
|
CCreatureAnim::ATTACK_UP
|
|
|
|
});
|
|
|
|
}
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
CCreatureAnim::EAnimType CCastAnimation::getForwardGroup() const
|
|
|
|
{
|
|
|
|
return findValidGroup({
|
|
|
|
CCreatureAnim::VCMI_CAST_FRONT,
|
|
|
|
CCreatureAnim::CAST_FRONT,
|
|
|
|
CCreatureAnim::SHOOT_FRONT,
|
|
|
|
CCreatureAnim::ATTACK_FRONT
|
|
|
|
});
|
|
|
|
}
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
CCreatureAnim::EAnimType CCastAnimation::getDownwardsGroup() const
|
|
|
|
{
|
|
|
|
return findValidGroup({
|
|
|
|
CCreatureAnim::VCMI_CAST_DOWN,
|
|
|
|
CCreatureAnim::CAST_DOWN,
|
|
|
|
CCreatureAnim::SHOOT_DOWN,
|
|
|
|
CCreatureAnim::ATTACK_DOWN
|
|
|
|
});
|
2017-09-08 13:25:12 +02:00
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void CCastAnimation::createProjectile(const Point & from, const Point & dest) const
|
2014-09-23 17:30:36 +03:00
|
|
|
{
|
2022-12-01 23:40:03 +02:00
|
|
|
if (!spell->animationInfo.projectile.empty())
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.projectilesController->createSpellProjectile(attackingStack, from, dest, spell);
|
2022-12-01 22:06:42 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2022-12-06 14:12:13 +02:00
|
|
|
uint32_t CCastAnimation::getAttackClimaxFrame() const
|
|
|
|
{
|
|
|
|
//FIXME: allow defining this parameter in config file, separately from attackClimaxFrame of missile attacks
|
|
|
|
uint32_t maxFrames = stackAnimation(attackingStack)->framesInGroup(group);
|
|
|
|
|
|
|
|
if (maxFrames > 2)
|
|
|
|
return maxFrames - 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, soundBase::soundID sound, std::string animationName, int effects):
|
|
|
|
CBattleAnimation(owner),
|
2022-12-01 22:06:42 +02:00
|
|
|
animation(std::make_shared<CAnimation>(animationName)),
|
|
|
|
sound(sound),
|
|
|
|
effectFlags(effects),
|
|
|
|
soundPlayed(false),
|
|
|
|
soundFinished(false),
|
|
|
|
effectFinished(false)
|
|
|
|
{
|
2014-09-23 17:30:36 +03:00
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, soundBase::soundID sound, std::string animationName, std::vector<BattleHex> hex, int effects):
|
|
|
|
CPointEffectAnimation(owner, sound, animationName, effects)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2022-12-02 01:55:09 +02:00
|
|
|
battlehexes = hex;
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, soundBase::soundID sound, std::string animationName, BattleHex hex, int effects):
|
|
|
|
CPointEffectAnimation(owner, sound, animationName, effects)
|
2022-12-01 22:06:42 +02:00
|
|
|
{
|
2022-12-02 01:55:09 +02:00
|
|
|
assert(hex.isValid());
|
|
|
|
battlehexes.push_back(hex);
|
2022-12-01 22:06:42 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, soundBase::soundID sound, std::string animationName, std::vector<Point> pos, int effects):
|
|
|
|
CPointEffectAnimation(owner, sound, animationName, effects)
|
2022-12-01 22:06:42 +02:00
|
|
|
{
|
|
|
|
positions = pos;
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, soundBase::soundID sound, std::string animationName, Point pos, int effects):
|
|
|
|
CPointEffectAnimation(owner, sound, animationName, effects)
|
2014-09-23 17:30:36 +03:00
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
positions.push_back(pos);
|
2014-11-27 15:51:16 +02:00
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CPointEffectAnimation::CPointEffectAnimation(BattleInterface & owner, soundBase::soundID sound, std::string animationName, Point pos, BattleHex hex, int effects):
|
|
|
|
CPointEffectAnimation(owner, sound, animationName, effects)
|
2022-12-02 01:55:09 +02:00
|
|
|
{
|
|
|
|
assert(hex.isValid());
|
|
|
|
battlehexes.push_back(hex);
|
|
|
|
positions.push_back(pos);
|
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
bool CPointEffectAnimation::init()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
if(!CBattleAnimation::checkInitialConditions())
|
2011-12-22 16:05:19 +03:00
|
|
|
return false;
|
2016-11-27 16:48:18 +02:00
|
|
|
|
2017-09-05 16:21:44 +02:00
|
|
|
animation->preload();
|
|
|
|
|
2018-03-30 13:02:04 +02:00
|
|
|
auto first = animation->getImage(0, 0, true);
|
2017-09-05 16:21:44 +02:00
|
|
|
if(!first)
|
2014-11-27 15:51:16 +02:00
|
|
|
{
|
2022-11-28 16:02:46 +02:00
|
|
|
delete this;
|
2017-09-05 16:21:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-02 01:55:09 +02:00
|
|
|
if (screenFill())
|
2017-09-05 16:21:44 +02:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
for(int i=0; i * first->width() < owner.pos.w ; ++i)
|
|
|
|
for(int j=0; j * first->height() < owner.pos.h ; ++j)
|
|
|
|
positions.push_back(Point( owner.pos.x + i * first->width(), owner.pos.y + j * first->height()));
|
2022-12-01 22:06:42 +02:00
|
|
|
}
|
2017-09-05 16:21:44 +02:00
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
BattleEffect be;
|
|
|
|
be.effectID = ID;
|
|
|
|
be.animation = animation;
|
|
|
|
be.currentFrame = 0;
|
2014-11-27 15:51:16 +02:00
|
|
|
|
2022-12-02 01:55:09 +02:00
|
|
|
for (size_t i = 0; i < std::max(battlehexes.size(), positions.size()); ++i)
|
2022-12-01 22:06:42 +02:00
|
|
|
{
|
2022-12-02 01:55:09 +02:00
|
|
|
bool hasTile = i < battlehexes.size();
|
|
|
|
bool hasPosition = i < positions.size();
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-02 01:55:09 +02:00
|
|
|
if (hasTile && !forceOnTop())
|
|
|
|
be.position = battlehexes[i];
|
|
|
|
else
|
|
|
|
be.position = BattleHex::INVALID;
|
2016-11-27 16:48:18 +02:00
|
|
|
|
2022-12-02 01:55:09 +02:00
|
|
|
if (hasPosition)
|
|
|
|
{
|
|
|
|
be.x = positions[i].x;
|
|
|
|
be.y = positions[i].y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
const CStack * destStack = owner.getCurrentPlayerInterface()->cb->battleGetStackByPos(battlehexes[i], false);
|
|
|
|
Rect tilePos = owner.fieldController->hexPositionAbsolute(battlehexes[i]);
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2022-12-02 01:55:09 +02:00
|
|
|
be.x = tilePos.x + tilePos.w/2 - first->width()/2;
|
2013-07-10 13:45:51 +03:00
|
|
|
|
2022-12-02 01:55:09 +02:00
|
|
|
if(destStack && destStack->doubleWide()) // Correction for 2-hex creatures.
|
|
|
|
be.x += (destStack->side == BattleSide::ATTACKER ? -1 : 1)*tilePos.w/2;
|
2014-11-27 15:51:16 +02:00
|
|
|
|
2022-12-02 01:55:09 +02:00
|
|
|
if (alignToBottom())
|
|
|
|
be.y = tilePos.y + tilePos.h - first->height();
|
|
|
|
else
|
|
|
|
be.y = tilePos.y - first->height()/2;
|
|
|
|
}
|
2022-12-13 13:58:16 +02:00
|
|
|
owner.effectsController->battleEffects.push_back(be);
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void CPointEffectAnimation::nextFrame()
|
|
|
|
{
|
|
|
|
playSound();
|
|
|
|
playEffect();
|
|
|
|
|
|
|
|
if (soundFinished && effectFinished)
|
2022-12-02 01:55:09 +02:00
|
|
|
{
|
|
|
|
//remove visual effect itself only if sound has finished as well - necessary for obstacles like force field
|
|
|
|
clearEffect();
|
2022-12-01 22:06:42 +02:00
|
|
|
delete this;
|
2022-12-02 01:55:09 +02:00
|
|
|
}
|
2022-12-01 22:06:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CPointEffectAnimation::alignToBottom() const
|
|
|
|
{
|
|
|
|
return effectFlags & ALIGN_TO_BOTTOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPointEffectAnimation::waitForSound() const
|
|
|
|
{
|
|
|
|
return effectFlags & WAIT_FOR_SOUND;
|
|
|
|
}
|
|
|
|
|
2022-12-02 01:55:09 +02:00
|
|
|
bool CPointEffectAnimation::forceOnTop() const
|
|
|
|
{
|
|
|
|
return effectFlags & FORCE_ON_TOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPointEffectAnimation::screenFill() const
|
|
|
|
{
|
|
|
|
return effectFlags & SCREEN_FILL;
|
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void CPointEffectAnimation::onEffectFinished()
|
|
|
|
{
|
|
|
|
effectFinished = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointEffectAnimation::onSoundFinished()
|
|
|
|
{
|
|
|
|
soundFinished = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointEffectAnimation::playSound()
|
|
|
|
{
|
|
|
|
if (soundPlayed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
soundPlayed = true;
|
|
|
|
if (sound == soundBase::invalid)
|
|
|
|
{
|
|
|
|
onSoundFinished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int channel = CCS->soundh->playSound(sound);
|
|
|
|
|
|
|
|
if (!waitForSound() || channel == -1)
|
|
|
|
onSoundFinished();
|
|
|
|
else
|
|
|
|
CCS->soundh->setCallback(channel, [&](){ onSoundFinished(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointEffectAnimation::playEffect()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-02 01:55:09 +02:00
|
|
|
if ( effectFinished )
|
|
|
|
return;
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
for(auto & elem : owner.effectsController->battleEffects)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
if(elem.effectID == ID)
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2013-07-16 21:12:47 +03:00
|
|
|
elem.currentFrame += AnimationControls::getSpellEffectSpeed() * GH.mainFPSmng->getElapsedMilliseconds() / 1000;
|
2011-12-22 16:05:19 +03:00
|
|
|
|
2017-09-05 16:21:44 +02:00
|
|
|
if(elem.currentFrame >= elem.animation->size())
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-02 01:55:09 +02:00
|
|
|
elem.currentFrame = elem.animation->size() - 1;
|
2022-12-01 22:06:42 +02:00
|
|
|
onEffectFinished();
|
|
|
|
break;
|
2011-12-22 16:05:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 22:06:42 +02:00
|
|
|
void CPointEffectAnimation::clearEffect()
|
2011-12-22 16:05:19 +03:00
|
|
|
{
|
2022-12-13 13:58:16 +02:00
|
|
|
auto & effects = owner.effectsController->battleEffects;
|
2022-11-27 20:01:52 +02:00
|
|
|
|
2022-12-13 15:10:31 +02:00
|
|
|
vstd::erase_if(effects, [&](const BattleEffect & effect){
|
|
|
|
return effect.effectID == ID;
|
|
|
|
});
|
2013-04-09 17:31:36 +03:00
|
|
|
}
|
2022-12-01 22:06:42 +02:00
|
|
|
|
|
|
|
CPointEffectAnimation::~CPointEffectAnimation()
|
|
|
|
{
|
|
|
|
assert(effectFinished);
|
|
|
|
assert(soundFinished);
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CWaitingAnimation::CWaitingAnimation(BattleInterface & owner):
|
|
|
|
CBattleAnimation(owner)
|
2022-12-01 22:06:42 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
void CWaitingAnimation::nextFrame()
|
|
|
|
{
|
|
|
|
// initialization conditions fulfilled, delay is over
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
CWaitingProjectileAnimation::CWaitingProjectileAnimation(BattleInterface & owner, const CStack * shooter):
|
|
|
|
CWaitingAnimation(owner),
|
2022-12-01 22:06:42 +02:00
|
|
|
shooter(shooter)
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool CWaitingProjectileAnimation::init()
|
|
|
|
{
|
|
|
|
for(auto & elem : pendingAnimations())
|
|
|
|
{
|
|
|
|
auto * attackAnim = dynamic_cast<CRangedAttackAnimation *>(elem);
|
|
|
|
|
|
|
|
if( attackAnim && shooter && attackAnim->stack->ID == shooter->ID && !attackAnim->isInitialized() )
|
|
|
|
{
|
|
|
|
// there is ongoing ranged attack that involves our stack, but projectile was not created yet
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:58:16 +02:00
|
|
|
if(owner.projectilesController->hasActiveProjectile(shooter))
|
2022-12-01 22:06:42 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|