def do(self, me): if (self.tool in me.things) == 0: # print "No tool" return tool = me.find_thing(self.tool)[0] if not hasattr(me, 'right_hand_wield') or me.right_hand_wield != tool.id: # FIXME We need to sort out how to tell seed one is wielding return Operation("wield", Entity(tool.id)) id = me.get_knowledge('focus', self.seed) if id is None: return seed = me.map.get(id) if seed is None: me.remove_knowledge('focus', self.seed) return if not seed.visible: me.remove_knowledge('focus', self.seed) return # Check that the seed isn't too close to other sources (to prevent us from planting too closely) sources_all = me.map.find_by_filter(self.source_filter) spacing_sqr = self.spacing * self.spacing for thing in sources_all: sqr_dist = square_distance(seed.location, thing.location) if sqr_dist and sqr_dist < spacing_sqr: # We've found a source which is too close to the seed, so we'll not plant this one me.remove_knowledge('focus', self.seed) return return Operation("use", Entity(seed.id, objtype="obj"))
def none_in_range(self, me): thing_all = me.map.find_by_filter(self.filter) for thing in thing_all: if square_distance(me.entity.location, thing.location) < self.square_range: return 0 return 1
def none_in_range(self, me): thing_all = me.map.find_by_filter(self.filter) for thing in thing_all: distance = square_distance(me.entity.location, thing.location) if distance and distance < self.square_range: return False return True
def do(self, me): thing_all = me.map.find_by_filter(self.filter) nearest = None nearsqrdist = self.range * self.range for thing in thing_all: # Check that it's not something we've already spotted if thing.id in self.spotted: # Have we forgotten about that we remembered it yet? if time.time() - self.spotted[ thing.id] > self.seconds_until_forgotten: self.spotted.pop(thing.id) else: continue sqr_dist = square_distance(me.entity.location, thing.location) # FIXME We need a more sophisticated check for parent. Perhaps just # check its not in a persons inventory? Requires the ability to # do decent type checks if sqr_dist and sqr_dist < nearsqrdist and thing.location.parent and me.entity.location.parent: if self.condition(thing): nearest = thing nearsqrdist = sqr_dist if nearest: print( "Spotted new thing matching '{}' at square distance of {}. Thing: {}" .format(self.what, nearsqrdist, str(nearest))) me.add_knowledge('focus', self.what, nearest.id) # We should only remember things if we can keep them in memory. if self.seconds_until_forgotten > 0: self.spotted[nearest.id] = time.time()
def is_thing_in_area(self, thing): if self.condition(thing): if self.current_location is None: return False sqr_dist = square_distance(self.current_location, thing.location) if sqr_dist and sqr_dist < self.sqr_range: return True return False
def in_range(self, me): focus_id = me.get_knowledge('focus', self.what) if focus_id is None: return thing = me.map.get(focus_id) if thing is None: return square_dist = square_distance(me.entity.location, thing.location) return square_dist and square_dist < self.square_proximity
def am_i_in_area(self, me): location = self.get_location_instance(me) if not location: # print "No location" return 0 if self.arrived: # print "Already arrived at location" square_dist = square_distance(me.entity.location, location) if square_dist > self.square_range: self.arrived = 0 # print "Moved away" return 0 else: # print "Still here", square_dist, self.square_range return 1 # print "I am not there" return 0