Fix overly-restrictive logic in check for ability to crush frozen liquids #63019
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Bugfixes "Fix overly-restrictive logic in check for ability to crush frozen liquids"
Purpose of change
Partially addresses #62952, specifically the part that is caused by flawed logic when checking whether the player has the tools required to crush frozen liquids.
The preexisting check was:
screw_tools
hammer_tools
hammer_tools
screw_tools
The intent behind this check is presumably to deal with the corner case where the player only has one tool that satisfies both hammer and screwdriver qualities -- that does not satisfy requirements because that one item cannot be used to hammer itself.
However, the logic is flawed and rejects some valid cases -- a tool that has both hammer and screwdriver qualities cannot be used to fulfill the screwdriver requirement (to be used in conjunction with another item that will serve as the hammer).
Describe the solution
Rewrite the logic. This required a bit of additional machinery in
item
class to get/check the qualities of an item itself excluding its contents, whereas preexisting code does these checks recursively, including any contents of the itemDescribe alternatives you've considered
a)
Not adding the new quality checking functions and just use preexisting
item::has_quality()
, i.e. code as at af50aa3This would have a different bug; an edge case due to the recursive nature of
item::has_quality()
. When the player only has one tool with both qualities they should fail the check. But if that item is in a container in inventory (e.g. a backpack) rather than wielded, then the container also reports having the required qualities. The container then counts as a second item in addition to the tool itself, and this situation would pass the test erroneously.b)
Instead if implementing
Item::get_quality_nonrecursive
, changeItem::get_quality
so that it has an additional boolean flag parameterrecursive
which defaults to true. (And likewise forhas_quality
). This could have caused complications because there is already another optional boolean paramstrict_boiling
. Opted for a separate function to minimize potential for mistakes.Testing
g
grab ice and note message indicating lack of tools for crushingsmall_repairkit
and make sure to wield it