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

Fix NPCs set to attack what you attack charging blindly #3226

Merged
merged 1 commit into from
Sep 23, 2023

Conversation

chaosvolt
Copy link
Member

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

  1. Compiled and load-tested.
  2. Recruited the starter NPC and set them to attack what I attack.
  3. Gave them a melee weapon and spawned in a zombie.
  4. Waited for the zed to approach, they do nothing until the zombie actually gets in melee range.
  5. Repeated this test but this time shot the zombie before it approached.
  6. NPC responds by charging the zed before it gets close.
  7. Checked affected file for astyle.

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:

            const nc_color col = m.get_color( player_messages.curmes );
            std::string message_text = m.get_with_count();
            if( !m.is_recent( player_messages.curmes ) ) {
                message_text = remove_color_tags( message_text );
            }

@github-actions github-actions bot added the src changes related to source code. label Sep 23, 2023
@chaosvolt chaosvolt merged commit 7ac04c1 into cataclysmbnteam:upload Sep 23, 2023
10 of 16 checks passed
@chaosvolt chaosvolt deleted the fix-npc-hit-engagement branch September 23, 2023 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
src changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants