From a9376eeebbdc5862755922147ba40c6bf226b97e Mon Sep 17 00:00:00 2001 From: mimo Date: Mon, 15 Feb 2016 19:30:17 +0000 Subject: [PATCH] update goal before pathing when moving target refs #3472 and improve unitMotion overlay This was SVN commit r17764. --- .../simulation2/components/CCmpUnitMotion.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source/simulation2/components/CCmpUnitMotion.cpp b/source/simulation2/components/CCmpUnitMotion.cpp index fa11df69f6..ef21879e53 100644 --- a/source/simulation2/components/CCmpUnitMotion.cpp +++ b/source/simulation2/components/CCmpUnitMotion.cpp @@ -665,6 +665,11 @@ private: */ bool CheckTargetMovement(const CFixedVector2D& from, entity_pos_t minDelta); + /** + * Update goal position if moving target + */ + bool UpdateFinalGoal(); + /** * Returns whether we are close enough to the target to assume it's a good enough * position to stop. @@ -811,6 +816,7 @@ void CCmpUnitMotion::PathResult(u32 ticket, const WaypointPath& path) if (ShouldConsiderOurselvesAtDestination(pos)) return; + UpdateFinalGoal(); RequestLongPath(pos, m_FinalGoal); m_PathState = PATHSTATE_WAITING_REQUESTING_LONG; return; @@ -1034,6 +1040,7 @@ void CCmpUnitMotion::Move(fixed dt) } } // Else, just entirely recompute + UpdateFinalGoal(); BeginPathing(pos, m_FinalGoal); // potential TODO: We could switch the short-range pathfinder for something else entirely. @@ -1259,6 +1266,23 @@ bool CCmpUnitMotion::CheckTargetMovement(const CFixedVector2D& from, entity_pos_ return true; } +bool CCmpUnitMotion::UpdateFinalGoal() +{ + if (m_TargetEntity == INVALID_ENTITY) + return false; + CmpPtr cmpUnitMotion(GetSimContext(), m_TargetEntity); + if (!cmpUnitMotion) + return false; + if (IsFormationMember()) + return false; + CFixedVector2D targetPos; + if (!ComputeTargetPosition(targetPos)) + return false; + m_FinalGoal.x = targetPos.X; + m_FinalGoal.z = targetPos.Y; + return true; +} + bool CCmpUnitMotion::ShouldConsiderOurselvesAtDestination(const CFixedVector2D& from) { if (m_TargetEntity != INVALID_ENTITY || m_FinalGoal.DistanceToPoint(from) > SHORT_PATH_GOAL_RADIUS) @@ -1827,6 +1851,10 @@ void CCmpUnitMotion::RenderPath(const WaypointPath& path, std::vectorGetPosition2D().X.ToFloat(); + float z = cmpPosition->GetPosition2D().Y.ToFloat(); + waypointCoords.push_back(x); + waypointCoords.push_back(z); lines.push_back(SOverlayLine()); lines.back().m_Color = color; SimRender::ConstructLineOnGround(GetSimContext(), waypointCoords, lines.back(), floating);