Skip to content

Commit

Permalink
feat(content): minumum and maximum auto-drive speed option (#4684)
Browse files Browse the repository at this point in the history
* feat(content): maximum auto-drive speed option

* style(autofix.ci): automated formatting

* Update options.cpp

* Minimum speed setable, too

* fixes

* style(autofix.ci): automated formatting

* Update src/options.cpp

Co-authored-by: scarf <greenscarf005@gmail.com>

* Min speed also defined

* nitpicky

* style(autofix.ci): automated formatting

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: scarf <greenscarf005@gmail.com>
  • Loading branch information
3 people committed May 22, 2024
1 parent 27c4695 commit d3b5595
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,16 @@ void options_manager::add_options_debug()
false );

get_option( "MADE_OF_EXPLODIUM" ).setPrerequisite( "OLD_EXPLOSIONS", "false" );

add_empty_line();

add( "MIN_AUTODRIVE_SPEED", debug, translate_marker( "Minimum auto-drive speed" ),
translate_marker( "Set the minimum speed for the auto-drive feature. In tiles/s. Default is 1 (6 km/h or 4 mph)." ),
1, 100, 1 );

add( "MAX_AUTODRIVE_SPEED", debug, translate_marker( "Maximum auto-drive speed" ),
translate_marker( "Set the maximum speed for the auto-drive feature. In tiles/s. Default is 9 (57 km/h or 36 mph)." ),
1, 100, 9 );
}

void options_manager::add_options_world_default()
Expand Down
8 changes: 6 additions & 2 deletions src/vehicle_autodrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "map_iterator.h"
#include "mapdata.h"
#include "messages.h"
#include "options.h"
#include "point.h"
#include "tileray.h"
#include "translations.h"
Expand Down Expand Up @@ -137,8 +138,6 @@ static constexpr int NAV_VIEW_SIZE_Y = NAV_MAP_SIZE_Y + 2 * NAV_VIEW_PADDING;
static constexpr int TURNING_INCREMENT = 15;
static constexpr int NUM_ORIENTATIONS = 360 / TURNING_INCREMENT;
// min and max speed in tiles/s
static constexpr int MIN_SPEED_TPS = 1;
static constexpr int MAX_SPEED_TPS = 10;
static constexpr int VMIPH_PER_TPS = static_cast<int>( vehicles::vmiph_per_tile );

/**
Expand Down Expand Up @@ -274,6 +273,7 @@ struct auto_navigation_data {
bool land_ok;
bool water_ok;
bool air_ok;
// the minimum speed to consider driving at, in tiles/s
// the maximum speed to consider driving at, in tiles/s
int max_speed_tps;
// max acceleration
Expand Down Expand Up @@ -799,6 +799,8 @@ void vehicle::autodrive_controller::compute_goal_zone()

void vehicle::autodrive_controller::precompute_data()
{

const int MAX_SPEED_TPS = get_option<int>( "MAX_AUTODRIVE_SPEED" );
const tripoint_abs_omt current_omt = driven_veh.global_omt_location();
const tripoint_abs_omt next_omt = driver.omt_path.back();
const tripoint_abs_omt next_next_omt = driver.omt_path.size() >= 2 ?
Expand Down Expand Up @@ -1087,12 +1089,14 @@ collision_check_result vehicle::autodrive_controller::check_collision_zone( orie

void vehicle::autodrive_controller::reduce_speed()
{
const int MIN_SPEED_TPS = get_option<int>( "MIN_AUTODRIVE_SPEED" );
data.max_speed_tps = MIN_SPEED_TPS;
}

std::optional<navigation_step> vehicle::autodrive_controller::compute_next_step()
{
precompute_data();
const int MIN_SPEED_TPS = get_option<int>( "MIN_AUTODRIVE_SPEED" );
const tripoint_abs_ms veh_pos = driven_veh.global_square_location();
while( !data.path.empty() && data.path.back().pos != veh_pos ) {
data.path.pop_back();
Expand Down

0 comments on commit d3b5595

Please sign in to comment.