From b659edd980f359a7fc64bb003eb4dcb79adc2c8a Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Mon, 14 Aug 2023 20:28:27 -0700 Subject: [PATCH] Yes --- dGame/dComponents/MovementAIComponent.cpp | 19 ++++++++++++++++++- dGame/dComponents/MovementAIComponent.h | 9 +++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index 107a3344..12443e0e 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -48,6 +48,7 @@ MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) : m_TimeTravelled = 0; m_CurrentSpeed = 0; m_MaxSpeed = 0; + m_StartingWaypointIndex = 0; m_CurrentPathWaypointIndex = 0; m_LockRotation = false; m_IsInReverse = false; @@ -65,12 +66,21 @@ void MovementAIComponent::SetupPath(const std::string& pathname) { if (pathData) { Game::logger->Log("MovementAIComponent", "found path %i %s", m_Parent->GetLOT(), path.c_str()); m_Path = pathData; + if (!HasAttachedPathStart() && m_Parent->HasVar(u"attached_path_start")) m_StartingWaypointIndex = m_Parent->GetVar(u"attached_path_start"); + if (m_Path && HasAttachedPathStart() && (m_StartingWaypointIndex < 0 || m_StartingWaypointIndex >= m_Path->pathWaypoints.size())) { + Game::logger->Log( + "MovementAIComponent", + "WARNING: attached path start is out of bounds for %i:%llu, defaulting path start to 0", + m_Parent->GetLOT(), m_Parent->GetObjectID()); + m_StartingWaypointIndex = 0; + } + if (m_Parent->GetLOT() == 12215) m_StartingWaypointIndex = 3; std::vector waypoints; for (auto& waypoint : m_Path->pathWaypoints) { waypoints.push_back(waypoint.position); } SetPath(waypoints); - SetMaxSpeed(30.0f); + SetMaxSpeed(3.0f); } else { Game::logger->Log("MovementAIComponent", "No path found for %i:%llu", m_Parent->GetLOT(), m_Parent->GetObjectID()); } @@ -324,6 +334,13 @@ void MovementAIComponent::SetPath(std::vector path, bool startInRevers // This is so AdvancePathWaypointIndex can do the recovery from effectively a paused state. m_CurrentPathWaypointIndex = m_IsInReverse ? m_CurrentPath.size() - 1 : 0; m_NextPathWaypointIndex = m_IsInReverse ? m_CurrentPath.size() - 1 : 0; + + if (HasAttachedPathStart()) { + m_CurrentPathWaypointIndex = m_StartingWaypointIndex; + m_NextPathWaypointIndex = m_StartingWaypointIndex; + m_Parent->SetPosition(m_CurrentPath.at(m_CurrentPathWaypointIndex)); + } + AdvancePathWaypointIndex(); SetDestination(GetCurrentPathWaypoint()); } diff --git a/dGame/dComponents/MovementAIComponent.h b/dGame/dComponents/MovementAIComponent.h index 9473957a..8e1ae878 100644 --- a/dGame/dComponents/MovementAIComponent.h +++ b/dGame/dComponents/MovementAIComponent.h @@ -216,6 +216,10 @@ public: const NiPoint3& GetCurrentPathWaypoint() const; + void SetPathStartingWaypointIndex(int32_t value) { m_StartingWaypointIndex = value; } + + bool HasAttachedPathStart() const { return m_StartingWaypointIndex != -1; } + /** * Returns the base speed from the DB for a given LOT * @param lot the lot to check for @@ -367,6 +371,11 @@ private: * The optional path this component will follow. */ const Path* m_Path = nullptr; + + /** + * The starting index for the provided path + */ + int32_t m_StartingWaypointIndex = -1; }; #endif // MOVEMENTAICOMPONENT_H