def get_job(self):
		"""Returns the next job or None"""
		if self.home_building is None:
			return None

		collectable_res = self.get_collectable_res()
		if len(collectable_res) == 0:
			return None

		jobs = JobList(self, self.job_ordering)
		# iterate all building that provide one of the resources
		for building in self.get_buildings_in_range(reslist=collectable_res):
			if self.check_possible_job_target(building): # check if we can pickup here on principle
				for res in collectable_res:
					# check if we can get res here now
					job = self.check_possible_job_target_for(building, res)
					if job is not None:
						jobs.append(job)

		# TODO: find out why order of  self.get_buildings_in_range(..) and therefor order of jobs differs from client to client
		# TODO: find out why WindAnimal.get_job(..) doesn't have this problem
		# for MP-Games the jobs must have the same ordering to ensure get_best_possible_job(..) returns the same result
		jobs.sort(key=lambda job: job.object.worldid)

		return self.get_best_possible_job(jobs)
	def get_job(self):
		"""Returns the next job or None"""
		if self.home_building is None:
			return None

		collectable_res = self.get_collectable_res()
		if not collectable_res:
			return None

		jobs = JobList(self, self.job_ordering)
		# iterate all building that provide one of the resources
		for building in self.get_buildings_in_range(reslist=collectable_res):
			# check if we can pickup here on principle
			target_possible = self._target_possible_cache.get(building, None)
			if target_possible is None: # not in cache, we have to check
				target_possible = self.check_possible_job_target(building)
				self._target_possible_cache[building] = target_possible

			if target_possible:
				# check for res here
				reslist = ( self.check_possible_job_target_for(building, res) for res in collectable_res )
				reslist = [i for i in reslist if i]

				if reslist: # we can do something here
					jobs.append( Job(building, reslist) )

		# TODO: find out why order of  self.get_buildings_in_range(..) and therefore order of jobs differs from client to client
		# TODO: find out why WildAnimal.get_job(..) doesn't have this problem
		# for MP-Games the jobs must have the same ordering to ensure get_best_possible_job(..) returns the same result
		jobs.sort(key=lambda job: job.object.worldid)

		return self.get_best_possible_job(jobs)
Esempio n. 3
0
    def get_job(self):
        """Returns the next job or None"""
        if self.home_building is None:
            return None

        collectable_res = self.get_collectable_res()
        if not collectable_res:
            return None

        jobs = JobList(self, self.job_ordering)
        # iterate all building that provide one of the resources
        for building in self.get_buildings_in_range(reslist=collectable_res):
            # check if we can pickup here on principle
            target_possible = self._target_possible_cache.get(building, None)
            if target_possible is None:  # not in cache, we have to check
                target_possible = self.check_possible_job_target(building)
                self._target_possible_cache[building] = target_possible

            if target_possible:
                # check for res here
                reslist = (self.check_possible_job_target_for(building, res)
                           for res in collectable_res)
                reslist = [i for i in reslist if i]

                if reslist:  # we can do something here
                    jobs.append(Job(building, reslist))

        # TODO: find out why order of  self.get_buildings_in_range(..) and therefore order of jobs differs from client to client
        # TODO: find out why WildAnimal.get_job(..) doesn't have this problem
        # for MP-Games the jobs must have the same ordering to ensure get_best_possible_job(..) returns the same result
        jobs.sort(key=lambda job: job.object.worldid)

        return self.get_best_possible_job(jobs)