Esempio n. 1
0
void CPathFind::FollowPath()
{
	if (!IsFollowingPath()) return;

	m_onPoint = false;

	// move mob to next point
	position_t* targetPoint = &m_points[m_currentPoint];

	StepTo(targetPoint, m_pathFlags & PATHFLAG_RUN);

	if (m_maxDistance && m_distanceMoved >= m_maxDistance)
	{
		// if I have a max distance, check to stop me
		Clear();

		m_onPoint = true;
	}
	else if (AtPoint(targetPoint))
	{
		m_currentPoint++;

		if (m_currentPoint >= m_pathLength)
		{
			// i'm finished!
			Clear();
		}

		m_onPoint = true;
	}
}
Esempio n. 2
0
bool CPathFind::PathTo(position_t point, uint8 pathFlags, bool clear)
{
    // don't follow a new path if the current path has script flag and new path doesn't
    if (IsFollowingPath() && (m_pathFlags & PATHFLAG_SCRIPT) && !(pathFlags & PATHFLAG_SCRIPT))
        return false;

    if (clear)
    {
        Clear();
    }

    m_pathFlags = pathFlags;

    if (isNavMeshEnabled())
    {
        bool result = false;

        if (m_pathFlags & PATHFLAG_WALLHACK)
        {
            result = FindClosestPath(&m_PTarget->loc.p, &point);
        }
        else
        {
            result = FindPath(&m_PTarget->loc.p, &point);
        }

        if (!result)
        {
            Clear();
        }

        return result;
    }
    else
    {
        m_pathLength = 1;

        m_points[0].x = point.x;
        m_points[0].y = point.y;
        m_points[0].z = point.z;
    }

    return true;
}
Esempio n. 3
0
void CPathFind::StopWithin(float within)
{
	if (!IsFollowingPath()) return;
	// TODO: cut up path

	position_t* lastPoint = &m_points[m_pathLength - 1];
	position_t* secondLastPoint = nullptr;

	if (m_pathLength == 1)
	{
		secondLastPoint = &m_PTarget->loc.p;
	}
	else
	{
		secondLastPoint = &m_points[m_pathLength - 2];
	}

	float distanceTo = distance(*lastPoint, *secondLastPoint);

	if (distanceTo > within)
	{
		// reduce last point to stop within the given number
		float radians = atanf((secondLastPoint->z - lastPoint->z) / (secondLastPoint->x - lastPoint->x)) * (M_PI / 180.0f);

		lastPoint->x -= cosf(radians) * within;
		lastPoint->z -= sinf(radians) * within;
	}
	else
	{
		// i'm already there, stop moving
		if (m_pathLength == 1)
		{
			Clear();
		}
		else
		{
			// remove last point, it'll make me too close
			m_pathLength--;
		}
	}
}