コード例 #1
0
	def extend_settlement_with_storage(self, target_position):
		"""Build a storage to extend the settlement towards the given position. Return a BUILD_RESULT constant."""
		if not self.have_resources(BUILDINGS.STORAGE):
			return BUILD_RESULT.NEED_RESOURCES

		storage_class = Entities.buildings[BUILDINGS.STORAGE]
		storage_spots = self.island.terrain_cache.get_buildability_intersection(storage_class.terrain_type,
			storage_class.size, self.settlement.buildability_cache, self.buildability_cache)
		storage_surrounding_offsets = Rect.get_surrounding_offsets(storage_class.size)
		coastline = self.land_manager.coastline

		options = []
		for (x, y) in sorted(storage_spots):
			builder = BasicBuilder.create(BUILDINGS.STORAGE, (x, y), 0)

			alignment = 1
			for (dx, dy) in storage_surrounding_offsets:
				coords = (x + dx, y + dy)
				if coords in coastline or coords not in self.plan or self.plan[coords][0] != BUILDING_PURPOSE.NONE:
					alignment += 1

			distance = distances.distance_rect_rect(target_position, builder.position)
			value = distance - alignment * 0.7
			options.append((-value, builder))
		return self.build_best_option(options, BUILDING_PURPOSE.STORAGE)
コード例 #2
0
    def extend_settlement_with_storage(self, target_position):
        """Build a storage to extend the settlement towards the given position. Return a BUILD_RESULT constant."""
        if not self.have_resources(BUILDINGS.STORAGE):
            return BUILD_RESULT.NEED_RESOURCES

        storage_class = Entities.buildings[BUILDINGS.STORAGE]
        storage_spots = self.island.terrain_cache.get_buildability_intersection(
            storage_class.terrain_type, storage_class.size,
            self.settlement.buildability_cache, self.buildability_cache)
        storage_surrounding_offsets = Rect.get_surrounding_offsets(
            storage_class.size)
        coastline = self.land_manager.coastline

        options = []
        for (x, y) in sorted(storage_spots):
            builder = BasicBuilder.create(BUILDINGS.STORAGE, (x, y), 0)

            alignment = 1
            for (dx, dy) in storage_surrounding_offsets:
                coords = (x + dx, y + dy)
                if coords in coastline or coords not in self.plan or self.plan[
                        coords][0] != BUILDING_PURPOSE.NONE:
                    alignment += 1

            distance = distances.distance_rect_rect(target_position,
                                                    builder.position)
            value = distance - alignment * 0.7
            options.append((-value, builder))
        return self.build_best_option(options, BUILDING_PURPOSE.STORAGE)
コード例 #3
0
ファイル: building.py プロジェクト: razluta/unknown-horizons
	def get_buildings_in_range(self):
		# TODO Think about moving this to the Settlement class
		buildings = self.settlement.buildings
		for building in buildings:
			if building is self:
				continue
			if distances.distance_rect_rect(self.position, building.position) <= self.radius:
				yield building
コード例 #4
0
	def get_buildings_in_range(self):
		# TODO Think about moving this to the Settlement class
		buildings = self.settlement.buildings
		for building in buildings:
			if building is self:
				continue
			if distances.distance_rect_rect(self.position, building.position) <= self.radius:
				yield building