def __init__(self, name, location=None, collector=None): """Constructor specific to characters. In it, we set up some Swallows-specific properties ('nerves'). """ Animate.__init__(self, name, location=location, collector=None) # this should really be *derived* from having a recent memory # of seeing a dead body in the bathroom. but for now, self.nerves = 'calm'
def believe_location(self, thing, location, informant=None, concealer=None): # we override this method of Animate in order to also remove # our suspicion that the item has been hidden. 'cos we found it. Animate.believe_location(self, thing, location, informant=informant, concealer=concealer) self.beliefs.remove(SuspicionOfHiding(thing))
def __init__(self, name, location=None, collector=None, revolver=None, brandy=None, dead_body=None): """Constructor specific to characters. In it, we set up some Swallows-specific properties ('nerves') and we set up some important items that this character needs to know about. This is maybe a form of dependency injection. """ Animate.__init__(self, name, location=location, collector=None) self.revolver = revolver self.brandy = brandy self.dead_body = dead_body # this should really be *derived* from having a recent memory # of seeing a dead body in the bathroom. but for now, self.nerves = 'calm'
def move_to(self, location): """Override some behaviour upon moving to a new location. """ Animate.move_to(self, location) if random.randint(0, 10) == 0: self.emit("It was so nice being in <2> again", [self, self.location], excl=True) # okay, look around you. for x in self.location.contents: assert x.location == self.location if x == self: continue if x.horror(): belief = self.recall_location(x) if belief: amount = random.choice(['shudder', 'wave']) emotion = random.choice(['fear', 'disgust', 'sickness', 'loathing']) self.emit("<1> felt a %s of %s as <he-1> looked at <2>" % (amount, emotion), [self, x]) self.remember_location(x, self.location) else: verb = random.choice(['screamed', 'yelped', 'went pale']) self.emit("<1> %s at the sight of <indef-2>" % verb, [self, x], excl=True) self.remember_location(x, self.location) self.nerves = 'shaken' elif x.animate(): other = x self.emit("<1> saw <2>", [self, other]) other.emit("<1> saw <2> walk into the %s" % self.location.noun(), [other, self]) self.remember_location(x, self.location) self.greet(x, "'Hello, <2>,' said <1>") for y in other.contents: if y.treasure(): self.emit( "<1> noticed <2> <was-2> carrying <indef-3>", [self, other, y]) if self.revolver.location == self: self.point_at(other, self.revolver) self.address(other, ThreatGiveMeTopic(self, subject=y), "'Please give me <3>, <2>, or I shall shoot you,' <he-1> said", [self, other, y]) return # check if we suspect something of being hidden. suspicions = list(self.beliefs.beliefs_of_class(SuspicionOfHiding)) # if we do... and we can do something about it... actionable_suspicions = [] for suspicion in suspicions: if not suspicion.subject.treasure(): continue if self.beliefs.get(ItemLocation(suspicion.subject)): continue actionable_suspicions.append(suspicion) if actionable_suspicions and self.revolver.location == self: suspicion = random.choice(actionable_suspicions) self.point_at(other, self.revolver) self.address(other, ThreatTellMeTopic(self, subject=suspicion.subject), "'Tell me where you have hidden <3>, <2>, or I shall shoot you,' <he-1> said", [self, other, suspicion.subject]) return elif x.notable(): self.emit("<1> saw <2>", [self, x]) self.remember_location(x, self.location)
def move_to(self, location): """Override some behaviour upon moving to a new location. """ Animate.move_to(self, location) if random.randint(0, 10) == 0: self.emit("It was so nice being in <2> again", [self, self.location], excl=True) # okay, look around you. for x in self.location.contents: assert x.location == self.location if x == self: continue if x.horror(): belief = self.recall_location(x) if belief: amount = random.choice(['shudder', 'wave']) emotion = random.choice( ['fear', 'disgust', 'sickness', 'loathing']) self.emit( "<1> felt a %s of %s as <he-1> looked at <2>" % (amount, emotion), [self, x]) self.remember_location(x, self.location) else: verb = random.choice(['screamed', 'yelped', 'went pale']) self.emit("<1> %s at the sight of <indef-2>" % verb, [self, x], excl=True) self.remember_location(x, self.location) self.nerves = 'shaken' elif x.animate(): other = x self.emit("<1> saw <2>", [self, other]) other.emit( "<1> saw <2> walk into the %s" % self.location.noun(), [other, self]) self.remember_location(x, self.location) self.greet(x, "'Hello, <2>,' said <1>") for y in other.contents: if y.treasure(): self.emit("<1> noticed <2> <was-2> carrying <indef-3>", [self, other, y]) if self.revolver.location == self: self.point_at(other, self.revolver) self.address( other, ThreatGiveMeTopic(self, subject=y), "'Please give me <3>, <2>, or I shall shoot you,' <he-1> said", [self, other, y]) return # check if we suspect something of being hidden. suspicions = list( self.beliefs.beliefs_of_class(SuspicionOfHiding)) # if we do... and we can do something about it... actionable_suspicions = [] for suspicion in suspicions: if not suspicion.subject.treasure(): continue if self.beliefs.get(ItemLocation(suspicion.subject)): continue actionable_suspicions.append(suspicion) if actionable_suspicions and self.revolver.location == self: suspicion = random.choice(actionable_suspicions) self.point_at(other, self.revolver) self.address( other, ThreatTellMeTopic(self, subject=suspicion.subject), "'Tell me where you have hidden <3>, <2>, or I shall shoot you,' <he-1> said", [self, other, suspicion.subject]) return elif x.notable(): self.emit("<1> saw <2>", [self, x]) self.remember_location(x, self.location)
def move_to(self, location): """Override some behaviour upon moving to a new location. """ Animate.move_to(self, location) if random.randint(0, 10) == 0: self.emit("It was so nice being in <2> again", [self, self.location], excl=True) # okay, look around you. for x in self.location.contents: assert x.location == self.location if x == self: continue if x.horror(): memory = self.recall(x) if memory: amount = pick(['shudder', 'wave']) emotion = pick(['fear', 'disgust', 'sickness', 'loathing']) self.emit("<1> felt a %s of %s as <he-1> looked at <2>" % (amount, emotion), [self, x]) self.remember(x, self.location) else: verb = pick(['screamed', 'yelped', 'went pale']) self.emit("<1> %s at the sight of <indef-2>" % verb, [self, x], excl=True) self.remember(x, self.location) self.nerves = 'shaken' elif x.animate(): other = x self.emit("<1> saw <2>", [self, other]) other.emit("<1> saw <2> walk into the %s" % self.location.noun(), [other, self]) self.remember(x, self.location) self.greet(x, "'Hello, <2>,' said <1>") for y in other.contents: if y.treasure(): self.emit( "<1> noticed <2> <was-2> carrying <indef-3>", [self, other, y]) if self.revolver.location == self: self.point_at(other, self.revolver) self.address(other, ThreatGiveMeTopic(self, subject=y), "'Please give me <3>, <2>, or I shall shoot you,' <he-1> said", [self, other, y]) return # another case of mind-reading. well, it helps the story advance! # (it would help more to double-check this against your OWN memory) if self.revolver.location == self: for thing in other.memories: memory = other.recall(thing) self_memory = self.recall(thing) if self_memory: continue if memory.i_hid_it_there and memory.subject is not self.revolver: self.point_at(other, self.revolver) self.address(other, ThreatTellMeTopic(self, subject=thing), "'Tell me where you have hidden <3>, <2>, or I shall shoot you,' <he-1> said", [self, other, thing]) return elif x.notable(): self.emit("<1> saw <2>", [self, x]) self.remember(x, self.location)