public void testTreeWithSequenceSelectorSequenceWithEndAfterEachParent() { float deltaTime = 389.87f; Init(); initTree2(); btree2.Tick(new TimeData(deltaTime)); // Check callData to ensure leaf node was invoked by the Tick. // Check Sequence 1 Actions Assert.Equal(FactionSuccess, callData[seq1Action1 + deltaTime]); Assert.Equal(FactionSuccess, callData[seq1Action2 + deltaTime]); // Check Condition Actions Assert.Equal(FevalActionTrue, callData[sel1Condition + deltaTime]); Assert.Equal(FactionFail, callData[sel1Action1 + deltaTime]); Assert.Equal(FactionSuccess, callData[sel1Action2 + deltaTime]); // Last Selector action is not called because previous one was successful Assert.False(callData.ContainsKey(sel1Action3 + deltaTime)); // Parallel Calls will now be executed b/c it is outside the scope of the selector Assert.Equal(FactionSuccess, callData[par1Action1 + deltaTime]); Assert.Equal(FactionSuccess, callData[par1Action2 + deltaTime]); Assert.Equal(FactionSuccess, callData[par1Action3 + deltaTime]); // Sequence2 will also be ignored because of the selector Assert.Equal(FactionSuccess, callData[seq2Action1 + deltaTime]); Assert.Equal(FactionSuccess, callData[seq2Action2 + deltaTime]); Assert.Equal(FactionSuccess, callData[seq2Action3 + deltaTime]); }
void FixedUpdate() { CheckTargetDetection(); CurrentBehaviours.Clear(); tree.Tick(Time.deltaTime); ComputeSteering(); }
public void testTreeWithSequenceSelectorSequenceWithNoEndBetweenParents() { float deltaTime = 89.6f; Init(); initTree1(); btree1.Tick(new TimeData(deltaTime)); // Check callData to ensure leaf node was invoked by the Tick. // Check Sequence 1 Actions Assert.Equal(FactionSuccess, callData[seq1Action1 + deltaTime]); Assert.Equal(FactionSuccess, callData[seq1Action2 + deltaTime]); // Check Condition Actions Assert.Equal(FevalActionTrue, callData[sel1Condition + deltaTime]); Assert.Equal(FactionFail, callData[sel1Action1 + deltaTime]); Assert.Equal(FactionSuccess, callData[sel1Action2 + deltaTime]); // Last Selector action is not called because previous one was successful Assert.False(callData.ContainsKey(sel1Action3 + deltaTime)); // Parallel Calls will not be executed b/c it is in selector scope Assert.False(callData.ContainsKey(par1Action1 + deltaTime)); Assert.False(callData.ContainsKey(par1Action2 + deltaTime)); Assert.False(callData.ContainsKey(par1Action3 + deltaTime)); // Sequence2 will also be ignored because it is also in selector scope Assert.False(callData.ContainsKey(seq2Action1 + deltaTime)); Assert.False(callData.ContainsKey(seq2Action2 + deltaTime)); Assert.False(callData.ContainsKey(seq2Action3 + deltaTime)); }
public void testParallelFailure() { float deltaTime = 123.87f; Init(); initTree2(); btree2.Tick(new TimeData(deltaTime)); // Check callData to ensure leaf node was invoked by the Tick. // Check Sequence 1 Actions Assert.Equal(FactionSuccess, callData[seq1Action1 + deltaTime]); Assert.Equal(FactionSuccess, callData[seq1Action2 + deltaTime]); // Check Condition Actions Assert.Equal(FevalActionTrue, callData[sel1Condition + deltaTime]); Assert.Equal(FactionFail, callData[sel1Action1 + deltaTime]); Assert.Equal(FactionFail, callData[sel1Action2 + deltaTime]); // Last Selector will be called because it is the only one that does not fail Assert.Equal(FactionSuccess, callData[sel1Action3 + deltaTime]); // Parallel Calls will be executed but because it meets failure criteria // the next parent will not be executed. Assert.Equal(FactionFail, callData[par1Action1 + deltaTime]); Assert.Equal(FactionFail, callData[par1Action2 + deltaTime]); Assert.Equal(FactionSuccess, callData[par1Action3 + deltaTime]); // Last Sequence will not be called - because of failure of parallel nodes Assert.False(callData.ContainsKey(seq2Action1 + deltaTime)); Assert.False(callData.ContainsKey(seq2Action2 + deltaTime)); Assert.False(callData.ContainsKey(seq2Action3 + deltaTime)); }
private void Update() { if (updateTree != null) { updateTree.Tick(new TimeData(Time.deltaTime)); } }
public string RegisterBehaviour(IBehaviourTreeNode node) { TimeData time = new TimeData(_objProc.ProcessingTickInterval); string behaviourID = _objProc.RegisterProcessingEvent(() => node.Tick(time)); return(behaviourID); }
public void testSecondSequenceSucceeds() { float deltaTime = 523.4f; Init(); initTree1(); btree1.Tick(new TimeData(deltaTime)); // Check callData to ensure leaf node was invoked by the Tick. // Check Sequence 1 Actions Assert.Equal(FactionSuccess, callData[seq1Action1 + deltaTime]); Assert.Equal(FactionSuccess, callData[seq1Action2 + deltaTime]); // Check Condition Actions Assert.Equal(FevalActionTrue, callData[sel1Condition + deltaTime]); Assert.Equal(FactionFail, callData[sel1Action1 + deltaTime]); Assert.Equal(FactionFail, callData[sel1Action2 + deltaTime]); // Last Selector will be called because it is the only one that does not fail Assert.Equal(FactionSuccess, callData[sel1Action3 + deltaTime]); // Parallel Calls will not be executed b/c it is in selector scope Assert.False(callData.ContainsKey(par1Action1 + deltaTime)); Assert.False(callData.ContainsKey(par1Action2 + deltaTime)); Assert.False(callData.ContainsKey(par1Action3 + deltaTime)); // Sequence2 will now be executed because of the end() placed after the parallel calls Assert.Equal(FactionSuccess, callData[seq2Action1 + deltaTime]); Assert.Equal(FactionSuccess, callData[seq2Action2 + deltaTime]); Assert.Equal(FactionSuccess, callData[seq2Action3 + deltaTime]); }
private void FixedUpdate() { if (fixedUpdateTree != null) { fixedUpdateTree.Tick(new TimeData(Time.fixedDeltaTime)); } }
public BehaviourTreeStatus Tick(TimeData time) { if (childNode == null) { throw new ApplicationException("Succeeder must have a child node!"); } childNode.Tick(time); return(BehaviourTreeStatus.Success); }
public BehaviourTreeStatus Tick(TimeData time) { var childStatus = childNode.Tick(time); if (childStatus == BehaviourTreeStatus.Failure) { return(BehaviourTreeStatus.Success); } return(BehaviourTreeStatus.Running); }
public void Run(object[] args) { TimeData time = new TimeData(_ops.ProcessingTickInterval); IBehaviourTreeNode node = (IBehaviourTreeNode)args[0]; NWCreature creature = (NWCreature)args[1]; if (creature.IsValid && !creature.IsDead && !creature.IsPossessedFamiliar && !creature.IsDMPossessed) { node.Tick(time); } }
private void LogicPulse() { tree.Tick(new TimeData()); // If we are stil running we want to return here if (running) { return; } pulse.Stop(); // Calling the onstop callback to signalise the core that we are done running the botbase fisher.OnStopCallback(); }
public BehaviourTreeStatus Tick(TimeData time) { if ((maxIterations > -1 || maxIterations == 0) && iterations >= maxIterations) { iterations = 0; return(BehaviourTreeStatus.Success); } childNode.Tick(time); iterations++; return(BehaviourTreeStatus.Running); }
public void RegisterBehaviour(IBehaviourTreeNode node, NWCreature creature) { TimeData time = new TimeData(_objProc.ProcessingTickInterval); string behaviourID = _objProc.RegisterProcessingEvent(() => { if (creature.IsValid) { node.Tick(time); } }); _state.NPCBehaviours.Add(behaviourID, creature); }
public BehaviourTreeStatus Tick(TreeData data) { if (childNode == null) { throw new ApplicationException("InverterNode must have a child node!"); } var result = childNode.Tick(data); if (result == BehaviourTreeStatus.Failure) { return BehaviourTreeStatus.Success; } else if (result == BehaviourTreeStatus.Success) { return BehaviourTreeStatus.Success; } else { return result; } }
public void Update(float deltaTime) { _tree.Tick(new TimeData(deltaTime)); // Hack in some environmental effects. // Currently breathability is all that affects if the shield is up or not. if (this.CanBreathe()) { // this.Breathe(deltaTime); ShieldStatus = false; } else { ShieldStatus = true; } if (_cbCharacterChanged != null) { _cbCharacterChanged(this); } }
IEnumerator TickTree(string inputval, System.Action <BehaviourTreeStatus, string> callback) { while (continueBehaviourTree) { done = false; Log("\n\n"); callData = new Dictionary <string, string>(); Log("============> Beginning of TickTree(): input Value=" + inputval + " ---> Loop Number: " + numloops); int numticks = 0; for (var e = btree1.Tick(new TimeData(Time.deltaTime)); e.MoveNext();) { ++numticks; yield return(e.Current); callback(e.Current, "Callback Called From TickTree() - Tick Number=" + numticks + " --> Behavior Status=" + e.Current); } Log("End of TickTree() - Done=true"); done = true; Log("--> Tree Hierarchy after:"); Log(btree1.getTreeAsString(" --> ")); Log("--> Tree Hierarchy Reset:"); btree1.SetStatusAll(BehaviourTreeStatus.Initial); Log(btree1.getTreeAsString(" --> ")); Debug.Log(report); report = ""; ++numloops; if (numloops > maxloops) { continueBehaviourTree = false; break; } yield return(new WaitForSeconds(2)); } yield return(null); }
public override BehaviourTreeStatus Tick(T time) { if (childNode == null) { throw new ApplicationException("InverterNode must have a child node!"); } var result = childNode.Tick(time); if (result == BehaviourTreeStatus.Failure) { return(BehaviourTreeStatus.Success); } else if (result == BehaviourTreeStatus.Success) { return(BehaviourTreeStatus.Failure); } else { return(result); } }
public IEnumerator <BehaviourTreeStatus> Tick(TimeData time) { if (childNode == null) { throw new ApplicationException("InverterNode must have a child node!"); } var result = childNode.Tick(time); result.MoveNext(); currentStatus = result.Current; if (isRunning()) { // keep looping until we exit running mode or we // run out of enum values. yield return(currentStatus); while (result.MoveNext()) { currentStatus = result.Current; if (!isRunning()) { break; } } } if (isFailed()) { currentStatus = BehaviourTreeStatus.Success; } else if (isSuccess()) { currentStatus = BehaviourTreeStatus.Failure; } yield return(currentStatus); }
// Update is called once per frame void Update() { tree.Tick(new TimeData(Time.deltaTime)); }
public void testRandomSelector() { float deltaTime = 523.4f; Init(); initTree1(); btree1.Tick(new TimeData(deltaTime)); // Check callData to ensure leaf node was invoked by the Tick. // Check Sequence 1 Actions Assert.Equal(FactionSuccess, callData[seq1Action1 + deltaTime]); Assert.Equal(FactionSuccess, callData[seq1Action2 + deltaTime]); // Check Condition Actions Assert.Equal(FevalActionTrue, callData[sel1Condition + deltaTime]); // the actions will be random and there is a 1/12 chance that it could be the 1st one // and may cause the unit test to fail. This line should be commented out for automated // unit testing. Assert.False(callData.ContainsKey(sel1Action1 + deltaTime)); // check that exactly only one action was triggered ... int numTriggered = 0; if (callData.ContainsKey(sel1Action1 + deltaTime)) { ++numTriggered; } if (callData.ContainsKey(sel1Action2 + deltaTime)) { ++numTriggered; } if (callData.ContainsKey(sel1Action3 + deltaTime)) { ++numTriggered; } if (callData.ContainsKey(sel1Action4 + deltaTime)) { ++numTriggered; } if (callData.ContainsKey(sel1Action5 + deltaTime)) { ++numTriggered; } if (callData.ContainsKey(sel1Action6 + deltaTime)) { ++numTriggered; } if (callData.ContainsKey(sel1Action7 + deltaTime)) { ++numTriggered; } if (callData.ContainsKey(sel1Action8 + deltaTime)) { ++numTriggered; } if (callData.ContainsKey(sel1Action9 + deltaTime)) { ++numTriggered; } if (callData.ContainsKey(sel1Action10 + deltaTime)) { ++numTriggered; } if (callData.ContainsKey(sel1Action11 + deltaTime)) { ++numTriggered; } if (callData.ContainsKey(sel1Action12 + deltaTime)) { ++numTriggered; } Assert.Equal(numTriggered, 1); // Check 2nd Condition Actions Assert.Equal(FevalActionTrue, callData[sel2Condition + deltaTime]); Assert.Equal(FactionFail, callData[sel2Action1 + deltaTime]); Assert.Equal(FactionFail, callData[sel2Action2 + deltaTime]); Assert.Equal(FactionFail, callData[sel2Action3 + deltaTime]); Assert.Equal(FactionFail, callData[sel2Action4 + deltaTime]); // The 5th Selector will be called because it is the first one that does not fail Assert.Equal(FactionSuccess, callData[sel2Action5 + deltaTime]); Assert.False(callData.ContainsKey(sel2Action6 + deltaTime)); Assert.False(callData.ContainsKey(sel2Action7 + deltaTime)); Assert.False(callData.ContainsKey(sel2Action8 + deltaTime)); Assert.False(callData.ContainsKey(sel2Action9 + deltaTime)); Assert.False(callData.ContainsKey(sel2Action10 + deltaTime)); Assert.False(callData.ContainsKey(sel2Action11 + deltaTime)); Assert.False(callData.ContainsKey(sel2Action12 + deltaTime)); }