Beispiel #1
0
        //private PlannerTask decomposeTask(Task task, int depth) {
        //because called form other node , so change the private to public
        public PlannerTask decomposeTask(Task task, int depth)
        {
            var methodsCount = task.GetChildrenCount();

            if (methodsCount == 0)
            {
                return null;
            }

            int depth1 = this.agent.Variables.Depth;
            PlannerTask methodTask = null;

            for (int i = 0; i < methodsCount; i++)
            {
                BehaviorNode method = task.GetChild(i);
                Debug.Check(method is Method);
                int depth2 = this.agent.Variables.Depth;
                using(var currentState = this.agent.Variables.Push(false))
                {
                    LogPlanMethodBegin(this.agent, method);
                    methodTask = this.decomposeNode(method, depth + 1);
                    LogPlanMethodEnd(this.agent, method, methodTask != null ? "success" : "failure");

                    if (methodTask != null)
                    {
                        // succeeded
                        break;
                    }
                }

                Debug.Check(this.agent.Variables.Depth == depth2);
            }

            Debug.Check(this.agent.Variables.Depth == depth1);
            return methodTask;
        }
Beispiel #2
0
        private PlannerTask BuildPlan(Task root)
        {
            LogManager.Instance.PLanningClearCache();

            int depth = this.agent.Variables.Depth;

            PlannerTask rootTask = null;
            using(var currentState = this.agent.Variables.Push(true))
            {
                this.agent.PlanningTop = this.agent.Variables.Top;
                Debug.Check(this.agent.PlanningTop >= 0);

                LogPlanBegin(this.agent, root);

                rootTask = this.decomposeNode(root, 0);

                LogPlanEnd(this.agent, root);

#if !BEHAVIAC_RELEASE
                BehaviorTask.CHECK_BREAKPOINT(this.agent, root, "plan", EActionResult.EAR_all);
#endif

                this.agent.PlanningTop = -1;
            }

            Debug.Check(this.agent.Variables.Depth == depth);

            return rootTask;
        }
Beispiel #3
0
 public void Init(Agent pAgent, Task rootTask)
 {
     this.agent = pAgent;
     this.m_rootTaskNode = rootTask;
 }
Beispiel #4
0
        private void LogPlanEnd(Agent a, Task root)
        {
#if !BEHAVIAC_RELEASE

            if (Config.IsLoggingOrSocketing)
            {
                string agentClassName = a.GetClassTypeName();
                string agentInstanceName = a.GetName();

                agentClassName = agentClassName.Replace(".", "::");
                agentInstanceName = agentInstanceName.Replace(".", "::");

                string ni = BehaviorTask.GetTickInfo(a, root, null);
                string buffer = string.Format("[plan_end]{0}#{1} {2}\n", agentClassName, agentInstanceName, ni);

                LogManager.Instance.Log(buffer);
            }

#endif
        }
Beispiel #5
0
        private void LogPlanBegin(Agent a, Task root)
        {
#if !BEHAVIAC_RELEASE

            if (Config.IsLoggingOrSocketing)
            {
                string agentClassName = a.GetClassTypeName();
                string agentInstanceName = a.GetName();

                agentClassName = agentClassName.Replace(".", "::");
                agentInstanceName = agentInstanceName.Replace(".", "::");

                string ni = BehaviorTask.GetTickInfo(a, root, "plan");
                int count = Workspace.Instance.GetActionCount(ni) + 1;
                string buffer = string.Format("[plan_begin]{0}#{1} {2} {3}\n", agentClassName, agentInstanceName, ni, count);

                LogManager.Instance.Log(buffer);

                a.Variables.Log(a, true);
            }

#endif
        }
Beispiel #6
0
        public Task RootTaskNode(Agent pAgent)
        {
            if (this.m_taskNode == null)
            {
                string szTreePath = this.GetReferencedTree(pAgent);
                BehaviorTree bt = Workspace.Instance.LoadBehaviorTree(szTreePath);

                if (bt != null && bt.GetChildrenCount() == 1)
                {
                    BehaviorNode root = bt.GetChild(0);
                    this.m_taskNode = root as Task;
                }
            }

            return this.m_taskNode;
        }