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: better define how NPCs generate starting weapon #4081

Merged
merged 3 commits into from
Jan 9, 2024

Conversation

chaosvolt
Copy link
Member

@chaosvolt chaosvolt commented Jan 9, 2024

Purpose of change

This aims to fix up some flaws with the hardcoded way in which NPCs generate their default starting weapons, clearing the way for better NPC gear variety in the future.

Describe the solution

C++ changes:

  1. In npc.cpp, updated npc::best_skill to only check for what counts as weapon skills, to prevent weird shit like an NPC how has high marksmanship skill than their pistol skill or whatever generating unarmed because by the code's logic their best skill isn't a weapon skill. Uses a neat bool as outlined below.
  2. Also in npc.cpp, updated the logic npc::starting_weapon a bit. Now it probably checks for all the skills in-repo that might reasonably qualify as a weapon skill, and fixed the fallback behavior to actually properly kick in as a default result and not being skippable if the NPC's top skill was an unexpected combat skill (as the fallback was only kicking in if combat skills were entirely absent). Now comes with the ability to define unarmed weapon groups and launchers for NPC classes. Additionally, axed the existing choices in fallback itemgroups in favor of always using npc_X itemgroups, as that allows bettr ability to define custom itemgroup choices.
  3. In skill.cpp and skill.h, defined Skill::is_weapon_skill which defines an additional tag for skill JSON, for defining all skills that presently qualify as a weapon skill.

JSON changes:

  1. Added weapon_skill tag to archery, launchers, handguns, rifles, shotguns, submachine guns, throwing, bashing weapons, cutting weapons, piercing weapons, and unarmed combat.
  2. Defined proper fallback itemgroups for all potential resulting NPC weapon choices, additionally fixing NPCs picking a crossbow (which has used rifle skill for ages) as their default if they have archery skill. Comes with some potential calls to improvised gun itemgroups, crossbows returning to rifle users where they belong, and some better selection of defaults for throwing NPCs. SMG, launcher, and unarmed groups all come with some chance to still generate the NPC unarmed (especially for launchers given how !!FUN!! an NPC spawning with a rocket launcher could be).

Describe alternatives you've considered

  1. We could support custom skills in mods if we were to figure out a way to smush npc::starting_weapon such that it feeds the ID of its skill to random_item_from automatically in place of the pre-defined strings. We may in the process also want to force it to construct the fallback itemgroup IDs in the same way instad of using predefined ones.
  2. Picking a better name for the weapon_skill tag that in some way better clarifies it's mainly used by NPC generation?
  3. Hardcoding the "filter out non-weapon skills" stuff directly into npc::best_skill, via explicitly telling it to exclude melee, marksmanship, and dodging.

Testing

  1. Checked affected JSON files for syntax and lint errors.
  2. Compiled and load-tested.
  3. Checked affected C++ files for astyle.
Screenshots:

This starter NPC spawned with a slingshot:
1

They had 7 marksmanship skill and only 5 in throwing, if not for the new property they would've defaulted to stabbing under current logic, and just spawned unarmed in current master.

All of these bandits generated armed for once, some had homemade hand cannons and the like mixed in with the standard glocks:
2

The two thugs still generated with melee weapons instead of guns since their skill is higher in that.

Additional context

Checklist

@github-actions github-actions bot added src changes related to source code. JSON related to game datas in JSON format. labels Jan 9, 2024
src/npc.cpp Show resolved Hide resolved
scarf005
scarf005 previously approved these changes Jan 9, 2024
@scarf005
Copy link
Member

scarf005 commented Jan 9, 2024

i think it'll be good to merge once the tests pass.

@chaosvolt
Copy link
Member Author

maybe we could use std::map to remove code duplication from line 832-854, like in this example:

Could tinker with in the future, I'd definitely like to at some point follow up on this by trying to figure out how to generate the groups used automatically.

That said, one lil adjustment right quick now that I think about it...

Copy link
Member

@scarf005 scarf005 left a comment

Choose a reason for hiding this comment

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

oh, by the way, i've commited std::map refactoring.

@scarf005 scarf005 merged commit a64a098 into cataclysmbnteam:main Jan 9, 2024
12 checks passed
@chaosvolt
Copy link
Member Author

oh, by the way, i've commited std::map refactoring.

Ah nice, thanks.

@chaosvolt chaosvolt deleted the bandit-weapon-spawns branch January 9, 2024 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JSON related to game datas in JSON format. src changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants