Jelajahi Sumber

Instant movement is now part of standard movement

Ivan Savenko 1 tahun lalu
induk
melakukan
6352f268b2
2 mengubah file dengan 44 tambahan dan 56 penghapusan
  1. 41 52
      client/HeroMovementController.cpp
  2. 3 4
      client/HeroMovementController.h

+ 41 - 52
client/HeroMovementController.cpp

@@ -244,7 +244,7 @@ void HeroMovementController::onMoveHeroApplied()
 	}
 	else
 	{
-		moveOnce(hero, LOCPLINT->localState->getPath(hero));
+		sendMovementRequest(hero, LOCPLINT->localState->getPath(hero));
 	}
 }
 
@@ -336,26 +336,50 @@ void HeroMovementController::requestMovementStart(const CGHeroInstance * h, cons
 {
 	assert(duringMovement == false);
 
+	duringMovement = true;
+	currentlyMovingHero = h;
+
+	CCS->curh->hide();
+	sendMovementRequest(h, path);
+}
+
+void HeroMovementController::sendMovementRequest(const CGHeroInstance * h, const CGPath & path)
+{
+	assert(duringMovement == true);
+
 	int heroMovementSpeed = settings["adventure"]["heroMoveTime"].Integer();
-	bool heroMovementInterruptible = heroMovementSpeed != 0;
+	bool useMovementBatching = heroMovementSpeed == 0;
 
-	if (heroMovementInterruptible)
-	{
-		duringMovement = true;
-		currentlyMovingHero = h;
+	const auto & currNode = path.currNode();
+	const auto & nextNode = path.nextNode();
+
+	assert(nextNode.turns == 0);
+	assert(currNode.coord == h->visitablePos());
 
-		CCS->curh->hide();
-		moveOnce(h, path);
+	if(nextNode.isTeleportAction())
+	{
+		stopMovementSound();
+		logGlobal->trace("Requesting hero teleportation to %s", nextNode.coord.toString());
+		LOCPLINT->cb->moveHero(h, h->pos, false);
+		return;
 	}
-	else
+
+	if (!useMovementBatching)
 	{
-		moveInstant(h, path);
+		updateMovementSound(h, currNode.coord, nextNode.coord, nextNode.action);
+
+		assert(h->pos.z == nextNode.coord.z); // Z should change only if it's movement via teleporter and in this case this code shouldn't be executed at all
+
+		logGlobal->trace("Requesting hero movement to %s", nextNode.coord.toString());
+
+		bool useTransit = nextNode.layer == EPathfindingLayer::AIR || nextNode.layer == EPathfindingLayer::WATER;
+		int3 nextCoord = h->convertFromVisitablePos(nextNode.coord);
+
+		LOCPLINT->cb->moveHero(h, nextCoord, useTransit);
+		return;
 	}
-}
 
-void HeroMovementController::moveInstant(const CGHeroInstance * h, const CGPath & path)
-{
-	bool useTransit = path.nextNode().layer == EPathfindingLayer::AIR || path.nextNode().layer == EPathfindingLayer::WATER;
+	bool useTransitAtStart = path.nextNode().layer == EPathfindingLayer::AIR || path.nextNode().layer == EPathfindingLayer::WATER;
 	std::vector<int3> pathToMove;
 
 	for (auto const & node : boost::adaptors::reverse(path.nodes))
@@ -370,7 +394,7 @@ void HeroMovementController::moveInstant(const CGHeroInstance * h, const CGPath
 			break; // ran out of move points
 
 		bool useTransitHere = node.layer == EPathfindingLayer::AIR || node.layer == EPathfindingLayer::WATER;
-		if (useTransitHere != useTransit)
+		if (useTransitHere != useTransitAtStart)
 			break;
 
 		int3 coord = h->convertFromVisitablePos(node.coord);
@@ -383,45 +407,10 @@ void HeroMovementController::moveInstant(const CGHeroInstance * h, const CGPath
 			break; // we reached event, garrison or some other visitable object - end this movement batch
 	}
 
+	assert(!pathToMove.empty());
 	if (!pathToMove.empty())
-	{
-		//updateMovementSound(h, path.currNode().coord, path.nextNode().coord, path.nextNode().action);
-		LOCPLINT->cb->moveHero(h, pathToMove, useTransit);
-	}
-}
-
-void HeroMovementController::moveOnce(const CGHeroInstance * h, const CGPath & path)
-{
-	// Moves hero once, sends request to server and immediately returns
-	// movement alongside paths will be done on receiving response from server
-
-	assert(duringMovement == true);
-
-	const auto & currNode = path.currNode();
-	const auto & nextNode = path.nextNode();
-
-	assert(nextNode.turns == 0);
-	assert(currNode.coord == h->visitablePos());
-
-	int3 nextCoord = h->convertFromVisitablePos(nextNode.coord);
-
-	if(nextNode.isTeleportAction())
-	{
-		stopMovementSound();
-		logGlobal->trace("Requesting hero teleportation to %s", nextNode.coord.toString());
-		LOCPLINT->cb->moveHero(h, h->pos, false);
-		return;
-	}
-	else
 	{
 		updateMovementSound(h, currNode.coord, nextNode.coord, nextNode.action);
-
-		assert(h->pos.z == nextNode.coord.z); // Z should change only if it's movement via teleporter and in this case this code shouldn't be executed at all
-
-		logGlobal->trace("Requesting hero movement to %s", nextNode.coord.toString());
-
-		bool useTransit = nextNode.layer == EPathfindingLayer::AIR || nextNode.layer == EPathfindingLayer::WATER;
-		LOCPLINT->cb->moveHero(h, nextCoord, useTransit);
-		return;
+		LOCPLINT->cb->moveHero(h, pathToMove, useTransitAtStart);
 	}
 }

+ 3 - 4
client/HeroMovementController.h

@@ -42,10 +42,9 @@ class HeroMovementController
 
 	void updatePath(const CGHeroInstance * hero, const TryMoveHero & details);
 
-	/// Moves hero 1 tile / path node
-	void moveOnce(const CGHeroInstance * h, const CGPath & path);
-
-	void moveInstant(const CGHeroInstance * h, const CGPath & path);
+	/// Sends one request to server to move selected hero alongside path.
+	/// Automatically selects between single-tile and multi-tile movement modes
+	void sendMovementRequest(const CGHeroInstance * h, const CGPath & path);
 
 	void endMove(const CGHeroInstance * h);