CleverRaven / CleverRaven/Cataclysm-DDA

"Downed" status for NPCs, to help prevent frustrating deaths and preserve questlines

Open
#62,349 7 comments 7 reactions 0 assignees View on GitHub
(P3 - Medium) [C++] <Enhancement / Feature> <Suggestion / Discussion> Missions NPC / Factions Quality of Life
Dominant language
C++
Stars
13.1k
Forks
4.6k
Avg merge
2d 1h
Merged PRs (30d)
205

Description

### Is your feature request related to a problem? Please describe.

We have an ongoing problem with story/quest giver NPCs dying to random zombie attack and preventing quest completion, especially in faction bases. Further, we have problems with faction bases getting utterly messed up by monster invasions. There are several ways we could deal with this, some of which may be better suited to a "story mode" option for the game. If we develop a solid system for dealing with quest NPC death we may be also able to consider making faction bases into global unique spawns, which would be good for immersion and prevent some exploitation.

Additionally, the solution proposed here also helps to reduce some unnecessary silly player deaths if implemented fully.

### Solution you would like.

This solution was proposed by @esotericist and I have written up her ideas and added some of my own.

There are numerous possible solutions to this plan, some of which are required for vanilla AI anyway, and some of which would be more of a 'story mode' option for the game to make it ever harder to accidentally lose quest lines.

An early option that shouldn't require a massive overhaul (I hope) is a "downed" status for NPCs. While complex, this system does a lot more than just help fix quest NPCs: it also becomes the start of a more interesting healthcare rescue system for critical injuries.

Addendum 15 july 2025: This is still all appropriate and desirable as listed.
- A "quick add" version of Downed to test this idea might be one that we only apply to player faction NPCs, primarily for use in #81834 but also perhaps for Friends to the End. This would generally not be something we'd use otherwise, until the bugs were sorted.
- In this 'simple' Downed version, we apply the Downed state to an NPC whose torso or head HP reaches 1 or less, and lock the HP at 1. They become invisible to monsters and unconscious.
- You can still do first aid on a downed person. They still take damage to their other limbs.
This is a very prototypic version of what is below, and would make it easier to continue developing the other stuff.

### Downed status
- When an NPC would die, check for nearby friendly faction NPCs. If there are any friendly faction NPCs within the reality bubble who are both alive and not themselves downed, then check if we should apply the `downed` status to this NPC. (Note, we may want "die" in this case to mean "vital body part goes to 1hp" rather than 0hp. Then we'd leave that body part at 1hp while the character is downed, but (as noted below) further damage would trigger the usual 'your torso breaks' effects and kill the npc.)
- Some NPC factions should always apply the 'downed' status - primarily NPC factions that are story-important.
- For the rest of NPCs, we should have a random 20% chance to apply Downed. Later, we can add things that adjust this such as amount of damage inflicted in the attack, but for now a flat random chance is enough.
- Downed NPCs cannot speak, see, hear, move, attack, heal damage, etc - with the exception of bleeding wounds, see below
- They can still be the targets of attacks but should be ignored by NPCs and monsters. Any further damage will kill them. (Ideally, monsters might target downed NPCs if they can't see any other target to go for).
- Stray bullets should pass over them if we can code that.
- If they have bleeding injuries they should continue to bleed and stop at the usual duration. When downed they cannot put pressure on their wounds. They can die of blood loss as usual.
- When downed, we apply a new heavily bleeding injury to whatever body part went to 0 hp. This injury should decrease bleeding over time, but it should be fairly slow, so generally it will nearly kill the NPC after a while on its own, and if the NPC had any other injuries (pretty likely since they were dropped) they're likely to die of blood loss.
- They can be the targets of healthcare actions to stop bleeding. This way you can stabilize a downed NPC, represented by bandaging their bleeding wounds.
- I would imagine it is unlikely we can make it possible to walk over top of a downed NPC, so to prevent blockage we may want to make it so that a monster or character stepping into the same tile as a downed NPC switches places with them, so that a downed NPC doesn't become an immovable obstacle. Alternatively, if we can make it so they can be stepped through, even better. (Esotericist suggests that since we can store creatures in items, maybe we can store the downed NPC in a "downed body" item)
- Downed NPCs ideally should not use equipment overlays and should show a different sprite eg. "NPC_downed", so that we can show a generic person lying on the ground to represent them properly. If we store them in a special "downed body" item this is easy to do.
- When there are no hostiles within the reality bubble and their bleeding is stopped, downed NPCs revive with 1hp on whatever body part was dropped to 0. Perform a check every 10 minutes or so.
- When a faction NPC dies and no non-downed allies are in the bubble, it dies for good, and all other downed NPCs die as well and are replaced with corpses.

#### Indestructible downed NPCs
- An external option "indestructible_downed_NPCs" should allow downed NPCs to be indestructible and not targetable. This should have settings "Never", "By_Faction", and "Always".
- When set to "always", then downed NPCs cannot take damage or be targeted by any means, they are completely invulnerable to damage. Even if all members of the faction are downed, they do not auto-die and will get back up when their bleeding timers run out.
- The blood loss portion should still happen, and they should continue to bleed through any bleeding wounds, but once blood volume hits 0 it stops going down; they don't die. When they revive, just as we give them a little hp to their broken limbs, we can also set them to have just enough blood volume to stay alive.
- "By_Faction" could also be thought of as "story mode". Specific NPC factions are invulnerable when downed, defined in the NPC faction JSON. This would be limited to NPC factions that contain major story quests, so for example bandits and player factions would not be invulnerable when downed, but free merchants and hub NPCs would.
- The default behaviour should be "never" but this allows people to make major quest NPCs invulnerable so that their stories don't get broken. "never" being default allows us to playtest more situations where you accidentally kill downed NPCs, and fix that in the future.

### Effect of change
- This allows groups of friendly NPCs to help each other, but we don't have to model all kinds of rescuing and things
- For non-player-faction NPCs, this lets them die only if you wipe out the faction. That pretty much effectively removes faction attrition and makes it so that even if the refugees all die, the faction will survive and revive them after a while. It's much, much harder to break quests now.

### What this doesn't fix
- NPCs still need a way to return to their starting position, but if we go with the position switching thing, at least this way you can nudge a downed NPC back into place I guess.
- At least initially, faction NPCs are still not very likely to help their downed compatriots, so this mostly just makes them easier for you to save through micromanagement.

### Extending to player faction
- It would be reasonable to extend this to the player faction, including the player avatar itself, but probably with some modification. Since player faction NPCs and character are less abstracted in terms of first aid and medical care, and aren't necessary quest givers, we need a bit more simulation.
- This should be something handled with a separate issue, but in short I would suggest that player faction characters take on the "downed" status under the same conditions as non-story NPCs.
- Overall this leads to a system where your player avatar dying could mean that you swap control to a nearby faction NPC and rescue yourself, which is a thing we absolutely want in game, that's so cool. In time, this would add means for other things we have wanted for a long time such as adding AI for NPCs to rescue each other.
- On a first pass, we face a bit of a problem: should we apply downed in a simpler, much more forgiving form, to player faction or not? If we apply a forgiving version, then we have to nerf it, which will lead to gnashing of teeth. If not, it will be a while before it is implemented. My own suggestion is that we be cautious to make the initial default form of "downed" be generally the most punishing version, so that changes adding things like better healthcare feel more like either refinements or buffs.

### Future directions
- Pretty early on, we'll want to make faction NPCs prioritize stabilizing their downed companions as soon as enemies are cleared. We might consider letting "story faction" npcs do this automatically without a healthcare check or using supplies, to represent that they have better access to medical facilities in their bases.
- Eventually we may wish to extend the ability to use Healthcare to rescue and stabilize a downed NPC. Using bandages and bleeding is a decent start but as we get wounds, we can have things like a sucking chest wound that causes a downed NPC to rapidly suffocate unless rescued.
- As healthcare options improve, we could allow non-hostile characters to count as allies for the purposes of downing, so if a free merchant caravan is attacked and the player is nearby, you have a chance to go over and rescue them.
- The chance for an NPC to be downed outside of story factions should be based on the severity of other injuries eg. blood loss, and the amount of damage inflicted. For example, coughing until your torso breaks would down you almost all the time since you're being nickel-and-dimed 1hp at a time. Getting a car smashed against you by a hulk and having your torso destroyed in one hit would almost always kill you outright. In general our standard "an attack from a zombie killed you" should be something like a 50-75% chance to down you instead.
- Chance of being killed could also be influenced by the number of other injuries you have and several stats such as blood volume left and cardiovascular health.

### Describe alternatives you have considered.

This doesn't fix all our problems with NPCs. Alternatives we have discussed include making quest-NPCs invulnerable, or making them vanish when hostiles are around, or making it impossible for monsters to enter special zones. Some of these may still be desirable as options, but mostly for different uses. This would be a better option in terms of both verisimilitude, and extendibility - the downed status becomes, as mentioned, a good jump-off for expanding into critical health care and resuscitation stuff.

### Additional context

Other vital features to fix the problems with monsters wiping out and messing up factions include:
- we need some new AI code to make certain NPCs cowards, running away from conflict instead of engaging. This would also be a good predecessor to getting true fleeing behaviour.
- We need to be able to define a static NPC's "home" location and have it return there after being displaced. This would also be good for NPCs that you have told to guard a location.
- We need to be able to tell certain static NPCs to never leave their "home" location unless certain criteria are met, such as being attacked themselves.

Even within the Downed system, it might be nice to have the ability to flag a particular NPC to always, always get "downed" instead of killed, even when everyone else is dead. Almost certainly not something we'd want in vanilla but it would allow us to do a "story mode" mod that made quest giver NPCs completely reliable.

Contributor guide

Open the contributing guide

Research direction

The issue names no files, tests, or entry points and covers a broad downed-NPC system with several possible implementations. Start by locating the existing NPC death, combat, faction, and healthcare systems, then establish a narrower first milestone and its tests before implementation. Done would require an agreed scope and verified behavior for that milestone.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
game-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.