Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp
Show First 20 Lines • Show All 1,069 Lines • ▼ Show 20 Lines | bool CCmpUnitMotion::HandleObstructedMove() | ||||
CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | ||||
if (!cmpPosition || !cmpPosition->IsInWorld()) | if (!cmpPosition || !cmpPosition->IsInWorld()) | ||||
return false; | return false; | ||||
if (m_FailedPathComputations >= 1) | if (m_FailedPathComputations >= 1) | ||||
// Inform other components - we might be ordered to stop, and computeGoal will then fail and return early. | // Inform other components - we might be ordered to stop, and computeGoal will then fail and return early. | ||||
MoveObstructed(); | MoveObstructed(); | ||||
CFixedVector2D pos = cmpPosition->GetPosition2D(); | |||||
// Oops, we hit something (very likely another unit). | |||||
PathGoal goal; | PathGoal goal; | ||||
if (!ComputeGoal(goal, m_MoveRequest)) | if (!ComputeGoal(goal, m_MoveRequest)) | ||||
return false; | return false; | ||||
// At this point we have a position in the world since ComputeGoal checked for that. | |||||
CFixedVector2D pos = cmpPosition->GetPosition2D(); | |||||
if (!InShortPathRange(goal, pos)) | if (!InShortPathRange(goal, pos)) | ||||
{ | { | ||||
// If we still have long waypoints, try and compute a short path to our next long waypoint. | // If we still have long waypoints, try and compute a short path to our next long waypoint. | ||||
// Assume the next waypoint is impassable and pop it. This helps unstuck entities in some cases, and we'll just | // Assume the next waypoint is impassable and pop it. This helps unstuck entities in some cases, and we'll just | ||||
// end up recomputing a long path if we pop all of them, so it's safe. | // end up recomputing a long path if we pop all of them, so it's safe. | ||||
if (m_LongPath.m_Waypoints.size() >= 1) | if (m_LongPath.m_Waypoints.size() >= 1) | ||||
m_LongPath.m_Waypoints.pop_back(); | m_LongPath.m_Waypoints.pop_back(); | ||||
if (!m_LongPath.m_Waypoints.empty()) | if (!m_LongPath.m_Waypoints.empty()) | ||||
▲ Show 20 Lines • Show All 492 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator