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._init_cache() self.settlements = [] self.wild_animals = [] self.num_trees = 0 self.path_nodes = IslandPathNodes(self) # 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) # 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:
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:
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.buildings = [] self.provider_buildings = ProviderHandler() 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:
def _get_island_db(self): # check if filename is a random map if random_map.is_random_island_id_string(self.file): # it's a random map id, create this map and load it return random_map.create_random_island(self.file) return DbReader(self.file) # Create a new DbReader instance to load the maps file.