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

Many small logic adjustments and bugfixes for NPC targeting / threat assessment #69840

Merged

Conversation

I-am-Erk
Copy link
Member

@I-am-Erk I-am-Erk commented Nov 28, 2023

Summary

Features "Several more small adjustments to NPC logic and bugfixes from reports"

Purpose of change

This is mostly another small cleanup of my code, which also takes the time to fix a few omissions or errors I've made along the way.

Edit: swap that, now it's a lot of small changes and a little bit of code cleanup. All of these are individually small, bases on error reports and player feedback.

Describe the solution

  • NPCs have been less afraid of crowds than I'd like, and overrating their own gear if they have any armour. I realized they were not averaging their resistances across damage types out, so since their armour evaluation was a sum of the four major combat damage types, not an average. I've divided the result by 4 to get an average so they shouldn't overrate their gear as much.
  • I took a closer look at how monster difficulty was being calculated, and realized that their stab and bullet armour was being ignored. This is part of why soldiers and cops were being underrated in difficulty. I also added a method to try to calculate the effect of their special attacks a bit; this will need some testing as the numbers are kind of arbitrary, but it should help with underrating ferals and other monsters that have a lot of special attacks. This all turned out to be unnecessary because the real issue was that I had made a math mistake when calculating difficulty, and the code was making bugs so I took it out for now.
  • I also removed some checks and balances from crowd calculations that were there from before my rewrites and shouldn't be necessary anymore.
  • In the process I changed some arbitrary numbers I'd set up for what an NPC considers "close" and "super close" for the purposes of evaluating threat from crowds of enemies. These numbers are now defined based on the NPC's weapon's effective range, rather than simply "is it a gun or not"... NPCs with polearms will now try to kite targets to keep them in melee range but too close. This one's gonna need some playtesting for sure. THis should also make melee characters try to break out of crowds a little sooner, to avoid getting surrounded.
  • My new additions to keep melee NPCs from running in would probably keep them from ever attacking if a ranged ally was between them and the enemy. I've added a check to avoid that problem. First the melee character checks if the enemy is further from them than it is from their ranged ally; then, they check if there are enemies getting in closer to their other allies, and allow engagement if that's the case. In this situation, that should mean their friends are already engaged so they should go in as well. This could be made smarter.
  • I renamed my combat_memory feature to make it look like the other caches that work similarly.
  • try to reduce NPC 'yo yo' behaviour when repositioning where they go too far and keep boinging all the way back to the player instead of just taking one or two steps and continuing.
  • NPCs were ignoring monsters like mi-go that come in, hit, and then back away. This is because the enemies were declaring themselves as "fleeing", and the code tells NPCs to ignore fleeing enemies. Now, if they have the hit-and-run flag, they'll remain hostile while fleeing. This should also be good for NPC threat assessments since a mi-go shouldn't stop being assessed as a threat while it's backing up for another attack.
  • if an NPC follower is farther than their safe distance (or 6 tiles if they've been told to roam free) they won't look for a corpse to pulp, and they'll only seek corpses within a radius equal to the distance you've told them to stay close.

I also flipped several NPC follower default behaviour switches that I think should be flipped by default:

  • by default followers will use silent weapons and avoid grenades
  • by default followers will stay within 4 paces, not roam freely
  • they'll also close doors behind them and avoid investigating noises.

Describe alternatives you've considered

I'm not sure if I like the way I've solved the melee problem. I may instead check if the enemy is closer to the ranged ally, but I'm not totally sure how that would work.

Testing

As far as I can tell these seem to be working as advertised. I'm sure there are some things I messed up, it's going to be a few dozen hours of playtesting to capture all the corner cases. On playtests, I was really impressed at how much easier and more natural it feels to sneak through a city with a follower, and I didn't ahve to give them orders to keep them from running into a fight.

Additional context

One tiny math error on my own part led to me doing a largish overhaul of monster difficulty calculations before I found the mistake. At least the work seems to be ok.

rename memory function to match other caches
fix a small oversight with melee engagement
Adjust swarming range to use weapon ranges instead of arbitrary numbers
@github-actions github-actions bot added NPC / Factions NPCs, AI, Speech, Factions, Ownership [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions labels Nov 29, 2023
@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Nov 29, 2023
added armour calculations
added some special attack calculations
@github-actions github-actions bot added [JSON] Changes (can be) made in JSON Monsters Monsters both friendly and unfriendly. and removed BasicBuildPassed This PR builds correctly, label assigned by github actions labels Nov 29, 2023
@github-actions github-actions bot added the <Enhancement / Feature> New features, or enhancements on existing label Nov 29, 2023
@I-am-Erk I-am-Erk changed the title Cleanup and small logic adjustments Many small logic adjustments and bugfixes for NPC targeting / threat assessment Nov 29, 2023
@github-actions github-actions bot removed the astyled astyled PR, label is assigned by github actions label Nov 29, 2023
@github-actions github-actions bot added the astyled astyled PR, label is assigned by github actions label Nov 30, 2023
@I-am-Erk I-am-Erk marked this pull request as ready for review November 30, 2023 04:57
We can return here later but I want this PR done.
@github-actions github-actions bot added the Code: Tests Measurement, self-control, statistics, balancing. label Nov 30, 2023
set tests to use a flag that's less likely to change. It is unlikely we'll set "forbid engagement" to default to on.
try disabling this line of the test because I have a headache
@github-actions github-actions bot removed the json-styled JSON lint passed, label assigned by github actions label Nov 30, 2023
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot added the json-styled JSON lint passed, label assigned by github actions label Nov 30, 2023
tests/npc_talk_test.cpp Outdated Show resolved Hide resolved
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Nov 30, 2023
@Maleclypse Maleclypse merged commit 924079e into CleverRaven:master Dec 2, 2023
23 of 26 checks passed
@I-am-Erk I-am-Erk deleted the npc-ai-changes-cleanup-and-small-fixes branch December 2, 2023 17:37
@I-am-Erk
Copy link
Member Author

I-am-Erk commented Dec 2, 2023

Thanks!

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` Code: Tests Measurement, self-control, statistics, balancing. <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 Monsters Monsters both friendly and unfriendly. NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants