Fix crossbow gunmod compatibility #1526
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.
Summary
SUMMARY: Bugfixes "Fix crossbows not counting as crossbows for the sake of gunmods, allow distinction between actual crossbows and pneumatic bolt driver"
Purpose of change
So recently I was poking through item.cpp and was reminded that the gunmod function that separates crossbows from other types of ranged weapon was never updated to account for crossbows using rifle skill, as it was switched from archery.
On looking at the function I decided that there were two ways to fix it. Either convert the "if ammo is bolt or it's a bullet crossbow, it's a crossbow" statement to not care about the archery skill, since it triggering would make the function return before it could grab the gun skill anyway. Or I could implement a flag check.
The main reason to do this is, aside from checking for specific ammo types and item IDs not being a good way to do this, there are going to be items that fire bolts but shouldn't count as a crossbow, example being the pneumatic bolt driver, plus you may have items that should be a crossbow but wouldn't be under that check. No vanilla examples of the former come to mind, though outside repo of course adds the example of wraithslayer crossbows in Arcana.
Describe the solution
item::gun_type
to classify items as a crossbow if they have theCROSSBOW
flag. This also meant removing the non-functional "return early if we see the archery skill" if statement since now if an item has the archery skill it tell it's a bow through the normal skill lookup.Describe alternatives you've considered
As mentioned, we could keep the messy-looking check for specific ammo and item types, but then bolt drivers would count as crossbows and other weirdness as mentioned previously.
Testing
Additional context
Relevant PR that switched gun skill of crossbows, by @kevingranade: CleverRaven/Cataclysm-DDA#21545
I checked and confirmed the same issue is present in DDA: https://github.com/CleverRaven/Cataclysm-DDA/blob/master/src/item.cpp#L10122 so they may wish to be made aware of it for the purpose of porting over BN's fix for it.