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

NPC AI/ fleeing adjustments 2: Come back, little NPC #67870

Merged
merged 14 commits into from
Aug 26, 2023

Conversation

I-am-Erk
Copy link
Member

@I-am-Erk I-am-Erk commented Aug 24, 2023

Summary

Features "Tweak NPC fleeing AI based on playtesting"

Purpose of change

This continues to work on NPC fleeing behaviour based on playtests from my prior PR, which mostly made NPCs more cowardly.

Describe the solution

  1. NPC Max Danger: break this into "monster" and "character" max danger. This allows NPCs to value your and their danger ratings higher than any monster can ever reach. This is pretty important I think, because you'll almost always be seriously outnumbered but far better equipped than your foes. The NPCs should be able to tell that. I believe the lack of distinction is why there are reports that late-game NPCs will never stand their ground even when supremely well equipped. This is handled somewhat by the way NPCs multiply assessments (something I've also made accessible to JSON now), but by splitting characters out from monsters, it means your NPC followers will also appreciate that a bandit with a sniper rifle is a bigger concern than even a very tough zombie.
  2. Add an additional coarse boost to assessed allied player threat when close to the player. If the NPC is at your side, they consider your combat ability more relevant than they do if you're far away. This is already figured in during threat evaluation, but there's an extra buff. This should help stop the NPC from fleeing when in formation with the "party leader". In the future I would like to make this part influenced by their trust in you.
    3. The big part so far: expose several critical NPC AI settings to global_options.json, allowing them to be adjusted without compiling. I will need some help with this to ensure they only check at runtime and aren't being constantly referred to, as I believe that will be potentially slow AF. caching was more fuss than I was willing to try
  3. NPCs actually feel pain! NPC pain is figured into their decision to flee, effectively lowering their personality trait for bravery. This is part of a random roll, so sometimes they can hold it together against pain.
  4. Fleeign NPC regroups on your position if they get too far away, this is determined by their individual settings on how close you've told them to stay.

NOTE: Currently the 'regroup' effect has them move to the same tile you are in, rather than near you. I'd love for them to move to 1 tile behind you relative to the assessed threat so that they don't get stuck telling you to get out of the way, but I don't understand position stuff nearly well enough for this.

end result: The effect I am hoping to get from combining the changes to fleeing behaviour with a higher "in formation" boost is that ally NPCs may choose the safest path to escape from a swarm of enemies, but then they will turn and rejoin you as they move too far away. Once they move to your side, the formation should buff their courage, so if you're staying and fighting they'll choose to as well. On the other hand, if you are running, they'll run with you. It seems to play this way in tests, but this kind of complex behaviour is heavily dependent on terrain and spread of enemies, so it's very tough to test short of just playing the game for several hours.

Describe alternatives you've considered

Infinite. I could be looking more into how NPCs evaluate danger instead of adding coarse adjustments. maybe I still will.
I plan to add some more tweaks to this or a follow up when I can.

Testing

Testing that player character proximity drops threat significantly:
image

However if you're far away the threats are still rated highly:
image

When they do run away, they check their rules. If you've told them to stay close, then they'll flee towards you rather than off into the distance.
image

There is a fair bit of jank here but I think I've got it working a lot better.

Things I need help on

  • I would like the NPC to track if they've been trying to flee for >2 turns and not moved, and if that's the case, decrease assessed danger and attempt to fight. This should be recursive, so if they still say "this is way too dangerous" they'll try another 2 turns and then reassess if they still can't escape. So if the enemy massively outclasses them they will struggle to escape a grab rather than standing their ground, but if it's a closer call, they'll change their mind and fight.
  • Similarly if an enemy moves adjacent to them while they're fleeing they should reassess their decision to flee and drop their assessment of the threat, as this could mean they're slower than the thing they're running from and should decide to stand their ground.
    - Currently the 'regroup' effect has them move to the same tile you are in, rather than near you. I'd love for them to move to 1 tile behind you relative to the assessed threat so that they don't get stuck telling you to get out of the way.
  • NPCs with guns don't seem to be smart enough to back away when the enemy gets close. I think fleeing code could be used for this but I don't know how. We wouldn't want to use quite the same code block because we don't want them shouting that they're running away or anything.

Edit: Akrieger showed me how to expose constants to JSON properly but I'm going to save that for a follow up PR so that we can get this one in

I will probably need a little help with this
@github-actions github-actions bot added <Enhancement / Feature> New features, or enhancements on existing NPC / Factions NPCs, AI, Speech, Factions, Ownership [JSON] Changes (can be) made in JSON [C++] Changes (can be) made in C++. Previously named `Code` astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels Aug 24, 2023
Now it won't kick in if the NPC is already close to you
* Expose NPC AI consts to options

I will probably need a little help with this

* Restore 'regroup on player'

Now it won't kick in if the NPC is already close to you

* Remove unnecessary messages
data/core/game_balance.json Outdated Show resolved Hide resolved
@I-am-Erk I-am-Erk marked this pull request as ready for review August 24, 2023 22:14
@I-am-Erk
Copy link
Member Author

This could be merged as is, but there are a few things I'd love to refine if someone with better code skills is around.

Also tweaks balance settings
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Aug 24, 2023
src/npcmove.cpp Outdated Show resolved Hide resolved
src/npcmove.cpp Outdated Show resolved Hide resolved
Co-authored-by: Dana Holdampf <6080772+gadgetpatch@users.noreply.github.com>
src/npcmove.cpp Outdated Show resolved Hide resolved
src/npcmove.cpp Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the astyled astyled PR, label is assigned by github actions label Aug 25, 2023
way more work than i anticipated
src/cached_options.cpp Outdated Show resolved Hide resolved
src/cached_options.h Outdated Show resolved Hide resolved
src/options.cpp Outdated Show resolved Hide resolved
@github-actions github-actions bot added the astyled astyled PR, label is assigned by github actions label Aug 25, 2023
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Aug 25, 2023
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Aug 25, 2023
@I-am-Erk I-am-Erk changed the title NPC AI/ fleeing adjustments 2: Adjust and expose NPC AI constants NPC AI/ fleeing adjustments 2: Come back, little NPC Aug 26, 2023
@Maleclypse Maleclypse merged commit 5634323 into CleverRaven:master Aug 26, 2023
29 checks passed
@I-am-Erk I-am-Erk deleted the npc-retreat2 branch August 28, 2023 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` <Enhancement / Feature> New features, or enhancements on existing [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants