Fix for Carnivores being able to eat low-calorie veggies #75534
Merged
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 for Carnivores being able to eat low-calorie veggies"
Purpose of change
Veggies under ~17 calories, including pickles, accidentally slip past the code block which checks whether or not a carnivore is prohibited from eating foods. This PR fixes that.
Describe the solution
Swapping in the method
compute_effective_nutrients()
for the methodnutrition_for()
when checking if a carnivore's meal has calories or not. The latter currently calls the former anyway, but introduces the problem when dividing the former result as casting to an int in C++ rounds the quotient down to zero when it's too small.A comment is also included in
nutrition_for()
warning developers of this danger.Describe alternatives you've considered
On Discord, we discussed instead simply giving 1 nutrition whenever
nutrition_for()
would start with caloric food but round it down to zero. This would still be a reasonable idea, and could safely be done even after this PR is merged, but I decided against it. This would have the following effects:Testing
Built from source, and compared a carnivore's ability to eat from a menu of foods before and after the change.
Additional context
Thanks to @GuardianDll, @harakka and @snup. for dev help, and to @GuardianDll for tracking down this bug!