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

NPCs suicidally try to heal you #57254

Open
worm-girl opened this issue Apr 29, 2022 · 12 comments
Open

NPCs suicidally try to heal you #57254

worm-girl opened this issue Apr 29, 2022 · 12 comments
Labels
NPC / Factions NPCs, AI, Speech, Factions, Ownership (P2 - High) High priority (for ex. important bugfixes) (S2 - Confirmed) Bug that's been confirmed to exist

Comments

@worm-girl
Copy link
Contributor

worm-girl commented Apr 29, 2022

Describe the bug

If you have a friendly NPC, even if they're guarding, can't see you, and there's a dangerous situation going on, any time you get hurt, they'll run over and try to bandage you. This is not only annoying, it doesn't make a ton of sense. Someone on the other side of a cave shouldn't know my leg is bleeding if I didn't say anything.

A temporary fix for anyone running into this issue is to have NPCs not carry medicine, but that's often a bad idea and doesn't make sense in roleplay.

Steps to reproduce

Give bandages to a friendly NPC
Get hurt
They will come try to heal you

Expected behavior

NPCs should have a toggleable option in dialog for whether to heal allies or not, and they also should have a check for if they can actually see their ally before they run over and try to heal. They should also never do this in combat, though it's possible there's a check there already and I'm just seeing corner cases. Lastly, they should never attempt to heal others if they've been instructed to guard.

Screenshots

No response

Versions and configuration

  • OS: Windows
    • OS Version: 10.0.19043.1645 (21H1)
  • Game Version: 3e81ac1 [64-bit]
  • Graphics Version: Tiles
  • Game Language: System language []
  • Mods loaded: [
    Dark Days Ahead [dda],
    Disable NPC Needs [no_npc_food],
    No Fungal Growth [no_fungal_growth],
    Bionic Professions [package_bionic_professions]
    ]

Additional context

No response

@github-actions github-actions bot added the (S1 - Need confirmation) Report waiting on confirmation of reproducibility label Apr 29, 2022
@Maleclypse Maleclypse added NPC / Factions NPCs, AI, Speech, Factions, Ownership (S2 - Confirmed) Bug that's been confirmed to exist and removed (S1 - Need confirmation) Report waiting on confirmation of reproducibility labels Jun 1, 2022
@I-am-Erk
Copy link
Member

I-am-Erk commented Nov 23, 2022

I don't agree with all of this.

NPCs should have a toggleable option in dialog for whether to heal allies or not

Agreed

they also should have a check for if they can actually see their ally before they run over and try to heal.

Agreed.

They should also never do this in combat, though it's possible there's a check there already and I'm just seeing corner cases.

Cautious agree. There are some niche cases where we may want it to happen but generally, NPC should not offer healing if there is an enemy in LOS.

Lastly, they should never attempt to heal others if they've been instructed to guard.

Disagree. If you have two NPCs on guard duty and one is heavily injured, I definitely want the other guard to go help them. It seems like pretty stupid behaviour to have one guard stand around and watch their allies bleed out. Eventually we would want some better prioritization but I don't think there's ever a case where this behaviour should be disallowed.


In terms of managing this bug for stable, we only need the third option: We need to ensure NPCs will not offer healing if there is an enemy in LOS. Additionally, characters should not accept healing if there is an enemy in their LOS. From an algorithm standpoint:

  • NPC1 wants to offer healing to NPC2.
  • Save NPC1 current location as a variable, "origin point"
  • check if NPC1 can see any enemies.
    • If no, move NPC1 adjacent to NPC2.
    • Check again if NPC1 can see enemies.
      • If no, check if NPC2 can see enemies.
      • If no, commence healing.
      • If yes, (open to options here) move back to the origin point.
      • Delete origin point data if an enemy is spotted at any point.
  • If at any point the NPC can see enemies, proceed with usual combat AI and delete origin point data

Later on this can become more nuanced but I think it works for now.

@I-am-Erk I-am-Erk added the (P2 - High) High priority (for ex. important bugfixes) label Nov 23, 2022
@I-am-Erk I-am-Erk mentioned this issue Nov 24, 2022
12 tasks
@worm-girl
Copy link
Contributor Author

In a perfect world, NPCs wouldn't watch each other bleed out, but guard mode is currently a pretty important band-aid. The fact that it mostly turns off NPC AI is extremely important to their survivability as they are not currently capable of making intelligent decisions about when they should behave in certain ways.

@I-am-Erk
Copy link
Member

Perhaps, but I don't think that's an argument in favour of keeping basic AI functions on them. It's an argument in favour of tuning their AI further. Can you name a situation where the stated algorithm would be bad behaviour from an NPC on guard mode?

@worm-girl
Copy link
Contributor Author

They're in a vehicle which is parked but needs to be ready for the player to hop in and drive the group to safety where they can then tend the wounded NPC without everyone getting eaten.

For their safety, the player has ordered them to stand in places where they cannot see a turret which will shoot them if they step out of cover.

The player is attempting to create a distraction in order to clear an escape route, which requires that everyone remain silent until the nearby zombies have gone off to investigate the talking doll or whatever.

The NPC has zero medical skill and is holding valuable medical supplies. The skilled player is trying to move in to administer treatment but is slightly slower or farther away.

The player has decided to leave a critically wounded NPC behind while fleeing an unwinnable situation and wants the other NPC to follow them or stay in the vehicle so they can escape instead of stopping to render aid.

Some of these could be more interesting than they are (particularly the last one) but the code does not currently exist to handle those kinds of complex interactions, and having guard mode keep NPCs from making their own decisions as much as possible will cut down on cases where the AI causes companions to make suicidal decisions with no hope of player intervention.

@I-am-Erk
Copy link
Member

I-am-Erk commented Nov 24, 2022

Actually, looking at the healing code in npcmove.cpp it may be possible to fix this for stable really, really easily.

Starting here:

if( one_in( 3 ) ) {

I'm not sure if there's code in other places governing this, but if my read is correct we can probably solve this specific issue for stable with the following change:

    if( one_in( 3 ) && ( danger <= NPC_DANGER_VERY_LOW ) ) {

As far as I'm seeing we're currently offering healing as a 1 in 3 chance, without any further situational assessment. This should just add the situational assessment.

@worm-girl
Copy link
Contributor Author

Our replies were almost simultaneous, lol. Hopefully that doesn't cause mine to get lost.

@I-am-Erk
Copy link
Member

I see yours. Those are valid concerns but I don't think there is sufficient reason to put in special casing for guard mode for stable, presuming my single line fix suggestion works. Rather I think that's good call to discuss adding a specific command that gets an NPC to hold position firmly, and/or looking at the root of the problem of NPCs walking out of vehicles or into danger. Both of those are relevant things that need fixing and shouldn't be all that hard to do, and leaning more on micromanagement through guard mode will mask the need.

@RenechCDDA
Copy link
Member

I was trying to reproduce this for the purposes of playtesting the linked PR, but I am unable to get NPCs to suicidally heal in combat. If they are out of line of sight when the injury occurs (added bleed effect via debug) then they still either flee or engage when coming into sight - they do not continue trying to heal. Can you provide some more info on when you encountered this? Maybe a save?

@worm-girl
Copy link
Contributor Author

worm-girl commented Nov 24, 2022

I posted this issue ages ago so I don't have a save. One notable situation had me wandering around in the depths of a trap-riddled cave and my npc guarding near the exit (same z level) who could not see me ran over to heal me. I had not disarmed or spotted all traps in the area so this was not desirable.

Another time, I was inside a house trying to fight a juggernaut while leaving my vulnerable NPC outside so they wouldn't engage. The juggernaut hurt me and the NPC ran inside to try to help, freaked out when they saw the juggernaut, and fled halfway across the town into a mob of zombies. If they'd been staying put it wouldn't have been an issue. In neither case could the NPC see me when I was injured, they were simply nearby.

A guarding NPC will stay put and watch you fight at a safe distance until you start bleeding, then they'll run over into range of a fight you'd prefer they didn't join. I-am-Erk's fix patches that behavior, so that's good enough for a merge. It may not solve the first two cases, but that would be a separate issue (npcs "seeing" you get wounded from out of LoS)

@RenechCDDA
Copy link
Member

After many tries I got one sort of reproduction of the "suicidal heal" behavior without Erk's patch, so reproduction on this was inconsistent to say the least. (A NPC continually chased me in circles as I ran away from a hulk). I threw a simple debugmsg into npc::address_needs debugmsg("Danger is %s", danger); and checked what it reported. It was 0 all the way up until the NPC encountered the hulk - then it stopped returning at all. Why? Because, it would seem, npc::address_needs is only normally called as part of npc::move and they... simply don't do that when it's time for combat. My best guess is that it's related to the cache passing in npc::address_needs, and if so it would also explain the inconsistent reproduction.

The only other place address_needs is called is npc::avoid_friendly_fire. After a rather convoluted test setup (image below) I was able to get them to temporarily ignore the enemies and try to heal me, but only while I was directly blocking the one-tile-wide hallway and even then only sometimes.

image

@worm-girl
Copy link
Contributor Author

IIRC, bleeding was recently moved to a limb-based effect rather than a hardcoded state, so it's possible NPCs are seeing it in fewer places now, causing the issue less frequently than was the case when this issue was opened.

@I-am-Erk
Copy link
Member

I think there are some issues here needing addressing, with NPCs not calling needs, but it appears it can be deferred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NPC / Factions NPCs, AI, Speech, Factions, Ownership (P2 - High) High priority (for ex. important bugfixes) (S2 - Confirmed) Bug that's been confirmed to exist
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants