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 for Carnivores being able to eat low-calorie veggies #75534

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

p4nc4k3z
Copy link
Contributor

@p4nc4k3z p4nc4k3z commented Aug 9, 2024

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.
menu1-pre-fix
menu1-post-fix

Describe the solution

Swapping in the method compute_effective_nutrients() for the method nutrition_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:

  • Magic food: All super-low-calorie-foods would give slightly more nutrition than they should. (Like one bite of an apple, but, still.)
  • Hibernation: Super-low-calorie foods currently skip the hibernation logic entirely, but would instead show messages and contribute (very slightly) to sleepiness.
  • Food poisoning: Eating rotten super-low-calorie food currently gives 6m of food poisoning, and would instead give 6-12m.
  • Acid/fertilizer: Drinking super-low-calorie acid w/ ACIDPROOF/ACIDBLOOD, or drinking super-low-calorie fertilizer w/ THRESH_PLANT could in theory would give additional calories, but a review of the available foods suggests none are applicable anyway.

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!

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Aug 9, 2024
Foods under ~17 calories, including pickles, were skipping the carnivore
check against prohibited foods.  This fix safely closes that edge case.
A comment is also included warning developers of danger from rounding.
@p4nc4k3z p4nc4k3z force-pushed the carnivore-low-cal-fix branch from cd51a36 to 7ec902e Compare August 9, 2024 17:43
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Aug 9, 2024
@Maleclypse Maleclypse merged commit b8dba37 into CleverRaven:master Aug 13, 2024
21 of 26 checks passed
@p4nc4k3z p4nc4k3z deleted the carnivore-low-cal-fix branch August 13, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants