Beispiel #1
0
        public void LogPlanForEachEnd(Agent a, DecoratorIterator pForEach, int index, int count, string result)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                string ni = BehaviorTask.GetTickInfo(a, pForEach, null);
                LogManager.Log("[plan_foreach_end]{0} {1} {2} {3}\n", ni, index, count, result);
            }
#endif
        }
Beispiel #2
0
        private void LogPlanMethodEnd(Agent a, BehaviorNode m, string result)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                string ni = BehaviorTask.GetTickInfo(a, m, null);
                LogManager.Log("[plan_method_end]{0} {1}\n", ni, result);
            }
#endif
        }
Beispiel #3
0
        public void LogPlanReferenceTreeExit(Agent a, ReferencedBehavior referencedNode)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                string ni = BehaviorTask.GetTickInfo(a, referencedNode, null);
                LogManager.Log("[plan_referencetree_exit]{0} {1}.xml\n", ni, referencedNode.ReferencedTree);
            }
#endif
        }
Beispiel #4
0
        public void LogPlanForEachBegin(Agent a, DecoratorIterator pForEach, int index, int count)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                string ni = BehaviorTask.GetTickInfo(a, pForEach, null);
                LogManager.Log("[plan_foreach_begin]{0} {1} {2}\n", ni, index, count);
                a.Variables.Log(a, true);
            }
#endif
        }
Beispiel #5
0
        private void LogPlanNodePreconditionFailed(Agent a, BehaviorNode n)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                string ni = BehaviorTask.GetTickInfo(a, n, null);

                LogManager.Log("[plan_node_pre_failed]{0}\n", ni);
            }
#endif
        }
Beispiel #6
0
        private void LogPlanNodeEnd(Agent a, BehaviorNode n, string result)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                string ni = BehaviorTask.GetTickInfo(a, n, null);

                LogManager.Instance.Log("[plan_node_end]{0} {1}\n", ni, result);
            }
#endif
        }
Beispiel #7
0
        private void LogPlanMethodBegin(Agent a, BehaviorNode m)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                string ni = BehaviorTask.GetTickInfo(a, m, null);
                LogManager.Log("[plan_method_begin]{0}\n", ni);

                a.Variables.Log(a, true);
            }
#endif
        }
Beispiel #8
0
        private void LogPlanNodeBegin(Agent a, BehaviorNode n)
        {
#if !BEHAVIAC_RELEASE
            if (Config.IsLoggingOrSocketing)
            {
                string ni = BehaviorTask.GetTickInfo(a, n, null);

                LogManager.Instance.Log("[plan_node_begin]{0}\n", ni);
                a.LogVariables(true);
            }
#endif
        }
Beispiel #9
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.Log(buffer);
            }
#endif
        }
Beispiel #10
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.Log(buffer);

                a.Variables.Log(a, true);
            }
#endif
        }
        public EBTStatus exec(Agent pAgent, EBTStatus childStatus)
        {
#if !BEHAVIAC_RELEASE
            Debug.Check(this.m_node == null || this.m_node.IsValid(pAgent, this),
                        string.Format("Agent In BT:{0} while the Agent used for: {1}", this.m_node.GetAgentType(), pAgent.GetClassTypeName()));
#endif//#if !BEHAVIAC_RELEASE
            bool bEnterResult = false;

            if (this.m_status == EBTStatus.BT_RUNNING)
            {
                bEnterResult = true;
            }
            else
            {
                //reset it to invalid when it was success/failure
                this.m_status = EBTStatus.BT_INVALID;
                bEnterResult  = this.onenter_action(pAgent);
            }

            if (bEnterResult)
            {
#if !BEHAVIAC_RELEASE
                if (Config.IsLoggingOrSocketing)
                {
                    string btStr = BehaviorTask.GetTickInfo(pAgent, this, "update");

                    //empty btStr is for internal BehaviorTreeTask
                    if (!string.IsNullOrEmpty(btStr))
                    {
                        LogManager.Instance.Log(pAgent, btStr, EActionResult.EAR_none, LogMode.ELM_tick);
                    }
                }
#endif
                bool bValid = this.CheckParentUpdatePreconditions(pAgent);

                if (bValid)
                {
                    this.m_status = this.update_current(pAgent, childStatus);
                }
                else
                {
                    this.m_status = EBTStatus.BT_FAILURE;

                    if (this.GetCurrentTask() != null)
                    {
                        this.update_current(pAgent, EBTStatus.BT_FAILURE);
                    }
                }

                if (this.m_status != EBTStatus.BT_RUNNING)
                {
                    //clear it

                    this.onexit_action(pAgent, this.m_status);

                    //this node is possibly ticked by its parent or by the topBranch who records it as currrent node
                    //so, we can't here reset the topBranch's current node
                }
                else
                {
                    BranchTask tree = this.GetTopManageBranchTask();

                    if (tree != null)
                    {
                        tree.SetCurrentTask(this);
                    }
                }
            }
            else
            {
                this.m_status = EBTStatus.BT_FAILURE;
            }

            return(this.m_status);
        }
Beispiel #12
0
        public EBTStatus exec(Agent pAgent)
        {
#if !BEHAVIAC_RELEASE
            Debug.Check(this.m_node == null || this.m_node.IsValid(pAgent, this),
                        string.Format("Agent In BT:{0} while the Agent used for: {1}", this.m_node.GetAgentType(), pAgent.GetClassTypeName()));
#endif//#if !BEHAVIAC_RELEASE
            bool bEnterResult = false;
            if (this.m_status == EBTStatus.BT_RUNNING)
            {
                bEnterResult = true;
            }
            else
            {
                //reset it to invalid when it was success/failure
                this.m_status = EBTStatus.BT_INVALID;

                bEnterResult = this.onenter_action(pAgent);

                //for continue ticking task, to set it as the cached current task
                bool bIsContinueTicking = this.isContinueTicking();
                if (bIsContinueTicking)
                {
                    BranchTask pBranch = this.GetParentBranch();

                    if (pBranch != null && pBranch != this)
                    {
                        //if 'this' is a tree, don't set it into it parent's current node
                        Debug.Check(!(this is BehaviorTreeTask));

                        pBranch.SetCurrentTask(this);
                    }
                }
            }

            if (bEnterResult)
            {
#if !BEHAVIAC_RELEASE
                if (Config.IsLoggingOrSocketing)
                {
                    string btStr = BehaviorTask.GetTickInfo(pAgent, this, "update");
                    //empty btStr is for internal BehaviorTreeTask
                    if (!string.IsNullOrEmpty(btStr))
                    {
                        LogManager.Log(pAgent, btStr, EActionResult.EAR_none, LogMode.ELM_tick);
                    }
                }
#endif
                EBTStatus returnStatus = this.GetReturnStatus();
                if (returnStatus == EBTStatus.BT_INVALID)
                {
                    this.m_status = this.update(pAgent, EBTStatus.BT_RUNNING);
                }
                else
                {
                    this.m_status = returnStatus;
                }

                if (this.m_status != EBTStatus.BT_RUNNING)
                {
                    //clear it
                    bool bIsContinueTicking = this.isContinueTicking();
                    if (bIsContinueTicking)
                    {
                        BranchTask pBranch = this.GetParentBranch();

                        if (pBranch != null && pBranch != this)
                        {
                            //if 'this' is a tree, don't set it into it parent's current node
                            Debug.Check(!(this is BehaviorTreeTask));

                            pBranch.SetCurrentTask(null);
                        }
                    }


                    this.onexit_action(pAgent, this.m_status);

                    //this node is possibly ticked by its parent or by the topBranch who records it as currrent node
                    //so, we can't here reset the topBranch's current node
                }
            }
            else
            {
                this.m_status = EBTStatus.BT_FAILURE;
            }

            EBTStatus currentStatus = this.m_status;
            if (this.m_status != EBTStatus.BT_RUNNING && this.NeedRestart())
            {
                //reset it to invalid when it needs restarting
                //don't need to reset the sub tree
                this.m_status = EBTStatus.BT_INVALID;
                this.SetReturnStatus(EBTStatus.BT_INVALID);
            }

            return(currentStatus);
        }