Example #1
0
    public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
    {
        Parallel parallel = (Parallel)node;
        bool bOk = false;
        //parallel currently is the same with sequence
        int childCount = parallel.GetChildrenCount();
        int i = 0;

        for (; i < childCount; ++i)
        {
            BehaviorNode childNode = parallel.GetChild(i);
            PlannerTask childTask = planner.decomposeNode(childNode, depth);

            if (childTask == null)
            {
                break;
            }

            seqTask.AddChild(childTask);
        }

        if (i == childCount)
        {
            bOk = true;
        }

        return bOk;
    }
Example #2
0
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            Sequence sequence = (Sequence)node;
            bool bOk = false;
            int childCount = sequence.GetChildrenCount();
            int i = 0;

            for (; i < childCount; ++i)
            {
                BehaviorNode childNode = sequence.GetChild(i);
                PlannerTask childTask = planner.decomposeNode(childNode, depth);

                if (childTask == null)
                {
                    break;
                }

                //clear the log cache so that the next node can log all properites
                LogManager.Instance.PLanningClearCache();
                seqTask.AddChild(childTask);
            }

            if (i == childCount)
            {
                bOk = true;
            }

            return bOk;
        }
Example #3
0
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            ReferencedBehavior taskSubTree = (ReferencedBehavior)node;
            bool bOk = false;
            Debug.Check(taskSubTree != null);
            int depth2 = planner.GetAgent().Variables.Depth;
            using(AgentState currentState = planner.GetAgent().Variables.Push(false))
            {
                //planner.agent.Variables.Log(planner.agent, true);
                taskSubTree.SetTaskParams(planner.GetAgent());

                Task task = taskSubTree.RootTaskNode;

                if (task != null)
                {
                    planner.LogPlanReferenceTreeEnter(planner.GetAgent(), taskSubTree);
                    task.Parent.InstantiatePars(planner.GetAgent());

                    PlannerTask childTask = planner.decomposeNode(task, depth);

                    if (childTask != null)
                    {
                        seqTask.AddChild(childTask);
                        bOk = true;
                    }

                    task.Parent.UnInstantiatePars(planner.GetAgent());
                    planner.LogPlanReferenceTreeExit(planner.GetAgent(), taskSubTree);
                    Debug.Check(true);
                }
            }

            Debug.Check(planner.GetAgent().Variables.Depth == depth2);
            return bOk;
        }
Example #4
0
        /// <summary>
        /// implement the decompose
        /// </summary>
        /// <param name="task"></param>
        /// <param name="seqTask"></param>
        /// <param name="depth"></param>
        /// <param name="planner"></param>
        /// <returns></returns>
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            bool bOk = false;
            Task task = (Task)node;
            PlannerTask childTask = planner.decomposeTask((Task)task, depth);

            if (childTask != null)
            {
                seqTask.AddChild(childTask);
                bOk = true;
            }

            return bOk;
        }
Example #5
0
        public override bool decompose(BehaviorNode branch, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            bool bOk = false;
            int childCount = branch.GetChildrenCount();
            Debug.Check(childCount == 1);
            BehaviorNode childNode = branch.GetChild(0);
            PlannerTask childTask = planner.decomposeNode(childNode, depth);

            if (childTask != null)
            {
                seqTask.AddChild(childTask);
                bOk = true;
            }

            return bOk;
        }
Example #6
0
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            ReferencedBehavior taskSubTree = (ReferencedBehavior)node;
            bool bOk = false;
            Debug.Check(taskSubTree != null);
            int depth2 = planner.GetAgent().Variables.Depth;
            using(AgentState currentState = planner.GetAgent().Variables.Push(false))
            {
                Agent pAgent = planner.GetAgent();

                string szTreePath = taskSubTree.GetReferencedTree(pAgent);
                BehaviorTreeTask subTreeTask = Workspace.Instance.CreateBehaviorTreeTask(szTreePath);

                taskSubTree.SetTaskParams(pAgent, subTreeTask);

                Task task = taskSubTree.RootTaskNode(planner.GetAgent());

                if (task != null)
                {
                    planner.LogPlanReferenceTreeEnter(planner.GetAgent(), taskSubTree);
                    //task.Parent.InstantiatePars(this.LocalVars);

                    BehaviorTreeTask oldCurrentTreeTask = pAgent.ExcutingTreeTask;
                    pAgent.ExcutingTreeTask = subTreeTask; 
                    PlannerTask childTask = planner.decomposeNode(task, depth);
                    pAgent.ExcutingTreeTask = oldCurrentTreeTask;

                    if (childTask != null)
                    {
                        //taskSubTree.SetTaskParams(planner.GetAgent(), childTask);
                        PlannerTaskReference subTreeRef = (PlannerTaskReference)seqTask;

                        subTreeRef.SubTreeTask = subTreeTask;
                        seqTask.AddChild(childTask);
                        bOk = true;
                    }

                    //task.Parent.UnInstantiatePars(this.LocalVars);
                    planner.LogPlanReferenceTreeExit(planner.GetAgent(), taskSubTree);
                    Debug.Check(true);
                }
            }

            Debug.Check(planner.GetAgent().Variables.Depth == depth2);
            return bOk;
        }
