Esempio n. 1
0
    def do_build(self):
        """Acctually builds the previews
		@return whether it was possible to build anything of the previews."""
        # used to check if a building was built with this click, later used to play a sound
        built = False

        # acctually do the build and build preparations
        for building in self.buildings:
            # remove fife instance, the building will create a new one.
            # Check if there is a matching fife instance, could be missing
            # in case of trees, which are hidden if not buildable
            if building in self.buildings_fife_instances:
                fife_instance = self.buildings_fife_instances.pop(building)
                self.renderer.removeColored(fife_instance)
                self.renderer.removeOutlined(fife_instance)
                fife_instance.getLocationRef().getLayer().deleteInstance(
                    fife_instance)

            if building.buildable:
                island = self.session.world.get_island(
                    building.position.origin)
                for position in building.position:
                    tile = island.get_tile(position)
                    if tile in self._buildable_tiles:
                        # for some kind of buildabilities, not every coord of the
                        # building is buildable (e.g. fisher: only coastline is marked
                        # as buildable). For those tiles, that are not buildable,
                        # we don't need to do anything.
                        self._buildable_tiles.remove(tile)
                        self.renderer.removeColored(tile._instance)
                built = True
                self._remove_listeners(
                )  # Remove changelisteners for update_preview
                # create the command and execute it
                cmd = Build(building=self._class, \
                            x=building.position.origin.x, \
                            y=building.position.origin.y, \
                            rotation=building.rotation, \
                            island= island, \
                            settlement=self.session.world.get_settlement(building.position.origin), \
                            ship=self.ship, \
                            tearset=building.tearset \
                            )
                cmd.execute(self.session)
            else:
                # check whether to issue a missing res notification
                # we need the localized resource name here
                if building in self.buildings_missing_resources:
                    res_name = self.session.db.get_res_name(
                        self.buildings_missing_resources[building])
                    self.session.ingame_gui.message_widget.add(building.position.origin.x, \
                                                               building.position.origin.y, \
                                                               'NEED_MORE_RES', {'resource' : _(res_name)})

        if built:
            PlaySound("build").execute(self.session, True)
            if self.gui is not None:
                self.gui.hide()
        self.buildings = []
        return built
    def do_build(self):
        """Acctually builds the previews
		@return whether it was possible to build anything of the previews."""
        # used to check if a building was built with this click, later used to play a sound
        built = False

        # acctually do the build and build preparations
        for building in self.buildings:
            # remove fife instance, the building will create a new one.
            # Check if there is a matching fife instance, could be missing
            # in case of trees, which are hidden if not buildable
            if building in self.buildings_fife_instances:
                fife_instance = self.buildings_fife_instances.pop(building)
                self.renderer.removeColored(fife_instance)
                self.renderer.removeOutlined(fife_instance)
                fife_instance.getLocationRef().getLayer().deleteInstance(fife_instance)

            if building.buildable:
                island = self.session.world.get_island(building.position.origin)
                for position in building.position:
                    tile = island.get_tile(position)
                    if tile in self._buildable_tiles:
                        # for some kind of buildabilities, not every coord of the
                        # building is buildable (e.g. fisher: only coastline is marked
                        # as buildable). For those tiles, that are not buildable,
                        # we don't need to do anything.
                        self._buildable_tiles.remove(tile)
                        self.renderer.removeColored(tile._instance)
                built = True
                self._remove_listeners()  # Remove changelisteners for update_preview
                # create the command and execute it
                cmd = Build(
                    building=self._class,
                    x=building.position.origin.x,
                    y=building.position.origin.y,
                    rotation=building.rotation,
                    island=island,
                    settlement=self.session.world.get_settlement(building.position.origin),
                    ship=self.ship,
                    tearset=building.tearset,
                )
                cmd.execute(self.session)
            else:
                # check whether to issue a missing res notification
                # we need the localized resource name here
                if building in self.buildings_missing_resources:
                    res_name = self.session.db.get_res_name(self.buildings_missing_resources[building])
                    self.session.ingame_gui.message_widget.add(
                        building.position.origin.x,
                        building.position.origin.y,
                        "NEED_MORE_RES",
                        {"resource": _(res_name)},
                    )

        if built:
            PlaySound("build").execute(self.session, True)
            if self.gui is not None:
                self.gui.hide()
        self.buildings = []
        return built
Esempio n. 3
0
	def do_build(self):
		"""Acctually builds the previews
		@return whether it was possible to build anything of the previews."""
		# used to check if a building was built with this click, later used to play a sound
		built = False

		# acctually do the build and build preparations
		for building in self.buildings:
			# remove fife instance, the building will create a new one.
			fife_instance = self.buildings_fife_instances.pop(building)
			self.renderer.removeColored(fife_instance)
			fife_instance.getLocationRef().getLayer().deleteInstance(fife_instance)

			if building.buildable:
				built = True
				self._remove_listeners() # Remove changelisteners for update_preview
				# create the command and execute it
				cmd = Build(building=self._class, \
				            x=building.position.origin.x, \
				            y=building.position.origin.y, \
				            rotation=building.rotation, \
				            island=self.session.world.get_island(building.position.origin), \
				            settlement=self.session.world.get_settlement(building.position.origin), \
				            ship=self.ship, \
				            tearset=building.tearset \
				            )
				cmd.execute(self.session)
			else:
				# check whether to issue a missing res notification
				# we need the localized resource name here
				if building in self.buildings_missing_resources:
					res_name = self.session.db.get_res_name( self.buildings_missing_resources[building] )
					self.session.ingame_gui.message_widget.add(building.position.origin.x, \
					                                           building.position.origin.y, \
					                                           'NEED_MORE_RES', {'resource' : _(res_name)})

		if built:
			PlaySound("build").execute(self.session, True)
			if self.gui is not None:
				self.gui.hide()
		self.buildings = []
		return built
	def fill_range(self):
		for (x, y) in self.coords_in_range():
			cmd = Build(self.field, x, y, self.instance.island)
			cmd.execute(self.instance.session)
