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

Fix overly-restrictive logic in check for ability to crush frozen liquids #63019

Merged
merged 3 commits into from
Jan 9, 2023
Merged
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
31 changes: 18 additions & 13 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9056,24 +9056,29 @@ ret_val<crush_tool_type> Character::can_crush_frozen_liquid( item_location loc )
if( has_quality( qual_DRILL ) ) {
enough_quality = true;
} else if( has_quality( qual_HAMMER ) && has_quality( qual_SCREW ) ) {
std::list<item_location> screw_tools;
std::vector<item_location> hammer_tools;
int num_hammer_tools = 0;
int num_screw_tools = 0;
int num_both_tools = 0;
for( item_location &tool : const_cast<Character *>( this )->all_items_loc() ) {
if( tool->has_quality( qual_HAMMER ) ) {
hammer_tools.emplace_back( tool );
bool can_hammer = false;
bool can_screw = false;
if( tool->has_quality_nonrecursive( qual_HAMMER ) ) {
can_hammer = true;
num_hammer_tools++;
}
if( tool->has_quality( qual_SCREW ) ) {
screw_tools.emplace_back( tool );
if( tool->has_quality_nonrecursive( qual_SCREW ) ) {
can_screw = true;
num_screw_tools++;
}
}
if( !screw_tools.empty() && !hammer_tools.empty() ) {
for( item_location &hammer : hammer_tools ) {
screw_tools.remove( hammer );
}
if( !screw_tools.empty() ) {
enough_quality = true;
if( can_hammer && can_screw ) {
num_both_tools++;
}
}
if( num_hammer_tools > 0 && num_screw_tools > 0 &&
// Only one tool that fulfils both requirements: can't hammer itself
!( num_hammer_tools == 1 && num_screw_tools == 1 && num_both_tools == 1 ) ) {
enough_quality = true;
}
}
success = enough_quality;
}
Expand Down
22 changes: 21 additions & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7374,7 +7374,12 @@ int64_t item::get_property_int64_t( const std::string &prop, int64_t def ) const
return def;
}

int item::get_quality( const quality_id &id, const bool strict_boiling ) const
bool item::has_quality_nonrecursive( const quality_id &qual, int level ) const
{
return get_quality_nonrecursive( qual ) >= level;
}

int item::get_quality_nonrecursive( const quality_id &id, const bool strict_boiling ) const
{
/**
* EXCEPTION: Items with quality BOIL only count as such if they are empty.
Expand Down Expand Up @@ -7403,6 +7408,21 @@ int item::get_quality( const quality_id &id, const bool strict_boiling ) const
}
}

return return_quality;
}

int item::get_quality( const quality_id &id, const bool strict_boiling ) const
{
/**
* EXCEPTION: Items with quality BOIL only count as such if they are empty.
*/
if( strict_boiling && id == qual_BOIL && !contents.empty_container() ) {
return INT_MIN;
}

// First check the item itself
int return_quality = get_quality_nonrecursive( id, false );

// If any contained item has a better quality, use that instead
return_quality = std::max( return_quality, contents.best_quality( id ) );

Expand Down
15 changes: 15 additions & 0 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,24 @@ class item : public visitable
void add_rain_to_container( bool acid, int charges = 1 );
/*@}*/

/**
* Returns true if this item itself is of at least quality level
* This version is non-recursive and does not check the item contents.
*/
bool has_quality_nonrecursive( const quality_id &qual, int level = 1 ) const;

/**
* Return the level of a given quality the tool may have, or INT_MIN if it
* does not have that quality, or lacks enough charges to have that quality.
* This version is non-recursive and does not check the item contents.
* @param strict_boiling True if containers must be empty to have BOIL quality
*/
int get_quality_nonrecursive( const quality_id &id, bool strict_boiling = true ) const;

/**
* Return the level of a given quality the tool may have, or INT_MIN if it
* does not have that quality, or lacks enough charges to have that quality.
* This version is recursive and will check the item contents as well.
* @param strict_boiling True if containers must be empty to have BOIL quality
*/
int get_quality( const quality_id &id, bool strict_boiling = true ) const;
Expand Down