Index: ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp =================================================================== --- ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp +++ ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp @@ -634,6 +634,13 @@ bool ShouldTreatTargetAsCircle(entity_pos_t range, entity_pos_t circleRadius) const; /** + * Returns true if the target position is valid. False otherwise. + * (this may indicate that the target is e.g. out of the world/dead). + * NB: for code-writing convenience, if we have no target, this returns true. + */ + bool TargetHasValidPosition() const; + + /** * Computes the current location of our target entity (plus offset). * Returns false if no target entity or no valid position. */ @@ -818,6 +825,18 @@ if (PossiblyAtDestination()) MoveSucceeded(); + else if (!TargetHasValidPosition()) + { + // Scrap waypoints - we don't know where to go. + // If the move request remains unchanged and the target again has a valid position later on, + // moving will be resumed. + // Units may want to move to move to the target's last known position, + // but that should be decided by UnitAI (handling MoveFailed), not UnitMotion. + m_LongPath.m_Waypoints.clear(); + m_ShortPath.m_Waypoints.clear(); + + MoveFailed(); + } CmpPtr cmpPosition(GetEntityHandle()); if (!cmpPosition || !cmpPosition->IsInWorld()) @@ -1057,6 +1076,15 @@ return true; } +bool CCmpUnitMotion::TargetHasValidPosition() const +{ + if (m_MoveRequest.m_Type != MoveRequest::ENTITY) + return true; + + CmpPtr cmpPosition(GetSimContext(), m_MoveRequest.m_Entity); + return cmpPosition && cmpPosition->IsInWorld(); +} + bool CCmpUnitMotion::ComputeTargetPosition(CFixedVector2D& out) const { if (m_MoveRequest.m_Entity == INVALID_ENTITY)