Fix for RAC and UAC ammo bingo state hanging game #4865
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.
I'm not sure if this has been around for a while, or is the fallout of recent changes, but we're seeing the game hang whenever two or more variable-rate ammo-based weapons (UACs and RACs, possibly others) end up with 0 remaining ammo during the weapon action handling phase of a turn. The root cause was that we explicitly assumed we'd never see an attack finding 0 rounds remaining when actually executed, so we'd have an attack set to make 1 shot with 0 remaining ammo... which made the game sad.
I don't want to go into much detail, but this was pretty hairy to debug due to the way that we call the same To-Hit calculation code all over the place in order to:
Suffice to say, the issue comes because, while we try to detect the zero-ammo situation before declaring or handling attacks, weapons that have variable firing rates don't currently do any up-front accounting. The player-selected mode of a RAC/5, for instance, is not taken into account until we actually handle the attack and begin consuming the weapon's linked ammo. At that point it is far too late to display a warning to the user or prevent a 2nd weapon's attack action from being created, because all the attacks have already been created and we're just totting up the numbers behind the scenes.
I've implemented a fix that will prevent the hanging, and consolidated some of the duplicate code between the RAC and UAC handlers. But there's still a lot that could work better here:
close #4861