Esempio n. 5
0
    def do_build(self):
        """Actually builds the previews
		@return a set of tiles where buildings have really been built"""
        changed_tiles = set()

        # actually do the build and build preparations
        for i, building in enumerate(self.buildings):
            # remove fife instance, the building will create a new one.
            # Check if there is a matching fife instance, could be missing
            # in case of trees, which are hidden if not buildable
            if building in self.buildings_fife_instances:
                fife_instance = self.buildings_fife_instances.pop(building)
                self.renderer.removeColored(fife_instance)
                self.renderer.removeOutlined(fife_instance)
                fife_instance.getLocationRef().getLayer().deleteInstance(
                    fife_instance)

            if building.buildable:
                island = self.session.world.get_island(
                    building.position.origin)
                for position in building.position:
                    tile = island.get_tile(position)
                    if tile in self._buildable_tiles:
                        # for some kind of buildabilities, not every coord of the
                        # building is buildable (e.g. fisher: only coastline is marked
                        # as buildable). For those tiles, that are not buildable,
                        # we don't need to do anything.
                        self._buildable_tiles.remove(tile)
                        self.renderer.removeColored(tile._instance)
                        changed_tiles.add(tile)
                self._remove_listeners(
                )  # Remove changelisteners for update_preview
                # create the command and execute it
                cmd = Build(
                    building=self._class,
                    x=building.position.origin.x,
                    y=building.position.origin.y,
                    rotation=building.rotation,
                    island=island,
                    settlement=self.session.world.get_settlement(
                        building.position.origin),
                    ship=self.ship,
                    tearset=building.tearset,
                    action_set_id=self.buildings_action_set_ids[i],
                )
                cmd.execute(self.session)
            else:
                if len(self.buildings
                       ) == 1:  # only give messages for single bulds
                    # first, buildable reasons such as grounds
                    # second, resources

                    if building.problem is not None:
                        msg = building.problem[1]
                        self.session.ingame_gui.message_widget.add_custom(
                            point=building.position.origin, messagetext=msg)

                    # check whether to issue a missing res notification
                    # we need the localized resource name here
                    elif building in self.buildings_missing_resources:
                        res_name = self.session.db.get_res_name(
                            self.buildings_missing_resources[building])
                        self.session.ingame_gui.message_widget.add(
                            point=building.position.origin,
                            string_id='NEED_MORE_RES',
                            message_dict={'resource': res_name})

        self.buildings = []
        self.buildings_action_set_ids = []
        return changed_tiles
Esempio n. 6
0
	def do_build(self):
		"""Actually builds the previews
		@return a set of tiles where buildings have really been built"""
		changed_tiles = set()

		# actually do the build and build preparations
		for i, building in enumerate(self.buildings):
			# remove fife instance, the building will create a new one.
			# Check if there is a matching fife instance, could be missing
			# in case of trees, which are hidden if not buildable
			if building in self.buildings_fife_instances:
				fife_instance = self.buildings_fife_instances.pop(building)
				self.renderer.removeColored(fife_instance)
				self.renderer.removeOutlined(fife_instance)
				fife_instance.getLocationRef().getLayer().deleteInstance(fife_instance)

			if building.buildable:
				island = self.session.world.get_island(building.position.origin)
				for position in building.position:
					tile = island.get_tile(position)
					if tile in self._buildable_tiles:
						# for some kind of buildabilities, not every coord of the
						# building is buildable (e.g. fisher: only coastline is marked
						# as buildable). For those tiles, that are not buildable,
						# we don't need to do anything.
						self._buildable_tiles.remove(tile)
						self.renderer.removeColored(tile._instance)
						changed_tiles.add(tile)
				self._remove_listeners() # Remove changelisteners for update_preview
				# create the command and execute it
				cmd = Build(building=self._class,
							x=building.position.origin.x,
							y=building.position.origin.y,
							rotation=building.rotation,
							island=island,
							settlement=self.session.world.get_settlement(building.position.origin),
							ship=self.ship,
							tearset=building.tearset,
							action_set_id=self.buildings_action_set_ids[i],
							)
				cmd.execute(self.session)
			else:
				if len(self.buildings) == 1: # only give messages for single bulds
					# first, buildable reasons such as grounds
					# second, resources

					if building.problem is not None:
						msg = building.problem[1]
						self.session.ingame_gui.message_widget.add_custom(
						  point=building.position.origin, messagetext=msg)

					# check whether to issue a missing res notification
					# we need the localized resource name here
					elif building in self.buildings_missing_resources:
						res_name = self.session.db.get_res_name( self.buildings_missing_resources[building] )
						self.session.ingame_gui.message_widget.add(
						  point=building.position.origin,
						  string_id='NEED_MORE_RES', message_dict={'resource' : res_name})

		self.buildings = []
		self.buildings_action_set_ids = []
		return changed_tiles
Esempio n. 7
0
	def fill_range(self):
		for (x, y) in self.coords_in_range():
			cmd = Build(self.field, x, y, self.instance.island)
			cmd.execute(self.instance.session)