示例#1
0
void gun_actor::load_internal( JsonObject &obj, const std::string & )
{
    gun_type = obj.get_string( "gun_type" );

    obj.read( "ammo_type", ammo_type );

    if( obj.has_array( "fake_skills" ) ) {
        JsonArray jarr = obj.get_array( "fake_skills" );
        while( jarr.has_more() ) {
            JsonArray cur = jarr.next_array();
            fake_skills[skill_id( cur.get_string( 0 ) )] = cur.get_int( 1 );
        }
    }

    obj.read( "fake_str", fake_str );
    obj.read( "fake_dex", fake_dex );
    obj.read( "fake_int", fake_int );
    obj.read( "fake_per", fake_per );

    auto arr = obj.get_array( "ranges" );
    while( arr.has_more() ) {
        auto mode = arr.next_array();
        if( mode.size() < 2 || mode.get_int( 0 ) > mode.get_int( 1 ) ) {
            obj.throw_error( "incomplete or invalid range specified", "ranges" );
        }
        ranges.emplace( std::make_pair<int, int>( mode.get_int( 0 ), mode.get_int( 1 ) ),
                        gun_mode_id( mode.size() > 2 ? mode.get_string( 2 ) : "" ) );
    }

    obj.read( "max_ammo", max_ammo );

    obj.read( "move_cost", move_cost );

    if( obj.read( "description", description ) ) {
        description = _( description );
    }
    if( obj.read( "failure_msg", failure_msg ) ) {
        failure_msg = _( failure_msg );
    }
    if( obj.read( "no_ammo_sound", no_ammo_sound ) ) {
        no_ammo_sound = _( no_ammo_sound );
    } else {
        no_ammo_sound = _( "Click." );
    }

    obj.read( "targeting_cost", targeting_cost );

    obj.read( "require_targeting_player", require_targeting_player );
    obj.read( "require_targeting_npc", require_targeting_npc );
    obj.read( "require_targeting_monster", require_targeting_monster );

    obj.read( "targeting_timeout", targeting_timeout );
    obj.read( "targeting_timeout_extend", targeting_timeout_extend );

    if( obj.read( "targeting_sound", targeting_sound ) ) {
        targeting_sound = _( targeting_sound );
    } else {
        targeting_sound = _( "Beep." );
    }

    obj.read( "targeting_volume", targeting_volume );

    obj.get_bool( "laser_lock", laser_lock );

    obj.read( "require_sunlight", require_sunlight );
}
void item::load_info( const std::string &data )
{
    std::istringstream dump(data);
    char check=dump.peek();
    if ( check == ' ' ) {
        // sigh..
        check=data[1];
    }
    if ( check == '{' ) {
        JsonIn jsin(dump);
        try {
            deserialize(jsin);
        } catch( const JsonError &jsonerr ) {
            debugmsg("Bad item json\n%s", jsonerr.c_str() );
        }
        return;
    }

    unset_flags();
    clear_vars();
    std::string idtmp, ammotmp, item_tag, mode;
    int lettmp, damtmp, acttmp, corp, tag_count, bday_;
    int owned; // Ignoring an obsolete member.
    dump >> lettmp >> idtmp >> charges >> damtmp >> tag_count;
    for( int i = 0; i < tag_count; ++i )
    {
        dump >> item_tag;
        if( !itag2ivar( item_tag, item_vars ) ) {
            item_tags.insert( item_tag );
        }
    }

    dump >> burnt >> poison >> ammotmp >> owned >> bday_ >>
         mode >> acttmp >> corp >> mission_id >> player_id;
    bday = time_point::from_turn( bday_ );
    corpse = NULL;
    getline(dump, corpse_name);
    if( corpse_name == " ''" ) {
        corpse_name.clear();
    } else {
        size_t pos = corpse_name.find_first_of( "@@" );
        while (pos != std::string::npos)  {
            corpse_name.replace( pos, 2, "\n" );
            pos = corpse_name.find_first_of( "@@" );
        }
        corpse_name = corpse_name.substr( 2, corpse_name.size() - 3 ); // s/^ '(.*)'$/\1/
    }
    gun_set_mode( gun_mode_id( mode ) );

    if( idtmp == "UPS_on" ) {
        idtmp = "UPS_off";
    } else if( idtmp == "adv_UPS_on" ) {
        idtmp = "adv_UPS_off" ;
    }
    convert( idtmp );

    invlet = char(lettmp);
    set_damage( damtmp );
    active = false;
    if (acttmp == 1) {
        active = true;
    }
}