From becd3d4e0310a70abc145f4c9b1b5926abcc812d Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Wed, 10 Jan 2024 15:23:29 +0100 Subject: [PATCH] Update first pass component selection to avoid poison --- src/activity_item_handling.cpp | 2 +- src/basecamp.cpp | 2 +- src/construction.cpp | 2 +- src/craft_command.cpp | 6 +++--- src/item.cpp | 12 ++++++++++++ src/item.h | 10 ++++++---- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/activity_item_handling.cpp b/src/activity_item_handling.cpp index ad9047958e900..b465bf2277b46 100644 --- a/src/activity_item_handling.cpp +++ b/src/activity_item_handling.cpp @@ -1777,7 +1777,7 @@ static bool construction_activity( Character &you, const zone_data * /*zone*/, comp_selection sel; sel.use_from = usage_from::both; sel.comp = comp; - std::list empty_consumed = you.consume_items( sel, 1, is_empty_crafting_component ); + std::list empty_consumed = you.consume_items( sel, 1, is_preferred_crafting_component ); int left_to_consume = 0; diff --git a/src/basecamp.cpp b/src/basecamp.cpp index 06b980685c0a0..eae0245be6c5a 100644 --- a/src/basecamp.cpp +++ b/src/basecamp.cpp @@ -913,7 +913,7 @@ void basecamp_action_components::consume_components() } for( const comp_selection &sel : item_selections_ ) { std::list 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() ) { diff --git a/src/construction.cpp b/src/construction.cpp index eab24a652125d..7c2e908489ee0 100644 --- a/src/construction.cpp +++ b/src/construction.cpp @@ -1030,7 +1030,7 @@ void place_construction( std::vector const &groups ) sel.use_from = usage_from::both; sel.comp = comp; std::list empty_consumed = player_character.consume_items( sel, 1, - is_empty_crafting_component ); + is_preferred_crafting_component ); int left_to_consume = 0; diff --git a/src/craft_command.cpp b/src/craft_command.cpp index 57edee02242df..d2ce13d5ec904 100644 --- a/src/craft_command.cpp +++ b/src/craft_command.cpp @@ -342,8 +342,8 @@ bool craft_command::continue_prompt_liquids( const std::function sane_consume_items( const comp_selection &it, Character *crafter, int batch, const std::function &filter ) { - std::function empty_container_filter = [&filter]( const item & it ) { - return it.is_container_empty() && filter( it ); + std::function preferred_component_filter = [&filter]( const item & it ) { + return is_preferred_component( it ) && filter( it ); }; map &m = get_map(); const std::vector it_pkt = it.comp.type->pockets; @@ -351,7 +351,7 @@ static std::list sane_consume_items( const comp_selection &it, !std::any_of( it_pkt.begin(), it_pkt.end(), []( const pocket_data & p ) { return p.type == pocket_type::CONTAINER && p.watertight; } ) ) { - std::list empty_consumed = crafter->consume_items( it, batch, empty_container_filter ); + std::list 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() ) { diff --git a/src/item.cpp b/src/item.cpp index 683b5f5740379..79706c381e6e0 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -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 ); +} diff --git a/src/item.h b/src/item.h index b85ee47fd1dbf..60dbb69ed78a9 100644 --- a/src/item.h +++ b/src/item.h @@ -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