Ejemplo n.º 1
0
    private Goal_Evaluator Arbitrate()
    {
        Goal_Evaluator mostDesirableGoal = null;
        float          bestDesirability  = 0;

        foreach (Goal_Evaluator evaluator in evaluators)
        {
            float desirability = evaluator.CalculateDesirability(owner, false);

            if (mostDesirableGoal == null || desirability > bestDesirability)
            {
                mostDesirableGoal = evaluator;
                bestDesirability  = desirability;
            }
        }

        if (ActiveGoal is GoalSync)
        {
            GoalSync goalSync = ActiveGoal as GoalSync;
            if (goalSync.Evaluator == mostDesirableGoal || goalSync.Evaluator.CalculateDesirability(owner, false) >= bestDesirability)
            {
                mostDesirableGoal = null;
            }
        }

        return(mostDesirableGoal);
    }
Ejemplo n.º 2
0
    public void Update()
    {
        if (ActiveGoal != null && (ActiveGoal.IsComplete || ActiveGoal.HasFailed))
        {
            ActiveGoal.Terminate();
            ActiveGoal = null;
        }

        /*if(owner.Debug){
         *  Debug.Log("--------------Goal List-------------");
         *  Goal currentGoal = ActiveGoal;
         *  GoalComposite currentCompositeGoal = ActiveGoal as GoalComposite;
         *  Debug.Log(currentGoal);
         *  while (currentCompositeGoal != null)
         *  {
         *      currentGoal = currentCompositeGoal.GetActiveGoal();
         *      if (currentGoal != null)
         *      {
         *          Debug.Log(currentGoal);
         *      }
         *      currentCompositeGoal = currentGoal as GoalComposite;
         *  }
         *  /*Debug.Log("--------------Steering-------------");
         *  Debug.Log(owner.Steering.Behavior);
         *  Debug.Log(owner.transform.position);
         *  Debug.Log(owner.Steering.Destination);*/
        //}

        Goal_Evaluator mostDesirableGoal = Arbitrate();

        if (mostDesirableGoal == null)
        {
            if (ActiveGoal != null)
            {
                ActiveGoal.Process();
            }
            return;
        }

        if (ActiveGoal == null || ActiveGoal.GetType() != mostDesirableGoal.GetGoalType())
        {
            if (ActiveGoal != null)
            {
                ActiveGoal.Terminate();
            }
            ActiveGoal = mostDesirableGoal.CreateGoal(owner);
        }

        if (ActiveGoal != null)
        {
            ActiveGoal.Process();
        }
    }
Ejemplo n.º 3
0
        //this method iterates through each goal evaluator and selects the one
        //that has the highest score as the current goal
        public void Arbitrate()
        {
            double         best          = 0;
            Goal_Evaluator MostDesirable = null;

            foreach (var curDes in m_Evaluators)
            {
                double desirabilty = curDes.CalculateDesirability(m_pOwner);

                if (desirabilty >= best)
                {
                    best          = desirabilty;
                    MostDesirable = curDes;
                }
            }

            if (MostDesirable != null)
            {
                MostDesirable.SetGoal(m_pOwner);
            }
        }
Ejemplo n.º 4
0
    public bool RequestGoal(Goal_Evaluator goalRequested)
    {
        /*GoalSync goalSync = ActiveGoal as GoalSync;
         * if(goalSync != null) return false;*/

        float goalRequestedDesirability = goalRequested.CalculateDesirability(owner, true);

        foreach (Goal_Evaluator evaluator in evaluators)
        {
            float desirability = evaluator.CalculateDesirability(owner, false);
            if (evaluator == goalRequested)
            {
                continue;
            }

            if (desirability > goalRequestedDesirability)
            {
                return(false);
            }
        }

        return(true);
    }