Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpUnitMotion.cpp
Show First 20 Lines • Show All 1,027 Lines • ▼ Show 20 Lines | if (m_PathState == PATHSTATE_FOLLOWING) | ||||
if (cmpUnitMotion && !cmpUnitMotion->IsMoving()) | if (cmpUnitMotion && !cmpUnitMotion->IsMoving()) | ||||
{ | { | ||||
CmpPtr<ICmpObstruction> cmpObstruction(GetEntityHandle()); | CmpPtr<ICmpObstruction> cmpObstruction(GetEntityHandle()); | ||||
if (cmpObstruction) | if (cmpObstruction) | ||||
cmpObstruction->SetMovingFlag(false); | cmpObstruction->SetMovingFlag(false); | ||||
m_Moving = false; | m_Moving = false; | ||||
CMessageMotionChanged msg(false, false); | CMessageMotionChanged msg(false, false); | ||||
GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); | GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); | ||||
return; | |||||
wraitii: Forgot to update this particular case also. | |||||
} | } | ||||
} | } | ||||
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<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); | |||||
CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), m_TargetEntity); | CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), m_TargetEntity); | ||||
if (cmpUnitMotion && cmpUnitMotion->IsMoving() && | if (!cmpUnitMotion || cmpObstructionManager->IsInTargetRange(GetEntityId(), m_TargetEntity, m_TargetMinRange, m_TargetMaxRange, false)) | ||||
MoveToTargetRange(m_TargetEntity, m_TargetMinRange, m_TargetMaxRange)) | { | ||||
return; | |||||
// Not in formation, so just finish moving | // Not in formation, so just finish moving | ||||
StopMoving(); | 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 | ||||
} | } | ||||
} | } | ||||
} | |||||
// If we have a target entity, and we're not miles away from the end of | // If we have a target entity, and we're not miles away from the end of | ||||
// our current path, and the target moved enough, then recompute our | // our current path, and the target moved enough, then recompute our | ||||
// whole path | // whole path | ||||
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); | ||||
▲ Show 20 Lines • Show All 372 Lines • ▼ Show 20 Lines | else if (maxRange >= entity_pos_t::Zero() && distance > maxRange) | ||||
if (goal.hw <= entity_pos_t::Zero()) | if (goal.hw <= entity_pos_t::Zero()) | ||||
goal.type = PathGoal::POINT; | goal.type = PathGoal::POINT; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// We're already in range - no need to move anywhere | // We're already in range - no need to move anywhere | ||||
if (m_FacePointAfterMove) | if (m_FacePointAfterMove) | ||||
FaceTowardsPointFromPos(pos, x, z); | FaceTowardsPointFromPos(pos, x, z); | ||||
return false; | return true; | ||||
} | } | ||||
} | } | ||||
m_State = STATE_INDIVIDUAL_PATH; | m_State = STATE_INDIVIDUAL_PATH; | ||||
m_TargetEntity = target; | m_TargetEntity = target; | ||||
m_TargetOffset = CFixedVector2D(); | m_TargetOffset = CFixedVector2D(); | ||||
m_TargetMinRange = minRange; | m_TargetMinRange = minRange; | ||||
m_TargetMaxRange = maxRange; | m_TargetMaxRange = maxRange; | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | else | ||||
goal.hw = obstruction.hw + goalDistance; | goal.hw = obstruction.hw + goalDistance; | ||||
goal.hh = obstruction.hh + goalDistance; | goal.hh = obstruction.hh + goalDistance; | ||||
} | } | ||||
} | } | ||||
else if (maxRange < entity_pos_t::Zero() || distance < maxRange || previousDistance < maxRange) | else if (maxRange < entity_pos_t::Zero() || distance < maxRange || previousDistance < maxRange) | ||||
{ | { | ||||
// We're already in range - no need to move anywhere | // We're already in range - no need to move anywhere | ||||
FaceTowardsPointFromPos(pos, goal.x, goal.z); | FaceTowardsPointFromPos(pos, goal.x, goal.z); | ||||
return false; | return true; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// We might need to move closer: | // We might need to move closer: | ||||
// Circumscribe the square | // Circumscribe the square | ||||
entity_pos_t circleRadius = halfSize.Length(); | entity_pos_t circleRadius = halfSize.Length(); | ||||
▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Forgot to update this particular case also.