Skip to content

Commit

Permalink
Make autoselect a default true option
Browse files Browse the repository at this point in the history
There are good arguments for and against this behavior, so the only
reasonable thing to do is to make it configurable.

Enabling this saves key presses plain and simple.

Disabling this makes directional actions more consistent since one can
always count on pressing the action key and the direction in quick
succession without waiting to see if a target was autoselected.

The default was subjectively chosen to be true based on general
impressions of popularity.
  • Loading branch information
ifreund committed Feb 1, 2020
1 parent 51d703c commit 3d68f8b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 33 deletions.
11 changes: 5 additions & 6 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "mapdata.h"
#include "messages.h"
#include "optional.h"
#include "options.h"
#include "output.h"
#include "path_info.h"
#include "translations.h"
Expand Down Expand Up @@ -1054,19 +1055,17 @@ cata::optional<tripoint> choose_adjacent( const std::string &message, const bool
}

cata::optional<tripoint> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, const action_id action, bool allow_vertical,
bool auto_select_if_single )
const std::string &failure_message, const action_id action, bool allow_vertical )
{
const std::function<bool( const tripoint & )> f = [&action]( const tripoint & p ) {
return can_interact_at( action, p );
};
return choose_adjacent_highlight( message, failure_message, f, allow_vertical,
auto_select_if_single );
return choose_adjacent_highlight( message, failure_message, f, allow_vertical );
}

cata::optional<tripoint> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, const std::function<bool ( const tripoint & )> &allowed,
const bool allow_vertical, const bool auto_select_if_single )
const bool allow_vertical )
{
// Highlight nearby terrain according to the highlight function
if( allowed != nullptr ) {
Expand All @@ -1090,7 +1089,7 @@ cata::optional<tripoint> choose_adjacent_highlight( const std::string &message,
add_msg( failure_message );
return cata::nullopt;
}
if( auto_select_if_single && single ) {
if( get_option<bool>( "AUTOSELECT_SINGLE_VALID_TARGET" ) && single ) {
return single;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,7 @@ cata::optional<tripoint> choose_direction( const std::string &message,
* @param[in] allow_vertical Allows direction vector to have vertical component if true
*/
cata::optional<tripoint> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, action_id action, bool allow_vertical = false,
bool auto_select_if_single = false );
const std::string &failure_message, action_id action, bool allow_vertical = false );

/**
* Request player input of adjacent tile with highlighting, possibly on different z-level
Expand All @@ -485,7 +484,7 @@ cata::optional<tripoint> choose_adjacent_highlight( const std::string &message,
*/
cata::optional<tripoint> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, const std::function<bool( const tripoint & )> &allowed,
bool allow_vertical = false, bool auto_select_if_single = false );
bool allow_vertical = false );

// (Press X (or Y)|Try) to Z
std::string press_x( action_id act );
Expand Down
4 changes: 2 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5318,7 +5318,7 @@ void game::examine()

const cata::optional<tripoint> examp_ = choose_adjacent_highlight( _( "Examine where?" ),
_( "There is nothing that can be examined nearby." ),
ACTION_EXAMINE, false, false );
ACTION_EXAMINE, false );
if( !examp_ ) {
return;
}
Expand Down Expand Up @@ -5524,7 +5524,7 @@ void game::pickup()
{
const cata::optional<tripoint> examp_ = choose_adjacent_highlight( _( "Pickup where?" ),
_( "There is nothing to pick up nearby." ),
ACTION_PICKUP, false, true );
ACTION_PICKUP, false );
if( !examp_ ) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ static void open()
map &m = g->m;

const cata::optional<tripoint> openp_ = choose_adjacent_highlight( _( "Open where?" ),
pgettext( "no door, gate, etc.", "There is nothing that can be opened nearby." ), ACTION_OPEN,
false, true );
pgettext( "no door, gate, curtain, etc.", "There is nothing that can be opened nearby." ),
ACTION_OPEN, false );

if( !openp_ ) {
return;
Expand Down Expand Up @@ -519,8 +519,8 @@ static void open()
static void close()
{
if( const cata::optional<tripoint> pnt = choose_adjacent_highlight( _( "Close where?" ),
pgettext( "no door, gate, etc.", "There is nothing that can be closed nearby." ), ACTION_CLOSE,
false, true ) ) {
pgettext( "no door, gate, etc.", "There is nothing that can be closed nearby." ),
ACTION_CLOSE, false ) ) {
doors::close_door( g->m, g->u, *pnt );
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2328,7 +2328,7 @@ int iuse::hammer( player *p, item *it, bool, const tripoint & )
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Pry where?" ), _( "There is nothing to pry nearby." ), f, false, true );
_( "Pry where?" ), _( "There is nothing to pry nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -2388,7 +2388,7 @@ int iuse::crowbar( player *p, item *it, bool, const tripoint &pos )
};

const cata::optional<tripoint> pnt_ = ( pos != p->pos() ) ? pos : choose_adjacent_highlight(
_( "Pry where?" ), _( "There is nothing to pry nearby." ), f, false, true );
_( "Pry where?" ), _( "There is nothing to pry nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -2738,7 +2738,7 @@ int iuse::dig( player *p, item *it, bool t, const tripoint & )

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Deposit excavated materials where?" ),
_( "There is nowhere to deposit the excavated materials." ), f, false, true );
_( "There is nowhere to deposit the excavated materials." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -2826,7 +2826,7 @@ int iuse::dig_channel( player *p, item *it, bool t, const tripoint & )

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Deposit excavated materials where?" ),
_( "There is nowhere to deposit the excavated materials." ), f, false, true );
_( "There is nowhere to deposit the excavated materials." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -2886,7 +2886,7 @@ int iuse::fill_pit( player *p, item *it, bool t, const tripoint & )
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Fill which pit or mound?" ), _( "There is no pit or mound to fill nearby." ), f, false, true );
_( "Fill which pit or mound?" ), _( "There is no pit or mound to fill nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -2943,7 +2943,7 @@ int iuse::clear_rubble( player *p, item *it, bool, const tripoint & )
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Clear rubble where?" ), _( "There is no rubble to clear nearby." ), f, false, true );
_( "Clear rubble where?" ), _( "There is no rubble to clear nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -3001,7 +3001,7 @@ int iuse::siphon( player *p, item *it, bool, const tripoint & )
}
if( found_more_than_one ) {
cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Siphon from where?" ), _( "There is nothing to siphon nearby." ), f, false, true );
_( "Siphon from where?" ), _( "There is nothing to siphon nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -3428,7 +3428,7 @@ int iuse::geiger( player *p, item *it, bool t, const tripoint &pos )
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight( _( "Scan whom?" ),
_( "There is no one to scan nearby." ), f, false, true );
_( "There is no one to scan nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -4767,7 +4767,7 @@ int iuse::chop_tree( player *p, item *it, bool t, const tripoint & )
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Chop down which tree?" ), _( "There is no tree to chop down nearby." ), f, false, true );
_( "Chop down which tree?" ), _( "There is no tree to chop down nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -4813,7 +4813,7 @@ int iuse::chop_logs( player *p, item *it, bool t, const tripoint & )
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Chop which tree trunk?" ), _( "There is no tree trunk to chop nearby." ), f, false, true );
_( "Chop which tree trunk?" ), _( "There is no tree trunk to chop nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -4886,7 +4886,7 @@ int iuse::oxytorch( player *p, item *it, bool, const tripoint & )
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Cut up metal where?" ), _( "There is no metal to cut up nearby." ), f, false, true );
_( "Cut up metal where?" ), _( "There is no metal to cut up nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -4976,7 +4976,7 @@ int iuse::hacksaw( player *p, item *it, bool t, const tripoint & )
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Cut up metal where?" ), _( "There is no metal to cut up nearby." ), f, false, true );
_( "Cut up metal where?" ), _( "There is no metal to cut up nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -5033,7 +5033,7 @@ int iuse::boltcutters( player *p, item *it, bool, const tripoint & )
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Cut up metal where?" ), _( "There is no metal to cut up nearby." ), f, false, true );
_( "Cut up metal where?" ), _( "There is no metal to cut up nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down Expand Up @@ -5122,7 +5122,7 @@ int iuse::mop( player *p, item *it, bool, const tripoint & )
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Mop where?" ), _( "There is nothing to mop nearby." ), f, false, true );
_( "Mop where?" ), _( "There is nothing to mop nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ int pick_lock_actor::use( player &p, item &it, bool, const tripoint & ) const
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Use your lockpick where?" ), _( "There is nothing to lockpick nearby." ), f, false, true );
_( "Use your lockpick where?" ), _( "There is nothing to lockpick nearby." ), f, false );
if( !pnt_ ) {
return 0;
}
Expand Down
7 changes: 7 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,13 @@ void options_manager::add_options_interface()
true
);

add( "AUTOSELECT_SINGLE_VALID_TARGET", "interface",
translate_marker( "Autoselect if exactly one valid target" ),
translate_marker( "If true, directional actions ( like \"Examine\", \"Open\", \"Pickup\" ) "
"will autoselect an adjacent tile if there is exactly one valid target." ),
true
);

add_empty_line();

add( "DIAG_MOVE_WITH_MODIFIERS_MODE", "interface",
Expand Down
4 changes: 2 additions & 2 deletions src/vehicle_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,8 +1709,8 @@ void vehicle::use_harness( int part, const tripoint &pos )
};

const cata::optional<tripoint> pnt_ = choose_adjacent_highlight(
_( "Where is the creature to harness?" ), _( "There is no creature to harness nearby." ), f, false,
true );
_( "Where is the creature to harness?" ), _( "There is no creature to harness nearby." ), f,
false );
if( !pnt_ ) {
add_msg( m_info, _( "Never mind." ) );
return;
Expand Down
3 changes: 2 additions & 1 deletion src/weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ weather_sum sum_conditions( const time_point &start, const time_point &end,

weather_type wtype = current_weather( location, t );
proc_weather_sum( wtype, data, t, tick_size );
data.wind_amount += get_local_windpower( g->weather.windspeed, overmap_buffer.ter( ms_to_omt_copy( location ) ),
data.wind_amount += get_local_windpower( g->weather.windspeed,
overmap_buffer.ter( ms_to_omt_copy( location ) ),
location,
g->weather.winddirection, false ) * to_turns<int>( tick_size );
}
Expand Down

0 comments on commit 3d68f8b

Please sign in to comment.