/** * Constructs an ExecutionAction that knows how to run a ModelAction. * * @param modelTask * the ModelAction to run. * @param executor * the BTExecutor that will manage this ExecutionAction. * @param parent * the parent ExecutionTask of this task. */ protected ExecutionAction(ModelAction modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (modelTask == null) { throw new ArgumentException("The ModelTask must not be null"); } }
/** * Constructs an ExecutionRandomSelector to run a specific ModelRandomSelector. * * @param modelTask * the ModelRandomSelector to run. * @param executor * the BTExecutor that will manage this ExecutionRandomSelector. * @param parent * the parent ExecutionTask of this task. */ public ExecutionRandomSelector(ModelTask modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (!(modelTask is ModelRandomSelector)) { throw new ArgumentException("The ModelTask must subclass ModelRandomSelector but it inherits from " + modelTask.GetType().Name); } }
/** * Constructs an ExecutionLeaf to run a specific ModelLeaf. * * @param modelTask * the ModelLeaf to run. * @param executor * the BTExecutor that will manage this ExecutionLeaf. * @param parent * the parent ExecutionTask of this task. */ protected ExecutionLeaf(ModelTask modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (!(modelTask is ModelLeaf)) { throw new ArgumentException("The ModelTask must subclass ModelLeaf but it inherits from " + modelTask.GetType().Name); } }
public void CanRegisterAnInterrupter() { var executor = new BTExecutor(new ModelSuccess(null)); var modelInterrupter = new ModelInterrupter(null, new ModelSuccess(null)); executor.RegisterInterrupter((ExecutionInterrupter)modelInterrupter.CreateExecutor(executor, null)); Assert.NotNull(executor.GetExecutionInterrupter(modelInterrupter)); }
/** * Creates an ExecutionStaticPriorityList that is able to run a * ModelStaticPriorityList task and that is managed by a BTExecutor. * * @param modelTask * the ModelStaticPriorityList that this * ExecutionStaticPriorityList is going to run. * @param executor * the BTExecutor in charge of running this * ExecutionStaticPriorityList. * @param parent * the parent ExecutionTask of this task. */ public ExecutionStaticPriorityList(ModelTask modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (!(modelTask is ModelStaticPriorityList)) { throw new ArgumentException("The ModelTask must subclass ModelStaticPriorityList but it inherits from " + modelTask.GetType().Name); } }
/** * Constructs an ExecutionHierarchicalContextManager that knows how to run a * ModelHierarchicalContextManager. * * @param modelTask * the ModelHierarchicalContextManager to run. * @param executor * the BTExecutor that will manage this ExecutionHierarchicalContextManager. * @param parent * the parent ExecutionTask of this task. */ public ExecutionHierarchicalContextManager(ModelTask modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (!(modelTask is ModelHierarchicalContextManager)) { throw new ArgumentException("The ModelTask must subclass ModelHierarchicalContextManager but it inherits from " + modelTask.GetType().Name); } }
/** * Constructs and ExecutionUntilFail that knows how to run a ModelUntilFail. * * @param modelTask * the ModelUntilFail that this ExecutionUntilFail will run. * @param executor * the BTExecutor that will manage this ExecutionUntilFail. * @param parent * the parent ExecutionTask of this task. */ public ExecutionUntilFail(ModelTask modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (!(modelTask is ModelUntilFail)) { throw new ArgumentException("The ModelTask must subclass ModelUntilFail but it inherits from " + modelTask.GetType().Name); } }
/** * Creates an ExecutionPerformInterruption that is able to run a * ModelPerformInterruption task and that is managed by a BTExecutor. * * @param modelTask * the ModelPerformInterruption that this * ExecutionPerformInterruption is going to run. * @param executor * the BTExecutor in charge of running this * ExecutionPerformInterruption. * @param parent * the parent ExecutionTask of this task. */ public ExecutionPerformInterruption(ModelTask modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (!(modelTask is ModelPerformInterruption)) { throw new ArgumentException("The ModelTask must subclass ModelPerformInterruption but it inherits from " + modelTask.GetType().Name); } }
/** * Constructs an ExecutionSubtreeLookup that knows how to run a * ModelSubtreeLookup. * * @param modelTask * the ModelSubtreeLookup to run. * @param executor * the BTExecutor that will manage this ExecutionSubtreeLookup. * @param parent * the parent ExecutionTask of this task. */ public ExecutionSubtreeLookup(ModelTask modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (!(modelTask is ModelSubtreeLookup)) { throw new ArgumentException("The ModelTask must subclass ModelSubtreeLookup but it inherits from " + modelTask.GetType().Name); } }
/** * Creates an ExecutionWait that is able to run a ModelWait task and that is * managed by a BTExecutor. * * @param modelTask * the ModelWait that this ExecutionWait is going to run. * @param executor * the BTExecutor in charge of running this ExecutionWait. * @param parent * the parent ExecutionTask of this task. */ public ExecutionWait(ModelTask modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (!(modelTask is ModelWait)) { throw new ArgumentException("The ModelTask must subclass ModelWait but it inherits from " + modelTask.GetType().Name); } Initialize(modelTask); }
/** * Creates an ExecutionLimit that knows how to run a ModelLimit. * * @param modelTask * the ModelLimit to run. * @param executor * the BTExecutor that will manage this ExecutionLimit. * @param parent * the parent ExecutionTask of this task. */ public ExecutionLimit(ModelTask modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (!(modelTask is ModelLimit)) { throw new ArgumentException("The ModelTask must subclass ModelLimitbut it inherits from " + modelTask.GetType().Name); } _maxNumTimes = ((ModelLimit)ModelTask).getMaxNumTimes(); _numRunsSoFar = 0; }
/** * Constructs an ExecutionVariableRenamer that knows how to run a * ModelVariableRenamer. * * @param modelTask * the ModelVariableRenamer to run. * @param executor * the BTExecutor in charge of running this * ExecutionVariableRenamer. * @param parent * the parent ExecutionTask of this task. */ public ExecutionVariableRenamer(ModelTask modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (!(modelTask is ModelVariableRenamer)) { throw new ArgumentException("The ModelTask must subclass ModelVariableRenamer but it inherits from " + modelTask.GetType().Name); } _variableName = ((ModelVariableRenamer)modelTask).VariableName; _newVariableName = ((ModelVariableRenamer)modelTask).NewVariableName; }
/** * Creates an ExecutionParallel that is able to run a ModelParallel task and * that is managed by a BTExecutor. * * @param modelTask * the ModelParallel that this ExecutionParallel is going to run. * @param executor * the BTExecutor in charge of running this ExecutionParallel. * @param parent * the parent ExecutionTask of this task. */ public ExecutionParallel(ModelTask modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { if (!(modelTask is ModelParallel)) { throw new ArgumentException("The ModelTask must subclass " + typeof(ModelParallel).Name + " but it inherits from " + modelTask.GetType().Name); } _policy = ((ModelParallel)modelTask).Policy; _modelChildren = modelTask.Children; Initialize(); }
/// ///Interrupts the ExecutionInterrupter. This method causes the ///ExecutionInterrupter to terminate its child and set the status that will ///be returned to <code>status</code>. Also, it requests to be inserted into ///the list of tickable nodes, since the terminated child will no longer ///react to ticks after being terminated. ///<p> ///A task that have not been spawned cannot be interrupted. It should be ///noted that if the task has already been terminated, this method does ///nothing. Also, if the task has already been interrupted, this method does ///nothing too. /// ///@param status /// the status that the ExecutionInterrupter will return. /// public void Interrupt(Status status) { if (!_interrupted) { /// ///If the task has not been spawned, throw an exception. /// if (!Spawned) { throw new Exception("Cannot interrupt an ExecutionInterrupter that has not been spawned"); } /// ///Also it is important to note that that if the task has been ///terminated it cannot be interrupted, since by doing so the task ///would insert itself into the list of tickable nodes (see below), ///which should not be done since the task has been terminated. /// if (!HasTerminated) { if (status != Status.Failure && status != Status.Success) { throw new ArgumentException("The specified status is not valid. Must be either Status.FAILURE or Status.SUCCESS"); } if (_executionChild.ModelTask.Interrupter != null) { var executor = new BTExecutor(_executionChild.ModelTask.Interrupter, Context); RunInterrupterBranch(executor, ((ModelInterrupter)ModelTask).NumInterrupterBranchTicks + 1); } _executionChild.Terminate(); ///It is very important for the ExecutionInterrupter to be ///inserted into the list of tickable nodes. If not, after being ///interrupted, it will not inform its parent about the ///termination of its child. Keep in mind that after terminating ///its child, the child will not react to ticks (actually it ///will leave the list of tickable nodes in the next AI cycle), ///so it has to be the interrupter itself that informs its ///parent about termination. Executor.RequestInsertionIntoList(BTExecutor.BTExecutorList.Tickable, this); _interrupted = true; _statusSet = status; } } }
/** * Resets the evaluation of all the guards. This method leaves all the guard * executors ({@link #guardsExecutors}) ready to start again the evaluation * of the guards. It internally terminates the IBTExecutor of each guard, * creates a new one, and then ticks it. */ private void resetGuardsEvaluation() { for (int i = 0; i < _guardsExecutors.Count; i++) { BTExecutor guardExecutor = _guardsExecutors[i]; if (guardExecutor != null) { guardExecutor.Terminate(); guardsResults[i] = Status.Running; var newExecutor = new BTExecutor(guardExecutor.GetBehaviourTree(), Context); newExecutor.CopyTasksStates(guardExecutor); newExecutor.Tick(); _guardsExecutors[i] = newExecutor; } } }
public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return(null); }
public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { _executionAction = (T)Activator.CreateInstance(typeof(T), this, executor, parent); return(_executionAction); }
/** * Creates an ExecutionSequence that is able to run a ModelSequence task and * that is managed by a BTExecutor. * * @param modelTask * the ModelSequence that this ExecutionSequence is going to run. * @param executor * the BTExecutor in charge of running this ExecutionSequence. * @param parent * the parent ExecutionTask of this task. */ public ExecutionSequence(ModelSequence modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { }
/** * Creates a suitable ExecutionTask that will be able to run this ModelTask * through the management of a BTExecutor. * * @param executor * the BTExecutor that will manage the returned ExecutionTask. * @param parent * the parent ExecutionTask for the returned ExecutionTask. * * @return an ExecutionTask that is able to run this ModelTask. */ public abstract ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent);
public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return(new ExecutionInterrupter(this, executor, parent)); }
public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return(new ExecutionSequence(this, executor, parent)); }
/** * Constructs an ExecutionCondition that knows how to run a ModelCondition. * * @param modelTask * the ModelCondition to run. * @param executor * the BTExecutor that will manage this ExecutionCondition. * @param parent * the parent ExecutionTask of this task. */ protected ExecutionCondition(ModelCondition modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { }
/** * Checks if there is an active guard with a priority higher than that of the active child. If * there is such a task, it terminates the active child and spawns the child of the guard with * higher priority, and {@link Status#RUNNING} is returned. If there is no such task, then the * status of the active child is returned. * <p> * If the spawning process failed, this method just returns {@link Status#FAILURE}. If the * spawning process has not finished yet, this method keeps evaluating the guards, and returns * {@link Status#RUNNING}. * * @see jbt.execution.core.ExecutionTask#internalTick() */ protected override Status InternalTick() { /* If the spawning process failed, return failure. */ if (_spawnFailed) { return(Status.Failure); } /* Evaluate guards. */ Tuple <Status, int> activeGuard = EvaluateGuards(); /* * If no child has been spawned yet (not all the guards had completed yet in the * internalSpawn() method)... */ if (_stillNotSpawned) { /* If all the guards have failed, return failure. */ if (activeGuard.Item1 == Status.Failure) { return(Status.Failure); } if (activeGuard.Item1 == Status.Running) { /* * If not all the guards have finished, do no nothing (return RUNNING). */ } else { /* * If all the guards have been evaluated and one succeeded, spawn the child. */ _spawnFailed = false; _stillNotSpawned = false; _activeChildIndex = activeGuard.Item2; _activeChild = _children[_activeChildIndex].CreateExecutor(Executor, this); _activeChild.AddTaskListener(this); _activeChild.Spawn(Context); /* Reset the guards evaluators. */ ResetGuardsEvaluation(); } return(Status.Running); } /* If this point has been reached, there must be an active child. */ if (activeGuard.Item1 == Status.Failure) { /* If all the guards have failed, return failure. */ return(Status.Failure); } if (activeGuard.Item1 == Status.Running) { /* * If the guards are being evaluated, return the status of the active child. */ return(_activeChild.Status); } if (activeGuard.Item2 != _activeChildIndex) { /* * If the child with the highest priority guard has changed, terminate the currently * active child. */ if (_activeChild.ModelTask.Interrupter != null) { var executor = new BTExecutor(_activeChild.ModelTask.Interrupter, Context); ExecutionInterrupter.RunInterrupterBranch(executor, 10); } _activeChild.Terminate(); _activeChildIndex = activeGuard.Item2; /* * Spawn the new child. */ _activeChild = _children[_activeChildIndex].CreateExecutor(Executor, this); _activeChild.AddTaskListener(this); _activeChild.Spawn(Context); ResetGuardsEvaluation(); return(Status.Running); } /* * If the child with the highest priority guard has not changed, return the status * of the active child. */ ResetGuardsEvaluation(); return(_activeChild.Status); }
/** * Returns an ExecutionContextManager that knows how to run this * ModelHierarchicalContextManager. * * @see jbt.model.core.ModelTask#createExecutor(jbt.execution.core.BTExecutor, * ExecutionTask) */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return(new ExecutionHierarchicalContextManager(this, executor, parent)); }
/** * Returns an ExecutionRandomSelector that knows how to run this * ModelRandomSelector. * * @see jbt.model.core.ModelTask#createExecutor(jbt.execution.core.BTExecutor, * ExecutionTask) */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return(new ExecutionRandomSelector(this, executor, parent)); }
/** * Returns an ExecutionUntilFail that knows how to run this ModelUntilFail. * * @see jbt.model.core.ModelTask#createExecutor(jbt.execution.core.BTExecutor, * ExecutionTask) */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return(new ExecutionUntilFail(this, executor, parent)); }
/** * Returns an ExecutionSafeOutputContextManager that knows how to run this * ModelSafeOutputContextManager. * * @see jbt.model.core.ModelTask#createExecutor(jbt.execution.core.BTExecutor, * ExecutionTask) */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return(new ExecutionSafeOutputContextManager(this, executor, parent)); }
/** * Returns a new {@link ExecutionVariableRenamer} that knows how to run this * ModelVariableRenamer. * * @see jbt.model.core.ModelTask#createExecutor(jbt.execution.core.BTExecutor, * jbt.execution.core.ExecutionTask) */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return(new ExecutionVariableRenamer(this, executor, parent)); }
/** * Returns an ExecutionSubtreeLookup that is able to run this * ModelSubtreeLookup. */ public override ExecutionTask CreateExecutor(BTExecutor executor, ExecutionTask parent) { return(new ExecutionSubtreeLookup(this, executor, parent)); }
public MyAction(ModelAction modelTask, BTExecutor executor, ExecutionTask parent) : base(modelTask, executor, parent) { ReturnStatusForInternalTick = Status.Running; }