Exemple #1
0
void vehicle::turret_unload( vehicle_part &pt )
{
    item &gun = pt.base;
    if( !gun.is_gun() || gun.ammo_type() == "NULL" ||
        gun.ammo_current() == "null" || gun.ammo_remaining() == 0 ) {
        return;
    }

    // return fuels to onboard vehicle tanks
    if( fuel_capacity( gun.ammo_current() ) > 0 ) {
        refill( gun.ammo_current(), gun.ammo_remaining() );
        gun.ammo_unset();
        return;
    }

    // otherwise unload to cargo space
    item ammo( gun.ammo_current(), calendar::turn, gun.ammo_remaining() );
    gun.ammo_unset();

    // @todo check ammo is not liquid or otherwise irrecoverable

    for( item &e : pt.items ) {
        if( e.merge_charges( ammo ) ) {
            return;
        }
    }
    pt.items.push_back( std::move( ammo ) );
}
/**
 * Prints a fuel gauge for a vehicle
 * @param w Pointer to the window to draw in.
 * @param y Y location to draw at.
 * @param x X location to draw at.
 * @param fuel_type ID of the fuel type to draw
 * @param verbose true if there should be anything after the gauge (either the %, or number)
 * @param desc true if the name of the fuel should be at the end
 */
void vehicle::print_fuel_indicator( const catacurses::window &win, int y, int x,
                                    const itype_id &fuel_type, bool verbose, bool desc ) const
{
    const char fsyms[5] = { 'E', '\\', '|', '/', 'F' };
    nc_color col_indf1 = c_light_gray;
    int cap = fuel_capacity( fuel_type );
    int f_left = fuel_left( fuel_type );
    nc_color f_color = item::find_type( fuel_type )->color;
    mvwprintz( win, y, x, col_indf1, "E...F" );
    int amnt = cap > 0 ? f_left * 99 / cap : 0;
    int indf = ( amnt / 20 ) % 5;
    mvwprintz( win, y, x + indf, f_color, "%c", fsyms[indf] );
    if( verbose ) {
        if( debug_mode ) {
            mvwprintz( win, y, x + 6, f_color, "%d/%d", f_left, cap );
        } else {
            mvwprintz( win, y, x + 6, f_color, "%d", ( f_left * 100 ) / cap );
            wprintz( win, c_light_gray, "%c", 045 );
        }
    }
    if( desc ) {
        wprintz( win, c_light_gray, " - %s", item::nname( fuel_type ).c_str() );
    }
}