Exemplo n.º 1
0
void OpheliaAI::AI_STATE_Escape_RunAway()
{
	if(Metacmd > 1)
	{
		int nStimType = ComputeStimuli();

		if(nStimType > 0)
		{
			ComputeState(nStimType);
			return;
		}
	}

	DFLOAT fDim = (DFLOAT)sqrt((m_vDims.x * m_vDims.x) + (m_vDims.z * m_vDims.z)) + 0.1f;

	switch(Metacmd)
	{
		case 1:		m_hTrackObject = FindObjectInRadius(m_pServerDE->GetClass("ExitHint"), m_fSeeingDist, FIND_VISIBLE | FIND_AVOID_TARGET);

					if(m_hTrackObject)
					{
						m_pServerDE->GetObjectPos(m_hTrackObject,&m_vTrackObjPos);

						MC_FacePos(m_vTrackObjPos);

						if(!m_MoveObj.CalculatePath(m_vTrackObjPos))
							SetNewState(STATE_Idle);
					}
					else
						SetNewState(STATE_AttackFar);
					
					break;
		case 2:	
		{
					DVector* pvPos = m_MoveObj.GetNextPathPoint();
					
					if(pvPos)
						MC_FacePos(*pvPos);	
					else
						SetNewState(STATE_Escape_RunAway);

					break;
		}
		case 3:		
		{
					DVector vPoint = *m_MoveObj.GetNextPathPoint();
					vPoint.y = m_MoveObj.GetPos().y;

					if(VEC_DIST(vPoint, m_MoveObj.GetPos()) <= fDim/2)
					{
						if(!m_MoveObj.MoveToNextPathPoint())
						{
							MC_FacePos(m_vTargetPos);
						}
						else
						{
							Metacmd = 2;
						}
					}
					else
						MC_Run();

					break;
		}
		case 4:		ComputeState();			break;
	}

	return;}
Exemplo n.º 2
0
void CivilianAI::AI_STATE_Escape_RunAway()
{
	DVector vDims;
	m_pServerDE->GetObjectDims(m_hObject,&vDims);
	DFLOAT fDim = (DFLOAT)sqrt((vDims.x * vDims.x) + (vDims.z * vDims.z)) + 0.1f;

	switch(Metacmd)
	{
		case 1:		
		{
					m_hTrackObject = FindObjectInRadius(m_pServerDE->GetClass("ExitHint"), m_fSeeingDist, FIND_VISIBLE);

					if(m_hTrackObject)
					{
						m_pServerDE->GetObjectPos(m_hTrackObject,&m_vTrackObjPos);

						DFLOAT fDist = VEC_DIST(m_vTrackObjPos, m_MoveObj.GetPos());
						
						if(fDist <= fDim/2)
						{
							SetNewState(STATE_Escape_Hide);
							break;
						}

						MC_FacePos(m_vTrackObjPos);

						DRotation rRot;
						DVector vU, vR, vF, vMyF;

						m_pServerDE->GetObjectRotation(m_hTrackObject, &rRot);
						m_pServerDE->GetRotationVectors(&rRot, &vU, &vR, &vF);

						VEC_COPY(vMyF, m_MoveObj.GetForwardVector());

						DFLOAT fHintDp = (vMyF.x * vF.x) + (vMyF.y * vF.y) + (vMyF.z * vF.z);

						if(fHintDp > 0)
						{					
							if(!m_MoveObj.CalculatePath(m_vTrackObjPos))
								SetNewState(STATE_Escape_Hide);
						}
						else
							SetNewState(STATE_Escape_Hide);
					}
					else
						SetNewState(STATE_Escape_Hide);
					
					break;
		}
		case 2:	
		{
					DVector* pvPos = m_MoveObj.GetNextPathPoint();
					
					if(pvPos)
						MC_FacePos(*pvPos);	
					else
						SetNewState(STATE_Escape_RunAway);

					break;
		}
		case 3:		
		{
					DVector vPoint = *m_MoveObj.GetNextPathPoint();
					vPoint.y = m_MoveObj.GetPos().y;

					if(VEC_DIST(vPoint, m_MoveObj.GetPos()) <= fDim/2)
					{
						if(!m_MoveObj.MoveToNextPathPoint())
						{
							MC_FacePos(m_vTargetPos);
						}
						else
						{
							Metacmd = 2;
						}
					}
					else
						MC_Run();

					break;
		}
		case 4:		ComputeState();			break;
	}

	return;
}