Cataclysm-dda: Rework recoil

Created on 16 Sep 2016  路  9Comments  路  Source: CleverRaven/Cataclysm-DDA

Our current implementation of recoil is flawed. Stats are for an S1 survivor (STR 10, WEAP 4).

Firstly recoil recovery (except via explicit aiming) is far to slow. In many cases unload/reload is actually more productive:

| Action | Minimum | Recovery/turn |
| --- | --- | --- |
| Walk | 600 | 9 |
| Pause | 600 | 18 |
| Reload | 600 | 100 |

  • When firing recoil is offset per event by an average of ( STR * 11 ) + ( WEAP * 3.5 )
  • Offset is applied only once per event (not per shot)
  • Our S1 survivor gets an effective bonus of 124

For 5 unaimed semi-auto shots fired without pause the resulting recoil +5 and turns required to pause to offset the produced recoil are shown:

| Name | Volume | Weight | Recoil | Recoil + 5 | Pause |
| --- | --- | --- | --- | --- | --- |
| A7 laser rifle | 12 | 3.0 | 0 | 0 | 0 |
| Ruger 10/22 | 10 | 2.3 | 15 | 0 | 0 |
| Walther PPK | 1 | 0.6 | 90 | 0 | 0 |
| H&K MP5 | 7 | 3.0 | 150 | 130 | 7 |
| TEC-9 | 3 | 1.5 | 180 | 280 | 15 |
| Glock 19 | 2 | 0.8 | 285 | 805 | 42 |
| AR-15 | 10 | 3.5 | 450 | 1630 | 86 |
| AKM | 9 | 3.5 | 480 | 1780 | 94 |
| M249 | 16 | 8.0 | 540 | 2080 | 109 |
| Elephant gun | 12 | 8.2 | 750 | 3130 | 165 |

Several problems:

  • Scale
    Nearly 9 minutes to recover from 5 shots from an ar15 is out by two orders of magnitude
  • Bounds
    Lower bound (~124) to recoil stat affects ~15% of unmodified guns with standard ammo
  • Balance
    Bulkier weapons should have better recoil handling (m249 vs ar15)
    Points of contact should be more significant than weight (glock_19 vs tec9)
Mechanics Change Aiming

Most helpful comment

New recoil algorithm

  • Guns all get a recoil bonus representing how securely it is possible to hold the gun
  • Default bonus is minimum number of hands to hold the gun in typical use
  • Gun mods which improve/worsen handling (eg. bipod) also contribute to bonus
  • Ammo provides recoil, roughly proportional to muzzle energy in joules
  • Helpfully most of these values are already documented in GAME_BALANCE.md
  • Weight is also important but the algorithm is biased towards the handling bonus
  • Recoil is added linearly per-shot so bursts become increasingly inaccurate

Below is the effective recoil for a number of different items using the formula:

recoil = ammo / ( ( (weight / 250) ^ 0.8) * (bonus ^ 1.2) )

| Gun | Weight | Bonus | Ammo | 1 | 3 | 5 | 8 | 10 | 25 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Walther PPK | 525 | 1 | 160 | 88 | | | | | |
| Glock 19 | 800 | 1 | 500 | 197 | | | | | |
| M1911 | 1000 | 1 | 620 | 205 | | | | | |
| Redhawk | 1400 | 1 | 1500 | 378 | | | | | |
| MP5 | 3000 | 2 | 500 | 30 | 89 | 149 | 238 | | |
| Sig 552 | 3200 | 2 | 1500 | 85 | 255 | 425 | 679 | | |
| G3 | 3980 | 2 | 3000 | 143 | 428 | 713 | 1141 | 1427 | |
| G3+bipod | 4380 | 3 | 3000 | 81 | 244 | 406 | 650 | 812 | |
| M249 | 6800 | 3 | 1500 | 29 | 86 | 143 | 229 | 286 | 714 |

Note in particular the difference between glock19 and mp5 and how adding a bipod to hk_g3 significantly improves the handling during bursts.

This algorithm has a number of advantages:

  • ammo values are scaled against real-world data which we already have available
  • output values are compatible with our current dispersion system avoiding need to rescale
  • avoids excessive JSON twiddling - most guns can use a default bonus dependent upon type
  • remains configurable, for example TDI vector can have a bonus of 2.5 representing better handling
  • semi-auto fire (effectively shot every 6s) is practical, subject to the previous aiming changes
  • bursts are actually useful in the right circumstances as opposed to a general liability
  • bursts that end early are handled correctly

All 9 comments

I definitely agree broadly with the reasoning here, but your numbers seem a bit strange. Isn't recoil also halved following the flat reduction when walking/moving?

