public void EnqueueForPlanning(GOAPAgent agent)
 {
     if (!Agents.Exists(x => x.Equals(agent)) && (Agents.Count < MaxAgentsPerFrame))
     {
         Agents.Add(agent);
     }
 }
Exemple #2
0
 /// <summary>
 /// Run all of your actions, then call TestForFinished
 /// </summary>
 public virtual void ActionUpdate(GOAPAgent agent)
 {
     foreach (Action effect in effects)
     {
         effect();
     }
     isActive = !TestForFinished();
 }
Exemple #3
0
        public List <GOAPAction> GetActionPlan(GOAPAgent Agent, List <GOAPState> WorldState, List <GOAPAction> AvailableActions, GOAPGoal goal)
        {
            List <GOAPAction> usable = new List <GOAPAction>();

            for (int i = 0; i < AvailableActions.Count; ++i)
            {
                if (AvailableActions[i].CanRun(Agent))
                {
                    usable.Add(AvailableActions[i]);
                }
            }

            List <Node> leaves       = new List <Node>();
            Node        startingNode = new Node(null, WorldState, 0, null);

            bool ableToGetPlan = BuildGraph(startingNode, leaves, AvailableActions, goal);

            if (!ableToGetPlan)
            {
                Debug.Log("Failed to get plan");
                return(null);
            }

            Node cheapestAction = null;

            foreach (Node leaf in leaves)
            {
                if (cheapestAction == null)
                {
                    cheapestAction = leaf;
                }
                else
                {
                    if (leaf.Cost < cheapestAction.Cost)
                    {
                        cheapestAction = leaf;
                    }
                }
            }

            List <GOAPAction> results = new List <GOAPAction>();
            Node temp = cheapestAction;

            while (temp != null)
            {
                if (temp.Action != null)
                {
                    results.Insert(0, temp.Action);
                }

                temp = temp.Parent;
            }

            return(results);
        }
Exemple #4
0
        public virtual bool CanRun(GOAPAgent agent)
        {
            Debug.Log("CanRun in " + this + " has not been implemented");
            bool statesMatch = true;

            foreach (GOAPState state in requiredStates)
            {
                foreach (bool match in state.Items)
                {
                    if (!match)
                    {
                        statesMatch = false;
                        break;
                    }
                }
            }
            return(statesMatch);
        }