diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 60265f60707bb..b979ed62a3fec 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -3691,6 +3691,18 @@ int vehicle::max_velocity( const bool fueled ) const return is_watercraft() ? max_water_velocity( fueled ) : max_ground_velocity( fueled ); } +int vehicle::max_reverse_velocity( const bool fueled ) const +{ + int max_vel = max_velocity( fueled ); + if( has_engine_type( fuel_type_battery, true ) ) { + // Electric motors can go in reverse as well as forward + return -max_vel; + } else { + // All other motive powers do poorly in reverse + return -max_vel / 4; + } +} + // the same physics as max_ground_velocity, but with a smaller engine power int vehicle::safe_ground_velocity( const bool fueled ) const { diff --git a/src/vehicle.h b/src/vehicle.h index 1120f924b5109..3b7a665f14f02 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -1191,6 +1191,8 @@ class vehicle int max_water_velocity( bool fueled = true ) const; // Get maximum velocity for the current movement mode int max_velocity( bool fueled = true ) const; + // Get maximum reverse velocity for the current movement mode + int max_reverse_velocity( bool fueled = true ) const; // Get safe ground velocity gained by combined power of all engines. // If fueled == true, then only the engines which the vehicle has fuel for are included diff --git a/src/vehicle_move.cpp b/src/vehicle_move.cpp index ef111cb60b704..e3cc3404576e6 100644 --- a/src/vehicle_move.cpp +++ b/src/vehicle_move.cpp @@ -147,8 +147,8 @@ void vehicle::thrust( int thd ) //pos or neg if accelerator or brake int vel_inc = ( ( thrusting ) ? accel : brk ) * thd; - if( thd == -1 && thrusting ) { - //accelerate 60% if going backward + // Reverse is only 60% acceleration, unless an electric motor is in use + if( thd == -1 && thrusting && !has_engine_type( fuel_type_battery, true ) ) { vel_inc = .6 * vel_inc; } @@ -213,7 +213,7 @@ void vehicle::thrust( int thd ) stop(); } else { // Increase velocity up to max_vel or min_vel, but not above. - const int min_vel = -max_vel / 4; + const int min_vel = max_reverse_velocity(); if( vel_inc > 0 ) { // Don't allow braking by accelerating (could happen with damaged engines) velocity = std::max( velocity, std::min( velocity + vel_inc, max_vel ) ); @@ -245,7 +245,7 @@ void vehicle::cruise_thrust( int amount ) } int safe_vel = safe_velocity(); int max_vel = max_velocity(); - int max_rev_vel = -max_vel / 4; + int max_rev_vel = max_reverse_velocity(); //if the safe velocity is between the cruise velocity and its next value, set to safe velocity if( ( cruise_velocity < safe_vel && safe_vel < ( cruise_velocity + amount ) ) ||