Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpUnitMotion.cpp
Show First 20 Lines • Show All 611 Lines • ▼ Show 20 Lines | private: | ||||
/** | /** | ||||
* Do the per-turn movement and other updates. | * Do the per-turn movement and other updates. | ||||
*/ | */ | ||||
void Move(fixed dt); | void Move(fixed dt); | ||||
/** | /** | ||||
* Returns true if we are possibly at our destination. | * Returns true if we are possibly at our destination. | ||||
*/ | */ | ||||
bool PossiblyAtDestination(); | bool PossiblyAtDestination() const; | ||||
/** | /** | ||||
* Process the move the unit will do this turn. | * Process the move the unit will do this turn. | ||||
* This does not send actually change the position. | * This does not send actually change the position. | ||||
* @returns true if the move was obstructed. | * @returns true if the move was obstructed. | ||||
*/ | */ | ||||
bool PerformMove(fixed dt, WaypointPath& shortPath, WaypointPath& longPath, CFixedVector2D& pos) const; | bool PerformMove(fixed dt, WaypointPath& shortPath, WaypointPath& longPath, CFixedVector2D& pos) const; | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | if (m_PathState == PATHSTATE_FOLLOWING) | ||||
// 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 (IsFormationMember()) | if (IsFormationMember()) | ||||
CheckTargetMovement(pos, CHECK_TARGET_MOVEMENT_MIN_DELTA_FORMATION); | CheckTargetMovement(pos, CHECK_TARGET_MOVEMENT_MIN_DELTA_FORMATION); | ||||
else | else | ||||
CheckTargetMovement(pos, CHECK_TARGET_MOVEMENT_MIN_DELTA); | CheckTargetMovement(pos, CHECK_TARGET_MOVEMENT_MIN_DELTA); | ||||
} | } | ||||
} | } | ||||
bool CCmpUnitMotion::PossiblyAtDestination() | bool CCmpUnitMotion::PossiblyAtDestination() const | ||||
{ | |||||
// If we're not currently computing any new paths: | |||||
if (m_LongPath.m_Waypoints.empty() && m_ShortPath.m_Waypoints.empty()) | |||||
{ | { | ||||
if (m_MoveRequest.m_Type == MoveRequest::NONE) | |||||
return false; | |||||
if (IsFormationMember()) | if (IsFormationMember()) | ||||
{ | { | ||||
// We've reached our assigned position. If the controller | // We've reached our assigned position. If the controller | ||||
// is idle, send a notification in case it should disband, | // is idle, send a notification in case it should disband, | ||||
// otherwise continue following the formation next turn. | // otherwise continue following the formation next turn. | ||||
CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), m_MoveRequest.m_Entity); | CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), m_MoveRequest.m_Entity); | ||||
if (cmpUnitMotion && !cmpUnitMotion->IsMoving()) | return cmpUnitMotion && !cmpUnitMotion->IsMoving(); | ||||
return true; | |||||
} | } | ||||
else | |||||
{ | |||||
CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); | CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); | ||||
if (cmpObstructionManager->IsInTargetRange(GetEntityId(), m_MoveRequest.m_Entity, m_MoveRequest.m_MinRange, m_MoveRequest.m_MaxRange, false)) | ENSURE(cmpObstructionManager); | ||||
return true; | |||||
} | 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); | |||||
if (m_MoveRequest.m_Type == MoveRequest::ENTITY) | |||||
return cmpObstructionManager->IsInTargetRange(GetEntityId(), m_MoveRequest.m_Entity, m_MoveRequest.m_MinRange, m_MoveRequest.m_MaxRange, false); | |||||
if (m_MoveRequest.m_Type == MoveRequest::OFFSET) | |||||
{ | |||||
CFixedVector2D 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); | |||||
} | } | ||||
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 760 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator