Index: source/simulation2/components/CCmpUnitMotion.cpp =================================================================== --- source/simulation2/components/CCmpUnitMotion.cpp +++ source/simulation2/components/CCmpUnitMotion.cpp @@ -244,6 +244,12 @@ MoveRequest(CFixedVector2D pos, entity_pos_t minRange, entity_pos_t maxRange) : m_Type(POINT), m_Position(pos), m_MinRange(minRange), m_MaxRange(maxRange) {}; MoveRequest(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) : m_Type(ENTITY), m_Entity(target), m_MinRange(minRange), m_MaxRange(maxRange) {}; MoveRequest(entity_id_t target, CFixedVector2D offset) : m_Type(OFFSET), m_Entity(target), m_Position(offset) {}; + + bool operator==(const MoveRequest& o) + { + return m_Type == o.m_Type && m_Entity == o.m_Entity && m_Position == o.m_Position && m_MinRange == o.m_MinRange && m_MaxRange == o.m_MaxRange; + } + } m_MoveRequest; // If the entity moves, it will do so at m_WalkSpeed * m_SpeedMultiplier. @@ -816,6 +822,28 @@ if (m_State == STATE_IDLE) return; + if (m_MoveRequest.m_Type == MoveRequest::ENTITY) + { + CFixedVector2D targetPos; + MoveRequest oldRequest = m_MoveRequest; + // If we can't compute our target position, our move will likely fail. + if (!ComputeTargetPosition(targetPos)) + { + MoveFailed(); + + // If following this message our orders were not changed, stop moving, + // since we don't know where the target is, and following the last known position + // is not a decision for UnitMotion to take (and it makes unhandled situations more obvious). + // However, if the order changed and we are computing a new path, + // keep the waypoints so that we don't stop for a turn and then start walking again, as that looks better. + if (m_MoveRequest == oldRequest) + { + m_LongPath.m_Waypoints.clear(); + m_ShortPath.m_Waypoints.clear(); + } + } + } + if (PossiblyAtDestination()) MoveSucceeded();