Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpUnitMotion.h
Show First 20 Lines • Show All 942 Lines • ▼ Show 20 Lines | void CCmpUnitMotion::PostMove(CCmpUnitMotionManager::MotionState& state, fixed dt) | ||||
{ | { | ||||
if (state.angle != state.initialAngle) | if (state.angle != state.initialAngle) | ||||
state.cmpPosition->TurnTo(state.angle); | state.cmpPosition->TurnTo(state.angle); | ||||
UpdateMovementState(fixed::Zero()); | UpdateMovementState(fixed::Zero()); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// Update the Position component after our movement (if we actually moved anywhere) | // Update the Position component after our movement (if we actually moved anywhere) | ||||
// When moving always set the angle in the direction of the movement. | |||||
CFixedVector2D offset = state.pos - state.initialPos; | CFixedVector2D offset = state.pos - state.initialPos; | ||||
// When moving always set the angle in the direction of the movement, | |||||
// if we are not trying to move, assume this is pushing-related movement, | |||||
// and maintain the current angle instead. | |||||
if (IsMoveRequested()) | |||||
state.angle = atan2_approx(offset.X, offset.Y); | state.angle = atan2_approx(offset.X, offset.Y); | ||||
state.cmpPosition->MoveAndTurnTo(state.pos.X, state.pos.Y, state.angle); | state.cmpPosition->MoveAndTurnTo(state.pos.X, state.pos.Y, state.angle); | ||||
// Calculate the mean speed over this past turn. | // Calculate the mean speed over this past turn. | ||||
UpdateMovementState(offset.Length() / dt); | UpdateMovementState(offset.Length() / dt); | ||||
} | } | ||||
if (state.wasObstructed && HandleObstructedMove(state.pos != state.initialPos)) | if (state.wasObstructed && HandleObstructedMove(state.pos != state.initialPos)) | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 367 Lines • ▼ Show 20 Lines | bool CCmpUnitMotion::TryGoingStraightToTarget(const CFixedVector2D& from) | ||||
ICmpObstructionManager::tag_t specificIgnore; | ICmpObstructionManager::tag_t specificIgnore; | ||||
if (m_MoveRequest.m_Type == MoveRequest::ENTITY) | if (m_MoveRequest.m_Type == MoveRequest::ENTITY) | ||||
{ | { | ||||
CmpPtr<ICmpObstruction> cmpTargetObstruction(GetSimContext(), m_MoveRequest.m_Entity); | CmpPtr<ICmpObstruction> cmpTargetObstruction(GetSimContext(), m_MoveRequest.m_Entity); | ||||
if (cmpTargetObstruction) | if (cmpTargetObstruction) | ||||
specificIgnore = cmpTargetObstruction->GetObstruction(); | specificIgnore = cmpTargetObstruction->GetObstruction(); | ||||
} | } | ||||
// Check movement against units - we want to use the short pathfinder to walk around those if needed. | |||||
if (specificIgnore.valid()) | if (specificIgnore.valid()) | ||||
{ | { | ||||
if (!cmpPathfinder->CheckMovement(SkipTagObstructionFilter(specificIgnore), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass)) | if (!cmpPathfinder->CheckMovement(GetObstructionFilter(specificIgnore), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass, true)) | ||||
return false; | return false; | ||||
} | } | ||||
else if (!cmpPathfinder->CheckMovement(GetObstructionFilter(), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass)) | else if (!cmpPathfinder->CheckMovement(GetObstructionFilter(), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass, true)) | ||||
return false; | return false; | ||||
// That route is okay, so update our path | // That route is okay, so update our path | ||||
m_LongPath.m_Waypoints.clear(); | m_LongPath.m_Waypoints.clear(); | ||||
m_ShortPath.m_Waypoints.clear(); | m_ShortPath.m_Waypoints.clear(); | ||||
m_ShortPath.m_Waypoints.emplace_back(Waypoint{ goalPos.X, goalPos.Y }); | m_ShortPath.m_Waypoints.emplace_back(Waypoint{ goalPos.X, goalPos.Y }); | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 378 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator