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

Safer NPC Ranged Weapon Use #75297

Merged
merged 4 commits into from
Jul 29, 2024

Conversation

ShnitzelX2
Copy link
Contributor

Summary

Bugfixes "safer NPC ranged weapon use"

Purpose of change

In my experience, NPC allies using guns are more dangerous than the monsters they fight. They tend to shoot the player and each other on accident, even with the "allies in line of fire" rule on.

I figured a good place to start was wont_hit_friend(), which makes three checks to see if an ally won't get hit by a shot:

  1. weapon confidence < 1. This was described by a comment as badly extracting dispersion from ranged confidence.
  2. range to target == 1. This is a faulty assumption, since bullets keep traveling after missing their target, and shots at range 1 are by no means guaranteed hits.
  3. angle difference between ally and target is > 30 degrees (60 degrees for ally distance 2, 90 degrees for ally distance 1). 30 degrees is the maximum final dispersion, so we can do better.

There's additional problems: trajectories are inherently less accurate than dispersion angles at close range, and until #71605 is merged, trajectories won't line up with dispersion angles anyways.

Describe the solution

Corresponding to the list above:

  1. removed completely (if there's a case where this matters and should still be in this function, let me know)
  2. range == 1 is only assumed for throwing and NOT for guns, since throwing at range 1 is safe
  3. angle differences use maximum weapon dispersion instead, removes close range check in favor of checking intended trajectory for allies

Describe alternatives you've considered

Testing

  • passed all tests locally
  • spawned three NPC allies with guns and tested various monster spawns with different engagement rules
  • made sure turning "allies in line of fire" off still works
  • made sure allies still could use melee, guns with bayonets

Additional context

This makes allies with guns fire more conservatively. As intended, you may have to turn the "allies in line of fire" rule off if you're getting mauled in melee by something and you want your ally to shoot an adjacent monster.

ShnitzelX2 and others added 3 commits July 17, 2024 15:26
-makes NPCs shooting guns safer for allies and player
-dispersion is pre-cap
-debug messages for dispersion, line of fire
-new helper function for all gun dispersion sources
@github-actions github-actions bot added NPC / Factions NPCs, AI, Speech, Factions, Ownership [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) json-styled JSON lint passed, label assigned by github actions labels Jul 28, 2024
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot added BasicBuildPassed This PR builds correctly, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Jul 28, 2024
@Maleclypse Maleclypse merged commit c96d56d into CleverRaven:master Jul 29, 2024
25 of 26 checks passed
@RenechCDDA RenechCDDA mentioned this pull request Aug 14, 2024
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 <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` 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.

2 participants