From b546c96193ca9f3094dd66311a2c9249cda9592b Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Mon, 7 Aug 2023 01:46:03 -0700 Subject: [PATCH] Add reversing --- dGame/dComponents/MovementAIComponent.cpp | 9 +++++++++ dGame/dComponents/MovementAIComponent.h | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index f0487ad5..f13ba0c8 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -141,6 +141,15 @@ nextAction: Game::entityManager->SerializeEntity(m_Parent); } +void MovementAIComponent::ReversePath() { + if (m_CurrentPath.empty()) return; + if (m_NextPathWaypointIndex < 0) m_NextPathWaypointIndex = 0; + if (m_NextPathWaypointIndex >= m_CurrentPath.size()) m_NextPathWaypointIndex = m_CurrentPath.size() - 1; + m_CurrentPathWaypointIndex = m_NextPathWaypointIndex; + m_IsInReverse = !m_IsInReverse; + AdvancePathWaypointIndex(); +} + bool MovementAIComponent::AdvancePathWaypointIndex() { m_CurrentPathWaypointIndex = m_NextPathWaypointIndex; if (m_IsInReverse) { diff --git a/dGame/dComponents/MovementAIComponent.h b/dGame/dComponents/MovementAIComponent.h index 76d12b32..00143ccf 100644 --- a/dGame/dComponents/MovementAIComponent.h +++ b/dGame/dComponents/MovementAIComponent.h @@ -175,8 +175,15 @@ public: bool IsPaused() const { return m_IsPaused; } + /** + * Pauses the current pathing of this entity. The current path waypoint will be saved for resuming later. + */ void Pause(); + /** + * Resumes pathing from the current position to the destination that was set + * when the entity was paused. + */ void Resume(); /** @@ -184,6 +191,8 @@ public: */ void Stop(); + void ReversePath(); + /** * Stops the current movement and moves the entity to a certain point. Will continue until it's close enough, * after which its AI is enabled again.