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

Feed NPCs using their stomachs when they eat from faction camps #47720

Merged
merged 1 commit into from
Mar 5, 2021

Conversation

RadHazard
Copy link
Contributor

Summary

Bugfixes "NPCs now eat from faction camps using their stomachs, eliminating phantom hunger pangs"

Purpose of change

Fixes #47663
Prior to this, NPCs simply teleported calories directly into their fat stores, which bypassed the entire stomach system. This was causing various oddities in behavior when they ate from faction camps compared to eating regular food.

Describe the solution

I simply created a fake food_summary item, filled it with the calories they would have otherwise teleported, and stuffed it into their bellies. The volume of the fake food is enough to fill them up without making them vomit, which is good enough for now but can certainly be improved if faction camps do more detailed food tracking in the future.

There were a few other minor changes as well:

  • NPCs only eat from camp stores when hungry, to stop them from vacuuming up all your food if they're underweight
  • NPCs eat a maximum of 2500 kcals in a sitting, again to stop the food vacuum
  • NPCs try to eat 100 more kcals than their kcal limit, to avoid them eating tiny amounts of food every 5 minutes.

Describe alternatives you've considered

I considered giving the fake food a fixed volume or volume dependent on calories, but it was hard to balance in a way to keep NPCs from eating too much and vomiting.

I considered giving the fake food vitamins, but vitamin deficiencies do nothing right now and if that changes in the future faction camps should be updated to track vitamins anyway.

I also considered more detailed tracking of vitamins and/or food volumes in the camp store, but that would be a much bigger sweeping change that would be better suited for after 0.F.

Testing

Scenarios I tested, using the debug tools introduced in #47716

  1. NPC with an empty stomach and 52200 stored calories -> They ate 150 calories which ended up in their stomach, making them full
  2. NPC with a stomach with 150 calories and 52200 stored calories -> They did not attempt to eat anything
  3. NPC with an empty stomach and 52200 stored calories, but only 100 were available -> They ate only 100 calories and emptied the larder
  4. NPC with an empty stomach, 52200 stored calories, and the larder was empty -> They complained about an empty larder
  5. NPC with an empty stomach and only 42250 stored calories -> They ate 2500 camp calories, and didn't attempt to eat any more until they digested enough to feel hungry an hour later

Incidentally, these would make good unit tests but I'm entirely unsure how to create a working faction camp in a unit test, so I wasn't able to implement them :(

Additional context

While messing around with this code, I observed that the hunger variable is now completely controlled by update_stomach(). Thus, any calls to set_hunger() or mod_hunger() outside of that method do absolutely nothing long term and almost certainly need to be changed.

See #47391 for examples of other places that still use mod_hunger()

@Maleclypse
Copy link
Member

Is there a maximum number of calories they'll eat in a day? Won't their stomach empty out of 2500 kcals in thirty minutes or so?

@RadHazard
Copy link
Contributor Author

RadHazard commented Feb 24, 2021

Is there a maximum number of calories they'll eat in a day? Won't their stomach empty out of 2500 kcals in thirty minutes or so?

No, but I don't think that's necessarily a problem. If instead of eating from the camp store they had a giant pile of smoked meat, they'd eat about as much in a day anyway if they were really that low on stored calories. Mostly the limit is there to stop absurd outcomes like them vacuuming up 20k calories in one sitting.

To be clear, NPCs will only eat up until they have 52250 stored calories (95% of the healthy calories value) and will stop even if they get hungry again. That limit was in the previous implementation and I carried it over into this one

@ZhilkinSerg ZhilkinSerg added <Bugfix> This is a fix for a bug (or closes open issue) NPC / Factions NPCs, AI, Speech, Factions, Ownership Player Faction Base / Camp All about the player faction base/camp/site labels Feb 24, 2021
@kevingranade kevingranade merged commit c0f9193 into CleverRaven:master Mar 5, 2021
Malorn-Deslor pushed a commit to Malorn-Deslor/Cataclysm-DDA that referenced this pull request Mar 5, 2021
Malorn-Deslor pushed a commit to Malorn-Deslor/Cataclysm-DDA that referenced this pull request Mar 5, 2021
krazyfencer pushed a commit to krazyfencer/Cataclysm-DDA that referenced this pull request Mar 6, 2021
@linonetwo
Copy link
Contributor

linonetwo commented Jun 22, 2021

This seems gets regression in https://github.com/CleverRaven/Cataclysm-DDA/releases/tag/cdda-experimental-2021-06-22-0605 Maybe this should have a test.

NPC in the camp still getting hungry.

@linonetwo
Copy link
Contributor

@RadHazard could you take a look at this? Camp fooding is not workong anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) NPC / Factions NPCs, AI, Speech, Factions, Ownership Player Faction Base / Camp All about the player faction base/camp/site
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPCs remain permanantly hungry when eating out of faction camp stores
5 participants