public bool Follow( bool run, int range )
{
Point3D goal = GetGoalLocation();
Direction d;
if ( Check( m_From.Location, goal, range ) )
return true;
bool repathed = CheckPath();
if ( !Enabled || !m_Path.Success )
{
d = m_From.GetDirectionTo( goal );
if ( run )
d |= Direction.Running;
m_From.SetDirection( d );
Move( d );
return Check( m_From.Location, goal, range );
}
d = m_From.GetDirectionTo( m_Next );
if ( run )
d |= Direction.Running;
m_From.SetDirection( d );
MoveResult res = Move( d );
if ( res == MoveResult.Blocked )
{
if ( repathed )
return false;
m_Path = null;
CheckPath();
if ( !m_Path.Success )
{
d = m_From.GetDirectionTo( goal );
if ( run )
d |= Direction.Running;
m_From.SetDirection( d );
Move( d );
return Check( m_From.Location, goal, range );
}
d = m_From.GetDirectionTo( m_Next );
if ( run )
d |= Direction.Running;
m_From.SetDirection( d );
res = Move( d );
if ( res == MoveResult.Blocked )
return false;
}
if ( m_From.X == m_Next.X && m_From.Y == m_Next.Y )
{
if ( m_From.Z == m_Next.Z )
{
++m_Index;
Advance( ref m_Next, m_Index );
}
else
{
m_Path = null;
}
}
return Check( m_From.Location, goal, range );
}
}