Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp
Show First 20 Lines • Show All 801 Lines • ▼ Show 20 Lines | void CCmpUnitMotion::Move(fixed dt) | ||||
if (!cmpPosition || !cmpPosition->IsInWorld()) | if (!cmpPosition || !cmpPosition->IsInWorld()) | ||||
return; | return; | ||||
CFixedVector2D initialPos = cmpPosition->GetPosition2D(); | CFixedVector2D initialPos = cmpPosition->GetPosition2D(); | ||||
// Keep track of the current unit's position during the update | // Keep track of the current unit's position during the update | ||||
CFixedVector2D pos = initialPos; | CFixedVector2D pos = initialPos; | ||||
// If we're chasing a potentially-moving unit and are currently close | |||||
// enough to its current position, and we can head in a straight line | |||||
// to it, then throw away our current path and go straight to it | |||||
if (m_PathState == PATHSTATE_FOLLOWING || | |||||
m_PathState == PATHSTATE_FOLLOWING_REQUESTING_SHORT || | |||||
m_PathState == PATHSTATE_FOLLOWING_REQUESTING_LONG) | |||||
TryGoingStraightToTargetEntity(initialPos); | |||||
bool wasObstructed = false; | bool wasObstructed = false; | ||||
if (m_PathState == PATHSTATE_FOLLOWING || | if (m_PathState == PATHSTATE_FOLLOWING || | ||||
m_PathState == PATHSTATE_FOLLOWING_REQUESTING_SHORT || | m_PathState == PATHSTATE_FOLLOWING_REQUESTING_SHORT || | ||||
m_PathState == PATHSTATE_FOLLOWING_REQUESTING_LONG) | m_PathState == PATHSTATE_FOLLOWING_REQUESTING_LONG) | ||||
{ | { | ||||
// TODO: there's some asymmetry here when units look at other | // TODO: there's some asymmetry here when units look at other | ||||
// units' positions - the result will depend on the order of execution. | // units' positions - the result will depend on the order of execution. | ||||
// Maybe we should split the updates into multiple phases to minimise | // Maybe we should split the updates into multiple phases to minimise | ||||
// that problem. | // that problem. | ||||
CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity()); | CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity()); | ||||
if (!cmpPathfinder) | if (!cmpPathfinder) | ||||
return; | return; | ||||
// If we're chasing a potentially-moving unit and are currently close | |||||
// enough to its current position, and we can head in a straight line | |||||
// to it, then throw away our current path and go straight to it | |||||
if (m_PathState == PATHSTATE_FOLLOWING) | |||||
TryGoingStraightToTargetEntity(initialPos); | |||||
fixed basicSpeed = m_Speed; | fixed basicSpeed = m_Speed; | ||||
// If in formation, run to keep up; otherwise just walk | // If in formation, run to keep up; otherwise just walk | ||||
if (IsFormationMember()) | if (IsFormationMember()) | ||||
basicSpeed = m_Speed.Multiply(m_RunMultiplier); | basicSpeed = m_Speed.Multiply(m_RunMultiplier); | ||||
// Find the speed factor of the underlying terrain | // Find the speed factor of the underlying terrain | ||||
// (We only care about the tile we start on - it doesn't matter if we're moving | // (We only care about the tile we start on - it doesn't matter if we're moving | ||||
// partially onto a much slower/faster tile) | // partially onto a much slower/faster tile) | ||||
▲ Show 20 Lines • Show All 799 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator