示例#1
0
    def get_job(self):
        pos = self.position.to_tuple()

        # try to get away with a random job (with normal forest density this works > 99% of the time)
        for i in xrange(
                min(5, self._building_index.get_num_buildings_in_range(pos))):
            provider = self._building_index.get_random_building_in_range(pos)
            if provider is not None and self.check_possible_job_target(
                    provider):
                # animals only collect one resource
                entry = self.check_possible_job_target_for(
                    provider, self._required_resource_id)
                if entry:
                    path = self.check_move(provider.loading_area)
                    if path:
                        job = Job(provider, [entry])
                        job.path = path
                        return job

        # NOTE: only use random job for now, see how it's working it
        # it speeds up animal.search_job by a third (0.00321 -> 0.00231)
        # and animal.get_job by 3/4 (0.00231 -> 0.00061)
        return None

        jobs = JobList(self, JobList.order_by.random)
        # try all possible jobs
        for provider in self.home_island.get_building_index(
                self._required_resource_id).get_buildings_in_range(pos):
            if self.check_possible_job_target(provider):
                job = self.check_possible_job_target_for(
                    provider, self._required_resource_id)
                if job is not None:
                    jobs.append(job)

        return self.get_best_possible_job(jobs)
示例#2
0
	def get_job(self):
		pos = self.position.to_tuple()

		# try to get away with a random job (with normal forest density this works > 99% of the time)
		for i in xrange(min(5, self._building_index.get_num_buildings_in_range(pos))):
			provider = self._building_index.get_random_building_in_range(pos)
			if provider is not None and self.check_possible_job_target(provider):
				# animals only collect one resource
				entry = self.check_possible_job_target_for(provider, self._required_resource_id)
				if entry:
					path = self.check_move(provider.loading_area)
					if path:
						job = Job(provider, [entry])
						job.path = path
						return job

		# NOTE: only use random job for now, see how it's working it
		# it speeds up animal.search_job by a third (0.00321 -> 0.00231)
		# and animal.get_job by 3/4 (0.00231 -> 0.00061)
		return None

		jobs = JobList(self, JobList.order_by.random)
		# try all possible jobs
		for provider in self.home_island.get_building_index(self._required_resource_id).get_buildings_in_range(pos):
			if self.check_possible_job_target(provider):
				job = self.check_possible_job_target_for(provider, self._required_resource_id)
				if job is not None:
					jobs.append(job)

		return self.get_best_possible_job(jobs)
示例#3
0
	def get_job(self):
		pos = self.position.to_tuple()

		# try to get away with a random job (with normal forest density this works > 99% of the time)
		for i in xrange(min(5, self._building_index.get_num_buildings_in_range(pos))):
			provider = self._building_index.get_random_building_in_range(pos)
			if provider is not None and self.check_possible_job_target(provider):
				# animals only collect one resource
				entry = self.check_possible_job_target_for(provider, self._required_resource_id)
				if entry:
					path = self.check_move(provider.loading_area)
					if path:
						job = Job(provider, [entry])
						job.path = path
						return job

		# NOTE: use random job, works fine and is faster than looking for the best
		return None
示例#4
0
    def get_job(self):
        pos = self.position.to_tuple()

        # try to get away with a random job (with normal forest density this works > 99% of the time)
        for i in range(
                min(5, self._building_index.get_num_buildings_in_range(pos))):
            provider = self._building_index.get_random_building_in_range(pos)
            if provider is not None and self.check_possible_job_target(
                    provider):
                # animals only collect one resource
                entry = self.check_possible_job_target_for(
                    provider, self._required_resource_id)
                if entry:
                    path = self.check_move(provider.loading_area)
                    if path:
                        job = Job(provider, [entry])
                        job.path = path
                        return job

        # NOTE: use random job, works fine and is faster than looking for the best
        return None