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

Fix Quash implementation, adds After You and Quash missing configs + tests #5400

Merged
merged 2 commits into from
Sep 18, 2024

Conversation

PhallenTree
Copy link

@PhallenTree PhallenTree commented Sep 18, 2024

Quash's current implementation has a fair amount of problems (in BS_TryQuash), which have been fixed.

  • First, it changes gBattlersByTurnOrder but not gActionsByTurnOrder which causes the same issue described in Fixes After You/Shell Trap not updating battlers' actions correctly #5384.
  • Due to if (!gProtectStructs[i].quash && !gProtectStructs[j].quash && GetWhichBattlerFaster(gBattlerByTurnOrder[i], gBattlerByTurnOrder[j], FALSE) == -1), anyone affected by Quash will move in that order (player's Left mon would move first, opponent's Left mon would move second, etc.)
  • Also after executing some swaps, it checks the wrong battler's Quash bit.
  • It also doesn't properly follow either of the turn order interactions (Gen5-7 or Gen8+).

If you don't want spend a lot of time analyzing the current implementation's code, here's a rundown:

  • Turn order is set to be equal to battler's positions (ignores any kind of other actions the battler was supposed to do)
  • It tries to order battlers by Speed order (but not the ones with the Quash bit, due to an error I assume)
  • Outcome of current implementation: battlers affected by Quash - turn order is changed to be equal to its position, instead of moving last; battlers not affected by Quash - turn order is priority/speed order.

So if the player's left mon is affected by Quash (via move), it will never act on that turn.
As proven by running the following test:

DOUBLE_BATTLE_TEST("Quash-affected player left pokemon can act")
{
    GIVEN {
        PLAYER(SPECIES_MUDKIP) { Speed(10); }
        PLAYER(SPECIES_WOBBUFFET) { Speed(30); }
        OPPONENT(SPECIES_TORCHIC) { Speed(20); }
        OPPONENT(SPECIES_TREECKO) { Speed(40); }
    } WHEN {
        TURN { MOVE(opponentRight, MOVE_QUASH, target: playerLeft); }
    } SCENE {
        ANIMATION(ANIM_TYPE_MOVE, MOVE_QUASH, opponentRight);
        ANIMATION(ANIM_TYPE_MOVE, MOVE_CELEBRATE, playerLeft);
    }
}

Added After You config B_AFTER_YOU_TURN_ORDER:

Generations V to VII
After You fails if the order remains the same after using After You.

Generation VIII onwards
After You no longer fails if the turn order remains the same after using After You.

Added Quash config B_QUASH_TURN_ORDER:

Generation V to VII
If multiple Pokémon are affected by Quash, they move in the order they were affected by Quash.

Generation VIII onwards
If multiple Pokémon are affected by Quash, they now move fastest to slowest.

Added tests for After You and Quash.

Discord contact info

PhallenTree

Copy link
Collaborator

@AlexOn1ine AlexOn1ine left a comment

Choose a reason for hiding this comment

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

Really nice work.

@AlexOn1ine AlexOn1ine merged commit 76656e8 into rh-hideout:master Sep 18, 2024
1 check passed
@AlexOn1ine AlexOn1ine added category: battle-mechanic Pertains to battle mechanics bugfix Bugfixes labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Bugfixes category: battle-mechanic Pertains to battle mechanics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants