Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpUnitMotion.cpp
Show First 20 Lines • Show All 1,059 Lines • ▼ Show 20 Lines | bool CCmpUnitMotion::ComputeTargetPosition(CFixedVector2D& out) const | ||||
if (m_MoveRequest.m_Type == MoveRequest::OFFSET) | if (m_MoveRequest.m_Type == MoveRequest::OFFSET) | ||||
{ | { | ||||
// There is an offset, so compute it relative to orientation | // There is an offset, so compute it relative to orientation | ||||
entity_angle_t angle = cmpPosition->GetRotation().Y; | entity_angle_t angle = cmpPosition->GetRotation().Y; | ||||
CFixedVector2D offset = m_MoveRequest.GetOffset().Rotate(angle); | CFixedVector2D offset = m_MoveRequest.GetOffset().Rotate(angle); | ||||
out = cmpPosition->GetPosition2D() + offset; | out = cmpPosition->GetPosition2D() + offset; | ||||
} | } | ||||
else | else | ||||
{ | |||||
out = cmpPosition->GetPosition2D(); | out = cmpPosition->GetPosition2D(); | ||||
// If the target is moving, we might never get in range if we just try to reach its current position, | |||||
// so we have to try and move to a position where we will be in-range, including their movement. | |||||
// Since we request paths asynchronously a the end of our turn, we need to account for twice the movement speed. | |||||
// TODO: be cleverer about this. It fixes fleeing nicely currently, but orthogonal movement should be considered, | |||||
// and the overall logic could be improved upon. | |||||
CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), m_MoveRequest.m_Entity); | |||||
if (cmpUnitMotion && cmpUnitMotion->IsMoving()) | |||||
out += (out - cmpPosition->GetPreviousPosition2D()) * 2; | |||||
} | |||||
return true; | return true; | ||||
} | } | ||||
bool CCmpUnitMotion::TryGoingStraightToTarget(const CFixedVector2D& from) | bool CCmpUnitMotion::TryGoingStraightToTarget(const CFixedVector2D& from) | ||||
{ | { | ||||
CFixedVector2D targetPos; | CFixedVector2D targetPos; | ||||
if (!ComputeTargetPosition(targetPos)) | if (!ComputeTargetPosition(targetPos)) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 560 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator