From 30c5e2465b8af1a053b6e6d9dd0b453ad389582c Mon Sep 17 00:00:00 2001 From: SeventhSandwich Date: Tue, 4 Feb 2020 13:39:34 -0500 Subject: [PATCH 1/7] Update crafting.cpp fixes ammo disassembly and allow players to input number of rounds --- src/crafting.cpp | 49 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/crafting.cpp b/src/crafting.cpp index 647ae4f228835..8a89d75d241ed 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -58,6 +58,7 @@ #include "ret_val.h" #include "string_formatter.h" #include "string_id.h" +#include "string_input_popup.h" #include "units.h" #include "type_id.h" #include "clzones.h" @@ -1883,16 +1884,17 @@ ret_val player::can_disassemble( const item &obj, const inventory &inv ) c monster ); } - if( obj.count_by_charges() && !r.has_flag( flag_UNCRAFT_SINGLE_CHARGE ) ) { - // Create a new item to get the default charges - int qty = r.create_result().charges; - if( obj.charges < qty ) { - auto msg = ngettext( "You need at least %d charge of %s.", - "You need at least %d charges of %s.", qty ); - return ret_val::make_failure( msg, qty, obj.tname() ); + if( !obj.is_ammo() ) { //we get ammo quantity to disassemble later on + if( obj.count_by_charges() && !r.has_flag( flag_UNCRAFT_SINGLE_CHARGE ) ) { + // Create a new item to get the default charges + int qty = r.create_result().charges; + if( obj.charges < qty ) { + auto msg = ngettext( "You need at least %d charge of %s.", + "You need at least %d charges of %s.", qty ); + return ret_val::make_failure( msg, qty, obj.tname() ); + } } } - const auto &dis = r.disassembly_requirements(); for( const auto &opts : dis.get_qualities() ) { @@ -1997,9 +1999,22 @@ bool player::disassemble( item_location target, bool interactive ) return false; } } + // If we're disassembling ammo, prompt the player to specify amount + // This could be extended more generally in the future + int num_dis = 0; + if( obj.is_ammo() ) { + string_input_popup popup_input; + const std::string title = string_format( _( "Disassemble how many %s [MAX: %d]: " ), + obj.type_name( 1 ), obj.charges ); + popup_input.title( title ).edit( num_dis ); + if( popup_input.canceled() || num_dis <= 0 ) { + add_msg( _( "Never mind." ) ); + return false; + } + } if( activity.id() != ACT_DISASSEMBLE ) { - assign_activity( ACT_DISASSEMBLE, r.time ); + assign_activity( ACT_DISASSEMBLE, r.time * num_dis ); } else if( activity.moves_left <= 0 ) { activity.moves_left = r.time; } @@ -2008,6 +2023,8 @@ bool player::disassemble( item_location target, bool interactive ) activity.index = false; activity.targets.emplace_back( std::move( target ) ); activity.str_values.push_back( r.result() ); + activity.position = std::min( num_dis, + obj.charges ); // Unused position attribute used to store ammo to disassemble return true; } @@ -2106,7 +2123,12 @@ void player::complete_disassemble( item_location &target, const recipe &dis ) if( dis_item.count_by_charges() ) { // remove the charges that one would get from crafting it - org_item.charges -= dis.create_result().charges; + if( org_item.is_ammo() ) { + //subtract selected number of rounds to disassemble + org_item.charges -= activity.position; + } else { + org_item.charges -= dis.create_result().charges; + } } // remove the item, except when it's counted by charges and still has some if( !org_item.count_by_charges() || org_item.charges <= 0 ) { @@ -2139,6 +2161,7 @@ void player::complete_disassemble( item_location &target, const recipe &dis ) // If the components aren't empty, we want items exactly identical to them // Even if the best-fit recipe does not involve those items std::list components = dis_item.components; + // If the components are empty, item is the default kind and made of default components if( components.empty() ) { const bool uncraft_liquids_contained = dis.has_flag( flag_UNCRAFT_LIQUIDS_CONTAINED ); @@ -2148,7 +2171,7 @@ void player::complete_disassemble( item_location &target, const recipe &dis ) item newit( comp.type, calendar::turn ); // Counted-by-charge items that can be disassembled individually // have their component count multiplied by the number of charges. - if( dis_item.count_by_charges() && dis.has_flag( flag_UNCRAFT_SINGLE_CHARGE ) ) { + if( dis_item.count_by_charges() && ( dis.has_flag( flag_UNCRAFT_SINGLE_CHARGE ) ) ) { compcount *= std::min( dis_item.charges, dis.create_result().charges ); } const bool is_liquid = newit.made_of( LIQUID ); @@ -2177,6 +2200,10 @@ void player::complete_disassemble( item_location &target, const recipe &dis ) newit.ammo_set( newit.ammo_default(), newit.ammo_capacity() ); } + if( dis_item.is_ammo() ) { //If ammo, overwrite component count with selected quantity of ammo + compcount = activity.position; + } + for( ; compcount > 0; compcount-- ) { components.emplace_back( newit ); } From 06c5177368fd2910f2629e578d8e6ca9a91e8235 Mon Sep 17 00:00:00 2001 From: SeventhSandwich Date: Tue, 4 Feb 2020 14:27:21 -0500 Subject: [PATCH 2/7] Update crafting.cpp bugfix: added check to disassembly time to prevent instant disassembly of non-ammo items --- src/crafting.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/crafting.cpp b/src/crafting.cpp index 8a89d75d241ed..c1850df7e931f 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -2014,7 +2014,8 @@ bool player::disassemble( item_location target, bool interactive ) } if( activity.id() != ACT_DISASSEMBLE ) { - assign_activity( ACT_DISASSEMBLE, r.time * num_dis ); + if (num_dis != 0) { assign_activity(ACT_DISASSEMBLE, r.time * num_dis); } + else { assign_activity(ACT_DISASSEMBLE, r.time); } } else if( activity.moves_left <= 0 ) { activity.moves_left = r.time; } From 067b2901b5f167934fff3a09313aba648deb00e2 Mon Sep 17 00:00:00 2001 From: SeventhSandwich Date: Tue, 4 Feb 2020 22:18:34 -0500 Subject: [PATCH 3/7] Update crafting.cpp incorporate BevapDin's suggested revisions --- src/crafting.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/crafting.cpp b/src/crafting.cpp index c1850df7e931f..04e50f4024a86 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -2172,9 +2172,12 @@ void player::complete_disassemble( item_location &target, const recipe &dis ) item newit( comp.type, calendar::turn ); // Counted-by-charge items that can be disassembled individually // have their component count multiplied by the number of charges. - if( dis_item.count_by_charges() && ( dis.has_flag( flag_UNCRAFT_SINGLE_CHARGE ) ) ) { + if( dis_item.count_by_charges() && dis.has_flag( flag_UNCRAFT_SINGLE_CHARGE ) ) { compcount *= std::min( dis_item.charges, dis.create_result().charges ); } + if (dis_item.is_ammo()) { //If ammo, overwrite component count with selected quantity of ammo + compcount *= activity.position; + } const bool is_liquid = newit.made_of( LIQUID ); if( uncraft_liquids_contained && is_liquid && newit.charges != 0 ) { // Spawn liquid item in its default container @@ -2201,10 +2204,6 @@ void player::complete_disassemble( item_location &target, const recipe &dis ) newit.ammo_set( newit.ammo_default(), newit.ammo_capacity() ); } - if( dis_item.is_ammo() ) { //If ammo, overwrite component count with selected quantity of ammo - compcount = activity.position; - } - for( ; compcount > 0; compcount-- ) { components.emplace_back( newit ); } From 79afbe7198247101c71f5c59026792f05d44faad Mon Sep 17 00:00:00 2001 From: SeventhSandwich Date: Wed, 5 Feb 2020 19:57:33 -0500 Subject: [PATCH 4/7] Update src/crafting.cpp Co-Authored-By: ZhilkinSerg --- src/crafting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crafting.cpp b/src/crafting.cpp index 04e50f4024a86..c94855dbe507b 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -2024,7 +2024,7 @@ bool player::disassemble( item_location target, bool interactive ) activity.index = false; activity.targets.emplace_back( std::move( target ) ); activity.str_values.push_back( r.result() ); - activity.position = std::min( num_dis, + // Unused position attribute used to store ammo to disassemble obj.charges ); // Unused position attribute used to store ammo to disassemble return true; From 7339e225a2e05491d4ae3790cf5cb472bee44e43 Mon Sep 17 00:00:00 2001 From: SeventhSandwich Date: Wed, 5 Feb 2020 19:57:41 -0500 Subject: [PATCH 5/7] Update src/crafting.cpp Co-Authored-By: ZhilkinSerg --- src/crafting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crafting.cpp b/src/crafting.cpp index c94855dbe507b..ead01ee757364 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -2025,7 +2025,7 @@ bool player::disassemble( item_location target, bool interactive ) activity.targets.emplace_back( std::move( target ) ); activity.str_values.push_back( r.result() ); // Unused position attribute used to store ammo to disassemble - obj.charges ); // Unused position attribute used to store ammo to disassemble + activity.position = std::min( num_dis, obj.charges ); return true; } From 88043abbbbc04464162a5d5078b32a52fafffb1e Mon Sep 17 00:00:00 2001 From: SeventhSandwich Date: Wed, 5 Feb 2020 19:57:54 -0500 Subject: [PATCH 6/7] Update src/crafting.cpp Co-Authored-By: ZhilkinSerg --- src/crafting.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/crafting.cpp b/src/crafting.cpp index ead01ee757364..17088dc6dfd7c 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -2175,7 +2175,8 @@ void player::complete_disassemble( item_location &target, const recipe &dis ) if( dis_item.count_by_charges() && dis.has_flag( flag_UNCRAFT_SINGLE_CHARGE ) ) { compcount *= std::min( dis_item.charges, dis.create_result().charges ); } - if (dis_item.is_ammo()) { //If ammo, overwrite component count with selected quantity of ammo + //If ammo, overwrite component count with selected quantity of ammo + if( dis_item.is_ammo() ) { compcount *= activity.position; } const bool is_liquid = newit.made_of( LIQUID ); From 4c2a7a78028fe35b2fb41dd13e4f7fceb0c1c803 Mon Sep 17 00:00:00 2001 From: SeventhSandwich Date: Wed, 5 Feb 2020 20:36:24 -0500 Subject: [PATCH 7/7] Update src/crafting.cpp Co-Authored-By: ZhilkinSerg --- src/crafting.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/crafting.cpp b/src/crafting.cpp index 17088dc6dfd7c..78ba3f4b0bbdb 100644 --- a/src/crafting.cpp +++ b/src/crafting.cpp @@ -2014,7 +2014,9 @@ bool player::disassemble( item_location target, bool interactive ) } if( activity.id() != ACT_DISASSEMBLE ) { - if (num_dis != 0) { assign_activity(ACT_DISASSEMBLE, r.time * num_dis); } + if( num_dis != 0 ) { + assign_activity( ACT_DISASSEMBLE, r.time * num_dis ); + } else { assign_activity(ACT_DISASSEMBLE, r.time); } } else if( activity.moves_left <= 0 ) { activity.moves_left = r.time;