Example #1
0
	def highlight_buildable(self, tiles_to_check=None):
		"""Highlights all buildable tiles.
		@param tiles_to_check: list of tiles to check for coloring."""
		self._build_logic.highlight_buildable(self, tiles_to_check)

		# also distinguish related buildings (lumberjack for tree)
		related = frozenset(self.session.db.get_inverse_related_building_ids(self._class.id))
		renderer = self.session.view.renderer['InstanceRenderer']
		if tiles_to_check is None:
			buildings_to_select = [ buildings_to_select for\
			                        settlement in self.session.world.settlements if \
			                        settlement.owner.is_local_player for \
			                        bid in related  for \
			                        buildings_to_select in settlement.buildings_by_id[bid] ]

			tiles = SelectableBuildingComponent.select_many(buildings_to_select, renderer)
			self._related_buildings_selected_tiles = frozenset(tiles)
		else:
			buildings_to_select = [ tile.object for tile in tiles_to_check if \
			                        tile.object is not None and tile.object.id in related ]
			for tile in tiles_to_check:
				# check if we need to recolor the tiles
				if tile in self._related_buildings_selected_tiles:
					SelectableBuildingComponent._add_selected_tile(tile, renderer, remember=False)

		for building in buildings_to_select:
			self._related_buildings.add(building)
    def highlight_buildable(self, tiles_to_check=None, new_buildings=True):
        """Highlights all buildable tiles and select buildings that are inversely related in order to show their range.
		@param tiles_to_check: list of tiles to check for coloring.
		@param new_buildings: Set to true if you have set tiles_to_check and there are new buildings. An internal structure for optimisation will be amended."""
        self._build_logic.highlight_buildable(self, tiles_to_check)

        # Also distinguish inversely related buildings (lumberjack for tree).
        # Highlight their range at all times.
        # (There is another similar highlight, but it only marks building when
        # the current build preview is in its range)
        related = self.session.db.get_inverse_related_building_ids(self._class.id)

        # If the current buildings has related buildings, also show other buildings
        # of this class. You usually don't want overlapping ranges of e.g. lumberjacks.
        if (
            self._class.id in self.session.db.get_buildings_with_related_buildings()
            and self._class.id != BUILDINGS.RESIDENTIAL_CLASS
        ):
            # TODO: generalize settler class exclusion, e.g. when refactoring it into components

            related = related + [self._class.id]  # don't += on retrieved data from db

        related = frozenset(related)

        renderer = self.session.view.renderer["InstanceRenderer"]
        if tiles_to_check is None or new_buildings:  # first run, check all
            buildings_to_select = [
                buildings_to_select
                for settlement in self.session.world.settlements
                if settlement.owner.is_local_player
                for bid in related
                for buildings_to_select in settlement.buildings_by_id[bid]
            ]

            tiles = SelectableBuildingComponent.select_many(buildings_to_select, renderer)
            self._related_buildings_selected_tiles = frozenset(tiles)
        else:  # we don't need to check all
            # duplicates filtered later
            buildings_to_select = [
                tile.object for tile in tiles_to_check if tile.object is not None and tile.object.id in related
            ]
            for tile in tiles_to_check:
                # check if we need to recolor the tiles
                if tile in self._related_buildings_selected_tiles:
                    SelectableBuildingComponent._add_selected_tile(tile, renderer, remember=False)

        for building in buildings_to_select:
            self._related_buildings.add(building)