fix: better define how NPCs generate starting weapon #4081
Merged
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.
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:
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.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 usingnpc_X
itemgroups, as that allows bettr ability to define custom itemgroup choices.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:
weapon_skill
tag to archery, launchers, handguns, rifles, shotguns, submachine guns, throwing, bashing weapons, cutting weapons, piercing weapons, and unarmed combat.Describe alternatives you've considered
npc::starting_weapon
such that it feeds the ID of its skill torandom_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.weapon_skill
tag that in some way better clarifies it's mainly used by NPC generation?npc::best_skill
, via explicitly telling it to exclude melee, marksmanship, and dodging.Testing
Screenshots:
This starter NPC spawned with a slingshot:
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:
The two thugs still generated with melee weapons instead of guns since their skill is higher in that.
Additional context
Checklist