Skip to content

Commit

Permalink
Pry behavior changes: clone new crate behavior to locked objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkInvis committed Jan 24, 2019
1 parent 7479b84 commit b13f597
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,45 +1176,47 @@ void iexamine::locked_object( player &p, const tripoint &examp )
return;
}

uilist selection_menu;

selection_menu.text = string_format( _( "The %s is locked..." ), g->m.tername( examp ) );

auto prying_items = p.crafting_inventory().items_with( []( const item & it ) -> bool {
return it.has_quality( quality_id( "PRY" ), 2 );
} );

iuse dummy;
if( prying_items.size() == 1 ) {
item temporary_item( prying_items[0]->type );
// They only had one item anyway, so just use it.
dummy.crowbar( &p, &temporary_item, false, examp );
return;
}

// Sort by their quality level.
std::sort( prying_items.begin(), prying_items.end(), []( const item * a, const item * b ) -> int {
return a->get_quality( quality_id( "PRY" ) ) > b->get_quality( quality_id( "PRY" ) );
} );

// Then display the items
int i = 0;
selection_menu.addentry( i++, true, MENU_AUTOASSIGN, _( "Leave it alone" ) );
for( auto iter : prying_items ) {
selection_menu.addentry( i++, true, MENU_AUTOASSIGN, string_format( _( "Use the %s" ),
iter->tname() ) );
}
if (get_option<bool>("AUTO_PRY_LOCKED")) {
// user has elected to never have an 'are you sure' prompt to pop open non-crate pryables while examining, just use the best prying tool available
auto selected_tool = prying_items[0];
item temporary_item(selected_tool->type);
dummy.crowbar(&p, &temporary_item, false, examp);
} else {
// original prying-tool list behavior
// Prepare and display menu for choice of tool (or none)
uilist selection_menu;

selection_menu.query();
auto index = selection_menu.ret;
selection_menu.text = string_format(_("The %s is locked..."), g->m.tername(examp));

if( index == 0 || index == UILIST_CANCEL ) {
none( p, examp );
return;
}
int i = 0;
selection_menu.addentry(i++, true, MENU_AUTOASSIGN, _("Leave it alone"));
for (auto iter : prying_items) {
selection_menu.addentry(i++, true, MENU_AUTOASSIGN, string_format(_("Use the %s"),
iter->tname()));
}

selection_menu.query();
auto index = selection_menu.ret;

item temporary_item( prying_items[index - 1]->type );
dummy.crowbar( &p, &temporary_item, false, examp );
if (index == 0 || index == UILIST_CANCEL) {
none(p, examp);
return;
}

item temporary_item(prying_items[index - 1]->type);
dummy.crowbar(&p, &temporary_item, false, examp);
}
}

void iexamine::bulletin_board(player &, const tripoint &examp)
Expand Down
6 changes: 6 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,12 @@ void options_manager::add_options_general()

add("AUTO_PRY", "general", translate_marker("Auto-pry crates on examine"),
translate_marker("If disabled, examining a crate will ask you which tool to use (or to leave the crate alone). Enable to always bypass this prompt and immediately use the best available prying tool."),
true
);

// separate option because locks can be far more dangerous than crates to pry open. todo: does examine try picking first, or just jump straight to prying? former is more ideal
add("AUTO_PRY_LOCKED", "general", translate_marker("Auto-pry locks on examine"),
translate_marker("If disabled, examining a non-crate locked object will ask you which tool to use (or to leave the crate alone). Enable to always bypass this prompt and immediately use the best available prying tool."),
false
);

Expand Down

0 comments on commit b13f597

Please sign in to comment.