Browse Source

* fixed displaying animation of creature starting moving

mateuszb 14 years ago
parent
commit
8a4187df16

+ 1 - 0
client/CAnimation.h

@@ -311,6 +311,7 @@ public:
 
 	enum EAnimType // list of creature animations, numbers were taken from def files
 	{
+		WHOLE_ANIM=-1, //just for convenience
 		MOVING=0, //will automatically add MOVE_START and MOVE_END to queue
 		MOUSEON=1,
 		HOLDING=2,

+ 33 - 30
client/CBattleInterface.cpp

@@ -377,7 +377,7 @@ bool CReverseAnim::init()
 	if(!priority && !isEarliest(false))
 		return false;
 	
-	owner->creAnims[stack->ID]->setType(8);
+	owner->creAnims[stack->ID]->setType(CCreatureAnim::TURN_R);
 
 	return true;
 }
@@ -421,7 +421,7 @@ void CReverseAnim::nextFrame()
 				}
 			}
 
-			owner->creAnims[stack->ID]->setType(7);
+			owner->creAnims[stack->ID]->setType(CCreatureAnim::TURN_L);
 			secondPartSetup = true;
 		}
 
@@ -436,7 +436,7 @@ void CReverseAnim::endAnim()
 {
 	CBattleAnimation::endAnim();
 	if( stack->alive() )//don't do that if stack is dead
-		owner->creAnims[stack->ID]->setType(2);
+		owner->creAnims[stack->ID]->setType(CCreatureAnim::HOLDING);
 
 	delete this;
 }
@@ -515,13 +515,13 @@ bool CDefenceAnim::init()
 	if(killed)
 	{
 		CCS->soundh->playSound(battle_sound(stack->getCreature(), killed));
-		owner->creAnims[stack->ID]->setType(5); //death
+		owner->creAnims[stack->ID]->setType(CCreatureAnim::DEATH); //death
 	}
 	else
 	{
 		// TODO: this block doesn't seems correct if the unit is defending.
 		CCS->soundh->playSound(battle_sound(stack->getCreature(), wince));
-		owner->creAnims[stack->ID]->setType(3); //getting hit
+		owner->creAnims[stack->ID]->setType(CCreatureAnim::HITTED); //getting hit
 	}
 
 	return true; //initialized successfuly
