public EBTStatus resume(Agent pAgent, EBTStatus status) { BranchTask prev = null; BehaviorTask p = this.m_currentTask; while (p != null) { BranchTask branch = p as BranchTask; if (branch != null) { prev = branch; p = branch.GetCurrentTask(); } else { prev = p.GetParent(); break; } } if (prev != null) { //prev is the last interrupted node, to find and let its parent update with 'status' which is the subtree's return status Debug.Check(status == EBTStatus.BT_SUCCESS || status == EBTStatus.BT_FAILURE); prev.onexit_action(pAgent, status); prev.SetReturnStatus(status); } return(status); }
private BranchTask GetTopManageBranchTask() { BranchTask tree = null; BehaviorTask task = this.m_parent; while (task != null) { if (task is BehaviorTreeTask) { //to overwrite the child branch tree = (BranchTask)task; break; } else if (task.m_node.IsManagingChildrenAsSubTrees()) { //until it is Parallel/SelectorLoop, it's child is used as tree to store current task break; } else if (task is BranchTask) { //this if must be after BehaviorTreeTask and IsManagingChildrenAsSubTrees tree = (BranchTask)task; } else { Debug.Check(false); } task = task.m_parent; } return(tree); }
protected EBTStatus resume_branch(Agent pAgent, EBTStatus status) { Debug.Check(this.m_currentTask != null); Debug.Check(status == EBTStatus.BT_SUCCESS || status == EBTStatus.BT_FAILURE); BranchTask parent = null; if (this.m_currentTask.GetNode().IsManagingChildrenAsSubTrees()) { parent = (BranchTask)this.m_currentTask; } else { parent = this.m_currentTask.GetParent(); } //clear it as it ends and the next exec might need to set it this.m_currentTask = null; if (parent != null) { EBTStatus s = parent.exec(pAgent, status); return(s); } return(EBTStatus.BT_INVALID); }
private bool oneventCurrentNode(Agent pAgent, string eventName) { Debug.Check(this.m_currentTask != null); EBTStatus s = this.m_currentTask.GetStatus(); Debug.Check(s == EBTStatus.BT_RUNNING && this.m_node.HasEvents()); bool bGoOn = this.m_currentTask.onevent(pAgent, eventName); //give the handling back to parents if (bGoOn && this.m_currentTask != null) { BranchTask parentBranch = this.m_currentTask.GetParent(); //back track the parents until the branch while (parentBranch != null && parentBranch != this) { Debug.Check(parentBranch.GetStatus() == EBTStatus.BT_RUNNING); bGoOn = parentBranch.onevent(pAgent, eventName); if (!bGoOn) { return(false); } parentBranch = parentBranch.GetParent(); } } return(bGoOn); }
protected EBTStatus tickCurrentNode(Agent pAgent) { EBTStatus status = this.m_currentTask.GetStatus(); if ((status != EBTStatus.BT_INVALID) && (status != EBTStatus.BT_RUNNING)) { return(status); } BehaviorTask currentTask = this.m_currentTask; EBTStatus childStatus = this.m_currentTask.exec(pAgent); if (childStatus != EBTStatus.BT_RUNNING) { BranchTask parent = currentTask.GetParent(); this.SetCurrentTask(null); while ((parent != null) && (parent != this)) { childStatus = parent.update(pAgent, childStatus); if (childStatus == EBTStatus.BT_RUNNING) { return(EBTStatus.BT_RUNNING); } parent.onexit_action(pAgent, childStatus); parent.m_status = childStatus; parent = parent.GetParent(); } } return(childStatus); }
public EBTStatus exec(Agent pAgent) { bool flag; if (this.m_status == EBTStatus.BT_RUNNING) { flag = true; } else { this.m_status = EBTStatus.BT_INVALID; flag = this.onenter_action(pAgent); bool flag2 = this.isContinueTicking(); if (flag2) { BranchTask parentBranch = this.GetParentBranch(); if (parentBranch != null && parentBranch != this) { parentBranch.SetCurrentTask(this); } } } if (flag) { 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) { bool flag3 = this.isContinueTicking(); if (flag3) { BranchTask parentBranch2 = this.GetParentBranch(); if (parentBranch2 != null && parentBranch2 != this) { parentBranch2.SetCurrentTask(null); } } this.onexit_action(pAgent, this.m_status); } } else { this.m_status = EBTStatus.BT_FAILURE; } EBTStatus status = this.m_status; if (this.m_status != EBTStatus.BT_RUNNING && this.NeedRestart()) { this.m_status = EBTStatus.BT_INVALID; this.SetReturnStatus(EBTStatus.BT_INVALID); } return(status); }
protected BehaviorTask() { this.m_status = EBTStatus.BT_INVALID; this.m_node = null; this.m_attachments = null; this.m_parent = null; }
private EBTStatus execCurrentTask(Agent pAgent) { Debug.Check(this.m_currentTask != null && this.m_currentTask.GetStatus() == EBTStatus.BT_RUNNING); //this.m_currentTask could be cleared in ::tick, to remember it EBTStatus status = this.m_currentTask.exec(pAgent); //give the handling back to parents if (status != EBTStatus.BT_RUNNING) { Debug.Check(status == EBTStatus.BT_SUCCESS || status == EBTStatus.BT_FAILURE); Debug.Check(this.m_currentTask.m_status == status); BranchTask parentBranch = this.m_currentTask.GetParent(); this.m_currentTask = null; //back track the parents until the branch while (parentBranch != null && parentBranch != this) { status = parentBranch.exec(pAgent, status); if (status == EBTStatus.BT_RUNNING) { return(EBTStatus.BT_RUNNING); } Debug.Check(parentBranch.m_status == status); parentBranch = parentBranch.GetParent(); } } return(status); }
public EBTStatus resume(Agent pAgent, EBTStatus status) { BranchTask parent = null; BehaviorTask currentTask = base.m_currentTask; while (currentTask != null) { BranchTask task3 = currentTask as BranchTask; if (task3 != null) { parent = task3; currentTask = task3.GetCurrentTask(); } else { parent = currentTask.GetParent(); break; } } if (parent != null) { parent.onexit_action(pAgent, status); parent.SetReturnStatus(status); } return(status); }
public virtual void Clear() { this.m_status = EBTStatus.BT_INVALID; this.m_parent = null; this.m_id = -1; this.FreeAttachments(); this.m_node = null; }
private bool CheckParentUpdatePreconditions(Agent pAgent) { bool bValid = true; if (this.m_bHasManagingParent) { bool bHasManagingParent = false; const int kMaxParentsCount = 512; int parentsCount = 0; BehaviorTask[] parents = new BehaviorTask[kMaxParentsCount]; BranchTask parentBranch = this.GetParent(); parents[parentsCount++] = this; //back track the parents until the managing branch while (parentBranch != null) { Debug.Check(parentsCount < kMaxParentsCount, "weird tree!"); parents[parentsCount++] = parentBranch; if (parentBranch.GetCurrentTask() == this) { //Debug.Check(parentBranch->GetNode()->IsManagingChildrenAsSubTrees()); bHasManagingParent = true; break; } parentBranch = parentBranch.GetParent(); } if (bHasManagingParent) { for (int i = parentsCount - 1; i >= 0; --i) { BehaviorTask pb = parents[i]; bValid = pb.CheckPreconditions(pAgent, true); if (!bValid) { break; } } } } else { bValid = this.CheckPreconditions(pAgent, true); } return(bValid); }
public BranchTask GetParentBranch() { for (BehaviorTask task = this.m_parent; task != null; task = task.m_parent) { BranchTask task2 = task as BranchTask; if ((task2 != null) && task2.isContinueTicking()) { return(task2); } } return(null); }
public BranchTask GetParentBranch() { for (BehaviorTask parent = this.m_parent; parent != null; parent = parent.m_parent) { BranchTask branchTask = parent as BranchTask; if (branchTask != null && branchTask.isContinueTicking()) { return(branchTask); } } return(null); }
protected EBTStatus tickCurrentNode(Agent pAgent) { Debug.Check(this.m_currentTask != null); EBTStatus s = this.m_currentTask.GetStatus(); if (s == EBTStatus.BT_INVALID || s == EBTStatus.BT_RUNNING) { //this.m_currentTask could be cleared in ::tick, to remember it BehaviorTask currentTask = this.m_currentTask; EBTStatus status = this.m_currentTask.exec(pAgent); //give the handling back to parents if (status != EBTStatus.BT_RUNNING) { Debug.Check(currentTask.m_status == EBTStatus.BT_SUCCESS || currentTask.m_status == EBTStatus.BT_FAILURE || (currentTask.m_status == EBTStatus.BT_INVALID && currentTask.NeedRestart())); BranchTask parentBranch = currentTask.GetParent(); this.SetCurrentTask(null); //back track the parents until the branch while (parentBranch != null && parentBranch != this) { status = parentBranch.update(pAgent, status); if (status == EBTStatus.BT_RUNNING) { return(EBTStatus.BT_RUNNING); } parentBranch.onexit_action(pAgent, status); parentBranch.m_status = status; Debug.Check(parentBranch.m_currentTask == null); parentBranch = parentBranch.GetParent(); } } return(status); } return(s); }
/** * a branch is a node whose isContinueTicking returns true * * BehaviorTreeTask, DecoratorTask, ParallelTask, SelectorLoopTask, etc. */ public BranchTask GetParentBranch() { BehaviorTask pTopNode = this.m_parent; while (pTopNode != null) { BranchTask pBranch = pTopNode as BranchTask; if (pBranch != null && pBranch.isContinueTicking()) { return(pBranch); } pTopNode = pTopNode.m_parent; } return(null); }
private bool oneventCurrentNode(Agent pAgent, string eventName) { EBTStatus status = this.m_currentTask.GetStatus(); bool flag = this.m_currentTask.onevent(pAgent, eventName); if (flag) { for (BranchTask task = this.m_currentTask.GetParent(); (task != null) && (task != this); task = task.GetParent()) { flag = task.onevent(pAgent, eventName); if (!flag) { return(false); } } } return(flag); }
private bool oneventCurrentNode(Agent pAgent, string eventName) { EBTStatus status = this.m_currentTask.GetStatus(); bool flag = this.m_currentTask.onevent(pAgent, eventName); if (flag) { BranchTask parent = this.m_currentTask.GetParent(); while (parent != null && parent != this) { flag = parent.onevent(pAgent, eventName); if (!flag) { return(false); } parent = parent.GetParent(); } } return(flag); }
public EBTStatus resume(Agent pAgent, EBTStatus status) { BranchTask branchTask = null; BranchTask branchTask2; for (BehaviorTask currentTask = this.m_currentTask; currentTask != null; currentTask = branchTask2.GetCurrentTask()) { branchTask2 = (currentTask as BranchTask); if (branchTask2 == null) { branchTask = currentTask.GetParent(); break; } branchTask = branchTask2; } if (branchTask != null) { branchTask.onexit_action(pAgent, status); branchTask.SetReturnStatus(status); } return(status); }
public void SetParent(BranchTask parent) { this.m_parent = parent; }
public virtual void Clear() { this.m_status = EBTStatus.BT_INVALID; this.m_parent = null; if (this.m_attachments != null) { this.m_attachments.Clear(); this.m_attachments = null; } this.m_node = null; }
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); }
public virtual void Clear() { this.m_status = EBTStatus.BT_INVALID; this.m_parent = null; this.m_id = -1; this.m_node = null; }
protected BehaviorTask() { m_status = EBTStatus.BT_INVALID; m_node = null; m_parent = null; m_bHasManagingParent = false; }
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); }
protected BehaviorTask() { m_status = EBTStatus.BT_INVALID; m_node = null; m_attachments = null; m_parent = null; }