CleverRaven / Cataclysm-DDA

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

NPCs not healing, always needing to sleep. #32493

Closed ProfoundDarkness closed 5 years ago

ProfoundDarkness commented 5 years ago

Describe the bug

NPCs are not healing. In general it seems like most NPC processes that happen over time are not working properly.

Steps To Reproduce

Steps to reproduce the behavior (from a new world/character shelter start):

  1. Get the nearby NPC to join you (may involve editing some stats).
  2. Modify (via debug) both your needs and NPC needs, set fatigue to be say 200 on both.
  3. Modify (via debug) the NPC's health on a body part to some value (I chose 8).
  4. Tell the NPC (via overrides) that it's OK to sleep.
  5. Go to sleep.
  6. Via debug, inspect NPC health.

Steps to reproduce the behavior (from included save file):

  1. Load save file.
  2. Go to sleep (may take a couple of tries due to itchy).
  3. After a full or mostly full rest, inspect the NPC's health via debug, specifically the health of the leg which I had previously set to 8.

Harney.zip

Expected behavior

NPCs heal at least a little bit over time. Somewhat more aside atm, they don't always need sleep.

Screenshots

The screenshots are from my main game to illustrate the problem though now disconnected from steps to reproduce/included save file.

Before going to sleep with NPC allowed to sleep, 12:46:38AM start sleep 12-46-38a

After waking up, NPC still asleep, 10:05:14AM end sleep 10-05-14a

Traits of NPC since some can cause healing problems, no bionics. NPC @ traits

Versions and configuration

Additional context

As in the reddit post mentioned in #32474 it seems my NPC stopped healing about the time the NPC optimizations were recently done (#32212 and #32342). I don't know if those PRs are the culprit however, just finding agreement with some on reddit that is about when my NPC stopped healing.

Reddit and other places I keep seeing basically a bunch of people talking about how needs are bugged with others responding that those complaining must be using the no needs mod. However once you get through such noise you see that NPCs seem to not be ticking through stuff over time properly.

I'll (probably) try and narrow it down to a particular commit since it's possible it's not the optimization passes. Also I don't expect that collection of mods is necessary.

(edit1) -Modified the steps to reproduce. -Include a handy save file that is (mostly) ready to go. -Also reduced the mod load to basics. -Shifted the focus of the issue towards NPCs not healing. There seems to be something going wrong with the fatigue value on NPCs but it's not completely frozen like health seems to be. Since it might not be related, better to narrow focus than try to keep everything.

(edit2) -Backed up to commit #32342 (d0e5f3d7d5049fa604baa27b807d5b1fff7fc784) and NPC didn't heal. Backed up just one more commit, NPC did heal. That seems to be the problem commit. Also after going one commit back from was the first time I saw an NPC wake up and stay up in testing. -I did try testing other commits after this one, not all of them of course but basically anything I noticed claiming to mess with NPCs, tried testing on that commit then backed up 1 commit and tested again.

ProfoundDarkness commented 5 years ago

OK. I think I found the commit where NPCs stopped healing.

(edit1) When I try reverting the following line back to just update_body() the NPC heals. So the branch through the npc_update_body() seems to be the failure point however that doesn't make sense on (VERY) cursory examination of the logic. Gonna play some more I guess while I'm feeling OK.

https://github.com/CleverRaven/Cataclysm-DDA/blob/6790e59e6437933b4ae4a2209835250e9378aead/src/game.cpp#L4306

(edit2) OK, playing in my favorite place, a debugger (which for some reason the Visual Studio debug compile runs SUPER SLOW, 10+min to load a small save) the linchpin seems to be the last_updated variable which is being updated every second/turn so the code after the if statement is never being executed. The following is the code snippet where the problem lies. To put it another way, the optimization for NPC body processing to happen every 10 seconds will NEVER happen because something else is modifying last_updated every turn.

https://github.com/CleverRaven/Cataclysm-DDA/blob/6790e59e6437933b4ae4a2209835250e9378aead/src/npc.cpp#L2157-L2165

(edit3) ah, I think I see the root issue, currently playing with a potential fix PR (that doesn't just roll back the optimization).