Exemplo n.º 1
0
int CLocalNav::PathTraversable(Vector &vecSource, Vector &vecDest, BOOL fNoMonsters)
{
	TraceResult tr;
	Vector vecSrcTmp;
	Vector vecDestTmp;
	Vector vecDir;
	Vector vecTmp;
	float flTotal;
	int retval;

	retval = TRAVERSABLE_NO;
	vecSrcTmp = vecSource;
	vecDestTmp = vecDest - vecSource;
	vecDir = vecDestTmp.Normalize();
	vecDir.z = 0;
	flTotal = vecDestTmp.Length2D();

	while (flTotal > 1)
	{
		if (flTotal >= s_flStepSize)
			vecDestTmp = vecSrcTmp + (vecDir * s_flStepSize);
		else
			vecDestTmp = vecDest;

		m_fTargetEntHit = FALSE;

		if (PathClear(vecSrcTmp, vecDestTmp, fNoMonsters, tr))
		{
			vecDestTmp = tr.vecEndPos;

			if (retval == TRAVERSABLE_NO)
				retval = TRAVERSABLE_SLOPE;
		}
		else
		{
			if (tr.fStartSolid)
				return TRAVERSABLE_NO;

			if (tr.pHit && !fNoMonsters && !FStringNull(tr.pHit->v.classname) && FClassnameIs(tr.pHit, "hostage_entity"))
				return TRAVERSABLE_NO;

			vecSrcTmp = tr.vecEndPos;

			if (tr.vecPlaneNormal.z > 0.7)
			{
				if (SlopeTraversable(vecSrcTmp, vecDestTmp, fNoMonsters, tr))
				{
					if (retval == TRAVERSABLE_NO)
						retval = TRAVERSABLE_SLOPE;
				}
				else
					return TRAVERSABLE_NO;
			}
			else
			{
				if (StepTraversable(vecSrcTmp, vecDestTmp, fNoMonsters, tr))
				{
					if (retval == TRAVERSABLE_NO)
						retval = TRAVERSABLE_STEP;
				}
				else if (StepJumpable(vecSrcTmp, vecDestTmp, fNoMonsters, tr))
				{
					if (retval == TRAVERSABLE_NO)
						retval = TRAVERSABLE_STEPJUMPABLE;
				}
				else
					return TRAVERSABLE_NO;
			}
		}
		vecTmp = vecDestTmp - Vector(0, 0, 300);
		if (PathClear(vecDestTmp, vecTmp, fNoMonsters, tr))
			return TRAVERSABLE_NO;

		if (!tr.fStartSolid)
			vecDestTmp = tr.vecEndPos;

		vecSrcTmp = vecDestTmp;

		if (!m_fTargetEntHit)
			flTotal = (vecDest - vecDestTmp).Length2D();
		else
			flTotal = 0;
	}

	vecDest = vecDestTmp;
	return retval;
}
Exemplo n.º 2
0
int CLocalNav::PathTraversable(Vector &vecSource, Vector &vecDest, int fNoMonsters)
{
	TraceResult tr;
	Vector vecSrcTmp;
	Vector vecDestTmp;
	Vector vecDir;
	float_precision flTotal;
	int retval = PATH_TRAVERSABLE_EMPTY;

	vecSrcTmp = vecSource;
	vecDestTmp = vecDest - vecSource;

	vecDir = vecDestTmp.NormalizePrecision();
	vecDir.z = 0;

	flTotal = vecDestTmp.Length2D();

	while (flTotal > 1.0f)
	{
		if (flTotal >= s_flStepSize)
		{
#ifndef PLAY_GAMEDLL
			vecDestTmp = vecSrcTmp + (vecDir * s_flStepSize);
#else
			// TODO: fix test demo
			vecDestTmp[0] = vecSrcTmp[0] + (vecDir[0] * s_flStepSize);
			vecDestTmp[1] = vecSrcTmp[1] + float(vecDir[1] * s_flStepSize);
			vecDestTmp[2] = vecSrcTmp[2] + (vecDir[2] * s_flStepSize);
#endif

		}
		else
			vecDestTmp = vecDest;

		m_fTargetEntHit = FALSE;

		if (PathClear(vecSrcTmp, vecDestTmp, fNoMonsters, tr))
		{
			vecDestTmp = tr.vecEndPos;

			if (retval == PATH_TRAVERSABLE_EMPTY)
			{
				retval = PATH_TRAVERSABLE_SLOPE;
			}
		}
		else
		{
			if (tr.fStartSolid)
			{
				return PATH_TRAVERSABLE_EMPTY;
			}

			if (tr.pHit && !fNoMonsters && tr.pHit->v.classname)
			{
				if (FClassnameIs(tr.pHit, "hostage_entity"))
				{
					return PATH_TRAVERSABLE_EMPTY;
				}
			}

			vecSrcTmp = tr.vecEndPos;

			if (tr.vecPlaneNormal.z <= MaxUnitZSlope)
			{
				if (StepTraversable(vecSrcTmp, vecDestTmp, fNoMonsters, tr))
				{
					if (retval == PATH_TRAVERSABLE_EMPTY)
					{
						retval = PATH_TRAVERSABLE_STEP;
					}
				}
				else
				{
					if (!StepJumpable(vecSrcTmp, vecDestTmp, fNoMonsters, tr))
					{
						return PATH_TRAVERSABLE_EMPTY;
					}

					if (retval == PATH_TRAVERSABLE_EMPTY)
					{
						retval = PATH_TRAVERSABLE_STEPJUMPABLE;
					}
				}
			}
			else
			{
				if (!SlopeTraversable(vecSrcTmp, vecDestTmp, fNoMonsters, tr))
				{
					return PATH_TRAVERSABLE_EMPTY;
				}

				if (retval == PATH_TRAVERSABLE_EMPTY)
				{
					retval = PATH_TRAVERSABLE_SLOPE;
				}
			}
		}

		Vector vecDropDest = vecDestTmp - Vector(0, 0, 300);

		if (PathClear(vecDestTmp, vecDropDest, fNoMonsters, tr))
		{
			return PATH_TRAVERSABLE_EMPTY;
		}

		if (!tr.fStartSolid)
			vecDestTmp = tr.vecEndPos;

		vecSrcTmp = vecDestTmp;

		BOOL fProgressThisTime = m_fTargetEntHit;
		Vector vecSrcThisTime = vecDest - vecDestTmp;

		if (fProgressThisTime)
			break;

		flTotal = vecSrcThisTime.Length2D();
	}

	vecDest = vecDestTmp;

	return retval;
}