diff --git a/src/vehicle.cpp b/src/vehicle.cpp index d8d8985421215..1c5d718b2691d 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -672,6 +672,10 @@ void vehicle::init_state( int init_veh_fuel, int init_veh_status ) } } + for( size_t i = 0; i < engines.size(); i++ ) { + auto_select_fuel( i ); + } + invalidate_mass(); } diff --git a/src/vehicle.h b/src/vehicle.h index 9a10fc14fe62b..1598064c09513 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -870,6 +870,8 @@ class vehicle // Fold up the vehicle bool fold_up(); + // Try select any fuel for engine, returns true if some fuel is available + bool auto_select_fuel( int e ); // Attempt to start an engine bool start_engine( int e ); // stop all engines diff --git a/src/vehicle_use.cpp b/src/vehicle_use.cpp index 2924a5a26afdb..55c5e590b2911 100644 --- a/src/vehicle_use.cpp +++ b/src/vehicle_use.cpp @@ -916,6 +916,27 @@ int vehicle::engine_start_time( const int e ) const return part_vpower_w( engines[ e ], true ) / watts_per_time + 100 * dmg + cold; } +bool vehicle::auto_select_fuel( int e ) +{ + vehicle_part &vp_engine = parts[ engines[ e ] ]; + const vpart_info &vp_engine_info = part_info( engines[e] ); + if( !vp_engine.is_available() ) { + return false; + } + if( vp_engine_info.fuel_type == fuel_type_none || + vp_engine_info.has_flag( "PERPETUAL" ) || + engine_fuel_left( e ) > 0 ) { + return true; + } + for( const itype_id &fuel_id : vp_engine_info.engine_fuel_opts() ) { + if( fuel_left( fuel_id ) > 0 ) { + vp_engine.fuel_set( fuel_id ); + return true; + } + } + return false; // not a single fuel type left for this engine +} + bool vehicle::start_engine( const int e ) { if( !is_engine_on( e ) ) { @@ -925,16 +946,7 @@ bool vehicle::start_engine( const int e ) const vpart_info &einfo = part_info( engines[e] ); vehicle_part &eng = parts[ engines[ e ] ]; - bool out_of_fuel = false; - if( einfo.fuel_type != fuel_type_none && engine_fuel_left( e ) <= 0 ) { - for( const itype_id &fuel_id : einfo.engine_fuel_opts() ) { - if( fuel_left( fuel_id ) > 0 ) { - eng.fuel_set( fuel_id ); - break; - } - } - out_of_fuel = true; - } + bool out_of_fuel = !auto_select_fuel( e ); Character &player_character = get_player_character(); if( out_of_fuel ) {