def get_buildings_in_range(self, reslist=None): """Returns all buildings in range . Overwrite in subclasses that need ranges around the pickup. @param res: optional, only search for buildings that provide res""" reach = RadiusRect(self.home_building.position, self.home_building.radius) return self.session.world.get_providers_in_range(reach, reslist=reslist)
def get_animals_in_range(self, reslist=None): """Returns animals from buildings in range""" reach = RadiusRect(self.home_building.position, self.home_building.radius) # don't consider res when searching for buildings, since only their animals are # the acctual providers buildings = self.home_building.island.get_providers_in_range(reach) animal_lists = (building.animals for building in buildings if hasattr(building, 'animals')) # use overloaded + for lists here in sum return sum(animal_lists, [])
def get_job(self): jobs = JobList(self, JobList.order_by.random) collectable_resources = self.get_needed_resources() # iterate over all possible providers and needed resources # and save possible job targets position_rect = Rect.init_from_topleft_and_size( self.position.x, self.position.y, 0, 0) reach = RadiusRect(position_rect, self.walking_range) for provider in self.home_island.get_providers_in_range(reach): if self.check_possible_job_target(provider): for res in collectable_resources: job = self.check_possible_job_target_for(provider, res) if job is not None: jobs.append(job) return self.get_best_possible_job(jobs)