You might be correct with that (at which point the scaling argument becomes invalid)

Are there still some situations where pausing can be more effective than aiming at reducing recoil? I can't tell from a glance at the new code in aiming.

Also is it still possible to get greater reduction in recoil by aiming until almost out of moves, then exiting the firing interface and pausing?

New recoil algorithm

  • Guns all get a recoil bonus representing how securely it is possible to hold the gun
  • Default bonus is minimum number of hands to hold the gun in typical use
  • Gun mods which improve/worsen handling (eg. bipod) also contribute to bonus
  • Ammo provides recoil, roughly proportional to muzzle energy in joules
  • Helpfully most of these values are already documented in GAME_BALANCE.md
  • Weight is also important but the algorithm is biased towards the handling bonus
  • Recoil is added linearly per-shot so bursts become increasingly inaccurate

Below is the effective recoil for a number of different items using the formula:

recoil = ammo / ( ( (weight / 250) ^ 0.8) * (bonus ^ 1.2) )

| Gun | Weight | Bonus | Ammo | 1 | 3 | 5 | 8 | 10 | 25 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Walther PPK | 525 | 1 | 160 | 88 | | | | | |
| Glock 19 | 800 | 1 | 500 | 197 | | | | | |
| M1911 | 1000 | 1 | 620 | 205 | | | | | |
| Redhawk | 1400 | 1 | 1500 | 378 | | | | | |
| MP5 | 3000 | 2 | 500 | 30 | 89 | 149 | 238 | | |
| Sig 552 | 3200 | 2 | 1500 | 85 | 255 | 425 | 679 | | |
| G3 | 3980 | 2 | 3000 | 143 | 428 | 713 | 1141 | 1427 | |
| G3+bipod | 4380 | 3 | 3000 | 81 | 244 | 406 | 650 | 812 | |
| M249 | 6800 | 3 | 1500 | 29 | 86 | 143 | 229 | 286 | 714 |

Note in particular the difference between glock19 and mp5 and how adding a bipod to hk_g3 significantly improves the handling during bursts.

This algorithm has a number of advantages:

  • ammo values are scaled against real-world data which we already have available
  • output values are compatible with our current dispersion system avoiding need to rescale
  • avoids excessive JSON twiddling - most guns can use a default bonus dependent upon type
  • remains configurable, for example TDI vector can have a bonus of 2.5 representing better handling
  • semi-auto fire (effectively shot every 6s) is practical, subject to the previous aiming changes
  • bursts are actually useful in the right circumstances as opposed to a general liability
  • bursts that end early are handled correctly

Possible enhancements could include capping the maximum applicable weight by STR, probably something like min(weight, STR * 500)

The code for various types of recoil reduction is quite scattered, despite often having broadly similiar functions. This has probably contributed to inconsistencies in the handling of recoil.

do_aim() in ranged.cpp
player::pause() in player.cpp
game::wield() and game::walk_move() in game.cpp
activity_handlers::reload_finish() in activity_handlers.cpp
npc::aim(), npc::move_to(), npc::move_pause() and npc::do_reload() in npcmove.cpp

If you're making broad changes to recoil then I think it might be helpful to consolidate the code as much as possible.

Considering movement the best design I can think of is that moving or dodging decreases your aim to at least MIN_RECOIL. For any action other than shooting player recoil should decay exponentially per turn. The purpose of recoil being to limit burst fire with aim_cost limiting shot rate.

Ideally we'd have different values of MIN_RECOIL for differing stances (walking, running, crawling) etc

Default bonus is minimum number of hands to hold the gun in typical use

Handguns are not typically used one-handed. While they _can_ be, the effects of one-handing a pistol of any reasonable caliber (e.g. 9mm) is fairly deleterious on recoil compensation, hence why most shooting stances advocate the use of both hands.

Plus, CDDA doesn't even (currently) properly model having multiple hands - when wielding an item, a character can only wield that one item, which to me implies that they're using both hands to hold the item (barring atypical cases like broken limbs or a character with a Fusion Blaster Arm CBM installed).

adding a bipod to hk_g3 significantly improves the handling during bursts.

while this issue is regarding recoil and not movement, this implies that the shooter is going prone every time they shoot, to make use of the bipod. Does the mod/math account for the time it takes to change position?

e: Argh, software keyboards are atrocious.

Handguns are not typically used one-handed.

You're overthinking it a little. The idea is that shoulder fired weapons are inherently more controllable than handguns.

Does the mod/math account for the time it takes to change position?

No, but a later implementation will do and probably also impose restriction on terrain thereby making the choice between a bipod and forward grip more important.

Was this page helpful?
0 / 5 - 0 ratings