Пример #1
0
    def create_sea_cache(self):
        # currently only 3x3 buildings can require nearby sea
        coast_set = self.cache[TerrainRequirement.LAND_AND_COAST][(3, 3)]
        near_sea = set()

        nearby_coords_list = []
        base_rect = Rect.init_from_topleft_and_size(0, 0, 3, 3)
        for coords in base_rect.get_radius_coordinates(self.sea_radius):
            nearby_coords_list.append(coords)

        world = self._island.session.world
        water_bodies = world.water_body
        sea_number = world.sea_number

        for bx, by in coast_set:
            for dx, dy in nearby_coords_list:
                coords = (bx + dx, by + dy)
                if coords in water_bodies and water_bodies[
                        coords] == sea_number:
                    near_sea.add((bx, by))
                    break

        self.cache[TerrainRequirement.LAND_AND_COAST_NEAR_SEA] = {}
        self.cache[TerrainRequirement.LAND_AND_COAST_NEAR_SEA][(3,
                                                                3)] = near_sea
Пример #2
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_CLASS:
				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
	def create_sea_cache(self):
		# currently only 3x3 buildings can require nearby sea
		coast_set = self.cache[TerrainRequirement.LAND_AND_COAST][(3, 3)]
		near_sea = set()

		nearby_coords_list = []
		base_rect = Rect.init_from_topleft_and_size(0, 0, 3, 3)
		for coords in base_rect.get_radius_coordinates(self.sea_radius):
			nearby_coords_list.append(coords)

		world = self._island.session.world
		water_bodies = world.water_body
		sea_number = world.sea_number

		for bx, by in coast_set:
			for dx, dy in nearby_coords_list:
				coords = (bx + dx, by + dy)
				if coords in water_bodies and water_bodies[coords] == sea_number:
					near_sea.add((bx, by))
					break

		self.cache[TerrainRequirement.LAND_AND_COAST_NEAR_SEA] = {}
		self.cache[TerrainRequirement.LAND_AND_COAST_NEAR_SEA][(3, 3)] = near_sea