-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Refactor how nutrients are stored and processed #35889
Conversation
Regarding this:
I actually had the exact same line of reasoning when I did the stomach refactor (#35143) but I discovered I was wrong -- tapeworm does effect calories AFAICT, so make sure this refactor doesn't make tapeworms twice as effective as intended. Other than that, I think this change is awesome. Adding arithmetic functions to |
I'm fairly sure |
Thanks for the review BevapDin. I was only moving that code from one place to another, but indeed there was a lot worth improving in it. |
1837243
to
719b267
Compare
I think I've now resolved all the above comments. |
Well, your test as written wouldn't have properly discovered whether my concern was valid or not, since effects are processed over time, and you don't pass any time at all in the test. That said, I have read through the code and determined that unless there's something really weird going on, you are right -- |
Yes, I realise it was a bit of a weak test. Thanks for taking the time to check and reassure us both. |
- Ensure the test doesn't run forever. - Make the test actually do something. - Update expected_day to match current behaviour.
Add a new nutrients struct, which consists of some calorie and vitamin info. Use this struct in food item definitions (specifically, islot_comestible) and in stomach. Turned out stomach already contained a nutrients struct, which contained the above together with water and total volume. That is renamed food_summary, and uses nutrients internally. The main advantage of this separate struct is that it simplifies the arithmetic used to compute aggregate food nutrient values based on components used to craft that food. That code was also refactored and split up to make it easier to understand and helps separate out the things which will need to be separate to work on CleverRaven#28180. The only intended observable behaviour change from this commit is that tapeworms now consume half of the calories you ingest, as well as half the vitamins (they used to only affect vitamins).
This function was unnecessarily messy for no particularly good reason.
719b267
to
36a0a33
Compare
Summary
SUMMARY: Infrastructure "Refactor how nutrients are stored and processed"
Purpose of change
While working towards a fix for #28180, I found the code working with nutrients to be difficult to follow and with different aspects mixed in the same function. This is an attempt to separate concerns to make it easier to work on #28180.
Describe the solution
nutrients
renamedfood_summary
and a newnutrients
struct introduced for a subset of its members.nutrients
struct inislot_comestible
.nutrients
to make it easy to perform nutrient-related calculations.Most of this is intended to have no observable change to game behaviour, with one exception: previously the tapeworm parasite halved all vitamins a
Character
consumed. Now it halves both the vitamins and the calories.While testing, I discovered that the
stave_test
was buggy -- it didn't actually test anything, and it had the potential to get stuck in an infinite loop. I fixed it, but in so doing found that it was already failing on master. Players are starving faster than the test indicates they ought to (30 days vs 46). This may be a problem, but it's orthogonal to this PR. @KorGgenT might want to look into that.Describe alternatives you've considered
Could have included water content in the
nutrients
struct, but currently water is not calculated based on components so it didn't really fit with the code structure.Testing
Unit tests only.