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 __init__(self, game_identifier, is_map, options=None): is_random_map = False if is_map: self.upgrader = None handle, self._temp_path = tempfile.mkstemp() os.close(handle) super(SavegameAccessor, self).__init__(dbfile=self._temp_path) with open('content/savegame_template.sql') as savegame_template: self.execute_script(savegame_template.read()) if isinstance(game_identifier, list): is_random_map = True random_island_sequence = game_identifier else: self._map_path = game_identifier else: self.upgrader = SavegameUpgrader(game_identifier) self._temp_path = None game_identifier = self.upgrader.get_path() super(SavegameAccessor, self).__init__(dbfile=game_identifier) map_name_data = self('SELECT value FROM metadata WHERE name = ?', 'map_name') if not map_name_data: is_random_map = True random_island_sequence = self('SELECT value FROM metadata WHERE name = ?', 'random_island_sequence')[0][0].split(' ') else: map_name = map_name_data[0][0] if map_name.startswith('USER_MAPS_DIR:'): self._map_path = PATHS.USER_MAPS_DIR + map_name[len('USER_MAPS_DIR:'):] elif os.path.isabs(map_name): self._map_path = map_name else: self._map_path = SavegameManager.get_filename_from_map_name(map_name) if is_random_map: handle, self._temp_path2 = tempfile.mkstemp() os.close(handle) random_map_db = DbReader(self._temp_path2) with open('content/map-template.sql') as map_template: random_map_db.execute_script(map_template.read()) for island_id, island_string in enumerate(random_island_sequence): create_random_island(random_map_db, island_id, island_string) random_map_db.close() self._map_path = self._temp_path2 self('INSERT INTO metadata VALUES(?, ?)', 'random_island_sequence', ' '.join(random_island_sequence)) if options is not None: if options.map_padding is not None: self("INSERT INTO map_properties VALUES(?, ?)", 'padding', options.map_padding) self('ATTACH ? AS map_file', self._map_path) if is_random_map: self.map_name = random_island_sequence elif os.path.isabs(self._map_path): self.map_name = self._map_path else: self.map_name = SavegameManager.get_savegamename_from_filename(self._map_path) map_padding = self("SELECT value FROM map_properties WHERE name = 'padding'") self.map_padding = int(map_padding[0][0]) if map_padding else MAP.PADDING self._load_building() self._load_settlement() self._load_concrete_object() self._load_production() self._load_storage() self._load_wildanimal() self._load_unit() self._load_building_collector() self._load_production_line() self._load_unit_path() self._load_storage_global_limit() self._load_health() self._load_fish_data() self._hash = None
def __init__(self, game_identifier, is_map, options=None): is_random_map = False if is_map: self.upgrader = None handle, self._temp_path = tempfile.mkstemp() os.close(handle) super().__init__(dbfile=self._temp_path) with open('content/savegame_template.sql') as savegame_template: self.execute_script(savegame_template.read()) if isinstance(game_identifier, list): is_random_map = True random_island_sequence = game_identifier else: self._map_path = game_identifier else: self.upgrader = SavegameUpgrader(game_identifier) self._temp_path = None game_identifier = self.upgrader.get_path() super().__init__(dbfile=game_identifier) map_name_data = self('SELECT value FROM metadata WHERE name = ?', 'map_name') if not map_name_data: is_random_map = True random_island_sequence = self( 'SELECT value FROM metadata WHERE name = ?', 'random_island_sequence')[0][0].split(' ') else: map_name = map_name_data[0][0] if map_name.startswith('USER_MAPS_DIR:'): self._map_path = PATHS.USER_MAPS_DIR + map_name[ len('USER_MAPS_DIR:'):] elif os.path.isabs(map_name): self._map_path = map_name else: self._map_path = SavegameManager.get_filename_from_map_name( map_name) if is_random_map: handle, self._temp_path2 = tempfile.mkstemp() os.close(handle) random_map_db = DbReader(self._temp_path2) with open('content/map-template.sql') as map_template: random_map_db.execute_script(map_template.read()) for island_id, island_string in enumerate(random_island_sequence): create_random_island(random_map_db, island_id, island_string) random_map_db.close() self._map_path = self._temp_path2 self('INSERT INTO metadata VALUES(?, ?)', 'random_island_sequence', ' '.join(random_island_sequence)) if options is not None: if options.map_padding is not None: self("INSERT INTO map_properties VALUES(?, ?)", 'padding', options.map_padding) if not os.path.exists(self._map_path): raise MapFileNotFound("Map file " + str(self._map_path) + " not found!") self('ATTACH ? AS map_file', self._map_path) if is_random_map: self.map_name = random_island_sequence elif os.path.isabs(self._map_path): self.map_name = self._map_path else: self.map_name = SavegameManager.get_savegamename_from_filename( self._map_path) map_padding = self( "SELECT value FROM map_properties WHERE name = 'padding'") self.map_padding = int( map_padding[0][0]) if map_padding else MAP.PADDING self._load_building() self._load_settlement() self._load_concrete_object() self._load_production() self._load_storage() self._load_wildanimal() self._load_unit() self._load_building_collector() self._load_production_line() self._load_unit_path() self._load_storage_global_limit() self._load_health() self._load_fish_data() self._hash = None
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.
def __init__(self, game_identifier, is_map): is_random_map = False if is_map: self.upgrader = None handle, self._temp_path = tempfile.mkstemp() os.close(handle) super(SavegameAccessor, self).__init__(dbfile=self._temp_path) with open("content/savegame_template.sql") as savegame_template: self.execute_script(savegame_template.read()) if isinstance(game_identifier, list): is_random_map = True random_island_sequence = game_identifier else: self._map_path = game_identifier else: self.upgrader = SavegameUpgrader(game_identifier) self._temp_path = None game_identifier = self.upgrader.get_path() super(SavegameAccessor, self).__init__(dbfile=game_identifier) map_name_data = self("SELECT value FROM metadata WHERE name = ?", "map_name") if not map_name_data: is_random_map = True random_island_sequence = self("SELECT value FROM metadata WHERE name = ?", "random_island_sequence")[0][ 0 ].split(" ") else: map_name = map_name_data[0][0] if os.path.isabs(map_name): self._map_path = map_name else: self._map_path = SavegameManager.get_filename_from_map_name(map_name) if is_random_map: handle, self._temp_path2 = tempfile.mkstemp() os.close(handle) random_map_db = DbReader(self._temp_path2) with open("content/map-template.sql") as map_template: random_map_db.execute_script(map_template.read()) for island_id, island_string in enumerate(random_island_sequence): create_random_island(random_map_db, island_id, island_string) random_map_db.close() self._map_path = self._temp_path2 self("INSERT INTO metadata VALUES(?, ?)", "random_island_sequence", " ".join(random_island_sequence)) self("ATTACH ? AS map_file", self._map_path) if is_random_map: self.map_name = random_island_sequence elif os.path.isabs(self._map_path): self.map_name = self._map_path else: self.map_name = SavegameManager.get_savegamename_from_filename(self._map_path) self._load_building() self._load_settlement() self._load_concrete_object() self._load_production() self._load_storage() self._load_wildanimal() self._load_unit() self._load_building_collector() self._load_production_line() self._load_unit_path() self._load_storage_global_limit() self._load_health() self._load_fish_data() self._hash = None
def __init__(self, game_identifier, is_map): is_random_map = False if is_map: self.upgrader = None handle, self._temp_path = tempfile.mkstemp() os.close(handle) super(SavegameAccessor, self).__init__(dbfile=self._temp_path) with open('content/savegame_template.sql') as savegame_template: self.execute_script(savegame_template.read()) if isinstance(game_identifier, list): is_random_map = True random_island_sequence = game_identifier else: self._map_path = game_identifier else: self.upgrader = SavegameUpgrader(game_identifier) self._temp_path = None game_identifier = self.upgrader.get_path() super(SavegameAccessor, self).__init__(dbfile=game_identifier) map_name_data = self('SELECT value FROM metadata WHERE name = ?', 'map_name') if not map_name_data: is_random_map = True random_island_sequence = self( 'SELECT value FROM metadata WHERE name = ?', 'random_island_sequence')[0][0].split(' ') else: map_name = map_name_data[0][0] if os.path.isabs(map_name): self._map_path = map_name else: self._map_path = SavegameManager.get_filename_from_map_name( map_name) if is_random_map: handle, self._temp_path2 = tempfile.mkstemp() os.close(handle) random_map_db = DbReader(self._temp_path2) with open('content/map-template.sql') as map_template: random_map_db.execute_script(map_template.read()) for island_id, island_string in enumerate(random_island_sequence): create_random_island(random_map_db, island_id, island_string) random_map_db.close() self._map_path = self._temp_path2 self('INSERT INTO metadata VALUES(?, ?)', 'random_island_sequence', ' '.join(random_island_sequence)) self('ATTACH ? AS map_file', self._map_path) if is_random_map: self.map_name = random_island_sequence elif os.path.isabs(self._map_path): self.map_name = self._map_path else: self.map_name = SavegameManager.get_savegamename_from_filename( self._map_path) self._load_building() self._load_settlement() self._load_concrete_object() self._load_production() self._load_storage() self._load_wildanimal() self._load_unit() self._load_building_collector() self._load_production_line() self._load_unit_path() self._load_storage_global_limit() self._load_health() self._load_fish_data() self._hash = None