@Override public void cancelCurrentExecution() { finishCurrentGoalExecution(); }
private void finishCurrentGoalExecution() { if (executingRootGoal == null) return; resetGoalList(); executingPriority = -1; executingRootGoal = null; }
private void setupExecution(GoalEntry entry) { finishCurrentGoalExecution(); executingPriority = entry.getPriority(); executingRootGoal = entry.getGoal(); addGoalToExecution(entry.getGoal()); }
@Override public void finishAndRemove() { Goal toRemove = executingRootGoal; finish(); if (toRemove != null) { removeGoal(toRemove); } }
@Override public void run() { if (possibleGoals.isEmpty() || paused) return; trySelectGoal(); for (int i = 0; i < executingGoals.size(); ++i) { Goal goal = executingGoals.get(i); goal.run(selector); } }
setupExecution(entry); return; setupExecution(entry); break; setupExecution(entry); break; setupExecution(selected); break;
@Override public void clear() { finishCurrentGoalExecution(); possibleGoals.clear(); }
@Override public void removeBehavior(Behavior behavior) { for (int i = 0; i < possibleGoals.size(); ++i) { Goal test = possibleGoals.get(i).getGoal(); if (test.equals(behavior)) { possibleGoals.remove(i--); if (test == executingRootGoal) finishCurrentGoalExecution(); } } }
@Override public void removeGoal(Goal goal) { Preconditions.checkNotNull(goal, "goal cannot be null"); for (int j = 0; j < possibleGoals.size(); ++j) { Goal test = possibleGoals.get(j).getGoal(); if (!test.equals(goal)) continue; possibleGoals.remove(j--); if (test == executingRootGoal) { finishCurrentGoalExecution(); } } if (goal instanceof PrioritisableGoal) { boolean foundOther = false; for (GoalEntry test : possibleGoals) { if (test.getGoal() instanceof PrioritisableGoal) { foundOther = true; break; } } if (!foundOther) hasPrioritisableGoal = false; } }