Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp
Show First 20 Lines • Show All 628 Lines • ▼ Show 20 Lines | private: | ||||
/** | /** | ||||
* Decide whether to approximate the given range from a square target as a circle, | * Decide whether to approximate the given range from a square target as a circle, | ||||
* rather than as a square. | * rather than as a square. | ||||
*/ | */ | ||||
bool ShouldTreatTargetAsCircle(entity_pos_t range, entity_pos_t circleRadius) const; | 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). | * Computes the current location of our target entity (plus offset). | ||||
* Returns false if no target entity or no valid position. | * Returns false if no target entity or no valid position. | ||||
*/ | */ | ||||
bool ComputeTargetPosition(CFixedVector2D& out) const; | bool ComputeTargetPosition(CFixedVector2D& out) const; | ||||
/** | /** | ||||
* Attempts to replace the current path with a straight line to the goal, | * Attempts to replace the current path with a straight line to the goal, | ||||
* if this goal is a point, is close enough and the route is not obstructed. | * if this goal is a point, is close enough and the route is not obstructed. | ||||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | if (m_State == STATE_STOPPING) | ||||
return; | return; | ||||
} | } | ||||
if (m_State == STATE_IDLE) | if (m_State == STATE_IDLE) | ||||
return; | return; | ||||
if (PossiblyAtDestination()) | if (PossiblyAtDestination()) | ||||
MoveSucceeded(); | 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<ICmpPosition> cmpPosition(GetEntityHandle()); | CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | ||||
if (!cmpPosition || !cmpPosition->IsInWorld()) | if (!cmpPosition || !cmpPosition->IsInWorld()) | ||||
return; | return; | ||||
CFixedVector2D initialPos = cmpPosition->GetPosition2D(); | CFixedVector2D initialPos = cmpPosition->GetPosition2D(); | ||||
// Keep track of the current unit's position during the update | // Keep track of the current unit's position during the update | ||||
▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | bool CCmpUnitMotion::HandleObstructedMove() | ||||
// Else, just entirely recompute | // Else, just entirely recompute | ||||
UpdateFinalGoal(); | UpdateFinalGoal(); | ||||
BeginPathing(pos, m_FinalGoal); | BeginPathing(pos, m_FinalGoal); | ||||
// 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 | |||||
{ | |||||
if (m_MoveRequest.m_Type != MoveRequest::ENTITY) | |||||
return true; | |||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_MoveRequest.m_Entity); | |||||
return cmpPosition && cmpPosition->IsInWorld(); | |||||
} | |||||
bool CCmpUnitMotion::ComputeTargetPosition(CFixedVector2D& out) const | bool CCmpUnitMotion::ComputeTargetPosition(CFixedVector2D& out) const | ||||
{ | { | ||||
if (m_MoveRequest.m_Entity == INVALID_ENTITY) | if (m_MoveRequest.m_Entity == INVALID_ENTITY) | ||||
return false; | return false; | ||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_MoveRequest.m_Entity); | CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), m_MoveRequest.m_Entity); | ||||
if (!cmpPosition || !cmpPosition->IsInWorld()) | if (!cmpPosition || !cmpPosition->IsInWorld()) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 598 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator