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) { 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; }
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; }
public virtual void Init(BehaviorNode node) { Debug.Check(node != null); this.m_node = node; this.m_id = this.m_node.GetId(); }
public static bool UpdateTransitions(Agent pAgent, BehaviorNode node, List<Transition> transitions, ref int nextStateId, EBTStatus result) { bool bTransitioned = false; if (transitions != null) { for (int i = 0; i < transitions.Count; ++i) { Transition transition = transitions[i]; if (transition.Evaluate(pAgent)) { nextStateId = transition.TargetStateId; Debug.Check(nextStateId != -1); //transition actions transition.ApplyEffects(pAgent, Effector.EPhase.E_BOTH); #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { BehaviorTask.CHECK_BREAKPOINT(pAgent, node, "transition", EActionResult.EAR_none); } #endif bTransitioned = true; break; } } } return bTransitioned; }
/// <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; }
public override void AddChild(BehaviorNode pBehavior) { Debug.Check(pBehavior is DecoratorWeight); DecoratorWeight pDW = (DecoratorWeight)(pBehavior); if (pDW != null) { base.AddChild(pBehavior); } else { Debug.Check(false, "only DecoratorWeightTask can be children"); } }
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; }
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; }
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; }
private void InstantiatePars(Agent pAgent) { BehaviorNode pNode = this.m_node; //pNode could be 0 when the bt is a sub tree of parallel node/referenced bt, etc. if (pNode != null && pNode.m_pars != null) { for (int i = 0; i < pNode.m_pars.Count; ++i) { Property property_ = pNode.m_pars[i]; // if(pAgent != null && property_.GetVariableName() == "par0_char_0") // { // behaviac.Debug.Check(true); // } property_.Instantiate(pAgent); } } }
public override void Attach(BehaviorNode pAttachment, bool bIsPrecondition, bool bIsEffector, bool bIsTransition) { if (bIsTransition) { Debug.Check(!bIsEffector && !bIsPrecondition); if (this.m_transitions == null) { this.m_transitions = new List <Transition>(); } Transition pTransition = pAttachment as Transition; Debug.Check(pTransition != null); this.m_transitions.Add(pTransition); return; } Debug.Check(bIsTransition == false); base.Attach(pAttachment, bIsPrecondition, bIsEffector, bIsTransition); }
protected BehaviorNode load(string agentType, BsonDeserizer d) { string pClassName = d.ReadString(); BehaviorNode pNode = BehaviorNode.Create(pClassName); Debug.Check(pNode != null, pClassName); string verString = d.ReadString(); int version = Convert.ToInt32(verString); if (pNode != null) { pNode.SetClassNameString(pClassName); string idString = d.ReadString(); pNode.SetId(Convert.ToInt32(idString)); pNode.load_properties_pars_attachments_children(version, agentType, d); } return(pNode); }
public override void Attach(BehaviorNode pAttachment, bool bIsPrecondition, bool bIsEffector, bool bIsTransition) { if (bIsTransition) { Debug.Check(!bIsEffector && !bIsPrecondition); if (this.m_transitions == null) { this.m_transitions = new List<Transition>(); } Transition pTransition = pAttachment as Transition; Debug.Check(pTransition != null); this.m_transitions.Add(pTransition); return; } Debug.Check(bIsTransition == false); base.Attach(pAttachment, bIsPrecondition, bIsEffector, bIsTransition); }
protected static BehaviorNode load(string agentType, SecurityElement node) { Debug.Check(node.Tag == "node"); int version = int.Parse(node.Attribute("version")); string pClassName = node.Attribute("class"); BehaviorNode pNode = BehaviorNode.Create(pClassName); Debug.Check(pNode != null); if (pNode != null) { pNode.SetClassNameString(pClassName); string idStr = node.Attribute("id"); pNode.SetId(Convert.ToInt32(idStr)); pNode.load_properties_pars_attachments_children(true, version, agentType, node); } return(pNode); }
public override void Init(BehaviorNode node) { base.Init(node); Debug.Check(node.GetChildrenCount() <= 1); if (node.GetChildrenCount() == 1) { BehaviorNode childNode = node.GetChild(0); if (childNode == null) { return; } BehaviorTask childTask = childNode.CreateAndInitTask(); this.addChild(childTask); } else { Debug.Check(true); } }
public static string GetTickInfo(Agent pAgent, BehaviorNode n, string action) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { if (pAgent != null && pAgent.IsMasked()) { //BEHAVIAC_PROFILE("GetTickInfo", true); string bClassName = n.GetClassNameString(); //filter out intermediate bt, whose class name is empty if (!string.IsNullOrEmpty(bClassName)) { string btName = GetParentTreeName(n); string bpstr = ""; if (!string.IsNullOrEmpty(btName)) { bpstr = string.Format("{0}.xml->", btName); } int nodeId = n.GetId(); bpstr += string.Format("{0}[{1}]", bClassName, nodeId); if (!string.IsNullOrEmpty(action)) { bpstr += string.Format(":{0}", action); } return(bpstr); } } } #endif return(string.Empty); }
protected void load_attachments(int version, string agentType, BsonDeserizer d) { d.OpenDocument(); BsonDeserizer.BsonTypes type = d.ReadType(); while (type == BsonDeserizer.BsonTypes.BT_AttachmentElement) { { d.OpenDocument(); string attachClassName = d.ReadString(); BehaviorNode pAttachment = BehaviorNode.Create(attachClassName); Debug.Check(pAttachment != null, attachClassName); if (pAttachment != null) { pAttachment.SetClassNameString(attachClassName); string idString = d.ReadString(); pAttachment.SetId(Convert.ToInt32(idString)); pAttachment.load_properties_pars_attachments_children(version, agentType, d); this.Attach(pAttachment); this.m_bHasEvents |= (pAttachment is Event); } d.CloseDocument(false); } type = d.ReadType(); } Debug.Check(type == BsonDeserizer.BsonTypes.BT_None); d.CloseDocument(false); }
//~Selector() //{ //} #if BEHAVIAC_USE_HTN 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); }
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; }
//~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); }
//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); }
public PlannerTaskMethod(BehaviorNode node, Agent pAgent) : base(node, pAgent) { }
public PlannerTaskReference(BehaviorNode node, Agent pAgent) : base(node, pAgent) { }
public PlannerTaskIterator(BehaviorNode node, Agent pAgent) : base(node, pAgent) { }
private bool decomposeComplex(BehaviorNode node, PlannerTaskComplex seqTask, int depth) { try { int depth1 = this.agent.Variables.Depth; bool bOk = false; bOk = node.decompose(node, seqTask, depth, this); Debug.Check(this.agent.Variables.Depth == depth1); return bOk; } catch (Exception ex) { Debug.Check(false, ex.Message); } return false; }
public virtual void Clear() { this.m_status = EBTStatus.BT_INVALID; this.m_parent = null; this.m_id = -1; this.m_node = null; }
//~SingeChildTask() //{ // m_root = null; //} public override void Init(BehaviorNode node) { base.Init(node); Debug.Check(node.GetChildrenCount() <= 1); if (node.GetChildrenCount() == 1) { BehaviorNode childNode = node.GetChild(0); BehaviorTask childTask = childNode.CreateAndInitTask(); this.addChild(childTask); } else { Debug.Check(true); } }
//CheckBreakpoint should be after log of onenter/onexit/update, as it needs to flush msg to the client public static void CHECK_BREAKPOINT(Agent pAgent, BehaviorNode b, string action, EActionResult actionResult) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { string bpstr = GetTickInfo(pAgent, b, action); if (!string.IsNullOrEmpty(bpstr)) { LogManager.Instance.Log(pAgent, bpstr, actionResult, LogMode.ELM_tick); if (Workspace.Instance.CheckBreakpoint(pAgent, b, action, actionResult)) { LogManager.Instance.Log(pAgent, bpstr, actionResult, LogMode.ELM_breaked); LogManager.Instance.Flush(pAgent); SocketUtils.Flush(); _MY_BREAKPOINT_BREAK_(pAgent, bpstr, actionResult); LogManager.Instance.Log(pAgent, bpstr, actionResult, LogMode.ELM_continue); LogManager.Instance.Flush(pAgent); SocketUtils.Flush(); } } } #endif }
public void SetCustomCondition(BehaviorNode node) { this.m_customCondition = node; }
public override void Init(BehaviorNode node) { Debug.Check(node != null); base.Init(node); }
public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner) { Debug.Check(false); return false; }
public virtual bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner) { Debug.Check(false, "Can't step into this line"); return false; }
private void LogPlanNodePreconditionFailed(Agent a, BehaviorNode n) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { string ni = BehaviorTask.GetTickInfo(a, n, null); LogManager.Instance.Log("[plan_node_pre_failed]{0}\n", ni); } #endif }
private void LogPlanMethodBegin(Agent a, BehaviorNode m) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { string ni = BehaviorTask.GetTickInfo(a, m, null); LogManager.Instance.Log("[plan_method_begin]{0}\n", ni); a.Variables.Log(a, true); } #endif }
private void LogPlanMethodEnd(Agent a, BehaviorNode m, string result) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { string ni = BehaviorTask.GetTickInfo(a, m, null); LogManager.Instance.Log("[plan_method_end]{0} {1}\n", ni, result); } #endif }
protected BehaviorTask() { m_status = EBTStatus.BT_INVALID; m_node = null; m_parent = null; m_bHasManagingParent = false; }
public override void Init(BehaviorNode node) { base.Init(node); if (!this.m_bIgnoreChildren) { Debug.Check(node.GetChildrenCount() > 0); int childrenCount = node.GetChildrenCount(); for (int i = 0; i < childrenCount; i++) { BehaviorNode childNode = node.GetChild(i); BehaviorTask childTask = childNode.CreateAndInitTask(); this.addChild(childTask); } } }
//~DecoratorTask() //{ //} public override void Init(BehaviorNode node) { base.Init(node); //DecoratorNode pDN = node as DecoratorNode; }
public PlannerTask decomposeNode(BehaviorNode node, int depth) { try { // Ensure that the planner does not get stuck in an infinite loop if (depth >= 256) { Debug.LogError("Exceeded task nesting depth. Does the graph contain an invalid cycle?"); return(null); } LogPlanNodeBegin(this.agent, node); int depth1 = this.agent.Variables.Depth; PlannerTask taskAdded = null; bool isPreconditionOk = node.CheckPreconditions(this.agent, false); if (isPreconditionOk) { bool bOk = true; taskAdded = PlannerTask.Create(node, this.agent); if (node is Action) { //nothing to do for action Debug.Check(true); } else { Debug.Check(taskAdded is PlannerTaskComplex); PlannerTaskComplex seqTask = taskAdded as PlannerTaskComplex; bOk = this.decomposeComplex(node, seqTask, depth); } if (bOk) { node.ApplyEffects(this.agent, Effector.EPhase.E_SUCCESS); } else { BehaviorTask.DestroyTask(taskAdded); taskAdded = null; } } else { //precondition failed LogPlanNodePreconditionFailed(this.agent, node); } LogPlanNodeEnd(this.agent, node, taskAdded != null ? "success" : "failure"); Debug.Check(this.agent.Variables.Depth == depth1); return(taskAdded); } catch (Exception ex) { Debug.Check(false, ex.Message); } return(null); }
public static string GetTickInfo(Agent pAgent, BehaviorNode n, string action) { #if !BEHAVIAC_RELEASE if (Config.IsLoggingOrSocketing) { if (pAgent != null && pAgent.IsMasked()) { //BEHAVIAC_PROFILE("GetTickInfo", true); string bClassName = n.GetClassNameString(); //filter out intermediate bt, whose class name is empty if (!string.IsNullOrEmpty(bClassName)) { string btName = GetParentTreeName(n); string bpstr = ""; if (!string.IsNullOrEmpty(btName)) { bpstr = string.Format("{0}.xml->", btName); } int nodeId = n.GetId(); bpstr += string.Format("{0}[{1}]", bClassName, nodeId); if (!string.IsNullOrEmpty(action)) { bpstr += string.Format(":{0}", action); } return bpstr; } } } #endif return string.Empty; }
//~PlannerTask() //{ } public PlannerTask(BehaviorNode node, Agent pAgent) : base() { this.m_node = node; this.m_id = this.m_node.GetId(); }
private static string GetParentTreeName(BehaviorNode n) { string btName = null; if (n is ReferencedBehavior) { n = n.Parent; } bool bIsTree = false; bool bIsRefTree = false; while (n != null) { bIsTree = (n is BehaviorTree); bIsRefTree = (n is ReferencedBehavior); if (bIsTree || bIsRefTree) { break; } n = n.Parent; } if (bIsTree) { BehaviorTree bt = n as BehaviorTree; btName = bt.GetName(); } else if (bIsRefTree) { ReferencedBehavior refTree = n as ReferencedBehavior; btName = refTree.ReferencedTree; } else { Debug.Check(false); } return btName; }
public PlannerTask decomposeNode(BehaviorNode node, int depth) { try { // Ensure that the planner does not get stuck in an infinite loop if (depth >= 256) { Debug.LogError("Exceeded task nesting depth. Does the graph contain an invalid cycle?"); return null; } LogPlanNodeBegin(this.agent, node); int depth1 = this.agent.Variables.Depth; PlannerTask taskAdded = null; bool isPreconditionOk = node.CheckPreconditions(this.agent, false); if (isPreconditionOk) { bool bOk = true; taskAdded = PlannerTask.Create(node, this.agent); if (node is Action) { //nothing to do for action Debug.Check(true); } else { Debug.Check(taskAdded is PlannerTaskComplex); PlannerTaskComplex seqTask = taskAdded as PlannerTaskComplex; bOk = this.decomposeComplex(node, seqTask, depth); } if (bOk) { node.ApplyEffects(this.agent, Effector.EPhase.E_SUCCESS); } else { BehaviorTask.DestroyTask(taskAdded); taskAdded = null; } } else { //precondition failed LogPlanNodePreconditionFailed(this.agent, node); } LogPlanNodeEnd(this.agent, node, taskAdded != null ? "success" : "failure"); Debug.Check(this.agent.Variables.Depth == depth1); return taskAdded; } catch (Exception ex) { Debug.Check(false, ex.Message); } return null; }
public override bool decompose(BehaviorNode node, PlannerTaskComplex seqTask, int depth, Planner planner) { Debug.Check(false); return(false); }
public PlannerTaskComplex(BehaviorNode node, Agent pAgent) : base(node, pAgent) { }
public override void Init(BehaviorNode node) { base.Init(node); }
public PlannerTaskSelector(BehaviorNode node, Agent pAgent) : base(node, pAgent) { }
public PlannerTaskParallel(BehaviorNode node, Agent pAgent) : base(node, pAgent) { }
public PlannerTaskLoop(BehaviorNode node, Agent pAgent) : base(node, pAgent) { }