Browse Source

- minor fixes to battle animations
- fixes crash on siege start

Ivan Savenko 12 years ago
parent
commit
43db5587a1

+ 2 - 2
client/battle/CBattleAnimations.cpp

@@ -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);
 	}

+ 1 - 1
client/battle/CBattleInterface.cpp

@@ -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);
 	}

+ 22 - 19
client/battle/CBattleInterfaceClasses.cpp

@@ -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 + 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())
+		ret.x = basePos.x + 22 * ( (hexNum.getY() + 1)%2 ) + 44 * hexNum.getX();
+		ret.y = basePos.y + 42 * hexNum.getY();
+
+		if (stack)
 		{
-			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;
+				}
 			}
 		}
 	}

+ 18 - 15
client/battle/CCreatureAnimation.cpp

@@ -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);
 }