Skip to content

Commit

Permalink
Refactor salvage_actor::cut_up (#58414)
Browse files Browse the repository at this point in the history
* Refactor cut_up

Move mat_set outside of the loop
Invert if
Remove useless braces

* Move uniform distribution into own function

* Refactor into lambdas

Efficiency is calculated once and assigned to a const
The recipe is found in a separate function, more clearly separating that
functionality from what should be done if no recipe is found

* Move find_recipe into own function

* Commenting + renaming

* Hide cut_up and unify try_to_cut and valid_to_cut

* Remove cutter item from cut_up

* Remove one const from function declaration

* Rebalance fab skill, update comments

Fab skill now has a more severe effect but is completely eliminated at
lvl 5

* Unsalvageable or count_by_charges items unsalavgeable

* Check uncraft before crafting recipes

* Limit mass returned from cut up

* Combine num, efficiency into num_adjusted

* cut_up_comp handles eff, remove extra loop

* Add chance to always salvage smth

* Use items count_by_charges instead of discarding

* Formatting

* Check for salvageable before count_by_charges

* Fix error and always round yields down

* Fix usage of get_wielded_item
  • Loading branch information
Willenbrink authored Jul 18, 2022
1 parent 64ff577 commit dcfd78b
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 194 deletions.
6 changes: 4 additions & 2 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5941,9 +5941,11 @@ void longsalvage_activity_actor::finish( player_activity &act, Character &who )
}

for( item &it : items ) {
if( actor->valid_to_cut_up( it ) ) {
// Check first and only if possible attempt it with player char
// This suppresses warnings unless it is an item the player wears
if( actor->valid_to_cut_up( nullptr, it ) ) {
item_location item_loc( map_cursor( who.pos() ), &it );
actor->cut_up( who, *salvage_tool, item_loc );
actor->try_to_cut_up( who, *salvage_tool, item_loc );
return;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8832,7 +8832,7 @@ void game::butcher()
if( it->is_corpse() ) {
corpses.push_back( it );
} else {
if( ( salvage_tool_index != INT_MIN ) && salvage_iuse->valid_to_cut_up( *it ) ) {
if( ( salvage_tool_index != INT_MIN ) && salvage_iuse->valid_to_cut_up( nullptr, *it ) ) {
salvageables.push_back( it );
}
if( u.can_disassemble( *it, crafting_inv ).success() ) {
Expand Down Expand Up @@ -9029,12 +9029,12 @@ void game::butcher()
break;
case BUTCHER_SALVAGE: {
if( !salvage_iuse || !salvage_tool ) {
debugmsg( "null salve_iuse or salvage_tool" );
debugmsg( "null salvage_iuse or salvage_tool" );
} else {
// Pick index of first item in the salvage stack
item *const target = &*salvage_stacks[indexer_index].first;
item_location item_loc( map_cursor( u.pos() ), target );
salvage_iuse->cut_up( u, *salvage_tool, item_loc );
salvage_iuse->try_to_cut_up( u, *salvage_tool, item_loc );
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ class salvage_inventory_preset: public inventory_selector_preset
}

bool is_shown( const item_location &loc ) const override {
return actor->valid_to_cut_up( *loc.get_item() );
return actor->valid_to_cut_up( nullptr, *loc.get_item() );
}

private:
Expand Down
1 change: 1 addition & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9928,6 +9928,7 @@ bool item::is_salvageable() const
if( is_null() ) {
return false;
}
// None of the materials are salvageable or they turn into the original item
const std::map<material_id, int> &mats = made_of();
if( std::none_of( mats.begin(), mats.end(), [this]( const std::pair<material_id, int> &m ) {
return m.first->salvaged_into().has_value() && m.first->salvaged_into().value() != type->get_id();
Expand Down
Loading

0 comments on commit dcfd78b

Please sign in to comment.