@@ -529,14 +529,14 @@ bool CDefenceAnim::init()
 
 void CDefenceAnim::nextFrame()
 {
-	if(!killed && owner->creAnims[stack->ID]->getType() != 3)
+	if(!killed && owner->creAnims[stack->ID]->getType() != CCreatureAnim::HITTED)
 	{
-		owner->creAnims[stack->ID]->setType(3);
+		owner->creAnims[stack->ID]->setType(CCreatureAnim::HITTED);
 	}
 
 	if(!owner->creAnims[stack->ID]->onLastFrameInGroup())
 	{
-		if( owner->creAnims[stack->ID]->getType() == 5 && (owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0
+		if( owner->creAnims[stack->ID]->getType() == CCreatureAnim::DEATH && (owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0
 			&& !owner->creAnims[stack->ID]->onLastFrameInGroup() )
 		{
 			owner->creAnims[stack->ID]->incrementFrame();
@@ -553,8 +553,8 @@ void CDefenceAnim::endAnim()
 {
 	//restoring animType
 
-	if(owner->creAnims[stack->ID]->getType() == 3)
-		owner->creAnims[stack->ID]->setType(2);
+	if(owner->creAnims[stack->ID]->getType() == CCreatureAnim::HITTED)
+		owner->creAnims[stack->ID]->setType(CCreatureAnim::HOLDING);
 
 	//printing info to console
 
@@ -584,7 +584,7 @@ bool CBattleStackMoved::init()
 		return false;
 
 	//a few useful variables
-	steps = owner->creAnims[stack->ID]->framesInGroup(0)*owner->getAnimSpeedMultiplier()-1;
+	steps = owner->creAnims[stack->ID]->framesInGroup(CCreatureAnim::MOVING)*owner->getAnimSpeedMultiplier()-1;
 	if(steps == 0) //this creature seems to have no move animation so we can end it immediately
 	{
 		endAnim();
@@ -617,9 +617,9 @@ bool CBattleStackMoved::init()
 		return false;
 	}
 
-	if(owner->creAnims[stack->ID]->getType() != 0)
+	if(owner->creAnims[stack->ID]->getType() != CCreatureAnim::MOVING)
 	{
-		owner->creAnims[stack->ID]->setType(0);
+		owner->creAnims[stack->ID]->setType(CCreatureAnim::MOVING);
 	}
 	//unit reversed
 
@@ -740,6 +740,7 @@ bool CBattleMoveStart::init()
 	}
 
 	CCS->soundh->playSound(battle_sound(stack->getCreature(), startMoving));
+	owner->creAnims[stack->ID]->setType(CCreatureAnim::MOVE_START);
 
 	return true;
 }
@@ -752,8 +753,8 @@ void CBattleMoveStart::nextFrame()
 	}
 	else
 	{
-		if((owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0)
-			owner->creAnims[stack->ID]->incrementFrame();
+ 		if((owner->animCount+1)%(4/owner->curInt->sysOpts.animSpeed)==0)
+ 			owner->creAnims[stack->ID]->incrementFrame();
 	}
 }
 
@@ -776,7 +777,8 @@ bool CBattleMoveEnd::init()
 	if( !isEarliest(true) )
 		return false;
 
-	if(!stack || owner->creAnims[stack->ID]->framesInGroup(21) == 0 || owner->creAnims[stack->ID]->getType() == 5)
+	if(!stack || owner->creAnims[stack->ID]->framesInGroup(CCreatureAnim::MOVE_END) == 0 ||
+		owner->creAnims[stack->ID]->getType() == CCreatureAnim::DEATH)
 	{
 		endAnim();
 
@@ -785,7 +787,7 @@ bool CBattleMoveEnd::init()
 
 	CCS->soundh->playSound(battle_sound(stack->getCreature(), endMoving));
 
-	owner->creAnims[stack->ID]->setType(21);
+	owner->creAnims[stack->ID]->setType(CCreatureAnim::MOVE_END);
 
 	return true;
 }
@@ -802,8 +804,8 @@ void CBattleMoveEnd::endAnim()
 {
 	CBattleAnimation::endAnim();
 
-	if(owner->creAnims[stack->ID]->getType() != 5)
-		owner->creAnims[stack->ID]->setType(2); //resetting to default
+	if(owner->creAnims[stack->ID]->getType() != CCreatureAnim::DEATH)
+		owner->creAnims[stack->ID]->setType(CCreatureAnim::HOLDING); //resetting to default
 
 	CCS->curh->show();
 	delete this;
@@ -830,7 +832,7 @@ void CBattleAttack::nextFrame()
 	}
 	else if(owner->creAnims[stack->ID]->onLastFrameInGroup())
 	{
-		owner->creAnims[stack->ID]->setType(2);
+		owner->creAnims[stack->ID]->setType(CCreatureAnim::HOLDING);
 		endAnim();
 		return; //execution of endAnim deletes this !!!
 	}
@@ -888,7 +890,8 @@ bool CMeleeAttack::init()
 
 	shooting = false;
 
-	static const int mutPosToGroup[] = {11, 11, 12, 13, 13, 12};
+	static const CCreatureAnim::EAnimType mutPosToGroup[] = {CCreatureAnim::ATTACK_UP, CCreatureAnim::ATTACK_UP,
+		CCreatureAnim::ATTACK_FRONT, CCreatureAnim::ATTACK_DOWN, CCreatureAnim::ATTACK_DOWN, CCreatureAnim::ATTACK_FRONT};
 
 	int revShiftattacker = (attackingStack->attackerOwned ? -1 : 1);
 
@@ -914,7 +917,7 @@ bool CMeleeAttack::init()
 		break;
 	default:
 		tlog1<<"Critical Error! Wrong dest in stackAttacking! dest: "<<dest<<" attacking stack pos: "<<attackingStackPosBeforeReturn<<" mutual pos: "<<mutPos<<std::endl;
-		group = 11;
+		group = CCreatureAnim::ATTACK_FRONT;
 		break;
 	}
 
@@ -1034,11 +1037,11 @@ bool CShootingAnim::init()
 	shooting = true;
 
 	if(projectileAngle > straightAngle) //upper shot
-		group = 14;
+		group = CCreatureAnim::SHOOT_UP;
 	else if(projectileAngle < -straightAngle) //lower shot
-		group = 16;
+		group = CCreatureAnim::SHOOT_DOWN;
 	else //straight shot
-		group = 15;
+		group = CCreatureAnim::SHOOT_FRONT;
 
 	return true;
 }
@@ -1772,9 +1775,9 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
 						console->alterTxt = buf;
 						console->whoSetAlter = 0;
 						mouseHoveredStack = shere->ID;
-						if(creAnims[shere->ID]->getType() == 2 && creAnims[shere->ID]->framesInGroup(1) > 0)
+						if(creAnims[shere->ID]->getType() == CCreatureAnim::HOLDING && creAnims[shere->ID]->framesInGroup(CCreatureAnim::MOUSEON) > 0)
 						{
-							creAnims[shere->ID]->playOnce(1);
+							creAnims[shere->ID]->playOnce(CCreatureAnim::MOUSEON);
 						}
 						
 					}
@@ -2210,7 +2213,7 @@ void CBattleInterface::newStack(const CStack * stack)
 	{
 		creAnims[stack->ID] = new CCreatureAnimation(stack->getCreature()->animDefName);	
 	}
-	creAnims[stack->ID]->setType(2);
+	creAnims[stack->ID]->setType(CCreatureAnim::HOLDING);
 	creAnims[stack->ID]->pos = Rect(coords.x, coords.y, creAnims[stack->ID]->fullWidth, creAnims[stack->ID]->fullHeight);
 	creDir[stack->ID] = stack->attackerOwned;
 }
@@ -2995,7 +2998,7 @@ void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to)
 			if(incrementFrame)
 			{
 				++standingFrame[ID];
-				if(standingFrame[ID] == creAnims[ID]->framesInGroup(2))
+				if(standingFrame[ID] == creAnims[ID]->framesInGroup(CCreatureAnim::HOLDING))
 				{
 					standingFrame.erase(standingFrame.find(ID));
 				}
@@ -3309,7 +3312,7 @@ void CBattleInterface::startAction(const BattleAction* action)
 		|| (action->actionType == BattleAction::WALK_AND_ATTACK && action->destinationTile != stack->position))
 	{
 		moveStarted = true;
-		if(creAnims[action->stackNumber]->framesInGroup(20))
+		if(creAnims[action->stackNumber]->framesInGroup(CCreatureAnim::MOVE_START))
 		{
 			const CStack * stack = curInt->cb->battleGetStackByID(action->stackNumber);
 			pendingAnims.push_back(std::make_pair(new CBattleMoveStart(this, stack), false));

+ 2 - 1
client/CBattleInterface.h

@@ -5,6 +5,7 @@
 #include <list>
 #include "GUIBase.h"
 #include "../lib/CCreatureSet.h"
+#include "CAnimation.h"
 
 /*
  * CBattleInterface.h, part of VCMI engine
@@ -191,7 +192,7 @@ class CBattleAttack : public CBattleStackAnimation
 protected:
 	THex dest; //atacked hex
 	bool shooting;
-	int group; //if shooting is true, print this animation group
+	CCreatureAnim::EAnimType group; //if shooting is true, print this animation group
 	const CStack * attackedStack;
 	const CStack * attackingStack;
 	int attackingStackPosBeforeReturn; //for stacks with return_after_strike feature

+ 6 - 6
client/CCreatureAnimation.cpp

@@ -14,12 +14,12 @@
  *
  */
 
-int CCreatureAnimation::getType() const
+CCreatureAnim::EAnimType CCreatureAnimation::getType() const
 {
 	return type;
 }
 
-void CCreatureAnimation::setType(int type)
+void CCreatureAnimation::setType(CCreatureAnim::EAnimType type)
 {
 	assert(framesInGroup(type) > 0 && "Bad type for void CCreatureAnimation::setType(int type)!");
 	this->type = type;
@@ -90,7 +90,7 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : internalFrame(0), onc
 
 	//init vars
 	curFrame = 0;
-	type = -1;
+	type = CCreatureAnim::WHOLE_ANIM;
 	frames = totalEntries;
 }
 
@@ -109,7 +109,7 @@ void CCreatureAnimation::incrementFrame()
 			internalFrame = 0;
 			if(once) //playing animation once - return to standing animation
 			{
-				type = 2;
+				type = CCreatureAnim::HOLDING;
 				once = false;
 				curFrame = frameGroups[2][0];
 			}
@@ -145,7 +145,7 @@ bool CCreatureAnimation::onLastFrameInGroup()
 	return false;
 }
 
-void CCreatureAnimation::playOnce(int type)
+void CCreatureAnimation::playOnce( CCreatureAnim::EAnimType type )
 {
 	setType(type);
 	once = true;
@@ -285,7 +285,7 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
 	}
 }
 
