Exemplo n.º 1
0
    def highlight_buildable(self, building_tool, tiles_to_check=None):
        """Highlights all buildable tiles.
		@param tiles_to_check: list of tiles to check for coloring."""

        # resolved variables from inner loops
        is_tile_buildable = building_tool._class.is_tile_buildable
        session = building_tool.session
        player = session.world.player

        if not self.subscribed:
            self.subscribed = True
            SettlementRangeChanged.subscribe(self._on_update)

        if tiles_to_check is not None:
            # Only check these tiles.
            for tile in tiles_to_check:
                if is_tile_buildable(session, tile, None):
                    building_tool._color_buildable_tile(tile)
        else:
            # Default build on island.
            for settlement in session.world.settlements:
                if settlement.owner == player:
                    island = session.world.get_island(
                        Point(*next(iter(settlement.ground_map.keys()))))
                    for tile in settlement.ground_map.values():
                        if is_tile_buildable(session,
                                             tile,
                                             None,
                                             island,
                                             check_settlement=False):
                            building_tool._color_buildable_tile(tile)
Exemplo n.º 2
0
	def early_end(self):
		"""Called to speed up session destruction."""
		assert self._enabled
		self._enabled = False
		SettlementRangeChanged.unsubscribe(self._on_settlement_range_changed)
		NewDisaster.unsubscribe(self.notify_new_disaster)
		MineEmpty.unsubscribe(self.notify_mine_empty)
Exemplo n.º 3
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)
Exemplo n.º 4
0
 def early_end(self):
     """Called to speed up session destruction."""
     assert self._enabled
     self._enabled = False
     SettlementRangeChanged.unsubscribe(self._on_settlement_range_changed)
     NewDisaster.unsubscribe(self.notify_new_disaster)
     MineEmpty.unsubscribe(self.notify_mine_empty)
Exemplo n.º 5
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)
Exemplo n.º 6
0
	def highlight_buildable(self, building_tool, tiles_to_check=None):
		"""Highlights all buildable tiles.
		@param tiles_to_check: list of tiles to check for coloring."""

		# resolved variables from inner loops
		is_tile_buildable = building_tool._class.is_tile_buildable
		session = building_tool.session
		player = session.world.player

		if not self.subscribed:
			self.subscribed = True
			SettlementRangeChanged.subscribe(self._on_update)

		if tiles_to_check is not None: # only check these tiles
			for tile in tiles_to_check:
				if is_tile_buildable(session, tile, None):
					building_tool._color_buildable_tile(tile)

		else: #default build on island
			for settlement in session.world.settlements:
				if settlement.owner == player:
					island = session.world.get_island(Point(*settlement.ground_map.iterkeys().next()))
					for tile in settlement.ground_map.itervalues():
						if is_tile_buildable(session, tile, None, island, check_settlement=False):
							building_tool._color_buildable_tile(tile)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
0
 def __init(self):
     self._enabled = True  # whether this player is enabled (currently disabled at the end of the game)
     self.world = self.session.world
     self.islands = {}
     self.settlement_managers = []
     self._settlement_manager_by_settlement_id = {}
     self.missions = set()
     self.fishers = []
     self.settlement_founder = SettlementFounder(self)
     self.unit_builder = UnitBuilder(self)
     self.unit_manager = UnitManager(self)
     self.combat_manager = CombatManager(self)
     self.strategy_manager = StrategyManager(self)
     self.behavior_manager = BehaviorManager(self)
     self.settlement_expansions = []  # [(coords, settlement)]
     self.goals = [DoNothingGoal(self)]
     self.special_domestic_trade_manager = SpecialDomesticTradeManager(self)
     self.international_trade_manager = InternationalTradeManager(self)
     SettlementRangeChanged.subscribe(self._on_settlement_range_changed)
Exemplo n.º 10
0
	def __init(self):
		self._enabled = True  # whether this player is enabled (currently disabled at the end of the game)
		self.world = self.session.world
		self.islands = {}
		self.settlement_managers = []
		self._settlement_manager_by_settlement_id = {}
		self.missions = set()
		self.fishers = []
		self.settlement_founder = SettlementFounder(self)
		self.unit_builder = UnitBuilder(self)
		self.unit_manager = UnitManager(self)
		self.combat_manager = CombatManager(self)
		self.strategy_manager = StrategyManager(self)
		self.behavior_manager = BehaviorManager(self)
		self.settlement_expansions = []  # [(coords, settlement)]
		self.goals = [DoNothingGoal(self)]
		self.special_domestic_trade_manager = SpecialDomesticTradeManager(self)
		self.international_trade_manager = InternationalTradeManager(self)
		SettlementRangeChanged.subscribe(self._on_settlement_range_changed)
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
0
 def early_end(self):
     """Called to speed up session destruction."""
     assert self._enabled
     self._enabled = False
     SettlementRangeChanged.unsubscribe(self._on_settlement_range_changed)
Exemplo n.º 15
0
 def remove(self, session):
     if self.subscribed:
         self.subscribed = False
         SettlementRangeChanged.unsubscribe(self._on_update)
Exemplo n.º 16
0
 def on_escape(self, session):
     session.ingame_gui.show_build_menu()  # This will call remove().
     if self.subscribed:
         self.subscribed = False
         SettlementRangeChanged.unsubscribe(self._on_update)
Exemplo n.º 17
0
	def early_end(self):
		"""Called to speed up session destruction."""
		assert self._enabled
		self._enabled = False
		SettlementRangeChanged.unsubscribe(self._on_settlement_range_changed)
Exemplo n.º 18
0
	def on_escape(self, session):
		session.ingame_gui.show_build_menu() # will call remove()
		if self.subscribed:
			self.subscribed = False
			SettlementRangeChanged.unsubscribe(self._on_update)
Exemplo n.º 19
0
	def remove(self, session):
		if self.subscribed:
			self.subscribed = False
			SettlementRangeChanged.unsubscribe(self._on_update)