protected override void InternalSpawn()
 {
     this.activeChildIndex = 0;
     this.children = this.ModelTask.Children;
     this.activeChild = this.children[this.activeChildIndex].CreateExecutor(this.BTExecutor, this);
     this.activeChild.Spawn(this.GetGlobalContext());
 }
 public ExecutionSelector(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(modelTask is ModelSelector)) {
         throw new ArgumentException("The ModelTask must subclass "
         + typeof(ModelSelector) + " but it inherits from "
         + modelTask.GetType().BaseType);
     }
 }
 public ExecutionComposite(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
     : base(modelTask, executor, parent)
 {
     if (!(typeof(ModelComposite).IsAssignableFrom(modelTask.GetType()))) {
         throw new ArgumentException("The ModelTask " + modelTask.GetType() + " must subclass "
         + typeof(ModelComposite) + " but it inherits from "
         + modelTask.GetType().BaseType);
     }
 }
 protected override TaskStatus InternalTick()
 {
     var childStatus = this.child.GetStatus();
     // Since we're repeating, do it again and spawn a new one
     if (childStatus != TaskStatus.RUNNING) {
         this.child = ((ModelDecorator)this.ModelTask).GetChild().CreateExecutor(this.BTExecutor, this);
         this.child.Spawn(this.GetGlobalContext());
     }
     return TaskStatus.RUNNING;
 }
 protected override void InternalSpawn()
 {
     this.decoratedExecutor = ((ModelDecorator)this.ModelTask).GetChild().CreateExecutor(this.BTExecutor, this);
     // This saves us, depending on situation, a lot of cpu time when we don't have to check
     // for the decorated executor status and run through a lot of decisions on each tick.
     // It may return running for a lot of ticks so better listen for when it actually changes
     this.decoratedExecutor.AddTaskStatusChangedCallback(this.DecoratedExecutorStatusChange);
     this.decoratedExecutor.Spawn(this.GetGlobalContext());
     // while not ticking return running
     doNotTick = true;
     failed = false; // if failed, return failed
     this.successModel = this.ModelTask.Children[1];
     this.failModel = this.ModelTask.Children[2];
     if (successModel == null && failModel == null) {
         throw new ArgumentException("At least one condition must be handled by a model in StatusResponder! Both were null!");
     }
 }
        public ExecutionTask(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
        {
            this.modelTask = modelTask;
            this.executor = executor;
            this.spawnable = true;
            this.tickable = false;
            this.status = TaskStatus.UNINITIALISED;

            if (parent == null) {
                this.position = new Position();
            }
            else {
                this.position = new Position(parent.position);
                this.position.AddMove(GetMove());
                this.parent = parent;
            }
        }
        protected override TaskStatus InternalTick()
        {
            TaskStatus childStatus = this.activeChild.GetStatus();

            if (childStatus == TaskStatus.RUNNING) {
                return TaskStatus.RUNNING;
            }
            else if (childStatus == TaskStatus.FAILURE || childStatus == TaskStatus.TERMINATED) {
                return TaskStatus.FAILURE;
            }
            else {
                if (this.activeChildIndex == this.children.Count - 1) {
                    return TaskStatus.SUCCESS;
                }
                else {
                    this.activeChildIndex++;
                    this.activeChild = this.children[this.activeChildIndex].CreateExecutor(this.BTExecutor, this);
                    this.activeChild.Spawn(this.GetGlobalContext());
                    return TaskStatus.RUNNING;
                }
            }
        }
 public void Tick()
 {
     TaskStatus currentStatus = this.GetStatus();
     if (currentStatus == TaskStatus.RUNNING || currentStatus == TaskStatus.UNINITIALISED) {
         this.ProcessQueues();
         if (!this.isInitialised) {
             this.executionBT = this.rootModel.CreateExecutor(this, null);
             this.executionBT.Spawn(this.context);
             this.isInitialised = true;
         }
         else {
             for (int i = 0; i < tickableTasks.Count; ++i) {
                 tickableTasks[i].Tick();
             }
         }
     }
 }
 public void Reset()
 {
     this.isInitialised = false;
     // Makes sure GetStatus returns UNINITIALISED next time
     this.executionBT = null;
     this.tickableTasks.Clear();
     this.tickableTasksDeletionQueue.Clear();
     this.tickableTasksInsertionQueue.Clear();
 }
 public void RequestTickableRemoval(ExecutionTask task)
 {
     tickableTasksDeletionQueue.Add(task);
 }
 public void RequestTickableInsertion(ExecutionTask task)
 {
     tickableTasksInsertionQueue.Add(task);
 }
 /// <summary>
 /// Creates a suitable ExecutionTask that will be able to run this ModelTask
 /// through the management of a BTExecutor.
 /// </summary>
 /// <param name="btExecutor"></param>
 /// <param name="parent"></param>
 /// <returns></returns>
 public abstract ExecutionTask CreateExecutor(IBTExecutor btExecutor, ExecutionTask parent);
        private void DecoratedExecutorStatusChange(TaskEvent e)
        {
            executingCondition = null;
            if ((e.NewStatus == TaskStatus.FAILURE || e.NewStatus == TaskStatus.TERMINATED) && failModel != null) {
                this.executingCondition = failModel.CreateExecutor(this.BTExecutor, this);
            }
            else if (e.NewStatus == TaskStatus.SUCCESS && successModel != null) {
                this.executingCondition = successModel.CreateExecutor(this.BTExecutor, this);
            }

            if (executingCondition != null) {
                executingCondition.Spawn(this.GetGlobalContext());
                doNotTick = false;
                failed = true;
            }
        }
 protected override void InternalSpawn()
 {
     this.child = ((ModelDecorator)this.ModelTask).GetChild().CreateExecutor(this.BTExecutor, this);
     this.child.Spawn(this.GetGlobalContext());
 }
 public override ExecutionTask CreateExecutor(IBTExecutor btExecutor, ExecutionTask parent)
 {
     return new ExecutionStatusResponder(this, btExecutor, parent);
 }
 public override ExecutionTask CreateExecutor(IBTExecutor btExecutor, ExecutionTask parent)
 {
     return new ExecutionSequence(this, btExecutor, parent);
 }