示例#1
0
 private void ActionFailure()
 {
     AILogger.CreateMessage("Action failed: " + currentAction.ToString(), agent);
     Stop();
     if (OnFinishedPlan != null)
     {
         OnFinishedPlan();
     }
 }
示例#2
0
 public void Unpause()
 {
     if (state == States.Paused)
     {
         state = States.Running;
         // TODO Unpause state machine
     }
     else
     {
         AILogger.CreateMessage("Error, cannot unpause from non-paused state. Current state = " + state.ToString(), agent);
     }
 }
示例#3
0
 public void Pause()
 {
     if (state == States.Running)
     {
         state = States.Paused;
         stateMachine.Pause();
     }
     else
     {
         AILogger.CreateMessage("Cannot Pause when not running. Current state = " + state.ToString(), agent);
     }
 }
示例#4
0
 public void Stop()
 {
     if (state == States.Stopped)
     {
         AILogger.CreateMessage("Already stopped", agent);
     }
     else
     {
         state = States.Stopped;
         stateMachine.Stop();
         actionPlan    = null;
         currentAction = null;
     }
 }
示例#5
0
        public void Init(GameObject owner)
        {
            state = States.Stopped;

            Owner = owner;
            Memory.Init(this);
            Actions.Init(this);
            Sensors.Init(this);
            Goals.Init(this);

            executor = new Executor <L, V>(this);
            planner  = new Planner <L, V>(this);

            Logger = new AILogger(logLevel);

            planner.OnActionPlanFound     += OnActionPlanFound;
            planner.OnActionPlanNotFound  += OnActionPlanNotFound;
            executor.OnActionPlanComplete += OnActionPlanComplete;

            OnInit();
        }
示例#6
0
        public void CalculateNewGoal()
        {
            AILogger.CreateMessage("Calculating new goal.", agent);

            List <AIGoal> goals = new List <AIGoal>(agent.GetGoals());

            goals.Sort((x, y) => x.Priority.CompareTo(y.Priority));

            if (goals.Count == 0)
            {
                return;
            }

            for (int i = 0; i < goals.Count; i++)
            {
                currentGoal = goals[i];
                if (!GoalAchieveableByActions(currentGoal))
                {
                    continue;
                }

                if (aStar.FindActionPlan(agent, this))
                {
                    actions = aStar.GetActionPlan();
                }
                else
                {
                    AILogger.CreateMessage("failed to find action plan.", agent);
                }
            }

            if (actions.Count > 0 && OnActionPlanFound != null)
            {
                OnActionPlanFound();
            }
        }