Esempio n. 1
0
        /// <summary>
        /// Get's all actions that fit as a child to the input action
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        List <GoapAction> GetMatchingActionChilds(GoapAction parent)
        {
            List <GoapAction> matches = new List <GoapAction>();

            // loop through all preconditions of the parent
            foreach (string condition in parent.preconditions.Keys)
            {
                // loop through all possible actions
                foreach (GoapAction action in possibleActions)
                {
                    // prevent it from endless looping
                    if (parent.GetType() == action.GetType())
                    {
                        continue;
                    }

                    // loop through all effects of the possible actions
                    foreach (string effect in action.effects.Keys)
                    {
                        // the keys and values are the same
                        if (condition == effect && parent.preconditions[condition] == action.effects[effect])
                        {
                            GoapAction tAction = action.Clone();

                            tAction.SetChilds(GetMatchingActionChilds(tAction));

                            matches.Add(tAction);
                        }
                    }
                }
            }

            return(matches);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a list of all actions that have the same goal
        /// </summary>
        /// <param name="parent">The parent goal</param>
        /// <returns>A list of (new) matching goals</returns>
        List <GoapAction> GetMatchingGoalChilds(GoapGoal parent)
        {
            List <GoapAction> matches = new List <GoapAction>();

            foreach (GoapAction action in possibleActions)
            {
                if (action.goal == parent.key)
                {
                    GoapAction tAction = action.Clone();

                    tAction.SetChilds(GetMatchingActionChilds(tAction));

                    matches.Add(tAction);
                }
            }

            return(matches);
        }