Example #1
0
	def remove_settlement(self, building):
		"""Removes the settlement property from tiles within the radius of the given building"""
		settlement = building.settlement
		buildings_to_abandon, settlement_coords_to_change = Tear.additional_removals_after_tear(building)
		assert building not in buildings_to_abandon
		self.abandon_buildings(buildings_to_abandon)
		
		flat_land_set = self.terrain_cache.cache[TerrainRequirement.LAND][(1, 1)]
		land_or_coast = self.terrain_cache.land_or_coast
		settlement_tiles_changed = []
		clean_coords = set()
		for coords in settlement_coords_to_change:
			tile = self.ground_map[coords]
			tile.settlement = None
			building = tile.object
			if building is not None:
				settlement.remove_building(building)
				building.owner = None
				building.settlement = None
			if coords in land_or_coast:
				clean_coords.add(coords)
			settlement_tiles_changed.append(self.ground_map[coords])
			del settlement.ground_map[coords]
			Minimap.update(coords)
			if coords in flat_land_set:
				self.available_flat_land += 1
		self.available_land_cache.add_area(clean_coords)

		self._register_change()
		if self.terrain_cache:
			settlement.buildability_cache.modify_area(clean_coords)

		SettlementRangeChanged.broadcast(settlement, settlement_tiles_changed)
Example #2
0
    def remove_settlement(self, building):
        """Removes the settlement property from tiles within the radius of the given building"""
        settlement = building.settlement
        buildings_to_abandon, settlement_coords_to_change = Tear.additional_removals_after_tear(
            building)
        assert building not in buildings_to_abandon
        self.abandon_buildings(buildings_to_abandon)

        flat_land_set = self.terrain_cache.cache[TerrainRequirement.LAND][(1,
                                                                           1)]
        land_or_coast = self.terrain_cache.land_or_coast
        settlement_tiles_changed = []
        clean_coords = set()
        for coords in settlement_coords_to_change:
            tile = self.ground_map[coords]
            tile.settlement = None
            building = tile.object
            if building is not None:
                settlement.remove_building(building)
                building.owner = None
                building.settlement = None
            if coords in land_or_coast:
                clean_coords.add(coords)
            settlement_tiles_changed.append(self.ground_map[coords])
            del settlement.ground_map[coords]
            Minimap.update(coords)
            if coords in flat_land_set:
                self.available_flat_land += 1
        self.available_land_cache.add_area(clean_coords)

        self._register_change()
        if self.terrain_cache:
            settlement.buildability_cache.modify_area(clean_coords)

        SettlementRangeChanged.broadcast(settlement, settlement_tiles_changed)
Example #3
0
    def set_tile(self, coords, tile_details):
        if coords not in self.world.full_map:
            return

        old_tile = self.world.full_map[coords]
        if old_tile and old_tile.id != -1 and old_tile._instance and old_tile not in self._tile_delete_set:
            if (old_tile.id, old_tile.shape,
                    old_tile.rotation) == tile_details:
                return
            self._tile_delete_set.add(old_tile)
            Scheduler().add_new_object(Callback(self._delete_tile_instance,
                                                old_tile),
                                       self,
                                       run_in=0)

        (ground_id, shape, rotation) = tile_details
        if ground_id != 0:
            ground = Entities.grounds['{:d}-{}'.format(ground_id,
                                                       shape)](self.session,
                                                               *coords)
            ground.act(rotation)
            self.world.full_map[coords] = ground
        else:
            self.world.full_map[coords] = self.world.fake_tile_map[coords]
        Minimap.update(coords)

        # update cam, that's necessary because of the static layer WATER
        self.session.view.cam.refresh()
Example #4
0
	def assign_settlement(self, position, radius, settlement):
		"""Assigns the settlement property to tiles within the circle defined by \
		position and radius.
		@param position: Rect
		@param radius:
		@param settlement:
		"""
		for coord in position.get_radius_coordinates(radius, include_self=True):
			tile = self.get_tile_tuple(coord)
			if tile is not None:
				if tile.settlement == settlement:
					continue
				if tile.settlement is None:
					tile.settlement = settlement
					settlement.ground_map[coord] = tile
					Minimap.update(coord)
					self._register_change(coord[0], coord[1])

					# notify all AI players when land ownership changes
					for player in self.session.world.players:
						if hasattr(player, 'on_settlement_expansion'):
							player.on_settlement_expansion(settlement, coord)

				building = tile.object
				# found a new building, that is now in settlement radius
				# assign buildings on tiles to settlement
				if building is not None and building.settlement is None and \
				   building.island == self: # don't steal from other islands
					building.settlement = settlement
					building.owner = settlement.owner
					settlement.add_building(building)
Example #5
0
	def assign_settlement(self, position, radius, settlement):
		"""Assigns the settlement property to tiles within the circle defined by \
		position and radius.
		@param position: Rect
		@param radius:
		@param settlement:
		"""
		settlement_coords_changed = []
		for coords in position.get_radius_coordinates(radius, include_self=True):
			if coords not in self.ground_map:
				continue

			tile = self.ground_map[coords]
			if tile.settlement is not None:
				continue

			tile.settlement = settlement
			settlement.ground_map[coords] = tile
			settlement_coords_changed.append(coords)

			building = tile.object
			# In theory fish deposits should never be on the island but this has been
			# possible since they were turned into a 2x2 building. Since they are never
			# entirely on the island then it is easiest to just make it impossible to own
			# fish deposits.
			if building is None or building.id == BUILDINGS.FISH_DEPOSIT:
				continue

			# Assign the entire building to the first settlement that covers some of it.
			assert building.settlement is None or building.settlement is settlement
			for building_coords in building.position.tuple_iter():
				building_tile = self.ground_map[building_coords]
				if building_tile.settlement is not settlement:
					assert building_tile.settlement is None
					building_tile.settlement = settlement
					settlement.ground_map[building_coords] = building_tile
					settlement_coords_changed.append(building_coords)

			building.settlement = settlement
			building.owner = settlement.owner
			settlement.add_building(building)

		if not settlement_coords_changed:
			return

		flat_land_set = self.terrain_cache.cache[TerrainRequirement.LAND][(1, 1)]
		settlement_tiles_changed = []
		for coords in settlement_coords_changed:
			settlement_tiles_changed.append(self.ground_map[coords])
			Minimap.update(coords)
			if coords in flat_land_set:
				self.available_flat_land -= 1
		self.available_land_cache.remove_area(settlement_coords_changed)

		self._register_change()
		if self.terrain_cache:
			settlement.buildability_cache.modify_area(settlement_coords_changed)

		SettlementRangeChanged.broadcast(settlement, settlement_tiles_changed)
Example #6
0
	def assign_settlement(self, position, radius, settlement):
		"""Assigns the settlement property to tiles within the circle defined by \
		position and radius.
		@param position: Rect
		@param radius:
		@param settlement:
		"""
		settlement_coords_changed = []
		for coords in position.get_radius_coordinates(radius, include_self=True):
			if coords not in self.ground_map:
				continue

			tile = self.ground_map[coords]
			if tile.settlement is not None:
				continue

			tile.settlement = settlement
			settlement.ground_map[coords] = tile
			settlement_coords_changed.append(coords)

			building = tile.object
			# In theory fish deposits should never be on the island but this has been
			# possible since they were turned into a 2x2 building. Since they are never
			# entirely on the island then it is easiest to just make it impossible to own
			# fish deposits.
			if building is None or building.id == BUILDINGS.FISH_DEPOSIT:
				continue

			# Assign the entire building to the first settlement that covers some of it.
			assert building.settlement is None or building.settlement is settlement
			for building_coords in building.position.tuple_iter():
				building_tile = self.ground_map[building_coords]
				if building_tile.settlement is not settlement:
					assert building_tile.settlement is None
					building_tile.settlement = settlement
					settlement.ground_map[building_coords] = building_tile
					settlement_coords_changed.append(building_coords)

			building.settlement = settlement
			building.owner = settlement.owner
			settlement.add_building(building)

		if not settlement_coords_changed:
			return

		flat_land_set = self.terrain_cache.cache[TerrainRequirement.LAND][(1, 1)]
		settlement_tiles_changed = []
		for coords in settlement_coords_changed:
			settlement_tiles_changed.append(self.ground_map[coords])
			Minimap.update(coords)
			if coords in flat_land_set:
				self.available_flat_land -= 1
		self.available_land_cache.remove_area(settlement_coords_changed)

		self._register_change()
		if self.terrain_cache:
			settlement.buildability_cache.modify_area(settlement_coords_changed)

		SettlementRangeChanged.broadcast(settlement, settlement_tiles_changed)
	def set_tile(self, coords, tile_details):
		if coords not in self.world.full_map:
			return

		old_tile = self.world.full_map[coords]
		if old_tile and old_tile.id != -1 and old_tile._instance and old_tile not in self._tile_delete_set:
			if (old_tile.id, old_tile.shape, old_tile.rotation + 45) == tile_details:
				return
			self._tile_delete_set.add(old_tile)
			Scheduler().add_new_object(Callback(self._delete_tile_instance, old_tile), self, run_in=0)

		(ground_id, shape, rotation) = tile_details
		if ground_id != 0:
			ground = Entities.grounds['%d-%s' % (ground_id, shape)](self.session, *coords)
			ground.act(rotation)
			self.world.full_map[coords] = ground
		else:
			self.world.full_map[coords] = self.world.fake_tile_map[coords]
		Minimap.update(coords)
	def set_tile(self, coords, tile_details):
		if coords not in self.world.full_map:
			return

		old_tile = self.world.full_map[coords]
		if old_tile and old_tile.id != -1 and old_tile._instance and old_tile not in self._tile_delete_set:
			if (old_tile.id, old_tile.shape, old_tile.rotation) == tile_details:
				return
			self._tile_delete_set.add(old_tile)
			Scheduler().add_new_object(Callback(self._delete_tile_instance, old_tile), self, run_in=0)

		(ground_id, shape, rotation) = tile_details
		if ground_id != 0:
			ground = Entities.grounds['{:d}-{}'.format(ground_id, shape)](self.session, *coords)
			ground.act(rotation)
			self.world.full_map[coords] = ground
		else:
			self.world.full_map[coords] = self.world.fake_tile_map[coords]
		Minimap.update(coords)

		# update cam, that's necessary because of the static layer WATER
		self.session.view.cam.refresh()
Example #9
0
    def assign_settlement(self, position, radius, settlement):
        """Assigns the settlement property to tiles within the circle defined by \
		position and radius.
		@param position: Rect
		@param radius:
		@param settlement:
		"""
        settlement_tiles_changed = []
        for coord in position.get_radius_coordinates(radius,
                                                     include_self=True):
            tile = self.get_tile_tuple(coord)
            if tile is not None:
                if tile.settlement == settlement:
                    continue
                if tile.settlement is None:
                    tile.settlement = settlement
                    settlement.ground_map[coord] = tile
                    Minimap.update(coord)
                    self._register_change(coord[0], coord[1])
                    settlement_tiles_changed.append(tile)

                    # notify all AI players when land ownership changes
                    for player in self.session.world.players:
                        if hasattr(player, 'on_settlement_expansion'):
                            player.on_settlement_expansion(settlement, coord)

                building = tile.object
                # found a new building, that is now in settlement radius
                # assign buildings on tiles to settlement
                if building is not None and building.settlement is None and \
                   building.island == self: # don't steal from other islands
                    building.settlement = settlement
                    building.owner = settlement.owner
                    settlement.add_building(building)

        if settlement_tiles_changed:
            SettlementRangeChanged.broadcast(settlement,
                                             settlement_tiles_changed)
Example #10
0
	def remove_settlement(self, position, radius, settlement):
		"""Removes the settlement property from tiles within the circle defined by \
		position and radius.
		@param position: Rect
		@param radius:
		@param settlement:
		"""
		buildings_to_abandon, settlement_coords_to_change = Tear.destroyable_buildings(position, settlement)
		self.abandon_buildings(buildings_to_abandon)
		
		flat_land_set = self.terrain_cache.cache[TerrainRequirement.LAND][(1, 1)]
		land_or_coast = self.terrain_cache.land_or_coast
		settlement_tiles_changed = []
		clean_coords = set()
		for coords in settlement_coords_to_change:
			tile = self.ground_map[coords]
			tile.settlement = None
			building = tile.object
			if building is not None:
				settlement.remove_building(building)
				building.owner = None
				building.settlement = None
			if coords in land_or_coast:
				clean_coords.add(coords)
			settlement_tiles_changed.append(self.ground_map[coords])
			del settlement.ground_map[coords]
			Minimap.update(coords)
			if coords in flat_land_set:
				self.available_flat_land += 1
		self.available_land_cache.add_area(clean_coords)

		self._register_change()
		if self.terrain_cache:
			settlement.buildability_cache.modify_area(clean_coords)

		SettlementRangeChanged.broadcast(settlement, settlement_tiles_changed)
Example #11
0
    def set_tile(self, coords, tile_details):
        if coords not in self.world.full_map:
            return

        old_tile = self.world.full_map[coords]
        if old_tile and old_tile.id != -1 and old_tile._instance and old_tile not in self._tile_delete_set:
            if (old_tile.id, old_tile.shape,
                    old_tile.rotation + 45) == tile_details:
                return
            self._tile_delete_set.add(old_tile)
            Scheduler().add_new_object(Callback(self._delete_tile_instance,
                                                old_tile),
                                       self,
                                       run_in=0)

        (ground_id, shape, rotation) = tile_details
        if ground_id != 0:
            ground = Entities.grounds['%d-%s' % (ground_id, shape)](
                self.session, *coords)
            ground.act(rotation)
            self.world.full_map[coords] = ground
        else:
            self.world.full_map[coords] = self.world.fake_tile_map[coords]
        Minimap.update(coords)