//----------------------------------------------------------------------------------------------- public void RestoreToLastDecomposedTask( out CompoundTask lastDecomposedTask, out Plan lastPlan, out Stack <Task> lastTaskHistory) { lastDecomposedTask = m_taskHistory.Pop(); lastPlan = m_planHistory.Pop(); lastTaskHistory = m_decompHistory.Pop(); }
//----------------------------------------------------------------------------------------------- public override Task Clone() { CompoundTask clone = new CompoundTask(m_name, m_modifierMask); clone.m_methods = m_methods; return clone; }
//----------------------------------------------------------------------------------------------- public void RecordTaskDecomposition( CompoundTask currentTask, Plan currentPlan, Stack <Task> decompHistory) { m_taskHistory.Push(currentTask); Plan planCopy = currentPlan.Clone(); m_planHistory.Push(planCopy); Stack <Task> decompClone = new Stack <Task>(decompHistory); m_decompHistory.Push(decompClone); }
//----------------------------------------------------------------------------------------------- private void HandleCompoundTask(CompoundTask task) { Method satisfiedMethod = task.FindSatisfiedMethod(m_workingWorldState); if (satisfiedMethod != null) { m_planHistory.RecordTaskDecomposition(task, m_finalPlan, m_tasksToProcess); DecomposeMethodAndAddToProcessStack(satisfiedMethod, task); } else { RestoreToLastDecomposedTask(); } }
//----------------------------------------------------------------------------------------------- private void DecomposeMethodAndAddToProcessStack(Method method, CompoundTask task) { List <Method.TaskWithModifiers> methodTasks = method.Subtasks; for (int taskIndex = (methodTasks.Count - 1); taskIndex >= 0; --taskIndex) { // Clone so we can store modifiers Task taskToPush = methodTasks[taskIndex].StoredTask.Clone(); if (methodTasks[taskIndex].StoredMods != null) { foreach (Task.eModifier mod in methodTasks[taskIndex].StoredMods) { taskToPush.AddModifier(mod); } } // Also add parent task's modifiers! taskToPush.CombineModifierMasks(task.ModifierMask); m_tasksToProcess.Push(taskToPush); } }