mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 18:01:39 +00:00
fix(movement): a bounce path turns round at its ends without reaching them twice
PathFollowWaypointsHelper goes on to waypoint 1, or to the one before the last, when it runs off an end of a bounce path. Here the turned path started with the waypoint the object stood on, so that waypoint was reached again at once and its commands ran twice. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -259,7 +259,12 @@ void MovementAIComponent::Run(const float deltaTime) {
|
||||
m_IsBounced = !m_IsBounced;
|
||||
std::vector<PathWaypoint> waypoints = m_Path->pathWaypoints;
|
||||
if (m_IsBounced) std::ranges::reverse(waypoints);
|
||||
// It turns round at the end: on to the waypoint before it, not to the end again
|
||||
// (PathFollowWaypointsHelper: waypoint 1, or count - 2)
|
||||
const bool turns = waypoints.size() > 1;
|
||||
if (turns) waypoints.erase(waypoints.begin());
|
||||
SetPath(waypoints);
|
||||
if (turns && !m_IsBounced) m_CurrentPathStart = 1;
|
||||
} else if (m_Path->pathBehavior == PathBehavior::Once) {
|
||||
// In this case we intended to follow a path and once we've followed it we camp there, otherwise we'd just wander home again.
|
||||
Stop();
|
||||
|
||||
@@ -121,3 +121,18 @@ TEST_F(MovementAIPathTest, ChangeWaypointCommandWithoutAWaypointStartsAtTheFirst
|
||||
|
||||
EXPECT_EQ(reached, (std::vector<uint32_t>{ 0, 0, 1, 2 }));
|
||||
}
|
||||
|
||||
// PathFollowWaypointsHelper turns round at an end: the end waypoint is reached once, then the one before it
|
||||
TEST_F(MovementAIPathTest, BouncePathReachesEachEndOnce) {
|
||||
AddPath(MakePath("BouncePath", 3, PathBehavior::Bounce));
|
||||
Entity entity(304, info);
|
||||
auto* const movement = Walker(entity);
|
||||
movement->SetPath("BouncePath");
|
||||
Walk(*movement, 120.0f);
|
||||
|
||||
ASSERT_GE(reached.size(), 9u);
|
||||
reached.resize(9);
|
||||
EXPECT_EQ(reached, (std::vector<uint32_t>{ 0, 1, 2, 1, 0, 1, 2, 1, 0 }));
|
||||
const std::vector<float> expectedX{ 10.0f, 20.0f, 30.0f, 20.0f, 10.0f, 20.0f, 30.0f, 20.0f, 10.0f };
|
||||
for (size_t i = 0; i < expectedX.size(); i++) EXPECT_NEAR(reachedX[i], expectedX[i], 0.01f) << i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user