Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QOL improvement: "Don't prompt for a direction for an action if there is only one direction possible" #33431

Merged
merged 2 commits into from
Aug 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,43 @@ int pick_lock_actor::use( player &p, item &it, bool, const tripoint & ) const
if( p.is_npc() ) {
return 0;
}
const cata::optional<tripoint> pnt_ = choose_adjacent( _( "Use your lockpick where?" ) );

std::set<ter_id> allowed_ter_id {
t_chaingate_l,
t_door_locked,
t_door_locked_alarm,
t_door_locked_interior,
t_door_locked_peep,
t_door_metal_pickable,
t_door_bar_locked
};

cata::optional<tripoint> pnt_;
//select adjacent point with locked door, but only if it is the only one
bool found = false;
for( const tripoint &pos : g->m.points_in_radius( p.pos(), 1 ) ) {
if( pos == g->u.pos() ) {
continue;
}
const ter_id type = g->m.ter( pos );
//is allowed?
if( allowed_ter_id.find( type ) != allowed_ter_id.end() ) {
if( pnt_ ) {
//found more that one
pnt_.reset();
break;
}
pnt_ = pos;
found = true;
}
}
if( !found ) {
p.add_msg_if_player( m_info, _( "No lock to pick." ) );
return 0;
}
if( !pnt_ ) {
pnt_ = choose_adjacent( _( "Use your lockpick where?" ) );
}
if( !pnt_ ) {
return 0;
}
Expand Down