Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpUnitMotion.cpp
Show First 20 Lines • Show All 700 Lines • ▼ Show 20 Lines | else if (m_PathState == PATHSTATE_WAITING_REQUESTING_SHORT || m_PathState == PATHSTATE_FOLLOWING_REQUESTING_SHORT) | ||||
if (m_ShortPath.m_Waypoints.empty()) | if (m_ShortPath.m_Waypoints.empty()) | ||||
{ | { | ||||
// If we're globally following a long path, try to remove the next waypoint, it might be obstructed | // If we're globally following a long path, try to remove the next waypoint, it might be obstructed | ||||
// If not, and we are not in a formation, retry | // If not, and we are not in a formation, retry | ||||
// unless we are close to our target and we don't have a target entity. | // unless we are close to our target and we don't have a target entity. | ||||
// This makes sure that units don't clump too much when they are not in a formation and tasked to move. | // This makes sure that units don't clump too much when they are not in a formation and tasked to move. | ||||
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(); | ||||
else if (IsFormationMember()) | |||||
{ | |||||
CMessageMotionChanged msg(true); | |||||
GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); | |||||
return; | |||||
} | |||||
CMessageMotionChanged msg(false); | CMessageMotionChanged msg(false); | ||||
GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); | GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); | ||||
CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | ||||
if (!cmpPosition || !cmpPosition->IsInWorld()) | if (!cmpPosition || !cmpPosition->IsInWorld()) | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | void CCmpUnitMotion::Move(fixed dt) | ||||
} | } | ||||
} | } | ||||
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; | ||||
if (IsFormationMember()) | |||||
{ | |||||
// We've reached our assigned position. If the controller | |||||
// is idle, send a notification in case it should disband, | |||||
// otherwise continue following the formation next turn. | |||||
CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), m_MoveRequest.m_Entity); | |||||
return cmpUnitMotion && !cmpUnitMotion->IsMoving(); | |||||
} | |||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); | CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); | ||||
ENSURE(cmpObstructionManager); | ENSURE(cmpObstructionManager); | ||||
if (m_MoveRequest.m_Type == MoveRequest::POINT) | if (m_MoveRequest.m_Type == MoveRequest::POINT) | ||||
return cmpObstructionManager->IsInPointRange(GetEntityId(), m_MoveRequest.m_Position.X, m_MoveRequest.m_Position.Y, m_MoveRequest.m_MinRange, m_MoveRequest.m_MaxRange, false); | return cmpObstructionManager->IsInPointRange(GetEntityId(), m_MoveRequest.m_Position.X, m_MoveRequest.m_Position.Y, m_MoveRequest.m_MinRange, m_MoveRequest.m_MaxRange, false); | ||||
if (m_MoveRequest.m_Type == MoveRequest::ENTITY) | if (m_MoveRequest.m_Type == MoveRequest::ENTITY) | ||||
return cmpObstructionManager->IsInTargetRange(GetEntityId(), m_MoveRequest.m_Entity, m_MoveRequest.m_MinRange, m_MoveRequest.m_MaxRange, false); | return cmpObstructionManager->IsInTargetRange(GetEntityId(), m_MoveRequest.m_Entity, m_MoveRequest.m_MinRange, m_MoveRequest.m_MaxRange, false); | ||||
if (m_MoveRequest.m_Type == MoveRequest::OFFSET) | if (m_MoveRequest.m_Type == MoveRequest::OFFSET) | ||||
{ | { | ||||
CmpPtr<ICmpUnitMotion> cmpControllerMotion(GetSimContext(), m_MoveRequest.m_Entity); | |||||
if (cmpControllerMotion && cmpControllerMotion->IsMoving()) | |||||
return false; | |||||
CFixedVector2D targetPos; | CFixedVector2D targetPos; | ||||
ComputeTargetPosition(targetPos); | ComputeTargetPosition(targetPos); | ||||
return cmpObstructionManager->IsInPointRange(GetEntityId(), m_MoveRequest.m_Position.X, m_MoveRequest.m_Position.Y, m_MoveRequest.m_MinRange, m_MoveRequest.m_MaxRange, false); | CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle()); | ||||
return cmpObstructionManager->IsInPointRange(GetEntityId(), targetPos.X, targetPos.Y, m_MoveRequest.m_MinRange, m_MoveRequest.m_MaxRange, false); | |||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
bool CCmpUnitMotion::PerformMove(fixed dt, WaypointPath& shortPath, WaypointPath& longPath, CFixedVector2D& pos) const | bool CCmpUnitMotion::PerformMove(fixed dt, WaypointPath& shortPath, WaypointPath& longPath, CFixedVector2D& pos) const | ||||
{ | { | ||||
if (m_PathState != PATHSTATE_FOLLOWING && | if (m_PathState != PATHSTATE_FOLLOWING && | ||||
m_PathState != PATHSTATE_FOLLOWING_REQUESTING_SHORT && | m_PathState != PATHSTATE_FOLLOWING_REQUESTING_SHORT && | ||||
▲ Show 20 Lines • Show All 739 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator