Skip to content

Commit

Permalink
added 'conditions', set message when pirate is drunk (the end)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitcraft committed Apr 23, 2013
1 parent 2c9134b commit 8cb6b72
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions npc/pirate/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def enter(self):
def update(self, time):
self.drunkness += 1
if self.drunkness >= 3:
print "DRUNK!"
self.parent.set_condition('drunk', True)
self.finish()

exported_actions = []
Expand Down Expand Up @@ -120,7 +120,7 @@ class drink_rum(ActionBuilder):
"""
def get_actions(self, caller, memory):
for pct in memory.of_class(PositionPrecept):
print "looking for rum", pct
#print "looking for rum", pct
if pct.position[0] == 'self' and pct.entity.name == "rum":
action = DrinkRumAction(caller)
action.effects.append(SimpleGoal(is_drunk=True))
Expand Down
10 changes: 10 additions & 0 deletions pygoap/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@ class for objects that agents can interact with

def __init__(self, name='noname'):
self.name = name
self._condition = {}

def get_actions(self, other):
"""
generate a list of actions that could be used with this object
"""
return []

def condition(self, name):
try:
return self._condition[name]
except KeyError:
return False

def set_condition(self, name, value):
self._condition[name] = value

def __repr__(self):
return "<Object: {}>".format(self.name)

Expand Down
5 changes: 5 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def run_once():
wench = Human("Female", "wench")
formosa.add(wench)

if time >= 1:
if pirate.condition('drunk'):
print "YAY! A drunk pirate is a happy pirate!"
print "Test concluded"

screen_buf.fill((0,128,255))
formosa.render(screen_buf)
pygame.transform.scale2x(screen_buf, screen)
Expand Down

0 comments on commit 8cb6b72

Please sign in to comment.