Skip to content

Commit

Permalink
Only add a repair item once to the list of possible repair items.
Browse files Browse the repository at this point in the history
Some (different) materials use the same repair item (iron and steel each use scrap metal). Repairing an item made of several of those materials would show a menu to the user for choosing which item to use for repairing. That menu had several identical entries (one for repairing iron with scrap metal, and one for repairing steel with scrap metal).

That selection is unnecessary as both choices consume the same item.

This commit detects that case and prevents the second entry from appearing.
  • Loading branch information
BevapDin committed Nov 18, 2019
1 parent a3b0f0f commit 02d7e90
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2944,7 +2944,6 @@ bool repair_item_actor::handle_components( player &pl, const item &fix,
}
}

std::vector<item_comp> comps;
if( valid_entries.empty() ) {
if( print_msg ) {
pl.add_msg_if_player( m_info, _( "Your %s is not made of any of:" ),
Expand Down Expand Up @@ -2979,8 +2978,16 @@ bool repair_item_actor::handle_components( player &pl, const item &fix,
}

// Go through all discovered repair items and see if we have any of them available
std::vector<item_comp> comps;
for( const auto &entry : valid_entries ) {
const auto component_id = entry.obj().repaired_with();
const itype_id &component_id = entry.obj().repaired_with();
// Certain (different!) materials are repaired with the same components (steel, iron, hard steel use scrap metal).
// This checks avoids adding the same component twice, which is annoying to the user.
if( std::find_if( comps.begin(), comps.end(), [&]( const item_comp & ic ) {
return ic.type == component_id;
} ) != comps.end() ) {
continue;
}
if( item::count_by_charges( component_id ) ) {
if( crafting_inv.has_charges( component_id, items_needed ) ) {
comps.emplace_back( component_id, items_needed );
Expand Down

0 comments on commit 02d7e90

Please sign in to comment.