Пример #1
0
        protected override bool CheckPreconditions(Agent pAgent, bool bIsAlive)
        {
            if (!bIsAlive)
            {
                //only try to Push when enter
                this.currentState = pAgent.Variables.Push(false);
                Debug.Check(currentState != null);
            }

            bool bOk = base.CheckPreconditions(pAgent, bIsAlive);

            if (!bIsAlive && !bOk)
            {
                this.currentState.Pop();
                this.currentState = null;
            }

            return(bOk);
        }
Пример #2
0
        public override IInstantiatedVariable GetVariable(uint varId)
        {
            if (this.state_stack != null && this.state_stack.Count > 0)
            {
                for (int i = this.state_stack.Count - 1; i >= 0; --i)
                {
                    AgentState t = this.state_stack[i];

                    IInstantiatedVariable pVar = t.GetVariable(varId);

                    if (pVar != null)
                    {
                        return(pVar);
                    }
                }
            }

            return(base.GetVariable(varId));
        }
Пример #3
0
        public override object GetObject(Agent pAgent, bool bMemberGet, CMemberBase pMember, uint varId)
        {
            if (this.state_stack != null && this.state_stack.Count > 0)
            {
                for (int i = this.state_stack.Count - 1; i >= 0; --i)
                {
                    AgentState t      = this.state_stack[i];
                    object     result = t.GetObject(pAgent, false, pMember, varId);

                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            object result1 = base.GetObject(pAgent, bMemberGet, pMember, varId);

            return(result1);
        }
Пример #4
0
        public override void SetObject(bool bMemberSet, Agent pAgent, bool bLocal, CMemberBase pMember, string variableName, object value, uint varId)
        {
            //if (variableName == "DirtyRooms")
            //{
            //    Debug.Check(true);
            //}

            // not in planning
            if (pAgent.PlanningTop == -1 && !bLocal)
            {
                base.SetObject(bMemberSet, pAgent, bLocal, pMember, variableName, value, varId);
                return;
            }

            if (this.state_stack != null && this.state_stack.Count > 0)
            {
                int stackIndex = 0;

                if (bLocal)
                {
                    //top
                    stackIndex = this.state_stack.Count - 1;
                }
                else
                {
                    //bottom
                    stackIndex = pAgent.PlanningTop;
                }

                AgentState t = this.state_stack[stackIndex];

                //if there are something in the state stack, it is used for planning, so, don't really set member
                t.SetObject(false, pAgent, bLocal, null, variableName, value, varId);
            }
            else
            {
                base.SetObject(bMemberSet, pAgent, bLocal, pMember, variableName, value, varId);
            }
        }
Пример #5
0
        public void Pop()
        {
#if BEHAVIAC_ENABLE_PUSH_OPT
            if (this.m_pushed > 0)
            {
                this.m_pushed--;

                if (this.m_variables.Count > 0)
                {
                    this.m_variables.Clear();
                    return;
                }

                return;
            }
#endif

            if (this.state_stack != null && this.state_stack.Count > 0)
            {
                AgentState top = this.state_stack[this.state_stack.Count - 1];
                top.Pop();
                return;
            }

            this.Clear();
            Debug.Check(this.state_stack == null);
            Debug.Check(this.parent != null);

            this.parent.PopTop();
            this.parent = null;

            lock (pool)
            {
                Debug.Check(!pool.Contains(this));
                pool.Push(this);
            }
        }
Пример #6
0
        //~ReferencedBehavior()
        //{
        //}

        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(planner.GetAgent());

                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);
        }
Пример #7
0
 public AgentState(AgentState parent)
 {
     this.parent = parent;
 }
Пример #8
0
        public AgentState Push(bool bForcePush)
        {
#if BEHAVIAC_ENABLE_PUSH_OPT

            if (!bForcePush)
            {
                //if the top has nothing new added, to use it again
                if (this.state_stack != null && this.state_stack.Count > 0)
                {
                    AgentState t = this.state_stack[this.state_stack.Count - 1];

                    if (!t.m_forced && t.m_variables.Count == 0)
                    {
                        t.m_pushed++;
                        return t;
                    }
                }
            }

#endif

            AgentState newly = null;
            lock(pool)
            {
                if (pool.Count > 0)
                {
                    newly = pool.Pop();
                    //set the parent
                    newly.parent = this;
                }
                else
                {
                    newly = new AgentState(this);
                }

                newly.m_forced = bForcePush;

                if (bForcePush)
                {
                    base.CopyTo(null, newly);
                }
            }

            if (this.state_stack == null)
            {
                this.state_stack = new List<AgentState>();
            }

            //add the newly one at the end of the list as the top
            this.state_stack.Add(newly);

            return newly;
        }
Пример #9
0
 public AgentState(AgentState parent)
 {
     this.parent = parent;
 }
Пример #10
0
        public void Pop()
        {
#if BEHAVIAC_ENABLE_PUSH_OPT

            if (this.m_pushed > 0)
            {
                this.m_pushed--;

                if (this.m_variables.Count > 0)
                {
                    this.m_variables.Clear();
                    return;
                }

                return;
            }

#endif

            if (this.state_stack != null && this.state_stack.Count > 0)
            {
                AgentState top = this.state_stack[this.state_stack.Count - 1];
                top.Pop();
                return;
            }

            this.Clear();
            Debug.Check(this.state_stack == null);
            Debug.Check(this.parent != null);

            this.parent.PopTop();
            this.parent = null;

            lock(pool)
            {
                Debug.Check(!pool.Contains(this));
                pool.Push(this);
            }
        }
Пример #11
0
            protected override bool CheckPreconditions(Agent pAgent, bool bIsAlive)
            {
                this.currentState = pAgent.Variables.Push(false);
                Debug.Check(currentState != null);

                bool bOk = base.CheckPreconditions(pAgent, bIsAlive);

                if (!bOk)
                {
                    this.currentState.Pop();
                    this.currentState = null;
                }

                return bOk;
            }
Пример #12
0
 protected override void onexit(Agent pAgent, EBTStatus s)
 {
     this.currentState = pAgent.Variables.Push(false);
     Debug.Check(currentState != null);
     base.onexit(pAgent, s);
 }
Пример #13
0
            protected override bool onenter(Agent pAgent)
            {
                //this.m_root = null;
                this.currentState = pAgent.Variables.Push(false);
                Debug.Check(currentState != null);

                if (this.ReQuery(pAgent))
                {
                    return true;
                }

                return false;
            }
Пример #14
0
        private void CopyTopValueTo(AgentState newly)
        {
            var e = this.m_variables.Keys.GetEnumerator();
            while (e.MoveNext())
            {
                uint id = e.Current;

                IInstantiatedVariable pVar = this.GetVariable(id);
                IInstantiatedVariable pNew = pVar.clone();

                newly.m_variables[id] = pNew;
            }
        }
Пример #15
0
            //~ReferencedBehaviorTask()
            //{
            //    Workspace.Instance.DestroyBehaviorTreeTask(this.m_subTree, null);
            //    this.m_subTree = null;
            //}

            protected override bool CheckPreconditions(Agent pAgent, bool bIsAlive)
            {
#if BEHAVIAC_USE_HTN
                this.currentState = pAgent.Variables.Push(false);
                Debug.Check(currentState != null);
#endif//

                bool bOk = base.CheckPreconditions(pAgent, bIsAlive);
#if BEHAVIAC_USE_HTN
                if (!bOk)
                {
                    this.currentState.Pop();
                    this.currentState = null;
                }
#endif//
                return bOk;
            }
Пример #16
0
 protected override void onexit(Agent pAgent, EBTStatus s)
 {
     this.currentState = pAgent.Variables.Push(false);
     Debug.Check(currentState != null);
     base.onexit(pAgent, s);
 }