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

Only consume ammo for shots that were actually fired #3569

Merged
merged 1 commit into from
Nov 30, 2024

Conversation

mszabo-wikia
Copy link
Contributor

@mszabo-wikia mszabo-wikia commented Nov 24, 2024

Changes

  • Centralize ammo management for verbs within Verb_ShootCE
  • Split ammo count check / selection and ammo consumption into separate methods
  • Consume ammo in OnCastSuccessful rather than before attempting the shot

References

Reasoning

  • Verb_LaunchProjectileCE doesn't need to know about CompAmmo, only Verb_ShootCE and derivatives do. The current system leads to reload / ammo management logic being copypasted across verb classes, which is error-prone.
  • We currently check for and reduce ammo count before checking if a shot can actually be fired. For burst weapons with interruptibleBurst = true, this can cause extra ammo to be consumed without a corresponding shot being made.

Testing

  • Compiles without warnings
  • Game runs without errors
  • Playtested a colony - spawned in a KPV with APHE and targeted a wooden wall directly next to it. With this change, this consumes 2 bullets instead of 3. Also tested automatic reloading and out of ammo behavior with a gun-wielding colonist.

We currently check for and reduce ammo count before checking if a shot
can actually be fired. For burst weapons with interruptibleBurst = true,
this can cause extra ammo to be consumed without a corresponding shot
being made. Instead, only consume ammo after firing the shot.
@mszabo-wikia mszabo-wikia requested review from a team as code owners November 24, 2024 23:29
Copy link

You can download the rebuilt assembly for this PR here: https://combatextended.lp-programming.com/CombatExtended-12000520980.zip

@github-actions github-actions bot added the Download in Comments This PR has a zipfile download available. label Nov 24, 2024
@mszabo-wikia
Copy link
Contributor Author

Note: While testing this, I found that the preexisting logic doesn't consistently enforce ammoConsumedPerShotCount, meaning it is possible to fire a weapon with ammoConsumedPerShotCount = X with less than X bullets in the mag. However, fixing that would be a larger change, since the assumption that a nonzero bullet count in the mag / inventory allows a weapon to be fired is widespread, so I opted against trying to fix it here.

Copy link
Contributor

@N7Huntsman N7Huntsman left a comment

Choose a reason for hiding this comment

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

Fixes the issue in my testing.

@N7Huntsman N7Huntsman merged commit 37d17ac into Development Nov 30, 2024
3 checks passed
@N7Huntsman N7Huntsman deleted the issue-3500 branch November 30, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Download in Comments This PR has a zipfile download available.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Some automatic weapons seem to 'ghost fire', consuming the ammo but not firing anything
3 participants