Example #1
0
    def __init(self, db, island_id, preview):
        """
		Load the actual island from a file
		@param preview: flag, map preview mode
		"""
        p_x, p_y, width, height = db(
            "SELECT MIN(x), MIN(y), (1 + MAX(x) - MIN(x)), (1 + MAX(y) - MIN(y)) FROM ground WHERE island_id = ?",
            island_id - 1001)[0]

        self.ground_map = {}
        for (x, y, ground_id, action_id, rotation) in db(
                "SELECT x, y, ground_id, action_id, rotation FROM ground WHERE island_id = ?",
                island_id - 1001):  # Load grounds
            if not preview:  # actual game, need actual tiles
                ground = Entities.grounds[str('{:d}-{}'.format(
                    ground_id, action_id))](self.session, x, y)
                ground.act(rotation)
            else:
                ground = MapPreviewTile(x, y, ground_id)
            # 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._init_cache()

        # Contains references to all resource deposits (but not mines)
        # on the island, regardless of the owner:
        # {building_id: {(x, y): building_instance, ...}, ...}
        self.deposits = defaultdict(dict)

        self.settlements = []
        self.wild_animals = []
        self.num_trees = 0

        # define the rectangle with the smallest area that contains every island tile its position
        min_x = min(list(zip(*self.ground_map.keys()))[0])
        max_x = max(list(zip(*self.ground_map.keys()))[0])
        min_y = min(list(zip(*self.ground_map.keys()))[1])
        max_y = max(list(zip(*self.ground_map.keys()))[1])
        self.position = Rect.init_from_borders(min_x, min_y, max_x, max_y)

        if not preview:
            # This isn't needed for map previews, but it is in actual games.
            self.path_nodes = IslandPathNodes(self)
            self.barrier_nodes = IslandBarrierNodes(self)

            # Repopulate wild animals every 2 mins if they die out.
            Scheduler().add_new_object(self.check_wild_animal_population,
                                       self,
                                       run_in=Scheduler().get_ticks(120),
                                       loops=-1)
        """TUTORIAL:
Example #2
0
    def __init(self, db, island_id, preview):
        """
		Load the actual island from a file
		@param preview: flag, map preview mode
		"""
        p_x, p_y, width, height = db(
            "SELECT MIN(x), MIN(y), (1 + MAX(x) - MIN(x)), (1 + MAX(y) - MIN(y)) FROM ground WHERE island_id = ?",
            island_id - 1001)[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 (x, y, ground_id, action_id, rotation) in db(
                "SELECT x, y, ground_id, action_id, rotation FROM ground WHERE island_id = ?",
                island_id - 1001):  # Load grounds
            if not preview:  # actual game, need actual tiles
                ground = Entities.grounds[str(
                    '%d-%s' % (ground_id, action_id))](self.session, x, y)
                ground.act(rotation)
            else:
                ground = MapPreviewTile(x, y, ground_id)
            # 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._init_cache()

        self.settlements = []
        self.wild_animals = []
        self.num_trees = 0

        # define the rectangle with the smallest area that contains every island tile its position
        min_x = min(zip(*self.ground_map.keys())[0])
        max_x = max(zip(*self.ground_map.keys())[0])
        min_y = min(zip(*self.ground_map.keys())[1])
        max_y = max(zip(*self.ground_map.keys())[1])
        self.position = Rect.init_from_borders(min_x, min_y, max_x, max_y)

        if not preview:  # this isn't needed for previews, but it is in actual games
            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: