Fix AI switching in absorbing mon incorrectly #6227
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.
Description
The AI uses FindMonThatAbsorbsOpponentsMove to determine if it should switch in an absorber. This function isn't used when determining what mon to send in after a KO, so there are cases where they AI sends in a new mon, then immediately switch in a mon to try to absorb the incoming attack.
This doesn't sound like bad behaviour, except the AI isn't predicting the incoming attack, it is just referencing whatever attack the player used most recently. This data is no longer reliable if the AI has just sent out a new mon for the player to engage with, so this behaviour should be disabled if the AI just sent out a new mon.
Basically we need some method of checking whether the mon the AI is currently analyzing is the same mon that the player was attacking on the previous turn, as if it isn't we can't assume their moves anymore (without prediction).
This PR fixes this by tracking the AI's species across a turn, and evaluating if the battler at the start of turn X is the same species as the mon at the start of turn X - 1.
Tagging #5229 because this behaviour will need to be overridden if the AI is using AI_FLAG_MOVE_PREDICTION, but that flag doesn't exist yet, and this will remind me to do so when I eventually get to that feature request lol
Issue(s) that this PR fixes
Closes #6124
Discord contact info
@Pawkkie