Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update first pass component selection to avoid poison #70824

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@ static bool construction_activity( Character &you, const zone_data * /*zone*/,
comp_selection<item_comp> sel;
sel.use_from = usage_from::both;
sel.comp = comp;
std::list<item> empty_consumed = you.consume_items( sel, 1, is_empty_crafting_component );
std::list<item> empty_consumed = you.consume_items( sel, 1, is_preferred_crafting_component );

int left_to_consume = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/basecamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ void basecamp_action_components::consume_components()
}
for( const comp_selection<item_comp> &sel : item_selections_ ) {
std::list<item> empty_consumed = player_character.consume_items( target_map, sel, batch_size_,
is_empty_crafting_component, src );
is_preferred_crafting_component, src );
int left_to_consume = 0;

if( !empty_consumed.empty() && empty_consumed.front().count_by_charges() ) {
Expand Down
2 changes: 1 addition & 1 deletion src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ void place_construction( std::vector<construction_group_str_id> const &groups )
sel.use_from = usage_from::both;
sel.comp = comp;
std::list<item> empty_consumed = player_character.consume_items( sel, 1,
is_empty_crafting_component );
is_preferred_crafting_component );

int left_to_consume = 0;

Expand Down
6 changes: 3 additions & 3 deletions src/craft_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,16 @@ bool craft_command::continue_prompt_liquids( const std::function<bool( const ite
static std::list<item> sane_consume_items( const comp_selection<item_comp> &it, Character *crafter,
int batch, const std::function<bool( const item & )> &filter )
{
std::function<bool( const item & )> empty_container_filter = [&filter]( const item & it ) {
return it.is_container_empty() && filter( it );
std::function<bool( const item & )> preferred_component_filter = [&filter]( const item & it ) {
return is_preferred_component( it ) && filter( it );
};
map &m = get_map();
const std::vector<pocket_data> it_pkt = it.comp.type->pockets;
if( ( item::count_by_charges( it.comp.type ) && it.comp.count > 0 ) ||
!std::any_of( it_pkt.begin(), it_pkt.end(), []( const pocket_data & p ) {
return p.type == pocket_type::CONTAINER && p.watertight;
} ) ) {
std::list<item> empty_consumed = crafter->consume_items( it, batch, empty_container_filter );
std::list<item> empty_consumed = crafter->consume_items( it, batch, preferred_component_filter );
int left_to_consume = 0;

if( !empty_consumed.empty() && empty_consumed.front().count_by_charges() ) {
Expand Down
12 changes: 12 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15112,3 +15112,15 @@ void item::combine( const item_contents &read_input, bool convert )
{
contents.combine( read_input, convert );
}

bool is_preferred_component( const item &component )
{
return component.is_container_empty() && ( !component.has_flag( flag_FORAGE_POISON ) ||
component.has_flag( flag_HIDDEN_POISON ) ) && ( !component.has_flag( flag_FORAGE_HALLU ) ||
component.has_flag( flag_HIDDEN_HALLU ) );
}

bool is_preferred_crafting_component( const item &component )
{
return is_preferred_component( component ) && is_crafting_component( component );
}
10 changes: 6 additions & 4 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -3229,12 +3229,14 @@ inline bool is_crafting_component( const item &component )
!component.is_filthy();
}

/**
* Filter for crafting components first pass searches excluding undesirable properties.
*/
bool is_preferred_component( const item &component );

/**
* Filter for empty crafting components first pass searches
*/
inline bool is_empty_crafting_component( const item &component )
{
return component.is_container_empty() && is_crafting_component( component );
}
bool is_preferred_crafting_component( const item &component );

#endif // CATA_SRC_ITEM_H
Loading