Пример #1
0
        /// <summary>
        ///   Generates a collection of active task nodes under this task. Used for debugging only.
        /// </summary>
        /// <param name="agentData"> Agent data. </param>
        /// <param name="taskNode"> Task node this task is located in. </param>
        /// <param name="activeTasks"> Collection of active task nodes. </param>
        public override void GetActiveTasks(
            IAgentData agentData, TaskNode taskNode, ref ICollection <TaskNode> activeTasks)
        {
            Data data = agentData.CurrentTaskData as Data;

            if (data == null)
            {
                throw new ArgumentException(string.Format("Expected parallel data for task '{0}'.", this.Name));
            }

            // Check if selector has an active child.
            if (data.RunningChildren.Count == 0)
            {
                return;
            }

            // Add task to active tasks and collect active tasks of active child.
            ++agentData.CurrentDeciderLevel;
            foreach (int childIdx in data.RunningChildren)
            {
                TaskNode childTaskNode = taskNode.CreateChildNode(this.Children[childIdx], childIdx);
                activeTasks.Add(childTaskNode);

                agentData.CurrentTaskData = data.ChildrenData[childIdx];
                this.Children[childIdx].GetActiveTasks(agentData, childTaskNode, ref activeTasks);
            }

            --agentData.CurrentDeciderLevel;
        }
Пример #2
0
        /// <summary>
        ///   Searches for tasks which forfill the passed predicate.
        /// </summary>
        /// <param name="taskNode"> Task node of this task. </param>
        /// <param name="predicate"> Predicate to forfill. </param>
        /// <param name="tasks"> List of tasks which forfill the passed predicate. </param>
        public override void FindTasks(TaskNode taskNode, Func <ITask, bool> predicate, ref ICollection <TaskNode> tasks)
        {
            // Check children.
            for (int index = 0; index < this.children.Count; index++)
            {
                ITask    child         = this.children[index];
                TaskNode childTaskNode = taskNode.CreateChildNode(child, index);
                if (predicate(child))
                {
                    tasks.Add(childTaskNode);
                }

                // Find tasks in child.
                child.FindTasks(childTaskNode, predicate, ref tasks);
            }
        }
Пример #3
0
        /// <summary>
        ///   Searches for tasks which forfill the passed predicate.
        /// </summary>
        /// <param name="taskNode"> Task node of this task. </param>
        /// <param name="predicate"> Predicate to forfill. </param>
        /// <param name="tasks"> List of tasks which forfill the passed predicate. </param>
        public override void FindTasks(TaskNode taskNode, Func <ITask, bool> predicate, ref ICollection <TaskNode> tasks)
        {
            if (this.Task == null)
            {
                return;
            }

            // Check child.
            TaskNode childTaskNode = taskNode.CreateChildNode(this.Task, 0);

            if (predicate(this.Task))
            {
                tasks.Add(childTaskNode);
            }

            // Find tasks in child.
            this.Task.FindTasks(childTaskNode, predicate, ref tasks);
        }
Пример #4
0
        /// <summary>
        ///   Generates a collection of active task nodes under this task. Used for debugging only.
        /// </summary>
        /// <param name="agentData"> Agent data. </param>
        /// <param name="taskNode"> Task node this task is located in. </param>
        /// <param name="activeTasks"> Collection of active task nodes. </param>
        public override void GetActiveTasks(
            IAgentData agentData, TaskNode taskNode, ref ICollection <TaskNode> activeTasks)
        {
            Data data = agentData.CurrentTaskData as Data;

            if (data == null)
            {
                throw new ArgumentException(string.Format("Expected selector data for task '{0}'.", this.Name));
            }

            // Check if selector has an active child.
            if (!MathUtils.IsWithinBounds(data.ActiveChildIdx, 0, this.Children.Count))
            {
                return;
            }

            // Add task to active tasks and collect active tasks of active child.
            TaskNode childTaskNode = taskNode.CreateChildNode(this.Children[data.ActiveChildIdx], data.ActiveChildIdx);

            activeTasks.Add(childTaskNode);
            this.GetActiveChildTasks(data.ActiveChildIdx, agentData, childTaskNode, ref activeTasks);
        }