예제 #1
0
파일: AIPatrol.cs 프로젝트: oathx/Six
		/// <summary>
		/// Frees the patrol.
		/// </summary>
		/// <returns><c>true</c>, if patrol was freed, <c>false</c> otherwise.</returns>
		/// <param name="ec">Ec.</param>
		public virtual bool				FreePatrol(AIEntityContext ec)
		{
			Vector3 vTarget = Vector3.zero;

			// get random target point
			if (!SceneSupport.GetSingleton().GetRandomPosition(ec.Owner.GetPosition(), Radius, ref vTarget))
				return false;

			// change to find path state
			IAIState curState = Machine.GetCurrentState ();
			if (curState.StateID != AITypeID.AI_PATH)
				Machine.ChangeState (AITypeID.AI_PATH);
			
			// construct find path event
			CmdEvent.AIFindPathEventArgs v = new CmdEvent.AIFindPathEventArgs ();
			v.Target 		= vTarget;
			v.MinDistance 	= ErrorRange;
			v.DrawLine		= true;
			v.LineWidth		= 0.05f;
			
			// post the find path event to machine
			Machine.PostEvent(
				new IEvent(EngineEventType.EVENT_AI, CmdEvent.CMD_LOGIC_AIFINDPATH, v)
				);

			return true;
		}
예제 #2
0
파일: AIPursue.cs 프로젝트: oathx/Six
		/// <summary>
		/// Puesues the target.
		/// </summary>
		/// <param name="vCenter">V center.</param>
		/// <param name="fRadius">F radius.</param>
		public virtual void 			PuesueTarget(Vector3 vCenter, float fRadius)
		{
			Vector3 vTarget = SceneSupport.GetSingleton ().GetRandomPosition (vCenter, fRadius);
			if (vTarget != Vector3.zero)
			{
				// change to find path state
				IAIState curState = Machine.GetCurrentState ();
				if (curState.StateID != AITypeID.AI_PATH)
					Machine.ChangeState (AITypeID.AI_PATH);
				
				// construct find path event
				CmdEvent.AIFindPathEventArgs v = new CmdEvent.AIFindPathEventArgs ();
				v.Target 		= vTarget;
				v.MinDistance 	= 1.0f;
				v.DrawLine		= true;
				v.LineWidth		= 0.1f;
				
				// post the find path event to machine
				Machine.PostEvent(
					new IEvent(EngineEventType.EVENT_AI, CmdEvent.CMD_LOGIC_AIFINDPATH, v)
					);
			}
		}
예제 #3
0
파일: AIFollow.cs 프로젝트: oathx/Six
		/// <summary>
		/// Follows the target.
		/// </summary>
		/// <param name="ec">Ec.</param>
		public virtual bool 			FollowTarget(AIEntityContext ec)
		{
			Vector3 vStart	= ec.Owner.GetPosition();
			Vector3 vEnd	= ec.Leader.GetPosition();
			Vector3 vTarget	= vStart;
			float	fError	= Distance > 0 ? Distance : Radius;

			// If the current is in the following range
			float fDistance = Vector3.Distance(vStart, vEnd);
			if (fError >= fDistance)
				return true;

			// If you set the distance, then calculate the point within this range.
			if (Distance > 0)
			{
				List<Vector3>
					vPath = new List<Vector3>();
				
				bool bResult = SceneSupport.GetSingleton().FindPath(vStart, vEnd, 0, ref vPath);
				if (bResult)
					CalcTargetPoint(vPath, ref vEnd, Distance);
			}

			// if set random radius then get a random position
			if (Radius > 0)
				SceneSupport.GetSingleton().GetRandomPosition(vEnd, Radius, ref vTarget);

			// change to find path state
			IAIState curState = Machine.GetCurrentState ();
			if (curState.StateID != AITypeID.AI_PATH)
				Machine.ChangeState (AITypeID.AI_PATH);
			
			// construct find path event
			CmdEvent.AIFindPathEventArgs v = new CmdEvent.AIFindPathEventArgs ();
			v.Target 		= vTarget;
			v.MinDistance 	= ErrorRange;
			v.DrawLine		= true;
			v.LineWidth		= 0.05f;
			
			// post the find path event to machine
			Machine.PostEvent(
				new IEvent(EngineEventType.EVENT_AI, CmdEvent.CMD_LOGIC_AIFINDPATH, v)
				);

			return true;
		}