Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpUnitMotion.cpp
Show First 20 Lines • Show All 542 Lines • ▼ Show 20 Lines | private: | ||||
{ | { | ||||
return m_PathState == PATHSTATE_FOLLOWING | return m_PathState == PATHSTATE_FOLLOWING | ||||
|| m_PathState == PATHSTATE_FOLLOWING_REQUESTING_LONG | || m_PathState == PATHSTATE_FOLLOWING_REQUESTING_LONG | ||||
|| m_PathState == PATHSTATE_FOLLOWING_REQUESTING_SHORT; | || m_PathState == PATHSTATE_FOLLOWING_REQUESTING_SHORT; | ||||
} | } | ||||
void MoveFailed() | void MoveFailed() | ||||
{ | { | ||||
StopMoving(); | |||||
CmpPtr<ICmpObstruction> cmpObstruction(GetEntityHandle()); | CmpPtr<ICmpObstruction> cmpObstruction(GetEntityHandle()); | ||||
if (cmpObstruction) | if (cmpObstruction) | ||||
cmpObstruction->SetMovingFlag(false); | cmpObstruction->SetMovingFlag(false); | ||||
CMessageMotionChanged msg(true); | CMessageMotionChanged msg(true); | ||||
GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); | GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | if (ticket != m_ExpectedPathTicket) | ||||
return; | return; | ||||
m_ExpectedPathTicket = 0; // we don't expect to get this result again | m_ExpectedPathTicket = 0; // we don't expect to get this result again | ||||
// Check that we are still able to do something with that path | // Check that we are still able to do something with that path | ||||
CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | ||||
if (!cmpPosition || !cmpPosition->IsInWorld()) | if (!cmpPosition || !cmpPosition->IsInWorld()) | ||||
{ | { | ||||
if (m_PathState == PATHSTATE_WAITING_REQUESTING_LONG || m_PathState == PATHSTATE_WAITING_REQUESTING_SHORT) | // We will probably fail to move so inform components but keep on trying anyways. | ||||
MoveFailed(); | MoveFailed(); | ||||
else if (m_PathState == PATHSTATE_FOLLOWING_REQUESTING_LONG || m_PathState == PATHSTATE_FOLLOWING_REQUESTING_SHORT) | |||||
StopMoving(); | |||||
return; | return; | ||||
} | } | ||||
if (m_PathState == PATHSTATE_WAITING_REQUESTING_LONG || m_PathState == PATHSTATE_FOLLOWING_REQUESTING_LONG) | if (m_PathState == PATHSTATE_WAITING_REQUESTING_LONG || m_PathState == PATHSTATE_FOLLOWING_REQUESTING_LONG) | ||||
{ | { | ||||
m_LongPath = path; | m_LongPath = path; | ||||
// If we are following a path, leave the old m_ShortPath so we can carry on following it | // If we are following a path, leave the old m_ShortPath so we can carry on following it | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if (m_ShortPath.m_Waypoints.empty()) | ||||
CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | ||||
if (!cmpPosition || !cmpPosition->IsInWorld()) | if (!cmpPosition || !cmpPosition->IsInWorld()) | ||||
return; | return; | ||||
CFixedVector2D pos = cmpPosition->GetPosition2D(); | CFixedVector2D pos = cmpPosition->GetPosition2D(); | ||||
if (CloseEnoughFromDestinationToStop(pos)) | if (CloseEnoughFromDestinationToStop(pos)) | ||||
{ | { | ||||
StopMoving(); | |||||
MoveSucceeded(); | MoveSucceeded(); | ||||
if (m_FacePointAfterMove) | if (m_FacePointAfterMove) | ||||
FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z); | FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z); | ||||
return; | return; | ||||
} | } | ||||
UpdateFinalGoal(); | UpdateFinalGoal(); | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | case PATHSTATE_FOLLOWING_REQUESTING_LONG: | ||||
if (wasObstructed) | if (wasObstructed) | ||||
{ | { | ||||
// 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)) | ||||
{ | { | ||||
StopMoving(); | |||||
MoveSucceeded(); | MoveSucceeded(); | ||||
if (m_FacePointAfterMove) | if (m_FacePointAfterMove) | ||||
FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z); | FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z); | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | if (m_PathState == PATHSTATE_FOLLOWING) | ||||
CMessageMotionChanged msg(false); | CMessageMotionChanged msg(false); | ||||
GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); | GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// check if target was reached in case of a moving target | // check if target was reached in case of a moving target | ||||
CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), m_TargetEntity); | CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); | ||||
if (cmpUnitMotion && cmpUnitMotion->IsMoving() && | if (cmpObstructionManager->IsInTargetRange(GetEntityId(), m_TargetEntity, m_TargetMinRange, m_TargetMaxRange, false)) | ||||
MoveToTargetRange(m_TargetEntity, m_TargetMinRange, m_TargetMaxRange)) | |||||
{ | { | ||||
// Not in formation, so just finish moving | |||||
StopMoving(); | |||||
m_State = STATE_IDLE; | m_State = STATE_IDLE; | ||||
MoveSucceeded(); | MoveSucceeded(); | ||||
if (m_FacePointAfterMove) | if (m_FacePointAfterMove) | ||||
FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z); | FaceTowardsPointFromPos(pos, m_FinalGoal.x, m_FinalGoal.z); | ||||
// TODO: if the goal was a square building, we ought to point towards the | // TODO: if the goal was a square building, we ought to point towards the | ||||
// nearest point on the square, not towards its center | // nearest point on the square, not towards its center | ||||
} | } | ||||
▲ Show 20 Lines • Show All 638 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator