예제 #1
0
    def load(self):
        filename = f'{self.cell_map:03}{self.cell_x:02}{self.cell_y:02}.map'
        maps_path = PathManager.get_map_file_path(filename)
        Logger.debug(f'[Maps] Loading map file: {filename}')

        if not path.exists(maps_path):
            Logger.warning(f'Unable to locate map file: {filename}')
        else:
            with open(maps_path, "rb") as map_tiles:
                version = PacketReader.read_string(map_tiles.read(10), 0)
                if version != MapTile.EXPECTED_VERSION:
                    Logger.error(f'Unexpected map version. Expected "{MapTile.EXPECTED_VERSION}", received "{version}".')
                    return

                # TODO: AreaFlags
                # for x in range(0, RESOLUTION_FLAGS + 1):
                #     for y in range(0, RESOLUTION_FLAGS + 1):
                #         self.explore_flag[x][y] = unpack('<H', map_tiles.read(2))[0]
                #
                # TODO: AreaTerrain
                # for x in range(0, RESOLUTION_TERRAIN + 1):
                #     for y in range(0, RESOLUTION_TERRAIN + 1):
                #         self.area_terrain[x][y] = map_tiles.read(1)[0]
                #
                # TODO: Liquids
                # for x in range(0, RESOLUTION_WATER + 1):
                #     for y in range(0, RESOLUTION_WATER + 1):
                #         self.water_level[x][y] = unpack('<f', map_tiles.read(4))[0]

                # Height Map
                for x in range(0, RESOLUTION_ZMAP + 1):
                    for y in range(0, RESOLUTION_ZMAP + 1):
                        self.z_coords[x][y] = unpack('<f', map_tiles.read(4))[0]
예제 #2
0
    def load(self):
        # Set as initialized to avoid another load() call from another thread.
        self.initialized = True

        filename = f'{self.cell_map:03}{self.cell_x:02}{self.cell_y:02}.map'
        maps_path = PathManager.get_map_file_path(filename)
        Logger.debug(
            f'[Maps] Loading map file: {filename}, Map:{self.cell_map} Tile:{self.cell_x},{self.cell_y}'
        )

        if not path.exists(maps_path):
            Logger.warning(
                f'Unable to locate map file: {filename}, Map:{self.cell_map} Tile:{self.cell_x},{self.cell_y}'
            )
            return
        else:
            with open(maps_path, "rb") as map_tiles:
                version = PacketReader.read_string(map_tiles.read(10), 0)
                if version != MapTile.EXPECTED_VERSION:
                    Logger.error(
                        f'Unexpected map version. Expected "{MapTile.EXPECTED_VERSION}", found "{version}".'
                    )
                    return

                # Height Map
                for x in range(RESOLUTION_ZMAP):
                    for y in range(RESOLUTION_ZMAP):
                        self.z_height_map[x][y] = unpack(
                            '<f', map_tiles.read(4))[0]

                # ZoneID, AreaNumber, AreaFlags, AreaLevel, AreaExploreFlag(Bit), AreaFactionMask
                for x in range(RESOLUTION_AREA_INFO):
                    for y in range(RESOLUTION_AREA_INFO):
                        zone_id = unpack('<i', map_tiles.read(4))[0]
                        if zone_id == -1:  # No area information.
                            continue
                        area_number = unpack('<I', map_tiles.read(4))[0]
                        area_flags = unpack('<B', map_tiles.read(1))[0]
                        area_level = unpack('<B', map_tiles.read(1))[0]
                        area_explore_bit = unpack('<H', map_tiles.read(2))[0]
                        area_faction_mask = unpack('<B', map_tiles.read(1))[0]
                        # noinspection PyTypeChecker
                        self.area_information[x][y] = AreaInformation(
                            zone_id, area_number, area_flags, area_level,
                            area_explore_bit, area_faction_mask)

                # Liquids
                for x in range(RESOLUTION_LIQUIDS):
                    for y in range(RESOLUTION_LIQUIDS):
                        liquid_type = unpack('<b', map_tiles.read(1))[0]
                        if liquid_type == -1:  # No liquid information / not rendered.
                            continue
                        height = unpack('<f', map_tiles.read(4))[0]
                        # noinspection PyTypeChecker
                        self.liquid_information[x][y] = LiquidInformation(
                            liquid_type, height)

        # This is a valid tile, set as loaded.
        self.is_valid = True
예제 #3
0
    def validate_version():
        # Use the first available tile map.
        filename = '0000000.map'
        maps_path = PathManager.get_map_file_path(filename)

        if not path.exists(maps_path):
            return False

        with open(maps_path, "rb") as map_tiles:
            version = PacketReader.read_string(map_tiles.read(10), 0)
            if version != MapTile.EXPECTED_VERSION:
                return False

        return True