Example #7
0
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            DecoratorIterator pForEach = (DecoratorIterator)node;
            bool bOk = false;
            int childCount = pForEach.GetChildrenCount();
            Debug.Check(childCount == 1);
            BehaviorNode childNode = pForEach.GetChild(0);

            bool bGoOn = true;
            int count = 0;
            int index = 0;

            while (bGoOn)
            {
                int depth2 = planner.GetAgent().Variables.Depth;
                using(AgentState currentState = planner.GetAgent().Variables.Push(false))
                {
                    bGoOn = pForEach.IterateIt(planner.GetAgent(), index, ref count);

                    if (bGoOn)
                    {
                        planner.LogPlanForEachBegin(planner.GetAgent(), pForEach, index, count);
                        PlannerTask childTask = planner.decomposeNode(childNode, depth);
                        planner.LogPlanForEachEnd(planner.GetAgent(), pForEach, index, count, childTask != null ? "success" : "failure");

                        if (childTask != null)
                        {
                            Debug.Check(seqTask is PlannerTaskIterator);
                            PlannerTaskIterator pForEachTask = seqTask as PlannerTaskIterator;
                            pForEachTask.Index = index;

                            seqTask.AddChild(childTask);
                            bOk = true;
                            break;
                        }

                        index++;
                    }
                }

                Debug.Check(planner.GetAgent().Variables.Depth == depth2);
            }

            return bOk;
        }
Example #8
0
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            Selector sel = (Selector)node;

            bool bOk = false;
            int childCount = sel.GetChildrenCount();
            int i = 0;

            for (; i < childCount; ++i)
            {
                BehaviorNode childNode = sel.GetChild(i);
                PlannerTask childTask = planner.decomposeNode(childNode, depth);

                if (childTask != null)
                {
                    seqTask.AddChild(childTask);
                    bOk = true;
                    break;
                }
            }

            return bOk;
        }
Example #9
0
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            Debug.Check(false);

            return(false);
        }
Example #10
0
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            Debug.Check(false);

            return false;
        }
Example #11
0
        //~DecoratorLoop()
        //{
        //}

#if BEHAVIAC_USE_HTN
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            DecoratorLoop loop       = (DecoratorLoop)node;
            bool          bOk        = false;
            int           childCount = loop.GetChildrenCount();

            Debug.Check(childCount == 1);
            BehaviorNode childNode = loop.GetChild(0);
            PlannerTask  childTask = planner.decomposeNode(childNode, depth);

            if (childTask != null)
            {
                seqTask.AddChild(childTask);
                bOk = true;
            }

            return(bOk);
        }
Example #12
0
 public virtual bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
 {
     Debug.Check(false, "Can't step into this line");
     return false;
 }
Example #13
0
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            Parallel parallel = (Parallel)node;
            bool     bOk      = false;
            //parallel currently is the same with sequence
            int childCount = parallel.GetChildrenCount();
            int i          = 0;

            for (; i < childCount; ++i)
            {
                BehaviorNode childNode = parallel.GetChild(i);
                PlannerTask  childTask = planner.decomposeNode(childNode, depth);

                if (childTask == null)
                {
                    break;
                }

                seqTask.AddChild(childTask);
            }

            if (i == childCount)
            {
                bOk = true;
            }

            return(bOk);
        }
Example #14
0
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            Selector sel = (Selector)node;

            bool bOk        = false;
            int  childCount = sel.GetChildrenCount();
            int  i          = 0;

            for (; i < childCount; ++i)
            {
                BehaviorNode childNode = sel.GetChild(i);
                PlannerTask  childTask = planner.decomposeNode(childNode, depth);

                if (childTask != null)
                {
                    seqTask.AddChild(childTask);
                    bOk = true;
                    break;
                }
            }

            return(bOk);
        }
Example #15
0
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            ReferencedBehavior taskSubTree = (ReferencedBehavior)node;
            bool bOk = false;

            Debug.Check(taskSubTree != null);
            int depth2 = planner.GetAgent().Variables.Depth;

            using (AgentState currentState = planner.GetAgent().Variables.Push(false))
            {
                //planner.agent.Variables.Log(planner.agent, true);
                taskSubTree.SetTaskParams(planner.GetAgent());

                Task task = taskSubTree.RootTaskNode;

                if (task != null)
                {
                    planner.LogPlanReferenceTreeEnter(planner.GetAgent(), taskSubTree);
                    task.Parent.InstantiatePars(planner.GetAgent());

                    PlannerTask childTask = planner.decomposeNode(task, depth);

                    if (childTask != null)
                    {
                        seqTask.AddChild(childTask);
                        bOk = true;
                    }

                    task.Parent.UnInstantiatePars(planner.GetAgent());
                    planner.LogPlanReferenceTreeExit(planner.GetAgent(), taskSubTree);
                    Debug.Check(true);
                }
            }

            Debug.Check(planner.GetAgent().Variables.Depth == depth2);
            return(bOk);
        }
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            DecoratorIterator pForEach = (DecoratorIterator)node;
            bool bOk        = false;
            int  childCount = pForEach.GetChildrenCount();

            Debug.Check(childCount == 1);
            BehaviorNode childNode = pForEach.GetChild(0);

            bool bGoOn = true;
            int  count = 0;
            int  index = 0;

            while (bGoOn)
            {
                int depth2 = planner.GetAgent().Variables.Depth;
                using (AgentState currentState = planner.GetAgent().Variables.Push(false))
                {
                    bGoOn = pForEach.IterateIt(planner.GetAgent(), index, ref count);

                    if (bGoOn)
                    {
                        planner.LogPlanForEachBegin(planner.GetAgent(), pForEach, index, count);
                        PlannerTask childTask = planner.decomposeNode(childNode, depth);
                        planner.LogPlanForEachEnd(planner.GetAgent(), pForEach, index, count, childTask != null ? "success" : "failure");

                        if (childTask != null)
                        {
                            Debug.Check(seqTask is PlannerTaskIterator);
                            PlannerTaskIterator pForEachTask = seqTask as PlannerTaskIterator;
                            pForEachTask.Index = index;

                            seqTask.AddChild(childTask);
                            bOk = true;
                            break;
                        }

                        index++;
                    }
                }

                Debug.Check(planner.GetAgent().Variables.Depth == depth2);
            }

            return(bOk);
        }
Example #17
0
        /// <summary>
        /// implement the decompose
        /// </summary>
        /// <param name="task"></param>
        /// <param name="seqTask"></param>
        /// <param name="depth"></param>
        /// <param name="planner"></param>
        /// <returns></returns>
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            bool        bOk       = false;
            Task        task      = (Task)node;
            PlannerTask childTask = planner.decomposeTask((Task)task, depth);

            if (childTask != null)
            {
                seqTask.AddChild(childTask);
                bOk = true;
            }

            return(bOk);
        }
Example #18
0
        public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner)
        {
            ReferencedBehavior taskSubTree = (ReferencedBehavior)node;
            bool bOk = false;

            Debug.Check(taskSubTree != null);
            int depth2 = planner.GetAgent().Variables.Depth;

            using (AgentState currentState = planner.GetAgent().Variables.Push(false))
            {
                Agent pAgent = planner.GetAgent();

                string           szTreePath  = taskSubTree.GetReferencedTree(pAgent);
                BehaviorTreeTask subTreeTask = Workspace.Instance.CreateBehaviorTreeTask(szTreePath);

                taskSubTree.SetTaskParams(pAgent, subTreeTask);

                Task task = taskSubTree.RootTaskNode(planner.GetAgent());

                if (task != null)
                {
                    planner.LogPlanReferenceTreeEnter(planner.GetAgent(), taskSubTree);
                    //task.Parent.InstantiatePars(this.LocalVars);

                    BehaviorTreeTask oldCurrentTreeTask = pAgent.ExcutingTreeTask;
                    pAgent.ExcutingTreeTask = subTreeTask;
                    PlannerTask childTask = planner.decomposeNode(task, depth);
                    pAgent.ExcutingTreeTask = oldCurrentTreeTask;

                    if (childTask != null)
                    {
                        //taskSubTree.SetTaskParams(planner.GetAgent(), childTask);
                        PlannerTaskReference subTreeRef = (PlannerTaskReference)seqTask;

                        subTreeRef.SubTreeTask = subTreeTask;
                        seqTask.AddChild(childTask);
                        bOk = true;
                    }

                    //task.Parent.UnInstantiatePars(this.LocalVars);
                    planner.LogPlanReferenceTreeExit(planner.GetAgent(), taskSubTree);
                    Debug.Check(true);
                }
            }

            Debug.Check(planner.GetAgent().Variables.Depth == depth2);
            return(bOk);
        }