/
composite.py
32 lines (26 loc) · 963 Bytes
/
composite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from goal import Goal
class CompositeGoal(Goal):
def __init__(self, owner):
Goal.__init__(self, owner)
self.subgoals = []
def removeAllSubgoals(self):
for s in self.subgoals:
s.terminate()
self.subgoals = []
def processSubgoals(self):
# remove all completed and failed goals from the front of the
# subgoal list
while (self.subgoals and (self.subgoals[0].isComplete or
self.subgoals[0].hasFailed)):
subgoal = self.subgoals.pop()
subgoal.terminate()
if (self.subgoals):
subgoal = self.subgoals.pop()
status = subgoal.process()
if status == COMPLETED and len(self.subgoals) > 1:
return ACTIVE
return status
else:
return COMPLETED
def addSubgoal(self, goal):
self.subgoals.append(goal)