Fix NPCs set to attack what you attack charging blindly #3226
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Bugfixes "Companion NPCs told to only attack what the player attacks no longer charge approaching enemies unless you've actually attacked the target first"
Purpose of change
This fixes NPCs set to "attack only what I attack" being stupid and bum-rushing targets you haven't marked for death yet, AKA what used to be my preferred NPC RoE setting back in the old days.
Describe the solution
In npcmove.cpp, changed
npc::method_of_attack
to add an extra boolean that checks if both the target has yet to be hit by the player and the NPC is set to engage targets you attack. If so, the bottom function for fallback behavior will tell them to hold fast as if they were not to not move, instead of going for a charge.Describe alternatives you've considered
If anyone can remember any other NPC AI settings that visibly don't work right, lemme know.
Testing
Also tested giving them a gun, if so they'll shoot attackers as they get near even if you haven't attacked. Not sure if that'd be desirable behavior or not, as opposed to the more obvious case of not making them charge enemies in melee you haven't engaged yet.
Additional context
At one point while testing I got an access violation that pointed to
Messages::display_messages
in npcmopve.cpp, pointing to this bit and saying "m
was nullpointer" but have not been able to reproduce this after several more tests: