コード例 #1
0
ファイル: island.py プロジェクト: court-jus/unknown-horizons
    def __init__(self, db, islandid, session):
        """
		@param db: db instance with island table
		@param islandid: id of island in that table
		@param session: reference to Session instance
		"""
        super(Island, self).__init__(worldid=islandid)
        self.session = session

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

        # create building indexers
        self.building_indexers = {}
        self.building_indexers[BUILDINGS.TREE_CLASS] = BuildingIndexer(
            WildAnimal.walking_range, self, self.session.random)

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

        # 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)
コード例 #2
0
    def load(cls, db, worldid, session):
        self = cls.__new__(cls)

        owner, tax = db(
            "SELECT owner, tax_setting FROM settlement WHERE rowid = ?",
            worldid)[0]
        self.__init(session, WorldObject.get_object_by_id(owner), tax)

        # load super here cause basic stuff is just set up now
        super(Settlement, self).load(db, worldid)

        # load all buildings from this settlement
        # the buildings will expand the area of the settlement by adding everything,
        # that is in the radius of the building, to the settlement.
        from horizons.world import load_building
        for building_id, building_type in \
          db("SELECT rowid, type FROM building WHERE location = ?", worldid):
            load_building(session, db, building_type, building_id)

        for res, amount in db(
                "SELECT res, amount FROM settlement_produced_res WHERE settlement = ?",
                worldid):
            self.produced_res[res] = amount

        # load inventory after buildings, since buildings, specifically storages, determine
        # the size of the settlement's inventory
        self.inventory.load(db, worldid)

        return self
コード例 #3
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)
コード例 #4
0
ファイル: settlement.py プロジェクト: mitfik/unknown-horizons
	def load(cls, db, worldid, session):
		self = cls.__new__(cls)

		owner = db("SELECT owner FROM settlement WHERE rowid = ?", worldid)[0][0]
		upgrade_permissions = {}
		tax_settings = {}
		for level, allowed, tax in db("SELECT level, upgrading_allowed, tax_setting FROM settlement_level_properties WHERE settlement = ?", worldid):
			upgrade_permissions[level] = allowed
			tax_settings[level] = tax
		self.__init(session, WorldObject.get_object_by_id(owner), upgrade_permissions, tax_settings)

		# load super here cause basic stuff is just set up now
		super(Settlement, self).load(db, worldid)

		# load all buildings from this settlement
		# the buildings will expand the area of the settlement by adding everything,
		# that is in the radius of the building, to the settlement.
		from horizons.world import load_building
		for building_id, building_type in \
				db("SELECT rowid, type FROM building WHERE location = ?", worldid):
			load_building(session, db, building_type, building_id)

		for res, amount in db("SELECT res, amount FROM settlement_produced_res WHERE settlement = ?", worldid):
			self.produced_res[res] = amount

		return self
コード例 #5
0
ファイル: island.py プロジェクト: court-jus/unknown-horizons
    def __init__(self, db, islandid, session):
        """
		@param db: db instance with island table
		@param islandid: id of island in that table
		@param session: reference to Session instance
		"""
        super(Island, self).__init__(worldid=islandid)
        self.session = session

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

        # create building indexers
        self.building_indexers = {}
        self.building_indexers[BUILDINGS.TREE_CLASS] = BuildingIndexer(
            WildAnimal.walking_range, self, self.session.random
        )

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

            # 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)
コード例 #6
0
	def load(cls, db, worldid, session):
		self = cls.__new__(cls)

		owner, tax = db("SELECT owner, tax_setting FROM settlement WHERE rowid = ?", worldid)[0]
		self.__init(session, WorldObject.get_object_by_id(owner), tax)

		# load super here cause basic stuff is just set up now
		super(Settlement, self).load(db, worldid)

		# load all buildings from this settlement
		# the buildings will expand the area of the settlement by adding everything,
		# that is in the radius of the building, to the settlement.
		from horizons.world import load_building
		for building_id, building_type in \
				db("SELECT rowid, type FROM building WHERE location = ?", worldid):
			load_building(session, db, building_type, building_id)

		for res, amount in db("SELECT res, amount FROM settlement_produced_res WHERE settlement = ?", worldid):
			self.produced_res[res] = amount

		# load inventory after buildings, since buildings, specifically storages, determine
		# the size of the settlement's inventory
		self.inventory.load(db, worldid)

		return self
コード例 #7
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)
コード例 #8
0
ファイル: island.py プロジェクト: ajwilliam/unknown-horizons
    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)
コード例 #9
0
	def load(cls, db, worldid, session, island):
		self = cls.__new__(cls)
		self.session = session
		super(Settlement, self).load(db, worldid)

		owner = db("SELECT owner FROM settlement WHERE rowid = ?", worldid)[0][0]
		upgrade_permissions = {}
		tax_settings = {}
		for level, allowed, tax in db("SELECT level, upgrading_allowed, tax_setting FROM settlement_level_properties WHERE settlement = ?", worldid):
			upgrade_permissions[level] = allowed
			tax_settings[level] = tax
		self.__init(session, WorldObject.get_object_by_id(owner), upgrade_permissions, tax_settings)

		# load the settlement tile map
		tile_data = db("SELECT data FROM settlement_tiles WHERE rowid = ?", worldid)[0][0]
		coords_list = [tuple(raw_coords) for raw_coords in json.loads(tile_data)] # json saves tuples as list
		for coords in coords_list:
			tile = island.ground_map[coords]
			self.ground_map[coords] = tile
			tile.settlement = self

		# load all buildings in this settlement
		from horizons.world import load_building
		for building_id, building_type in \
			  db("SELECT rowid, type FROM building WHERE location = ?", worldid):
			building = load_building(session, db, building_type, building_id)
			if building_type == BUILDINGS.WAREHOUSE:
				self.warehouse = building

		for res, amount in db("SELECT res, amount FROM settlement_produced_res WHERE settlement = ?", worldid):
			self.produced_res[res] = amount

		return self
コード例 #10
0
	def load(cls, db, worldid, session, island):
		self = cls.__new__(cls)
		self.session = session
		super(Settlement, self).load(db, worldid)

		owner = db("SELECT owner FROM settlement WHERE rowid = ?", worldid)[0][0]
		upgrade_permissions = {}
		tax_settings = {}
		for level, allowed, tax in db("SELECT level, upgrading_allowed, tax_setting FROM settlement_level_properties WHERE settlement = ?", worldid):
			upgrade_permissions[level] = allowed
			tax_settings[level] = tax
		self.__init(session, WorldObject.get_object_by_id(owner), upgrade_permissions, tax_settings)

		# load the settlement tile map
		tile_data = db("SELECT data FROM settlement_tiles WHERE rowid = ?", worldid)[0][0]
		coords_list = [tuple(raw_coords) for raw_coords in json.loads(tile_data)] # json saves tuples as list
		for coords in coords_list:
			tile = island.ground_map[coords]
			self.ground_map[coords] = tile
			tile.settlement = self

		# load all buildings in this settlement
		from horizons.world import load_building
		for building_id, building_type in \
			  db("SELECT rowid, type FROM building WHERE location = ?", worldid):
			building = load_building(session, db, building_type, building_id)
			if building_type == BUILDINGS.WAREHOUSE:
				self.warehouse = building

		for res, amount in db("SELECT res, amount FROM settlement_produced_res WHERE settlement = ?", worldid):
			self.produced_res[res] = amount

		return self
コード例 #11
0
ファイル: island.py プロジェクト: lmchawla/unknown-horizons
	def __init__(self, db, islandid, session):
		"""
		@param db: db instance with island table
		@param islandid: id of island in that table
		@param session: reference to Session instance
		"""
		super(Island, self).__init__(worldid=islandid)
		self.session = session

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

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

		# 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)
コード例 #12
0
	def load(cls, db, worldid, session, island):
		self = cls.__new__(cls)
		self.session = session
		super(Settlement, self).load(db, worldid)

		owner = db("SELECT owner FROM settlement WHERE rowid = ?", worldid)[0][0]
		upgrade_permissions = {}
		tax_settings = {}
		for level, allowed, tax in db("SELECT level, upgrading_allowed, tax_setting FROM settlement_level_properties WHERE settlement = ?", worldid):
			upgrade_permissions[level] = allowed
			tax_settings[level] = tax
		self.__init(session, WorldObject.get_object_by_id(owner), upgrade_permissions, tax_settings)

		try:
			# normal tile loading for new savegames
			tile_data = db("SELECT data FROM settlement_tiles WHERE rowid = ?", worldid)[0][0]
			tile_data = json.loads(tile_data)
			for (x, y) in tile_data: # NOTE: json saves tuples as list
				tup = (x, y)
				tile = island.ground_map[tup]
				self.ground_map[tup] = tile
				tile.settlement = self
		except sqlite3.OperationalError:
			print "Updating data of outdated savegame.."
			# old savegame, create settlement tiles provisionally (not correct, but useable)
			# TODO: remove when there aren't any savegames from before december 2011 any more
			for b_type, x, y in db("SELECT type, x, y FROM building WHERE location = ?", worldid):
				cls = Entities.buildings[b_type]
				position = Rect.init_from_topleft_and_size(x, y, cls.size[0], cls.size[1])
				for coord in position.get_radius_coordinates(cls.radius, include_self=True):
					tile = island.get_tile_tuple(coord)
					if tile is not None:
						if tile.settlement is None:
							self.ground_map[coord] = island.ground_map[coord]
							tile.settlement = self

		# load super here cause basic stuff is just set up now

		# load all buildings from this settlement
		# the buildings will expand the area of the settlement by adding everything,
		# that is in the radius of the building, to the settlement.
		from horizons.world import load_building
		for building_id, building_type in \
			  db("SELECT rowid, type FROM building WHERE location = ?", worldid):
			building = load_building(session, db, building_type, building_id)
			if building_type == BUILDINGS.WAREHOUSE:
				self.warehouse = building

		for res, amount in db("SELECT res, amount FROM settlement_produced_res WHERE settlement = ?", worldid):
			self.produced_res[res] = amount

		return self
コード例 #13
0
    def __init__(self, db, islandid, session):
        """
		@param db: db instance with island table
		@param islandid: id of island in that table
		@param session: reference to Session instance
		"""
        super(Island, self).__init__(worldid=islandid)
        self.session = session

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

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

        # 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)
コード例 #14
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)