Fix Beat Up's battle script to avoid an out-of-bounds array access #2541
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.
Description
Instead of using
gBattleCommunication[0]
to keep track of the current Beat Up slot for its damage calc, this PR introduces a dedicated field ingBattleStruct
,beatUpSlot
, which gets initialised to0
at the start of battle. This fixes #2540, as the damage calculation was being called by AI calculations before the script for Beat Up was ran to setgBattleCommunication[0]
, leading to an out-of-bounds array access. For an abundance of caution, the incrementing ofgBattleStruct->beatUpSlot
has also been moved to occur after the damage calculation takes place, so that no shenanigans with- 1
needs to take place. I also overloaded theCmd_trybeatup
battle script command so that it's more clear that Beat Up's effect changes depending on theB_BEAT_UP
setting, as before it wasn't clear by looking at that function alone that it was effectively unused whenB_BEAT_UP
was>= GEN_5
.Discord contact info
Spherical Ice#4683