diff --git a/src/crafting_gui.cpp b/src/crafting_gui.cpp index d83863eede1c1..964e2551cea9d 100644 --- a/src/crafting_gui.cpp +++ b/src/crafting_gui.cpp @@ -19,6 +19,7 @@ #include "crafting.h" #include "cursesdef.h" #include "input.h" +#include "inventory.h" #include "item.h" #include "itype.h" #include "json.h" @@ -533,12 +534,34 @@ const recipe *select_crafting_recipe( int &batch_size ) _( "Batch time savings: %s" ), current[line]->batch_savings_string() ); + const int makes = current[line]->makes_amount(); + if( makes > 1 ) { + ypos += fold_and_print( w_data, point( xpos, ypos ), pane, col, + _( "Recipe makes: %d" ), + makes ); + } + print_colored_text( w_data, point( xpos, ypos++ ), col, col, string_format( _( "Dark craftable? %s" ), current[line]->has_flag( flag_BLIND_EASY ) ? _( "Easy" ) : current[line]->has_flag( flag_BLIND_HARD ) ? _( "Hard" ) : _( "Impossible" ) ) ); + + std::string nearby_string; + const int nearby_amount = crafting_inv.count_item( current[line]->result() ); + + if( nearby_amount == 0 ) { + nearby_string = "0"; + } else if( nearby_amount > 9000 ) { + // at some point you get too many to count at a glance and just know you have a lot + nearby_string = _( "It's Over 9000!!!" ); + } else { + nearby_string = string_format( "%d", nearby_amount ); + } + ypos += fold_and_print( w_data, point( xpos, ypos ), pane, col, + _( "Nearby: %s" ), nearby_string ); + const bool can_craft_this = available[line].can_craft; if( can_craft_this && !available[line].can_craft_non_rotten ) { ypos += fold_and_print( w_data, point( xpos, ypos ), pane, col, diff --git a/src/inventory.cpp b/src/inventory.cpp index 0f7194f359f83..a1637b4a1c5b4 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -1034,6 +1034,20 @@ enchantment inventory::get_active_enchantment_cache( const Character &owner ) co return temp_cache; } +int inventory::count_item( const itype_id &item_type ) const +{ + int num = 0; + const itype_bin bin = get_binned_items(); + if( bin.find( item_type ) == bin.end() ) { + return num; + } + const std::list items = get_binned_items().find( item_type )->second; + for( const item *it : items ) { + num += it->count(); + } + return num; +} + void inventory::assign_empty_invlet( item &it, const Character &p, const bool force ) { const std::string auto_setting = get_option( "AUTO_INV_ASSIGN" ); diff --git a/src/inventory.h b/src/inventory.h index 0e2922d632ed3..93abdc2d3f355 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -232,6 +232,8 @@ class inventory : public visitable // gets a singular enchantment that is an amalgamation of all items that have active enchantments enchantment get_active_enchantment_cache( const Character &owner ) const; + int count_item( const itype_id &item_type ) const; + private: invlet_favorites invlet_cache; char find_usable_cached_invlet( const itype_id &item_type ); diff --git a/src/recipe.cpp b/src/recipe.cpp index 27ad2b17c3c10..57fee29a831f0 100644 --- a/src/recipe.cpp +++ b/src/recipe.cpp @@ -481,7 +481,7 @@ item recipe::create_result() const if( !newit.craft_has_charges() ) { newit.charges = 0; } else if( result_mult != 1 ) { - // TODO: Make it work for charge-less items + // TODO: Make it work for charge-less items (update makes amount) newit.charges *= result_mult; } @@ -910,6 +910,18 @@ bool recipe::hot_result() const return false; } +int recipe::makes_amount() const +{ + int makes; + if( charges.has_value() ) { + makes = charges.value(); + } else { + makes = item::find_type( result_ )->charges_default(); + } + // return either charges * mult or 1 + return makes ? makes * result_mult : 1 ; +} + void recipe::incorporate_build_reqs() { if( !blueprint_reqs ) { diff --git a/src/recipe.h b/src/recipe.h index bc4b39c6e7802..87cf5f1c800ca 100644 --- a/src/recipe.h +++ b/src/recipe.h @@ -229,6 +229,9 @@ class recipe bool hot_result() const; + // Returns the ammount or charges recipe will produce. + int makes_amount() const; + private: void incorporate_build_reqs(); void add_requirements( const std::vector> &reqs );