Skip to content

Commit

Permalink
In progress disassembly follows the same rule as making a new one (#5…
Browse files Browse the repository at this point in the history
…1221)

* same rule for in progress disassebmly

* Dont spill ebooks while disassembling e-ink
  • Loading branch information
Menschheit authored Aug 30, 2021
1 parent 515f804 commit d19fbab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
10 changes: 3 additions & 7 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4179,14 +4179,10 @@ void disassemble_activity_actor::start( player_activity &act, Character &who )
act.set_to_null();
return;
}

if( act.targets.back()->typeId() != itype_disassembly ) {
target = who.create_in_progress_disassembly( act.targets.back() );
} else {
target = act.targets.back();
act.position = target->charges;
if( act.targets.back()->typeId() == itype_disassembly ) {
act.position = act.targets.back()->charges;
}

target = who.create_in_progress_disassembly( act.targets.back() );
act.targets.pop_back();

if( !check_if_disassemble_okay( target, who ) ) {
Expand Down
47 changes: 26 additions & 21 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2164,30 +2164,35 @@ ret_val<bool> Character::can_disassemble( const item &obj, const read_only_visit

item_location Character::create_in_progress_disassembly( item_location target )
{
const auto &r = recipe_dictionary::get_uncraft( target->typeId() );
item &orig_item = *target.get_item();

item new_disassembly( &r, orig_item );

// Remove any batteries, ammo, contents and mods first
remove_ammo( orig_item, *this );
remove_radio_mod( orig_item, *this );
if( orig_item.is_container() ) {
orig_item.spill_contents( pos() );
}
if( orig_item.count_by_charges() ) {
// remove the charges that one would get from crafting it
if( orig_item.is_ammo() && !r.has_flag( "UNCRAFT_BY_QUANTITY" ) ) {
//subtract selected number of rounds to disassemble
orig_item.charges -= activity.position;
new_disassembly.charges = activity.position;
} else {
orig_item.charges -= r.create_result().charges;
new_disassembly.charges = r.create_result().charges;
item new_disassembly;
if( target->typeId() == itype_disassembly ) {
new_disassembly = item( orig_item );
} else {
const auto &r = recipe_dictionary::get_uncraft( target->typeId() );
new_disassembly = item( &r, orig_item );

// Remove any batteries, ammo, contents and mods first
remove_ammo( orig_item, *this );
remove_radio_mod( orig_item, *this );
if( orig_item.is_container() ) {
orig_item.spill_contents( pos() );
}
if( orig_item.count_by_charges() ) {
// remove the charges that one would get from crafting it
if( orig_item.is_ammo() && !r.has_flag( "UNCRAFT_BY_QUANTITY" ) ) {
//subtract selected number of rounds to disassemble
orig_item.charges -= activity.position;
new_disassembly.charges = activity.position;
} else {
orig_item.charges -= r.create_result().charges;
new_disassembly.charges = r.create_result().charges;
}
}
}
// remove the item, except when it's counted by charges and still has some
if( !orig_item.count_by_charges() || orig_item.charges <= 0 ) {
if( !orig_item.count_by_charges() || orig_item.charges <= 0 ||
target->typeId() == itype_disassembly ) {
target.remove_item();
}

Expand Down Expand Up @@ -2608,7 +2613,7 @@ void drop_or_handle( const item &newit, Character &p )
void remove_ammo( item &dis_item, Character &p )
{
dis_item.remove_items_with( [&p]( const item & it ) {
if( it.is_irremovable() ) {
if( it.is_irremovable() || ( !it.is_gunmod() && !it.is_toolmod() ) ) {
return false;
}
drop_or_handle( it, p );
Expand Down

0 comments on commit d19fbab

Please sign in to comment.