From 194eceb06e79122b824e6d32be0c6ac0af857493 Mon Sep 17 00:00:00 2001 From: Theundyingcode Date: Tue, 1 Sep 2020 22:19:35 -0400 Subject: [PATCH 1/5] Add Amounts --- src/crafting_gui.cpp | 20 ++++++++++++++++++++ src/inventory.cpp | 14 ++++++++++++++ src/inventory.h | 2 ++ 3 files changed, 36 insertions(+) diff --git a/src/crafting_gui.cpp b/src/crafting_gui.cpp index cd06f7cdc4ca8..4dc5f4c2a9658 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" @@ -518,6 +519,25 @@ const recipe *select_crafting_recipe( int &batch_size ) 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 c679cdd008423..55aa249969b6a 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 ); From 3bb94a3504644333d1f6fde98f34dcb923a46202 Mon Sep 17 00:00:00 2001 From: Theundyingcode Date: Wed, 2 Sep 2020 00:11:10 -0400 Subject: [PATCH 2/5] make amount --- src/crafting_gui.cpp | 7 +++++++ src/recipe.cpp | 15 ++++++++++++++- src/recipe.h | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/crafting_gui.cpp b/src/crafting_gui.cpp index 4dc5f4c2a9658..8870dd77dbe45 100644 --- a/src/crafting_gui.cpp +++ b/src/crafting_gui.cpp @@ -513,6 +513,13 @@ 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" ), diff --git a/src/recipe.cpp b/src/recipe.cpp index b5221650b9101..be6bcfedfa1f7 100644 --- a/src/recipe.cpp +++ b/src/recipe.cpp @@ -492,7 +492,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; } @@ -930,6 +930,19 @@ 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_proficiency::deserialize( JsonIn &jsin ) { load( jsin.get_object() ); diff --git a/src/recipe.h b/src/recipe.h index 1f394ff48d342..682a627d6ac66 100644 --- a/src/recipe.h +++ b/src/recipe.h @@ -227,6 +227,9 @@ class recipe bool hot_result() const; + // Returns the ammount or charges recipe will produce. + int makes_amount() const; + private: void add_requirements( const std::vector> &reqs ); From e127c08dc6b01ed34e593c6e5e8ff917eab55f29 Mon Sep 17 00:00:00 2001 From: Theundyingcode Date: Wed, 2 Sep 2020 21:22:03 -0400 Subject: [PATCH 3/5] Fixup --- src/crafting_gui.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/crafting_gui.cpp b/src/crafting_gui.cpp index 52d68b2bd502c..66628f340127e 100644 --- a/src/crafting_gui.cpp +++ b/src/crafting_gui.cpp @@ -553,18 +553,14 @@ const recipe *select_crafting_recipe( int &batch_size ) 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 ); - } + } 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 ); + _( "Nearby: %s" ), nearby_string ); const bool can_craft_this = available[line].can_craft; if( can_craft_this && !available[line].can_craft_non_rotten ) { From 1a88d6cd651c6ca019d115780a6ab733bbfa678c Mon Sep 17 00:00:00 2001 From: Theundyingcode Date: Thu, 3 Sep 2020 18:08:29 -0400 Subject: [PATCH 4/5] Got Astyle working --- src/crafting_gui.cpp | 14 +++++++------- src/inventory.cpp | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/crafting_gui.cpp b/src/crafting_gui.cpp index 66628f340127e..964e2551cea9d 100644 --- a/src/crafting_gui.cpp +++ b/src/crafting_gui.cpp @@ -535,10 +535,10 @@ const recipe *select_crafting_recipe( int &batch_size ) current[line]->batch_savings_string() ); const int makes = current[line]->makes_amount(); - if ( makes > 1 ) { + if( makes > 1 ) { ypos += fold_and_print( w_data, point( xpos, ypos ), pane, col, - _( "Recipe makes: %d" ), - makes ); + _( "Recipe makes: %d" ), + makes ); } print_colored_text( @@ -547,20 +547,20 @@ const recipe *select_crafting_recipe( int &batch_size ) 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 ) { + if( nearby_amount == 0 ) { nearby_string = "0"; - } else if ( nearby_amount > 9000 ) { + } 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 ); + _( "Nearby: %s" ), nearby_string ); const bool can_craft_this = available[line].can_craft; if( can_craft_this && !available[line].can_craft_non_rotten ) { diff --git a/src/inventory.cpp b/src/inventory.cpp index 6583c71d8cdb1..a1637b4a1c5b4 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -1034,15 +1034,15 @@ enchantment inventory::get_active_enchantment_cache( const Character &owner ) co return temp_cache; } -int inventory::count_item( const itype_id& item_type ) const +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() ) { + 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 ) { + const std::list items = get_binned_items().find( item_type )->second; + for( const item *it : items ) { num += it->count(); } return num; From 2494b726a704b29ae8abfc7c1392a637c4015dfd Mon Sep 17 00:00:00 2001 From: Theundyingcode Date: Thu, 3 Sep 2020 18:13:08 -0400 Subject: [PATCH 5/5] missed astyling recipe.cpp --- src/recipe.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/recipe.cpp b/src/recipe.cpp index a964dfc4adbb1..57fee29a831f0 100644 --- a/src/recipe.cpp +++ b/src/recipe.cpp @@ -913,16 +913,15 @@ bool recipe::hot_result() const int recipe::makes_amount() const { int makes; - if (charges.has_value()) { + if( charges.has_value() ) { makes = charges.value(); - } - else { - makes = item::find_type(result_)->charges_default(); + } else { + makes = item::find_type( result_ )->charges_default(); } // return either charges * mult or 1 - return makes ? makes * result_mult : 1 ; + return makes ? makes * result_mult : 1 ; } - + void recipe::incorporate_build_reqs() { if( !blueprint_reqs ) {