void material_type::load( JsonObject &jsobj )
{
    mandatory( jsobj, was_loaded, "name", _name, translated_string_reader );

    mandatory( jsobj, was_loaded, "bash_resist", _bash_resist );
    mandatory( jsobj, was_loaded, "cut_resist", _cut_resist );
    mandatory( jsobj, was_loaded, "acid_resist", _acid_resist );
    mandatory( jsobj, was_loaded, "elec_resist", _elec_resist );
    mandatory( jsobj, was_loaded, "fire_resist", _fire_resist );
    mandatory( jsobj, was_loaded, "chip_resist", _chip_resist );
    mandatory( jsobj, was_loaded, "density", _density );

    optional( jsobj, was_loaded, "salvaged_into", _salvaged_into, "null" );
    optional( jsobj, was_loaded, "repaired_with", _repaired_with, "null" );
    optional( jsobj, was_loaded, "edible", _edible, false );
    optional( jsobj, was_loaded, "soft", _soft, false );

    auto arr = jsobj.get_array( "vitamins" );
    while( arr.has_more() ) {
        auto pair = arr.next_array();
        _vitamins.emplace( vitamin_id( pair.get_string( 0 ) ), pair.get_float( 1 ) );
    }

    mandatory( jsobj, was_loaded, "bash_dmg_verb", _bash_dmg_verb, translated_string_reader );
    mandatory( jsobj, was_loaded, "cut_dmg_verb", _cut_dmg_verb, translated_string_reader );

    JsonArray jsarr = jsobj.get_array( "dmg_adj" );
    while( jsarr.has_more() ) {
        _dmg_adj.push_back( _( jsarr.next_string().c_str() ) );
    }

    JsonArray burn_data_array = jsobj.get_array( "burn_data" );
    for( size_t intensity = 0; intensity < MAX_FIELD_DENSITY; intensity++ ) {
        if( burn_data_array.has_more() ) {
            JsonObject brn = burn_data_array.next_object();
            _burn_data[ intensity ] = load_mat_burn_data( brn );
        } else {
            // If not specified, supply default
            bool flammable = _fire_resist <= ( int )intensity;
            mat_burn_data mbd;
            if( flammable ) {
                mbd.burn = 1;
            }

            _burn_data[ intensity ] = mbd;
        }
    }
}
示例#2
0
void material_type::load( JsonObject &jsobj, const std::string & )
{
    mandatory( jsobj, was_loaded, "name", _name );

    mandatory( jsobj, was_loaded, "bash_resist", _bash_resist );
    mandatory( jsobj, was_loaded, "cut_resist", _cut_resist );
    mandatory( jsobj, was_loaded, "acid_resist", _acid_resist );
    mandatory( jsobj, was_loaded, "elec_resist", _elec_resist );
    mandatory( jsobj, was_loaded, "fire_resist", _fire_resist );
    mandatory( jsobj, was_loaded, "chip_resist", _chip_resist );
    mandatory( jsobj, was_loaded, "density", _density );

    assign( jsobj, "salvaged_into", _salvaged_into );
    optional( jsobj, was_loaded, "repaired_with", _repaired_with, "null" );
    optional( jsobj, was_loaded, "edible", _edible, false );
    optional( jsobj, was_loaded, "soft", _soft, false );

    auto arr = jsobj.get_array( "vitamins" );
    while( arr.has_more() ) {
        auto pair = arr.next_array();
        _vitamins.emplace( vitamin_id( pair.get_string( 0 ) ), pair.get_float( 1 ) );
    }

    mandatory( jsobj, was_loaded, "bash_dmg_verb", _bash_dmg_verb );
    mandatory( jsobj, was_loaded, "cut_dmg_verb", _cut_dmg_verb );

    JsonArray jsarr = jsobj.get_array( "dmg_adj" );
    while( jsarr.has_more() ) {
        _dmg_adj.push_back( jsarr.next_string() );
    }

    JsonArray burn_data_array = jsobj.get_array( "burn_data" );
    for( size_t intensity = 0; intensity < MAX_FIELD_DENSITY; intensity++ ) {
        if( burn_data_array.has_more() ) {
            JsonObject brn = burn_data_array.next_object();
            _burn_data[ intensity ] = load_mat_burn_data( brn );
        } else {
            // If not specified, supply default
            bool flammable = _fire_resist <= static_cast<int>( intensity );
            mat_burn_data mbd;
            if( flammable ) {
                mbd.burn = 1;
            }

            _burn_data[ intensity ] = mbd;
        }
    }
    auto bp_array = jsobj.get_array( "burn_products" );
    while( bp_array.has_more( ) ) {
        auto pair = bp_array.next_array();
        _burn_products.emplace_back( pair.get_string( 0 ), static_cast< float >( pair.get_float( 1 ) ) );
    }

    auto compactor_in_array = jsobj.get_array( "compact_accepts" );
    while( compactor_in_array.has_more( ) ) {
        _compact_accepts.emplace_back( compactor_in_array.next_string() );
    }
    auto compactor_out_array = jsobj.get_array( "compacts_into" );
    while( compactor_out_array.has_more( ) ) {
        _compacts_into.emplace_back( compactor_out_array.next_string() );
    }
}