From 8cb6b72f2675e1ce727ae20ca1a0bf8f5988e5bf Mon Sep 17 00:00:00 2001 From: bitcraft Date: Mon, 22 Apr 2013 19:36:30 -0500 Subject: [PATCH] added 'conditions', set message when pirate is drunk (the end) --- npc/pirate/actions.py | 4 ++-- pygoap/environment.py | 10 ++++++++++ test.py | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/npc/pirate/actions.py b/npc/pirate/actions.py index eb187cb..a8b25fe 100644 --- a/npc/pirate/actions.py +++ b/npc/pirate/actions.py @@ -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 = [] @@ -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)) diff --git a/pygoap/environment.py b/pygoap/environment.py index f987271..dd94272 100644 --- a/pygoap/environment.py +++ b/pygoap/environment.py @@ -29,6 +29,7 @@ class for objects that agents can interact with def __init__(self, name='noname'): self.name = name + self._condition = {} def get_actions(self, other): """ @@ -36,6 +37,15 @@ def get_actions(self, other): """ 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 "".format(self.name) diff --git a/test.py b/test.py index b83e97f..a0aa17b 100644 --- a/test.py +++ b/test.py @@ -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)