Przeglądaj źródła

Fix stack rendering order during movement

Ivan Savenko 2 lat temu
rodzic
commit
6c04581655

+ 18 - 18
client/battle/BattleAnimationClasses.cpp

@@ -316,9 +316,10 @@ MeleeAttackAnimation::MeleeAttackAnimation(BattleInterface & owner, const CStack
 	setGroup(selectGroup(multiAttack));
 	setGroup(selectGroup(multiAttack));
 }
 }
 
 
-StackMoveAnimation::StackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex _currentHex):
+StackMoveAnimation::StackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex prevHex, BattleHex nextHex):
 	BattleStackAnimation(owner, _stack),
 	BattleStackAnimation(owner, _stack),
-	currentHex(_currentHex)
+	prevHex(prevHex),
+	nextHex(nextHex)
 {
 {
 }
 }
 
 
@@ -341,14 +342,14 @@ bool MovementAnimation::init()
 		return false;
 		return false;
 	}
 	}
 
 
-	logAnim->info("CMovementAnimation::init: stack %s moves %d -> %d", stack->getName(), oldPos, currentHex);
+	logAnim->info("CMovementAnimation::init: stack %s moves %d -> %d", stack->getName(), prevHex, nextHex);
 
 
 	//reverse unit if necessary
 	//reverse unit if necessary
-	if(owner.stacksController->shouldRotate(stack, oldPos, currentHex))
+	if(owner.stacksController->shouldRotate(stack, prevHex, nextHex))
 	{
 	{
 		// it seems that H3 does NOT plays full rotation animation during movement
 		// it seems that H3 does NOT plays full rotation animation during movement
 		// Logical since it takes quite a lot of time
 		// Logical since it takes quite a lot of time
-		rotateStack(oldPos);
+		rotateStack(prevHex);
 	}
 	}
 
 
 	if(myAnim->getType() != ECreatureAnimType::MOVING)
 	if(myAnim->getType() != ECreatureAnimType::MOVING)
@@ -361,8 +362,8 @@ bool MovementAnimation::init()
 		owner.moveSoundHander = CCS->soundh->playSound(battle_sound(stack->getCreature(), move), -1);
 		owner.moveSoundHander = CCS->soundh->playSound(battle_sound(stack->getCreature(), move), -1);
 	}
 	}
 
 
-	Point begPosition = owner.stacksController->getStackPositionAtHex(oldPos, stack);
-	Point endPosition = owner.stacksController->getStackPositionAtHex(currentHex, stack);
+	Point begPosition = owner.stacksController->getStackPositionAtHex(prevHex, stack);
+	Point endPosition = owner.stacksController->getStackPositionAtHex(nextHex, stack);
 
 
 	timeToMove = AnimationControls::getMovementDuration(stack->getCreature());
 	timeToMove = AnimationControls::getMovementDuration(stack->getCreature());
 
 
