bool vehicle::can_enable( const vehicle_part &pt, bool alert ) const { if( std::none_of( parts.begin(), parts.end(), [&pt]( const vehicle_part & e ) { return &e == &pt; } ) || pt.removed ) { debugmsg( "Cannot enable removed or non-existent part" ); } if( pt.is_broken() ) { return false; } if( pt.info().has_flag( "PLANTER" ) && !warm_enough_to_plant() ) { if( alert ) { add_msg( m_bad, _( "It is too cold to plant anything now." ) ); } return false; } // @todo: check fuel for combustion engines if( pt.info().epower < 0 && fuel_left( fuel_type_battery, true ) <= 0 ) { if( alert ) { add_msg( m_bad, _( "Insufficient power to enable %s" ), pt.name() ); } return false; } return true; }
vehicle::turret_status vehicle::turret_query( const vehicle_part &pt ) const { if( !pt.base.ammo_sufficient() ) { return turret_status::no_ammo; } auto ups = pt.base.get_gun_ups_drain() * pt.base.gun_current_mode().qty; if( ups > fuel_left( fuel_type_battery ) ) { return turret_status::no_power; } return turret_status::ready; }
/** * 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() ); } }