Beispiel #1
0
		/// <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;
		}
Beispiel #2
0
		/// <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;
		}