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 attack #47562

Merged
merged 3 commits into from
Jul 9, 2021
Merged

Npc attack #47562

merged 3 commits into from
Jul 9, 2021

Conversation

KorGgenT
Copy link
Member

@KorGgenT KorGgenT commented Feb 17, 2021

Summary

Features "Implement new logic for NPCs to choose their attacks"

Purpose of change

We've been wanting to improve the npc ai, but afaik noone wanted to carry that torch. so here i am! :D

Describe the solution

requires #47207 as it has commits from this PR to break it up a bit.

implement a new npc_attack class with child classes for the different styles of attacks. in this PR, that is melee, gun, throw, and activate_item. throw has a fairly basic implementation because i needed the npc to understand that grenades needed to be thrown, and the activate item attack is for feature parity with npcs using grenades. Unfortunately, it looks pretty involved to properly estimate when it's a good idea to throw a grenade, so the likelyhood of an npc throwing a grenade is "not unless i'm surrounded, can't run, and there's no other option". grenades will have to be their own PR.

add a new method in npc to evaluate all of its possible attack options and save the npc_attack and its data (called npc_attack_effectiveness) into the ai_cache. then just activate it via npc_attack::use.

Describe alternatives you've considered

Watching npcs throw their pants at zombies

Testing

i'm writing some tests, and additionally i have run some live tests where i equipped an npc with a specific item and watched what they did with it. i can confirm that they throw items, use attack spells, fire guns, and use melee weapons. they also use grenades if their surrounded and are naked! (if they don't choose to run away first)
I'm drafting this to get it out in the open for some code review, though i'm pretty aware that i'm not done writing up the tests.

Additional context

follow ups should be, in no particular order:

  • spell
  • bionics
  • mutations
  • grenades
  • some other item activations perhaps?

@KorGgenT KorGgenT added <Enhancement / Feature> New features, or enhancements on existing NPC / Factions NPCs, AI, Speech, Factions, Ownership [C++] Changes (can be) made in C++. Previously named `Code` 0.F Feature Freeze labels Feb 17, 2021
src/npc_attack.h Outdated Show resolved Hide resolved
src/npcmove.cpp Outdated Show resolved Hide resolved
@actual-nh
Copy link
Contributor

I have been contemplating how to have a monster not use a particular option unless pressed - something more than "only do it every X turns". Possibly dependent on Anger above starting and Morale below starting?

@BrettDong
Copy link
Member

Need to add virtual destructor to other classes as well.

@KorGgenT
Copy link
Member Author

i really don't understand why exactly

@KorGgenT
Copy link
Member Author

KorGgenT commented Feb 17, 2021

blergh, i've run both the astyle and json linting tools from VS but they didn't do it (for the json.. turns out i ran astyle on the wrong branch)

src/npc_attack.cpp Outdated Show resolved Hide resolved
src/npc_attack.cpp Outdated Show resolved Hide resolved
src/npc_attack.h Outdated Show resolved Hide resolved
src/npc_attack.h Outdated Show resolved Hide resolved
src/npc_attack.h Outdated Show resolved Hide resolved
src/npc_attack.h Outdated Show resolved Hide resolved
src/npc_attack.h Outdated Show resolved Hide resolved
Copy link
Contributor

@mlangsdorf mlangsdorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, it looks good and I didn't see any structural problems in the code. @Aivean should probably look over it for performance improvements but I'll leave that to his expertise.

Submission wise, I think a bunch of this can be broken into separate PRs for easier review. There's a lot of generic infrastructure work before you get into actually implementing the changes to the NPC AI. Normally, I wouldn't make such an issue about it, but this is such a large PR that it usefully could be trimmed.

src/character.cpp Outdated Show resolved Hide resolved
src/item.cpp Outdated Show resolved Hide resolved
src/item.cpp Outdated Show resolved Hide resolved
src/magic.cpp Outdated Show resolved Hide resolved
src/npc_attack.cpp Outdated Show resolved Hide resolved
@KorGgenT
Copy link
Member Author

please excuse the individual commits for now, i'm trying to do miniscule changes to fix up the error messages in order to squash them into the correct commit later.

@kevingranade
Copy link
Member

This pull request has been mentioned on Cataclysm: Dark Days Ahead. There might be relevant details there:

https://discourse.cataclysmdda.org/t/magiclysm-a-total-fantasy-overhaul/20612/512

This implements a class that owns all of the logic for an npc evaluating the best weapon to use in the moment.
@I-am-Erk I-am-Erk merged commit 8d721b4 into CleverRaven:master Jul 9, 2021
@KorGgenT KorGgenT deleted the npc_attack branch July 10, 2021 03:20
pjf added a commit to pjf/Cataclysm-DDA that referenced this pull request Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` <Enhancement / Feature> New features, or enhancements on existing NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants