Skip to content

Commit

Permalink
Merge pull request #139 from Lee-Adamson/LA-Patches
Browse files Browse the repository at this point in the history
Fixed vehicle fuel/battery bug.
  • Loading branch information
AtomicFox556 authored Nov 28, 2023
2 parents 4db5647 + 7d16cca commit 2fe9dce
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,24 +309,24 @@ void vehicle::init_state( map &placed_on, int init_veh_fuel, int init_veh_status
vp.ammo_unset(); // clear if no valid fuel
return;
}
const int max = vp.ammo_capacity( fuel->ammo->type );
const int tank_max = vp.ammo_capacity( fuel->ammo->type );
if( init_veh_fuel < 0 ) {
const double min = get_option<float>( "VEH_MIN_FUEL" );
double max = get_option<float>( "VEH_MAX_FUEL" );
if( min > max ) {
const double fuel_min = get_option<float>( "VEH_MIN_FUEL" );
double fuel_max = get_option<float>( "VEH_MAX_FUEL" );
if( fuel_min > fuel_max ) {
debugmsg( "Options set up incorrectly: minimum vehicle fuel shouldn't be higher than maximum vehicle fuel." );
max = min;
fuel_max = fuel_min;
}
// map.emplace(...).first returns iterator to the new or existing element
const double roll = fuels.emplace( fuel, normal_roll( 0.3,
0.15 ) * ( ( min + max ) / 0.6 ) ).first->second;
vp.ammo_set( fuel, max * std::clamp( roll, min, max ) );
0.15 ) * ( ( fuel_min + fuel_max ) / 0.6 ) ).first->second;
vp.ammo_set( fuel, tank_max * std::clamp( roll, fuel_min, fuel_max ) );
} else if( init_veh_fuel == 0 ) {
vp.ammo_unset();
} else if( init_veh_fuel > 0 && init_veh_fuel < 100 ) {
vp.ammo_set( fuel, max * init_veh_fuel / 100 );
vp.ammo_set( fuel, tank_max * init_veh_fuel / 100 );
} else { // init_veh_fuel >= 100
vp.ammo_set( fuel, max );
vp.ammo_set( fuel, tank_max );
}
};
// veh_status is initial vehicle damage
Expand Down

0 comments on commit 2fe9dce

Please sign in to comment.