Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp
Show First 20 Lines • Show All 512 Lines • ▼ Show 20 Lines | public: | ||||
virtual bool MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange); | virtual bool MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange); | ||||
virtual bool MoveToTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange); | virtual bool MoveToTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange); | ||||
virtual void MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z); | virtual void MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z); | ||||
virtual void FaceTowardsPoint(entity_pos_t x, entity_pos_t z); | virtual void FaceTowardsPoint(entity_pos_t x, entity_pos_t z); | ||||
virtual void StopMoving() | virtual void StopMoving() | ||||
{ | { | ||||
if (m_FacePointAfterMove) | |||||
{ | |||||
CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | |||||
if (cmpPosition && cmpPosition->IsInWorld()) | |||||
FaceTowardsPointFromPos(cmpPosition->GetPosition2D(), m_FinalGoal.x, m_FinalGoal.z); | |||||
} | |||||
m_MoveRequest = MoveRequest(); | m_MoveRequest = MoveRequest(); | ||||
m_ExpectedPathTicket = 0; | m_ExpectedPathTicket = 0; | ||||
m_State = STATE_STOPPING; | m_State = STATE_STOPPING; | ||||
m_PathState = PATHSTATE_NONE; | m_PathState = PATHSTATE_NONE; | ||||
m_LongPath.m_Waypoints.clear(); | m_LongPath.m_Waypoints.clear(); | ||||
m_ShortPath.m_Waypoints.clear(); | m_ShortPath.m_Waypoints.clear(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | if (m_ShortPath.m_Waypoints.empty()) | ||||
if (!cmpPosition || !cmpPosition->IsInWorld()) | if (!cmpPosition || !cmpPosition->IsInWorld()) | ||||
return; | return; | ||||
CFixedVector2D pos = cmpPosition->GetPosition2D(); | CFixedVector2D pos = cmpPosition->GetPosition2D(); | ||||
if (CloseEnoughFromDestinationToStop(pos)) | if (CloseEnoughFromDestinationToStop(pos)) | ||||
{ | { | ||||
MoveSucceeded(); | MoveSucceeded(); | ||||
if (m_FacePointAfterMove) | |||||
FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z); | |||||
return; | return; | ||||
} | } | ||||
UpdateFinalGoal(); | UpdateFinalGoal(); | ||||
RequestLongPath(pos, m_FinalGoal); | RequestLongPath(pos, m_FinalGoal); | ||||
m_PathState = PATHSTATE_WAITING_REQUESTING_LONG; | m_PathState = PATHSTATE_WAITING_REQUESTING_LONG; | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | case PATHSTATE_FOLLOWING_REQUESTING_LONG: | ||||
{ | { | ||||
// Oops, we hit something (very likely another unit). | // Oops, we hit something (very likely another unit). | ||||
// This is when we might easily get stuck wrongly. | // This is when we might easily get stuck wrongly. | ||||
// check if we've arrived. | // check if we've arrived. | ||||
if (CloseEnoughFromDestinationToStop(pos)) | if (CloseEnoughFromDestinationToStop(pos)) | ||||
{ | { | ||||
MoveSucceeded(); | MoveSucceeded(); | ||||
if (m_FacePointAfterMove) | |||||
FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z); | |||||
return; | return; | ||||
} | } | ||||
// If we still have long waypoints, try and compute a short path | // If we still have long waypoints, try and compute a short path | ||||
// This will get us around units, amongst others. | // This will get us around units, amongst others. | ||||
// However in some cases a long waypoint will be in located in the obstruction of | // However in some cases a long waypoint will be in located in the obstruction of | ||||
// an idle unit. In that case, we need to scrap that waypoint or we might never be able to reach it. | // an idle unit. In that case, we need to scrap that waypoint or we might never be able to reach it. | ||||
// I am not sure why this happens but the following code seems to work. | // I am not sure why this happens but the following code seems to work. | ||||
▲ Show 20 Lines • Show All 708 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator