protected override DecompositionStatus OnDecomposeSlot(IContext <StateType> ctx, Slot <StateType> task, int taskIndex, int[] oldStackDepth, out Queue <ITask <StateType> > result) { var status = task.Decompose(ctx, 0, out var subPlan); // If result is null, that means the entire planning procedure should cancel. if (status == DecompositionStatus.Rejected) { if (ctx.LogDecomposition) { Log(ctx, $"Sequence.OnDecomposeSlot:{status}: Decomposing {task.Name} was rejected.", ConsoleColor.Red); } Plan.Clear(); ctx.TrimToStackDepth(oldStackDepth); result = null; return(DecompositionStatus.Rejected); } // If the decomposition failed if (status == DecompositionStatus.Failed) { if (ctx.LogDecomposition) { Log(ctx, $"Sequence.OnDecomposeSlot:{status}: Decomposing {task.Name} failed.", ConsoleColor.Red); } Plan.Clear(); ctx.TrimToStackDepth(oldStackDepth); result = Plan; return(DecompositionStatus.Failed); } while (subPlan.Count > 0) { var p = subPlan.Dequeue(); if (ctx.LogDecomposition) { Log(ctx, $"Sequence.OnDecomposeSlot:Decomposing {task.Name}:Pushed {p.Name} to plan!", ConsoleColor.Blue); } Plan.Enqueue(p); } if (ctx.HasPausedPartialPlan) { if (ctx.LogDecomposition) { Log(ctx, $"Sequence.OnDecomposeSlot:Return partial plan at index {taskIndex}!", ConsoleColor.DarkBlue); } if (taskIndex < Subtasks.Count - 1) { ctx.PartialPlanQueue.Enqueue(new PartialPlanEntry <StateType>() { Task = this, TaskIndex = taskIndex + 1, }); } result = Plan; return(DecompositionStatus.Partial); } result = Plan; if (ctx.LogDecomposition) { Log(ctx, $"Sequence.OnDecomposeSlot:Succeeded!", ConsoleColor.Green); } return(DecompositionStatus.Succeeded); }
protected abstract DecompositionStatus OnDecomposeSlot(IContext ctx, Slot task, int taskIndex, int[] oldStackDepth, out Queue <ITask> result);