-int CCreatureAnimation::framesInGroup(int group) const
+int CCreatureAnimation::framesInGroup(CCreatureAnim::EAnimType group) const
 {
 	if(frameGroups.find(group) == frameGroups.end())
 		return 0;

+ 6 - 5
client/CCreatureAnimation.h

@@ -6,6 +6,7 @@
 #include "CDefHandler.h"
 #include "GUIBase.h"
 #include "../client/CBitmapHandler.h"
+#include "CAnimation.h"
 
 /*
  * CCreatureAnimation.h, part of VCMI engine
@@ -63,15 +64,15 @@ private:
 	unsigned char * FDef; //animation raw data
 	int curFrame, internalFrame; //number of currently displayed frame
 	unsigned int frames; //number of frames
+	CCreatureAnim::EAnimType type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
 public:
 	std::map<int, std::vector<int> > frameGroups; //groups of frames; [groupID] -> vector of frame IDs in group
-	int type; //type of animation being displayed (-1 - whole animation, >0 - specified part [default: -1])
 	int fullWidth, fullHeight; //read-only, please!
 	CCreatureAnimation(std::string name); //c-tor
 	~CCreatureAnimation(); //d-tor
 
-	void setType(int type); //sets type of animation and cleares framecount
-	int getType() const; //returns type of animation
+	void setType(CCreatureAnim::EAnimType type); //sets type of animation and cleares framecount
+	CCreatureAnim::EAnimType getType() const; //returns type of animation
 
 
 	template<int bpp>
@@ -84,9 +85,9 @@ public:
 	bool onLastFrameInGroup();
 
 	bool once;
-	void playOnce(int type); //plays once given stage of animation, then resets to 2
+	void playOnce(CCreatureAnim::EAnimType type); //plays once given stage of animation, then resets to 2
 
-	int framesInGroup(int group) const; //retirns number of fromes in given group
+	int framesInGroup(CCreatureAnim::EAnimType group) const; //retirns number of fromes in given group
 };
 
 #endif // __CCREATUREANIMATION_H__

+ 2 - 2
client/CPlayerInterface.cpp

@@ -579,10 +579,10 @@ void CPlayerInterface::battleStacksHealedRes(const std::vector<std::pair<ui32, u
 	for(int b=0; b<healedStacks.size(); ++b)
 	{
 		const CStack * healed = cb->battleGetStackByID(healedStacks[b].first);
-		if(battleInt->creAnims[healed->ID]->getType() == 5)
+		if(battleInt->creAnims[healed->ID]->getType() == CCreatureAnim::DEATH)
 		{
 			//stack has been resurrected
-			battleInt->creAnims[healed->ID]->setType(2);
+			battleInt->creAnims[healed->ID]->setType(CCreatureAnim::HOLDING);
 		}
 	}