Example #1
0
	def add_settlement(self, position, radius, player):
		"""Adds a settlement to the island at the position x, y with radius as area of influence.
		@param position: Rect describing the position of the new warehouse
		@param radius: int radius of the area of influence.
		@param player: int id of the player that owns the settlement"""
		settlement = Settlement(self.session, player)
		settlement.initialize()
		settlement.init_buildability_cache(self.terrain_cache)
		self.add_existing_settlement(position, radius, settlement)
		NewSettlement.broadcast(self, settlement, position.center)

		return settlement
Example #2
0
	def __init__(self, db, islandid, session, preview=False):
		"""
		@param db: db instance with island table
		@param islandid: id of island in that table
		@param session: reference to Session instance
		@param preview: flag, map preview mode
		"""
		super(Island, self).__init__(worldid=islandid)

		if False:
			from horizons.session import Session
			assert isinstance(session, Session)
		self.session = session

		x, y, filename = db("SELECT x, y, file FROM island WHERE rowid = ? - 1000", islandid)[0]
		self.__init(Point(x, y), filename, preview=preview)

		if not preview:
			# create building indexers
			from horizons.world.units.animal import WildAnimal
			self.building_indexers = {}
			self.building_indexers[BUILDINGS.TREE] = BuildingIndexer(WildAnimal.walking_range, self, self.session.random)

		# load settlements
		for (settlement_id,) in db("SELECT rowid FROM settlement WHERE island = ?", islandid):
			settlement = Settlement.load(db, settlement_id, self.session, self)
			self.settlements.append(settlement)

		if not preview:
			# load buildings
			from horizons.world import load_building
			for (building_worldid, building_typeid) in \
				  db("SELECT rowid, type FROM building WHERE location = ?", islandid):
				load_building(self.session, db, building_typeid, building_worldid)
Example #3
0
	def add_settlement(self, position, radius, player, load=False):
		"""Adds a settlement to the island at the position x, y with radius as area of influence.
		@param position: Rect describing the position of the new warehouse
		@param radius: int radius of the area of influence.
		@param player: int id of the player that owns the settlement"""
		settlement = Settlement(self.session, player)
		settlement.initialize()
		self.add_existing_settlement(position, radius, settlement, load)
		# TODO: Move this to command, this message should not appear while loading
		self.session.ingame_gui.message_widget.add(string_id='NEW_SETTLEMENT',
		                                           point=position.center,
		                                           message_dict={'player':player.name},
		                                           play_sound=player.is_local_player)

		NewSettlement.broadcast(self, settlement)

		return settlement
Example #4
0
    def add_settlement(self, position, radius, player, load=False):
        """Adds a settlement to the island at the position x, y with radius as area of influence.
		@param position: Rect describing the position of the new warehouse
		@param radius: int radius of the area of influence.
		@param player: int id of the player that owns the settlement"""
        settlement = Settlement(self.session, player)
        settlement.initialize()
        self.add_existing_settlement(position, radius, settlement, load)
        # TODO: Move this to command, this message should not appear while loading
        self.session.ingame_gui.message_widget.add(
            string_id='NEW_SETTLEMENT',
            point=position.center,
            message_dict={'player': player.name},
            play_sound=player.is_local_player)

        NewSettlement.broadcast(self, settlement)

        return settlement
Example #5
0
    def __init__(self, db, island_id, session, preview=False):
        """
		@param db: db instance with island table
		@param island_id: id of island in that table
		@param session: reference to Session instance
		@param preview: flag, map preview mode
		"""
        super(Island, self).__init__(worldid=island_id)

        self.session = session

        self.terrain_cache = None
        self.available_land_cache = None
        self.__init(db, island_id, preview)

        if not preview:
            # Create building indexers.
            from horizons.world.units.animal import WildAnimal
            self.building_indexers = {}
            self.building_indexers[BUILDINGS.TREE] = BuildingIndexer(
                WildAnimal.walking_range, self, self.session.random)

        # Load settlements.
        for (settlement_id, ) in db(
                "SELECT rowid FROM settlement WHERE island = ?", island_id):
            settlement = Settlement.load(db, settlement_id, self.session, self)
            self.settlements.append(settlement)

        if preview:
            # Caches and buildings are not required for map preview.
            return

        self.terrain_cache = TerrainBuildabilityCache(self)
        flat_land_set = self.terrain_cache.cache[TerrainRequirement.LAND][(1,
                                                                           1)]
        self.available_flat_land = len(flat_land_set)
        available_coords_set = set(self.terrain_cache.land_or_coast)

        for settlement in self.settlements:
            settlement.init_buildability_cache(self.terrain_cache)
            for coords in settlement.ground_map:
                available_coords_set.discard(coords)
                if coords in flat_land_set:
                    self.available_flat_land -= 1

        self.available_land_cache = FreeIslandBuildabilityCache(self)

        # Load buildings.
        from horizons.world import load_building
        buildings = db("SELECT rowid, type FROM building WHERE location = ?",
                       island_id)
        for (building_worldid, building_typeid) in buildings:
            load_building(self.session, db, building_typeid, building_worldid)
Example #6
0
    def __init__(self, db, island_id, session, preview=False):
        """
		@param db: db instance with island table
		@param island_id: id of island in that table
		@param session: reference to Session instance
		@param preview: flag, map preview mode
		"""
        super(Island, self).__init__(worldid=island_id)

        self.session = session

        self.terrain_cache = None
        self.available_land_cache = None
        self.__init(db, island_id, preview)

        if not preview:
            # Create building indexers.
            from horizons.world.units.animal import WildAnimal

            self.building_indexers = {}
            self.building_indexers[BUILDINGS.TREE] = BuildingIndexer(
                WildAnimal.walking_range, self, self.session.random
            )

            # Load settlements.
        for (settlement_id,) in db("SELECT rowid FROM settlement WHERE island = ?", island_id):
            settlement = Settlement.load(db, settlement_id, self.session, self)
            self.settlements.append(settlement)

        if preview:
            # Caches and buildings are not required for map preview.
            return

        self.terrain_cache = TerrainBuildabilityCache(self)
        flat_land_set = self.terrain_cache.cache[TerrainRequirement.LAND][(1, 1)]
        self.available_flat_land = len(flat_land_set)
        available_coords_set = set(self.terrain_cache.land_or_coast)

        for settlement in self.settlements:
            settlement.init_buildability_cache(self.terrain_cache)
            for coords in settlement.ground_map:
                available_coords_set.discard(coords)
                if coords in flat_land_set:
                    self.available_flat_land -= 1

        self.available_land_cache = FreeIslandBuildabilityCache(self)

        # Load buildings.
        from horizons.world import load_building

        buildings = db("SELECT rowid, type FROM building WHERE location = ?", island_id)
        for (building_worldid, building_typeid) in buildings:
            load_building(self.session, db, building_typeid, building_worldid)
Example #7
0
    def add_settlement(self, position, radius, player, load=False):
        """Adds a settlement to the island at the position x, y with radius as area of influence.
		@param position: Rect describing the position of the new warehouse
		@param radius: int radius of the area of influence.
		@param player: int id of the player that owns the settlement"""
        settlement = Settlement(self.session, player)
        settlement.initialize()
        settlement.init_buildability_cache(self.terrain_cache)
        self.add_existing_settlement(position, radius, settlement, load)
        NewSettlement.broadcast(self, settlement, position.center)

        return settlement
Example #8
0
    def __init__(self, db, island_id, session, preview=False):
        """
		@param db: db instance with island table
		@param island_id: id of island in that table
		@param session: reference to Session instance
		@param preview: flag, map preview mode
		"""
        super(Island, self).__init__(worldid=island_id)

        if False:
            from horizons.session import Session
            assert isinstance(session, Session)
        self.session = session

        self.__init(db, island_id, preview)

        if not preview:
            # create building indexers
            from horizons.world.units.animal import WildAnimal
            self.building_indexers = {}
            self.building_indexers[BUILDINGS.TREE] = BuildingIndexer(
                WildAnimal.walking_range, self, self.session.random)

        # load settlements
        for (settlement_id, ) in db(
                "SELECT rowid FROM settlement WHERE island = ?", island_id):
            settlement = Settlement.load(db, settlement_id, self.session, self)
            self.settlements.append(settlement)

        if not preview:
            # load buildings
            from horizons.world import load_building
            for (building_worldid, building_typeid) in \
               db("SELECT rowid, type FROM building WHERE location = ?", island_id):
                load_building(self.session, db, building_typeid,
                              building_worldid)