Skip to content

Commit

Permalink
Merge pull request #44630 from irwiss/fix-44349
Browse files Browse the repository at this point in the history
Fix 44349 - autoselect fuel type on vehicle spawn
  • Loading branch information
kevingranade authored Oct 8, 2020
2 parents 1dffb98 + e1f9d0f commit 9e9fec8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 2 additions & 0 deletions src/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 22 additions & 10 deletions src/vehicle_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand All @@ -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 ) {
Expand Down

0 comments on commit 9e9fec8

Please sign in to comment.