From 6f0c7370abb910ec727aa184cdd1f777780a9de9 Mon Sep 17 00:00:00 2001 From: ipcyborg Date: Wed, 21 Aug 2019 18:08:40 +0300 Subject: [PATCH 1/2] Fixed "Don't prompt for a direction for an action if there is only one direction possible #33402" - for lockpicking --- src/iuse_actor.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index 79f2378e400d0..ce6bb8b8df984 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -930,7 +930,37 @@ int pick_lock_actor::use( player &p, item &it, bool, const tripoint & ) const if( p.is_npc() ) { return 0; } - const cata::optional pnt_ = choose_adjacent( _( "Use your lockpick where?" ) ); + + std::set 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 pnt_; + //select adjacent point with locked door, but only if it is the only one + 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; + } + } + if( !pnt_ ) { + pnt_ = choose_adjacent( _( "Use your lockpick where?" ) ); + } if( !pnt_ ) { return 0; } From bd04e4a646f6816b53753a6e12293c642233b3f0 Mon Sep 17 00:00:00 2001 From: ipcyborg Date: Wed, 21 Aug 2019 18:29:10 +0300 Subject: [PATCH 2/2] Added message and cancel action if there is no lock to pick --- src/iuse_actor.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/iuse_actor.cpp b/src/iuse_actor.cpp index ce6bb8b8df984..167115a46bf88 100644 --- a/src/iuse_actor.cpp +++ b/src/iuse_actor.cpp @@ -943,6 +943,7 @@ int pick_lock_actor::use( player &p, item &it, bool, const tripoint & ) const cata::optional 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; @@ -956,8 +957,13 @@ int pick_lock_actor::use( player &p, item &it, bool, const tripoint & ) const 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?" ) ); }