Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp
Show First 20 Lines • Show All 668 Lines • ▼ Show 20 Lines | if (m_ShortPath.m_Waypoints.empty()) | ||||
if (CloseEnoughFromDestinationToStop(pos)) | if (CloseEnoughFromDestinationToStop(pos)) | ||||
{ | { | ||||
MoveSucceeded(); | MoveSucceeded(); | ||||
return; | return; | ||||
} | } | ||||
PathGoal goal; | PathGoal goal; | ||||
ComputeGoal(goal, m_MoveRequest); | if (ComputeGoal(goal, m_MoveRequest)) | ||||
RequestLongPath(pos, goal); | RequestLongPath(pos, goal); | ||||
return; | return; | ||||
} | } | ||||
// else we could, so reset our number of tries. | // else we could, so reset our number of tries. | ||||
m_Tries = 0; | m_Tries = 0; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | void CCmpUnitMotion::Move(fixed dt) | ||||
if (wasObstructed && HandleObstructedMove()) | if (wasObstructed && HandleObstructedMove()) | ||||
return; | return; | ||||
// We may need to recompute our path sometimes (e.g. if our target moves). | // We may need to recompute our path sometimes (e.g. if our target moves). | ||||
// Since we request paths asynchronously anyways, this does not need to be done before moving. | // Since we request paths asynchronously anyways, this does not need to be done before moving. | ||||
if (PathingUpdateNeeded(pos)) | if (PathingUpdateNeeded(pos)) | ||||
{ | { | ||||
PathGoal goal; | PathGoal goal; | ||||
ComputeGoal(goal, m_MoveRequest); | if (ComputeGoal(goal, m_MoveRequest)) | ||||
BeginPathing(pos, goal); | BeginPathing(pos, goal); | ||||
} | } | ||||
} | } | ||||
bool CCmpUnitMotion::PossiblyAtDestination() const | bool CCmpUnitMotion::PossiblyAtDestination() const | ||||
{ | { | ||||
if (m_MoveRequest.m_Type == MoveRequest::NONE) | if (m_MoveRequest.m_Type == MoveRequest::NONE) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | bool CCmpUnitMotion::HandleObstructedMove() | ||||
{ | { | ||||
PathGoal goal = { PathGoal::POINT, m_LongPath.m_Waypoints.back().x, m_LongPath.m_Waypoints.back().z }; | PathGoal goal = { PathGoal::POINT, m_LongPath.m_Waypoints.back().x, m_LongPath.m_Waypoints.back().z }; | ||||
RequestShortPath(pos, goal, true); | RequestShortPath(pos, goal, true); | ||||
return true; | return true; | ||||
} | } | ||||
// Else, just entirely recompute | // Else, just entirely recompute | ||||
PathGoal goal; | PathGoal goal; | ||||
ComputeGoal(goal, m_MoveRequest); | if (!ComputeGoal(goal, m_MoveRequest)) | ||||
return false; | |||||
BeginPathing(pos, goal); | BeginPathing(pos, goal); | ||||
// potential TODO: We could switch the short-range pathfinder for something else entirely. | // potential TODO: We could switch the short-range pathfinder for something else entirely. | ||||
return true; | return true; | ||||
} | } | ||||
bool CCmpUnitMotion::TargetHasValidPosition(const MoveRequest& moveRequest) const | bool CCmpUnitMotion::TargetHasValidPosition(const MoveRequest& moveRequest) const | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | if ((targetPos - from).CompareLength(DIRECT_PATH_RANGE) > 0) | ||||
return false; | return false; | ||||
CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity()); | CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity()); | ||||
if (!cmpPathfinder) | if (!cmpPathfinder) | ||||
return false; | return false; | ||||
// Move the goal to match the target entity's new position | // Move the goal to match the target entity's new position | ||||
PathGoal goal; | PathGoal goal; | ||||
ComputeGoal(goal, m_MoveRequest); | if (!ComputeGoal(goal, m_MoveRequest)) | ||||
return false; | |||||
goal.x = targetPos.X; | goal.x = targetPos.X; | ||||
goal.z = targetPos.Y; | goal.z = targetPos.Y; | ||||
// (we ignore changes to the target's rotation, since only buildings are | // (we ignore changes to the target's rotation, since only buildings are | ||||
// square and buildings don't move) | // square and buildings don't move) | ||||
// Find the point on the goal shape that we should head towards | // Find the point on the goal shape that we should head towards | ||||
CFixedVector2D goalPos = goal.NearestPointOnGoal(from); | CFixedVector2D goalPos = goal.NearestPointOnGoal(from); | ||||
▲ Show 20 Lines • Show All 430 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator