CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.65k stars 4.18k forks source link

NPCs remain permanantly hungry when eating out of faction camp stores #47663

Closed RadHazard closed 3 years ago

RadHazard commented 3 years ago

Describe the bug

NPCs remain perpetually hungry when being fed through faction camp stores. Their stored calories are correctly being updated so they don't actually starve, but their hunger meter remains maxed out, which causes them to complain of hunger and refuse to train you.

Steps To Reproduce

  1. Recruit an NPC
  2. Build a faction camp
  3. Stock the camp larder with at least 50 kcal of food
  4. Edit the NPC's needs so that they have 300 hunger and have 52200 stored kcal (50 kcal below the number at which they start eating from the camp larder)
  5. Wait a few moments and check the NPC needs screen. Observe that NPC's hunger remains 300 calories, though their stored kcal is back up to 52250

Expected behavior

Feeding NPCs through faction camps fills their stomachs properly so they don't complain of hunger or refuse to train you

Versions and configuration

Additional context

Second half of #47596

The relevant code: https://github.com/CleverRaven/Cataclysm-DDA/blob/0731d8517713c9357b25ac7c6f55eb137432f04e/src/npcmove.cpp#L3818-L3826

While testing this again on the latest version, I've noticed something interesting -- sometimes the hunger does seem to get updated and sometimes it does not. It seems like larger calorie deficits more reliably cause their hunger to go down, while a deficit of only 50 kcal usually causes hunger to remain at maximum. I'm not sure why.

RadHazard commented 3 years ago

Hmm... looking through the character code more, I'm starting to think the issue is with the stomach simulation. mod_hunger() doesn't seem to update the stomach contents at all, and whenever the stomach updates it completely clobbers the current hunger value.

Testing seems to confirm my findings. If you update the NPC's hunger rating in the needs menu then wait 5 minutes, it goes back to what it was before.

Jamuro-g commented 3 years ago

are you using the npc no needs mod by any chance?

asking because mod_hunger() & mod_stored_kcal() should indeed not update with it enabled.

actual-nh commented 3 years ago

Hmm... looking through the character code more, I'm starting to think the issue is with the stomach simulation. mod_hunger() doesn't seem to update the stomach contents at all, and whenever the stomach updates it completely clobbers the current hunger value.

I think the problem is that the code is directly putting calories in their stored kcal, not into their stomachs.

RadHazard commented 3 years ago

are you using the npc no needs mod by any chance?

asking because mod_hunger() & mod_stored_kcal() should indeed not update with it enabled.

I am not using that mod, no

I think the problem is that the code is directly putting calories in their stored kcal, not into their stomachs.

Yeah, that's again what I meant but didn't say clearly :/ The fix should be to just send the calories into their stomach instead, but a quick glance at the stomach shows that it's a fair bit more complicated than just stomach.add_calories() or something of the like.

I think it would be fairly straightforward to just make a fake food_summary object to feed to the stomach, but I'm not sure if it would be preferable to do that or to try and keep more detailed track of the kinds of foods stuffed into the faction camp. Notably, at the moment I don't think NPCs are getting any vitamins from faction camp food, so a more detailed simulation may be warranted before vitamin deficiencies get changed to actually do something