@@ -395,7 +396,7 @@ void MovementAnimation::nextFrame()
 	if(progress >= 1.0)
 	if(progress >= 1.0)
 	{
 	{
 		// Sets the position of the creature animation sprites
 		// Sets the position of the creature animation sprites
-		Point coords = owner.stacksController->getStackPositionAtHex(currentHex, stack);
+		Point coords = owner.stacksController->getStackPositionAtHex(nextHex, stack);
 		myAnim->pos.moveTo(coords);
 		myAnim->pos.moveTo(coords);
 
 
 		// true if creature haven't reached the final destination hex
 		// true if creature haven't reached the final destination hex
@@ -403,8 +404,8 @@ void MovementAnimation::nextFrame()
 		{
 		{
 			// update the next hex field which has to be reached by the stack
 			// update the next hex field which has to be reached by the stack
 			curentMoveIndex++;
 			curentMoveIndex++;
-			oldPos = currentHex;
-			currentHex = destTiles[curentMoveIndex];
+			prevHex = nextHex;
+			nextHex = destTiles[curentMoveIndex];
 
 
 			// request re-initialization
 			// request re-initialization
 			initialized = false;
 			initialized = false;
@@ -418,7 +419,7 @@ MovementAnimation::~MovementAnimation()
 {
 {
 	assert(stack);
 	assert(stack);
 
 
-	myAnim->pos.moveTo(owner.stacksController->getStackPositionAtHex(currentHex, stack));
+	myAnim->pos.moveTo(owner.stacksController->getStackPositionAtHex(nextHex, stack));
 
 
 	if(owner.moveSoundHander != -1)
 	if(owner.moveSoundHander != -1)
 	{
 	{
@@ -427,11 +428,10 @@ MovementAnimation::~MovementAnimation()
 	}
 	}
 }
 }
 
 
-MovementAnimation::MovementAnimation(BattleInterface & owner, const CStack *_stack, std::vector<BattleHex> _destTiles, int _distance)
-	: StackMoveAnimation(owner, _stack, _destTiles.front()),
+MovementAnimation::MovementAnimation(BattleInterface & owner, const CStack *stack, std::vector<BattleHex> _destTiles, int _distance)
+	: StackMoveAnimation(owner, stack, stack->getPosition(), _destTiles.front()),
 	  destTiles(_destTiles),
 	  destTiles(_destTiles),
 	  curentMoveIndex(0),
 	  curentMoveIndex(0),
-	  oldPos(stack->getPosition()),
 	  begX(0), begY(0),
 	  begX(0), begY(0),
 	  distanceX(0), distanceY(0),
 	  distanceX(0), distanceY(0),
 	  timeToMove(0.0),
 	  timeToMove(0.0),
@@ -441,7 +441,7 @@ MovementAnimation::MovementAnimation(BattleInterface & owner, const CStack *_sta
 }
 }
 
 
 MovementEndAnimation::MovementEndAnimation(BattleInterface & owner, const CStack * _stack, BattleHex destTile)
 MovementEndAnimation::MovementEndAnimation(BattleInterface & owner, const CStack * _stack, BattleHex destTile)
-: StackMoveAnimation(owner, _stack, destTile)
+: StackMoveAnimation(owner, _stack, destTile, destTile)
 {
 {
 	logAnim->debug("Created movement end anim for %s", stack->getName());
 	logAnim->debug("Created movement end anim for %s", stack->getName());
 }
 }
@@ -483,7 +483,7 @@ MovementEndAnimation::~MovementEndAnimation()
 }
 }
 
 
 MovementStartAnimation::MovementStartAnimation(BattleInterface & owner, const CStack * _stack)
 MovementStartAnimation::MovementStartAnimation(BattleInterface & owner, const CStack * _stack)
-	: StackMoveAnimation(owner, _stack, _stack->getPosition())
+	: StackMoveAnimation(owner, _stack, _stack->getPosition(), _stack->getPosition())
 {
 {
 	logAnim->debug("Created movement start anim for %s", stack->getName());
 	logAnim->debug("Created movement start anim for %s", stack->getName());
 }
 }
@@ -514,7 +514,7 @@ bool MovementStartAnimation::init()
 }
 }
 
 
 ReverseAnimation::ReverseAnimation(BattleInterface & owner, const CStack * stack, BattleHex dest)
 ReverseAnimation::ReverseAnimation(BattleInterface & owner, const CStack * stack, BattleHex dest)
-	: StackMoveAnimation(owner, stack, dest)
+	: StackMoveAnimation(owner, stack, dest, dest)
 {
 {
 	logAnim->debug("Created reverse anim for %s", stack->getName());
 	logAnim->debug("Created reverse anim for %s", stack->getName());
 }
 }
@@ -560,7 +560,7 @@ void ReverseAnimation::setupSecondPart()
 		return;
 		return;
 	}
 	}
 
 
-	rotateStack(currentHex);
+	rotateStack(nextHex);
 
 
 	if(myAnim->framesInGroup(ECreatureAnimType::TURN_R))
 	if(myAnim->framesInGroup(ECreatureAnimType::TURN_R))
 	{
 	{

+ 3 - 4
client/battle/BattleAnimationClasses.h

@@ -136,10 +136,11 @@ public:
 class StackMoveAnimation : public BattleStackAnimation
 class StackMoveAnimation : public BattleStackAnimation
 {
 {
 public:
 public:
-	BattleHex currentHex;
+	BattleHex nextHex;
+	BattleHex prevHex;
 
 
 protected:
 protected:
-	StackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex _currentHex);
+	StackMoveAnimation(BattleInterface & owner, const CStack * _stack, BattleHex prevHex, BattleHex nextHex);
 };
 };
 
 
 /// Move animation of a creature
 /// Move animation of a creature
@@ -149,8 +150,6 @@ private:
 	std::vector<BattleHex> destTiles; //full path, includes already passed hexes
 	std::vector<BattleHex> destTiles; //full path, includes already passed hexes
 	ui32 curentMoveIndex; // index of nextHex in destTiles
 	ui32 curentMoveIndex; // index of nextHex in destTiles
 
 
-	BattleHex oldPos; //position of stack before move
-
 	double begX, begY; // starting position
 	double begX, begY; // starting position
 	double distanceX, distanceY; // full movement distance, may be negative if creture moves topleft
 	double distanceX, distanceY; // full movement distance, may be negative if creture moves topleft
 
 

+ 1 - 1
client/battle/BattleStacksController.cpp

@@ -122,7 +122,7 @@ BattleHex BattleStacksController::getStackCurrentPosition(const CStack * stack)
 		if (StackMoveAnimation *move = dynamic_cast<StackMoveAnimation*>(anim))
 		if (StackMoveAnimation *move = dynamic_cast<StackMoveAnimation*>(anim))
 		{
 		{
 			if (move->stack == stack)
 			if (move->stack == stack)
-				return move->currentHex;
+				return std::max(move->prevHex, move->nextHex);
 		}
 		}
 	}
 	}
 	return stack->getPosition();
 	return stack->getPosition();