Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)