executeSubgoals method
Executes the current subgoal of this composite goal.
Implementation
GoalStatus executeSubgoals() {
final subgoals = this.subgoals;
// remove all completed and failed goals from the back of the subgoal list
for ( int i = subgoals.length - 1; i >= 0; i -- ) {
final subgoal = subgoals[ i ];
if ( ( subgoal.completed == true ) || ( subgoal.failed == true ) ) {
// if the current subgoal is a composite goal, terminate its subgoals too
if ( subgoal is CompositeGoal ) {
subgoal.clearSubgoals();
}
// terminate the subgoal itself
subgoal.terminate();
subgoals.removeLast();
}
else {
break;
}
}
// if any subgoals remain, process the one at the back of the list
final subgoal = currentSubgoal();
if ( subgoal != null ) {
subgoal.activateIfInactive();
subgoal.execute();
// if subgoal is completed but more subgoals are in the list, return 'ACTIVE'
// status in order to keep processing the list of subgoals
if ( ( subgoal.completed == true ) && ( subgoals.length > 1 ) ) {
return GoalStatus.active;
}
else {
return subgoal.status;
}
}
else {
return GoalStatus.completed;
}
}