1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-09 07:13:54 +02:00

- minor fixes to battle animations

- fixes crash on siege start
This commit is contained in:
Ivan Savenko 2013-07-16 22:59:39 +00:00
parent 1a77fee7f7
commit 43db5587a1
4 changed files with 43 additions and 37 deletions

View File

@ -198,10 +198,10 @@ bool CDefenceAnimation::init()
// wait for 1/2 of attack animation
if (!rangedAttack && getMyAnimType() != CCreatureAnim::DEFENCE)
{
float fps = AnimationControls::getCreatureAnimationSpeed(
float frameLength = AnimationControls::getCreatureAnimationSpeed(
stack->getCreature(), owner->creAnims[stack->ID], getMyAnimType());
timeToWait = myAnim->framesInGroup(getMyAnimType()) / fps;
timeToWait = myAnim->framesInGroup(getMyAnimType()) * frameLength / 2;
myAnim->setType(CCreatureAnim::HOLDING);
}

View File

@ -601,7 +601,7 @@ void CBattleInterface::show(SDL_Surface * to)
SDL_SetClipRect(to, &pos);
//printing background and hexes
if(activeStack != nullptr && creAnims[activeStack->ID]->getType() != CCreatureAnim::MOVING) //show everything with range
if(activeStack != nullptr && creAnims[activeStack->ID]->isIdle()) //show everything with range
{
blitAt(backgroundWithHexes, pos.x, pos.y, to);
}

View File

@ -485,6 +485,8 @@ void CBattleResultWindow::bExitf()
Point CClickableHex::getXYUnitAnim(BattleHex hexNum, const CStack * stack, CBattleInterface * cbi)
{
assert(cbi);
Point ret(-500, -500); //returned value
if(stack && stack->position < 0) //creatures in turrets
{
@ -506,28 +508,29 @@ Point CClickableHex::getXYUnitAnim(BattleHex hexNum, const CStack * stack, CBatt
static const Point basePos(-190, -139); // position of creature in topleft corner
static const int imageShiftX = 30; // X offset to base pos for facing right stacks, negative for facing left
ret.y = basePos.y + 42 * hexNum.getY(); //counting y
//counting x
if(cbi->creDir[stack->ID])
ret.x = basePos.x + 22 * ( (hexNum.getY() + 1)%2 ) + 44 * hexNum.getX();
ret.y = basePos.y + 42 * hexNum.getY();
if (stack)
{
ret.x = basePos.x + imageShiftX + 22 * ( (hexNum.getY() + 1)%2 ) + 44 * hexNum.getX();
}
else
{
ret.x = basePos.x - imageShiftX + 22 * ( (hexNum.getY() + 1)%2 ) + 44 * hexNum.getX();
}
//shifting position for double - hex creatures
if(stack && stack->doubleWide())
{
if(stack->attackerOwned)
{
if(cbi->creDir[stack->ID])
ret.x -= 44;
}
if(cbi->creDir[stack->ID])
ret.x += imageShiftX;
else
ret.x -= imageShiftX;
//shifting position for double - hex creatures
if(stack->doubleWide())
{
if(!cbi->creDir[stack->ID])
ret.x += 44;
if(stack->attackerOwned)
{
if(cbi->creDir[stack->ID])
ret.x -= 44;
}
else
{
if(!cbi->creDir[stack->ID])
ret.x += 44;
}
}
}
}

View File

@ -48,19 +48,24 @@ CCreatureAnimation * AnimationControls::getAnimation(const CCreature * creature)
float AnimationControls::getCreatureAnimationSpeed(const CCreature * creature, const CCreatureAnimation * anim, size_t group)
{
CCreatureAnim::EAnimType type = CCreatureAnim::EAnimType(group);
assert(creature->animation.walkAnimationTime != 0);
assert(creature->animation.attackAnimationTime != 0);
assert(anim->framesInGroup(type) != 0);
// possible new fields for creature format:
//split "Attack time" into "Shoot Time" and "Cast Time"
// a lot of arbitrary multipliers, mostly to make animation speed closer to H3
CCreatureAnim::EAnimType type = CCreatureAnim::EAnimType(group);
const float baseSpeed = 10;
const float speedMult = settings["battle"]["animationSpeed"].Float() * 20;
const float speed = baseSpeed * speedMult;
const float baseSpeed = 0.1;
const float speedMult = settings["battle"]["animationSpeed"].Float();
const float speed = baseSpeed / speedMult;
switch (type)
{
case CCreatureAnim::MOVING:
return speed / creature->animation.walkAnimationTime / anim->framesInGroup(type);
return speed * 2 * creature->animation.walkAnimationTime / anim->framesInGroup(type);
case CCreatureAnim::MOUSEON:
case CCreatureAnim::HOLDING:
@ -72,30 +77,28 @@ float AnimationControls::getCreatureAnimationSpeed(const CCreature * creature, c
case CCreatureAnim::CAST_UP:
case CCreatureAnim::CAST_FRONT:
case CCreatureAnim::CAST_DOWN:
return speed * 2 / creature->animation.attackAnimationTime / anim->framesInGroup(type);
return speed * 4 * creature->animation.attackAnimationTime / anim->framesInGroup(type);
// as strange as it looks like "attackAnimationTime" does not affects melee attacks
// necessary because length of attack animation must be same for all creatures for synchronization
// necessary because length of these animations must be same for all creatures for synchronization
case CCreatureAnim::ATTACK_UP:
case CCreatureAnim::ATTACK_FRONT:
case CCreatureAnim::ATTACK_DOWN:
case CCreatureAnim::HITTED:
case CCreatureAnim::DEFENCE:
return speed * 2 / anim->framesInGroup(type);
case CCreatureAnim::DEATH:
case CCreatureAnim::HITTED: // time-wise equals 1/2 of attack animation length
return speed / anim->framesInGroup(type);
return speed * 3 / anim->framesInGroup(type);
case CCreatureAnim::TURN_L:
case CCreatureAnim::TURN_R:
return speed;
return speed / 3;
case CCreatureAnim::MOVE_START:
case CCreatureAnim::MOVE_END:
return speed / 5;
return speed / 3;
case CCreatureAnim::DEAD:
return speed / 5;
return speed;
default:
assert(0);
@ -433,5 +436,5 @@ void CCreatureAnimation::pause()
void CCreatureAnimation::play()
{
speed = speedController(this, type);
speed = 1 / speedController(this, type);
}