mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-23 00:28:08 +02:00
- minor fixes to battle animations
- fixes crash on siege start
This commit is contained in:
@ -198,10 +198,10 @@ bool CDefenceAnimation::init()
|
|||||||
// wait for 1/2 of attack animation
|
// wait for 1/2 of attack animation
|
||||||
if (!rangedAttack && getMyAnimType() != CCreatureAnim::DEFENCE)
|
if (!rangedAttack && getMyAnimType() != CCreatureAnim::DEFENCE)
|
||||||
{
|
{
|
||||||
float fps = AnimationControls::getCreatureAnimationSpeed(
|
float frameLength = AnimationControls::getCreatureAnimationSpeed(
|
||||||
stack->getCreature(), owner->creAnims[stack->ID], getMyAnimType());
|
stack->getCreature(), owner->creAnims[stack->ID], getMyAnimType());
|
||||||
|
|
||||||
timeToWait = myAnim->framesInGroup(getMyAnimType()) / fps;
|
timeToWait = myAnim->framesInGroup(getMyAnimType()) * frameLength / 2;
|
||||||
|
|
||||||
myAnim->setType(CCreatureAnim::HOLDING);
|
myAnim->setType(CCreatureAnim::HOLDING);
|
||||||
}
|
}
|
||||||
|
@ -601,7 +601,7 @@ void CBattleInterface::show(SDL_Surface * to)
|
|||||||
SDL_SetClipRect(to, &pos);
|
SDL_SetClipRect(to, &pos);
|
||||||
|
|
||||||
//printing background and hexes
|
//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);
|
blitAt(backgroundWithHexes, pos.x, pos.y, to);
|
||||||
}
|
}
|
||||||
|
@ -485,6 +485,8 @@ void CBattleResultWindow::bExitf()
|
|||||||
|
|
||||||
Point CClickableHex::getXYUnitAnim(BattleHex hexNum, const CStack * stack, CBattleInterface * cbi)
|
Point CClickableHex::getXYUnitAnim(BattleHex hexNum, const CStack * stack, CBattleInterface * cbi)
|
||||||
{
|
{
|
||||||
|
assert(cbi);
|
||||||
|
|
||||||
Point ret(-500, -500); //returned value
|
Point ret(-500, -500); //returned value
|
||||||
if(stack && stack->position < 0) //creatures in turrets
|
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 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
|
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
|
ret.x = basePos.x + 22 * ( (hexNum.getY() + 1)%2 ) + 44 * hexNum.getX();
|
||||||
//counting x
|
ret.y = basePos.y + 42 * hexNum.getY();
|
||||||
if(cbi->creDir[stack->ID])
|
|
||||||
|
if (stack)
|
||||||
{
|
{
|
||||||
ret.x = basePos.x + imageShiftX + 22 * ( (hexNum.getY() + 1)%2 ) + 44 * hexNum.getX();
|
if(cbi->creDir[stack->ID])
|
||||||
}
|
ret.x += imageShiftX;
|
||||||
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;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
ret.x -= imageShiftX;
|
||||||
|
|
||||||
|
//shifting position for double - hex creatures
|
||||||
|
if(stack->doubleWide())
|
||||||
{
|
{
|
||||||
if(!cbi->creDir[stack->ID])
|
if(stack->attackerOwned)
|
||||||
ret.x += 44;
|
{
|
||||||
|
if(cbi->creDir[stack->ID])
|
||||||
|
ret.x -= 44;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!cbi->creDir[stack->ID])
|
||||||
|
ret.x += 44;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,19 +48,24 @@ CCreatureAnimation * AnimationControls::getAnimation(const CCreature * creature)
|
|||||||
|
|
||||||
float AnimationControls::getCreatureAnimationSpeed(const CCreature * creature, const CCreatureAnimation * anim, size_t group)
|
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:
|
// possible new fields for creature format:
|
||||||
//split "Attack time" into "Shoot Time" and "Cast Time"
|
//split "Attack time" into "Shoot Time" and "Cast Time"
|
||||||
|
|
||||||
// a lot of arbitrary multipliers, mostly to make animation speed closer to H3
|
// a lot of arbitrary multipliers, mostly to make animation speed closer to H3
|
||||||
CCreatureAnim::EAnimType type = CCreatureAnim::EAnimType(group);
|
const float baseSpeed = 0.1;
|
||||||
const float baseSpeed = 10;
|
const float speedMult = settings["battle"]["animationSpeed"].Float();
|
||||||
const float speedMult = settings["battle"]["animationSpeed"].Float() * 20;
|
const float speed = baseSpeed / speedMult;
|
||||||
const float speed = baseSpeed * speedMult;
|
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case CCreatureAnim::MOVING:
|
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::MOUSEON:
|
||||||
case CCreatureAnim::HOLDING:
|
case CCreatureAnim::HOLDING:
|
||||||
@ -72,30 +77,28 @@ float AnimationControls::getCreatureAnimationSpeed(const CCreature * creature, c
|
|||||||
case CCreatureAnim::CAST_UP:
|
case CCreatureAnim::CAST_UP:
|
||||||
case CCreatureAnim::CAST_FRONT:
|
case CCreatureAnim::CAST_FRONT:
|
||||||
case CCreatureAnim::CAST_DOWN:
|
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
|
// 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_UP:
|
||||||
case CCreatureAnim::ATTACK_FRONT:
|
case CCreatureAnim::ATTACK_FRONT:
|
||||||
case CCreatureAnim::ATTACK_DOWN:
|
case CCreatureAnim::ATTACK_DOWN:
|
||||||
|
case CCreatureAnim::HITTED:
|
||||||
case CCreatureAnim::DEFENCE:
|
case CCreatureAnim::DEFENCE:
|
||||||
return speed * 2 / anim->framesInGroup(type);
|
|
||||||
|
|
||||||
case CCreatureAnim::DEATH:
|
case CCreatureAnim::DEATH:
|
||||||
case CCreatureAnim::HITTED: // time-wise equals 1/2 of attack animation length
|
return speed * 3 / anim->framesInGroup(type);
|
||||||
return speed / anim->framesInGroup(type);
|
|
||||||
|
|
||||||
case CCreatureAnim::TURN_L:
|
case CCreatureAnim::TURN_L:
|
||||||
case CCreatureAnim::TURN_R:
|
case CCreatureAnim::TURN_R:
|
||||||
return speed;
|
return speed / 3;
|
||||||
|
|
||||||
case CCreatureAnim::MOVE_START:
|
case CCreatureAnim::MOVE_START:
|
||||||
case CCreatureAnim::MOVE_END:
|
case CCreatureAnim::MOVE_END:
|
||||||
return speed / 5;
|
return speed / 3;
|
||||||
|
|
||||||
case CCreatureAnim::DEAD:
|
case CCreatureAnim::DEAD:
|
||||||
return speed / 5;
|
return speed;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
@ -433,5 +436,5 @@ void CCreatureAnimation::pause()
|
|||||||
|
|
||||||
void CCreatureAnimation::play()
|
void CCreatureAnimation::play()
|
||||||
{
|
{
|
||||||
speed = speedController(this, type);
|
speed = 1 / speedController(this, type);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user