Exemplo n.º 1
0
    def __init(self, origin, filename):
        """
		Load the actual island from a file
		@param origin: Point
		@param filename: String, filename of island db or random map id
		"""
        self.file = filename
        self.origin = origin

        # check if filename is a random map
        if random_map.is_random_island_id_string(filename):
            # it's a random map id, create this map and load it
            db = random_map.create_random_island(filename)
        else:
            db = DbReader(
                filename
            )  # Create a new DbReader instance to load the maps file.

        p_x, p_y, width, height = db(
            "SELECT (MIN(x) + ?), (MIN(y) + ?), (1 + MAX(x) - MIN(x)), (1 + MAX(y) - MIN(y)) FROM ground",
            self.origin.x, self.origin.y)[0]

        # rect for quick checking if a tile isn't on this island
        # NOTE: it contains tiles, that are not on the island!
        self.rect = Rect(Point(p_x, p_y), width, height)

        self.ground_map = {}
        for (rel_x, rel_y, ground_id
             ) in db("SELECT x, y, ground_id FROM ground"):  # Load grounds
            ground = Entities.grounds[ground_id](self.session,
                                                 self.origin.x + rel_x,
                                                 self.origin.y + rel_y)
            # These are important for pathfinding and building to check if the ground tile
            # is blocked in any way.
            self.ground_map[(ground.x, ground.y)] = ground

        self.settlements = []
        self.wild_animals = []

        self.path_nodes = IslandPathNodes(self)

        # repopulate wild animals every 2 mins if they die out.
        Scheduler().add_new_object(self.check_wild_animal_population, self,
                                   Scheduler().get_ticks(120), -1)
        """TUTORIAL: