コード例 #1
0
	static terrain_filter cfg_to_value(const config &cfg)
	{
		if (const config &v = cfg.child("value")) {
			return terrain_filter(vconfig(v), manager::get_ai_info().units);
		}
		static config c("not");
		return terrain_filter(vconfig(c),manager::get_ai_info().units);
	}
コード例 #2
0
	static terrain_filter cfg_to_value(const config &cfg)
	{
		if (const config &v = cfg.child("value")) {
			return terrain_filter(vconfig(v), *resources::units);
		}
		static config c("not");
		return terrain_filter(vconfig(c),*resources::units);
	}
コード例 #3
0
bool have_location(const vconfig& cfg)
{
    std::set<map_location> res;
    terrain_filter(cfg, resources::filter_con).get_locations(res);

    std::vector<std::pair<int,int> > counts = cfg.has_attribute("count")
            ? utils::parse_ranges(cfg["count"]) : default_counts;
    return in_ranges<int>(res.size(), counts);
}
コード例 #4
0
ファイル: menu_item.cpp プロジェクト: AI0867/wesnoth
/**
 * Returns whether or not *this is applicable given the context.
 * Assumes game variables x1, y1, and unit have been set.
 * @param[in]  hex  The hex where the menu will appear.
 */
bool wml_menu_item::can_show(const map_location & hex) const
{
	// Failing the [show_if] tag means no show.
	if ( !show_if_.empty() && !conditional_passed(show_if_) )
		return false;

	// Failing the [fiter_location] tag means no show.
	if ( !filter_location_.empty() &&
	     !terrain_filter(filter_location_, *resources::units)(hex) )
		return false;

	// Failing to have a required selection means no show.
	if ( needs_select_ && !resources::gamedata->last_selected.valid() )
		return false;

	// Passed all tests.
	return true;
}
コード例 #5
0
int main( int argc, const char *argv[] )
{
    const int numargs = 2;  // including command name
    
    int last_count = -1;

    struct Terrain_Progress_Callback progress = { print_progress, &last_count };

    char *endptr;

    int nrows;
    int ncols;

    float *data;
    
    int error;

    printf( "\nTiming tester for terrain texture shading program - version %s\n", version );

    // Validate parameters:

//  command_name = "TEXTURE_TESTER";
    command_name = get_command_name( argv );

    if (argc == 1) {
        usage_exit( 0 );
    } else if (argc < numargs) {
        usage_exit( "Not enough command-line parameters." );
    } else if (argc > numargs) {
        usage_exit( "Too many command-line parameters." );
    }
        
    nrows = (int)strtol( argv[1], &endptr, 10 );
    ncols = nrows;
    if (endptr == argv[1] || *endptr != '\0') {
        usage_exit( "First parameter (detail) must be a number." );
    }
    
    data = (float *)malloc( (long)nrows * (long)ncols * sizeof( float ) );
    
    memset( data, 0, (long)nrows * (long)ncols * sizeof( float ) );

    // Process data:

    printf( "Processing %d column x %d row array...\n", ncols, nrows );
    fflush( stdout );

    gettimeofday(&tp2, NULL);
    error = terrain_filter(
        data, 1.0, nrows, ncols, 1.0, 1.0, TERRAIN_METERS, 0.0, &progress );

    if (error) {
        assert( error == TERRAIN_FILTER_MALLOC_ERROR );
        prefix_error();
        fprintf( stderr, "Memory allocation error occurred during processing of data.\n" );
        exit( EXIT_FAILURE );
    }
    
    free( data );
    
    printf( "DONE.\n" );

    return EXIT_SUCCESS;
}
コード例 #6
0
ファイル: texture.c プロジェクト: cwygoda/texture-shading
int main( int argc, const char *argv[] )
{
    const int minargs = 4;  // including command name
    
    int last_count = -1;

    struct Terrain_Progress_Callback progress = { print_progress, &last_count };

    int argnum;

    const char *thisarg;
    char *endptr;
    char extension[4];  // 3 chars plus null terminator

    char *in_dat_name;
    char *in_hdr_name;
    char *in_prj_name;
    char *out_dat_name;
    char *out_hdr_name;
    char *out_prj_name;

    double detail;

    FILE *in_dat_file;
    FILE *in_hdr_file;
    FILE *in_prj_file;
    FILE *out_dat_file;
    FILE *out_hdr_file;
    FILE *out_prj_file;
    
    int nrows;
    int ncols;
    double xmin;
    double xmax;
    double ymin;
    double ymax;
    double xdim;
    double ydim;
    float *data;
    char *software;
    
    enum Terrain_Coord_Type coord_type;
    
    int proj_type;
    int has_nulls;
    int all_ints;

    double lat1 = 0.0;  // default unless -merc option used
    double lat2 = 0.0;  // default unless -merc option used
    double center_lat;
    double temp;

    int error;

    printf( "\nTerrain texture shading program - version %s, built %s\n", sw_version, sw_date );

    // Validate parameters:

//  command_name = "TEXTURE";
    command_name = get_command_name( argv );

    if (argc == 1) {
        usage_exit( 0 );
    } else if (argc < minargs) {
        usage_exit( "Not enough command-line parameters." );
    }
    
    argnum = 1;
    
    thisarg = argv[argnum++];
    if ( strchr( thisarg, '/' ) ) {
        // read fraction: integer/integer
        detail = (double)strtol( thisarg, &endptr, 10 );
        if (endptr == thisarg || *endptr != '/' || endptr[1] < '1' || endptr[1] > '9') {
            usage_exit( "First parameter (detail) must be a number or fraction." );
        }
        detail /= (double)strtol( endptr+1, &endptr, 10 );
    } else {
        // read decimal number
        detail = strtod( thisarg, &endptr );
    }
    if (endptr == thisarg || *endptr != '\0') {
        usage_exit( "First parameter (detail) must be a number or fraction." );
    }

    software = (char *)malloc( strlen(sw_format) + strlen(sw_name) + strlen(sw_version) + strlen(sw_date) );
    if (!software) {
        prefix_error();
        fprintf( stderr, "Memory allocation error occurred.\n" );
        exit( EXIT_FAILURE );
    }
    sprintf( software, sw_format, sw_name, sw_version, sw_date );

    // Validate filenames and open files:

    strncpy( extension, "flt", 4 );
    get_filenames( argv[argnum++], &in_dat_name, &in_hdr_name, &in_prj_name, extension );
    
    strncpy( extension, "flt", 4 );
    get_filenames( argv[argnum++], &out_dat_name, &out_hdr_name, &out_prj_name, extension );
    
    if (!strcmp( in_hdr_name, out_hdr_name )) {
        usage_exit( "Input and outfile filenames must not be the same." );
    }
    
    while (argnum < argc) {
        thisarg = argv[argnum++];
        if (*thisarg != '-') {
            prefix_error();
            fprintf( stderr, "Extra command-line parameter '%s' not recognized.\n", thisarg );
            usage_exit( 0 );
        }
        ++thisarg;
        if (strncmp( thisarg, "mercator", 4 ) == 0 || strncmp( thisarg, "Mercator", 4 ) == 0) {
            if (argnum+1 >= argc) {
                usage_exit( "Option -mercator must be followed by two numeric latitude values." );
            }
            thisarg = argv[argnum++];
            lat1 = strtod( thisarg, &endptr );
            if (endptr == thisarg || *endptr != '\0') {
                usage_exit( "Option -mercator must be followed by two numeric latitude values." );
            }
            thisarg = argv[argnum++];
            lat2 = strtod( thisarg, &endptr );
            if (endptr == thisarg || *endptr != '\0') {
                usage_exit( "Option -mercator must be followed by two numeric latitude values." );
            }
            if (lat1 == lat2) {
                usage_exit( "Min & max mercator latitudes cannot be equal." );
            }
            if (lat1 > lat2) {
                temp = lat1;
                lat1 = lat2;
                lat2 = temp;
            }
            if (lat1 <= -90.0 || lat2 >= 90.0) {
                usage_exit( "Mercator latitude limits must be between -90 and +90 (exclusive)." );
            }
        } else if (strncmp( thisarg, "cellreg", 4 ) == 0 ||
                   strncmp( thisarg, "corner",  6 ) == 0)
        {
            // ignore flag - cellreg is currently assumed
        } else if (strncmp( thisarg, "gridreg", 4 ) == 0 ||
                   strncmp( thisarg, "center",  6 ) == 0)
        {
            fprintf( stderr, "\n" );
            fprintf( stderr, "*** WARNING: " );
            fprintf( stderr, "Option -%s is not yet implemented.\n", thisarg );
            fprintf( stderr, "***          " );
            fprintf( stderr, "Treating data as cell-registered (corner-aligned).\n" );
        } else {
            prefix_error();
            fprintf( stderr, "Command-line option '-%s' not recognized.\n", thisarg );
            usage_exit( 0 );
        }
    }
    
    in_hdr_file = fopen( in_hdr_name, "rb" );   // use binary mode for compatibility
    if (!in_hdr_file) {
        prefix_error();
        fprintf( stderr, "Could not open input file '%s'.\n", in_hdr_name );
        usage_exit( 0 );
    }

    in_dat_file = fopen( in_dat_name, "rb" );
    if (!in_dat_file) {
        prefix_error();
        fprintf( stderr, "Could not open input file '%s'.\n", in_dat_name );
        usage_exit( 0 );
    }
    
    free( in_dat_name );
    free( in_hdr_name );

    out_hdr_file = fopen( out_hdr_name, "wb" ); // use binary mode for compatibility
    if (!out_hdr_file) {
        prefix_error();
        fprintf( stderr, "Could not open output file '%s'.\n", out_hdr_name );
        usage_exit( 0 );
    }

    out_dat_file = fopen( out_dat_name, "wb" );
    if (!out_dat_file) {
        prefix_error();
        fprintf( stderr, "Could not open output file '%s'.\n", out_dat_name );
        usage_exit( 0 );
    }
    
    free( out_dat_name );
    free( out_hdr_name );

    // Read .flt and .hdr files:

    printf( "Reading input files...\n" );
    fflush( stdout );

    data = read_flt_hdr_files(
        in_dat_file, in_hdr_file, &nrows, &ncols, &xmin, &xmax, &ymin, &ymax,
        &has_nulls, &all_ints, 0 );
    
    fclose( in_dat_file );
    fclose( in_hdr_file );

    if (has_nulls) {
        fprintf( stderr, "*** WARNING: " );
        fprintf( stderr, "Input .flt file contains void (NODATA) points.\n" );
        fprintf( stderr, "***          " );
        fprintf( stderr, "Assuming these are ocean points - setting these elevations to 0.\n" );
    }
    
    if (all_ints && detail > 0.0) {
        fprintf( stderr, "*** WARNING: " );
        fprintf( stderr, "Input .flt file appears to contain only integer values.\n" );
        fprintf( stderr, "***          " );
        fprintf( stderr, "This may degrade the quality of the result.\n" );
    }

    // Process data:

    xdim = (xmax - xmin) / (double)ncols;
    ydim = (ymax - ymin) / (double)nrows;

    // determine projection type
    proj_type = determine_projection( xmin, xmax, ymin, ymax, xdim, ydim );
    
    if (proj_type < 0) {
        coord_type = TERRAIN_DEGREES;
        center_lat = 0.5 * (ymin + ymax);
        
        printf( "\nInput data appears to be in lat/lon (geographic) coordinates.\n" );
        fflush( stdout );
    } else if (proj_type > 0) {
        coord_type = TERRAIN_METERS;
        center_lat = 0.0;   // ignored when coord_type == TERRAIN_METERS
        
        printf( "\nInput data appears to be projected into linear coordinates " );
        printf( "(easting/northing).\n" );
        fflush( stdout );
    } else {
        prefix_error();
        fprintf( stderr, "Unable to determine projection type from info in .hdr file.\n" );
        exit( EXIT_FAILURE );
    }

    if (lat1 != lat2) {
        if (proj_type < 0) {
            usage_exit( "Option -mercator is invalid for data in geographic coordinates." );
        }
        proj_type = 2;  // indicate Mercator projection
        
        printf( "Assuming input data is in normal-aspect Mercator projection.\n" );
        printf( "Latitude range %.3f deg %c to %.3f deg %c.\n",
            fabs(lat1), lat1>=0.0 ? 'N' : 'S', fabs(lat2), lat2>=0.0 ? 'N' : 'S' );
        printf( "(NOTE: Do NOT use option -mercator with UTM projection.)\n\n" );

    }
    
    // check pixel aspect ratio and size of map extent
    check_aspect( xmin, xmax, ymin, ymax, xdim, ydim, proj_type );
    
    if (detail <= 0.0 || detail > 2.0) {
        fprintf( stderr, "*** WARNING: " );
        fprintf( stderr, "Unusual value for detail exponent. Is this correct?\n" );
    }
    
    printf(
        "Processing %d column x %d row array using detail = %f...\n",
        ncols, nrows, detail );
    fflush( stdout );

    error = terrain_filter(
        data, detail, nrows, ncols, xdim, ydim, coord_type, center_lat, &progress );

    if (error) {
        assert( error == TERRAIN_FILTER_MALLOC_ERROR );
        prefix_error();
        fprintf( stderr, "Memory allocation error occurred during processing of data.\n" );
        exit( EXIT_FAILURE );
    }
    
    if (lat1 != lat2) {
        fix_mercator( data, detail, nrows, ncols, lat1, lat2 );
    }

    // Write .flt and .hdr files:

    printf( "Writing output files...\n" );
    fflush( stdout );

    write_flt_hdr_files(
        out_dat_file, out_hdr_file, nrows, ncols, xmin, xmax, ymin, ymax, data, software );
    
    fclose( out_dat_file );
    fclose( out_hdr_file );

    free( data );
    free( software );
    
    // Copy optional .prj file:

    in_prj_file = fopen( in_prj_name, "rb" );   // use binary mode for compatibility
    if (in_prj_file) {
        out_prj_file = fopen( out_prj_name, "wb" ); // use binary mode for compatibility
        if (!out_prj_file) {
            fprintf( stderr, "*** WARNING: " );
            fprintf( stderr, "Could not open output file '%s'.\n", out_prj_name );
        } else {
            // copy file and change any "ZUNITS" line to "ZUNITS NO"
            copy_prj_file( in_prj_file, out_prj_file );

            fclose( out_prj_file );
        }
        fclose( in_prj_file );
    }

    free( in_prj_name );
    free( out_prj_name );

    printf( "DONE.\n" );

    return EXIT_SUCCESS;
}