Fix After You for gen8 (#2646)

Fix After You
This commit is contained in:
DizzyEggg 2023-02-16 21:59:36 +01:00 committed by GitHub
parent 6b08120d5f
commit d637ee3b13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 26 deletions

View file

@ -191,6 +191,7 @@ struct SpecialStatus
u8 weatherAbilityDone:1; u8 weatherAbilityDone:1;
u8 terrainAbilityDone:1; u8 terrainAbilityDone:1;
u8 emergencyExited:1; u8 emergencyExited:1;
u8 afterYou:1;
}; };
struct SideTimer struct SideTimer

View file

@ -9394,7 +9394,7 @@ static void Cmd_various(void)
break; break;
case VARIOUS_AFTER_YOU: case VARIOUS_AFTER_YOU:
if (GetBattlerTurnOrderNum(gBattlerAttacker) > GetBattlerTurnOrderNum(gBattlerTarget) if (GetBattlerTurnOrderNum(gBattlerAttacker) > GetBattlerTurnOrderNum(gBattlerTarget)
|| GetBattlerTurnOrderNum(gBattlerAttacker) == GetBattlerTurnOrderNum(gBattlerTarget) + 1) || GetBattlerTurnOrderNum(gBattlerAttacker) + 1 == GetBattlerTurnOrderNum(gBattlerTarget))
{ {
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3);
} }
@ -9419,6 +9419,7 @@ static void Cmd_various(void)
gBattlerByTurnOrder[2] = gBattlerTarget; gBattlerByTurnOrder[2] = gBattlerTarget;
gBattlerByTurnOrder[3] = data[2]; gBattlerByTurnOrder[3] = data[2];
} }
gSpecialStatuses[gBattlerTarget].afterYou = 1;
gBattlescriptCurrInstr += 7; gBattlescriptCurrInstr += 7;
} }
return; return;

View file

@ -323,7 +323,7 @@ void HandleAction_UseMove(void)
{ {
gCurrentMove = gBattleStruct->zmove.toBeUsed[gBattlerAttacker]; gCurrentMove = gBattleStruct->zmove.toBeUsed[gBattlerAttacker];
} }
moveTarget = GetBattlerMoveTargetType(gBattlerAttacker, gCurrentMove); moveTarget = GetBattlerMoveTargetType(gBattlerAttacker, gCurrentMove);
if (gBattleMons[gBattlerAttacker].hp != 0) if (gBattleMons[gBattlerAttacker].hp != 0)
@ -909,9 +909,8 @@ void HandleAction_NothingIsFainted(void)
void HandleAction_ActionFinished(void) void HandleAction_ActionFinished(void)
{ {
#if B_RECALC_TURN_AFTER_ACTIONS >= GEN_8 #if B_RECALC_TURN_AFTER_ACTIONS >= GEN_8
u8 i, j; u32 i, j;
u8 battler1 = 0; bool32 afterYouActive = gSpecialStatuses[gBattlerByTurnOrder[gCurrentTurnActionNumber + 1]].afterYou;
u8 battler2 = 0;
#endif #endif
*(gBattleStruct->monToSwitchIntoId + gBattlerByTurnOrder[gCurrentTurnActionNumber]) = PARTY_SIZE; *(gBattleStruct->monToSwitchIntoId + gBattlerByTurnOrder[gCurrentTurnActionNumber]) = PARTY_SIZE;
gCurrentTurnActionNumber++; gCurrentTurnActionNumber++;
@ -938,29 +937,32 @@ void HandleAction_ActionFinished(void)
gBattleResources->battleScriptsStack->size = 0; gBattleResources->battleScriptsStack->size = 0;
#if B_RECALC_TURN_AFTER_ACTIONS >= GEN_8 #if B_RECALC_TURN_AFTER_ACTIONS >= GEN_8
// i starts at `gCurrentTurnActionNumber` because we don't want to recalculate turn order for mon that have already if (!afterYouActive)
// taken action. It's been previously increased, which we want in order to not recalculate the turn of the mon that just finished its action
for (i = gCurrentTurnActionNumber; i < gBattlersCount - 1; i++)
{ {
for (j = i + 1; j < gBattlersCount; j++) // i starts at `gCurrentTurnActionNumber` because we don't want to recalculate turn order for mon that have already
// taken action. It's been previously increased, which we want in order to not recalculate the turn of the mon that just finished its action
for (i = gCurrentTurnActionNumber; i < gBattlersCount - 1; i++)
{ {
u8 battler1 = gBattlerByTurnOrder[i]; for (j = i + 1; j < gBattlersCount; j++)
u8 battler2 = gBattlerByTurnOrder[j];
if (gProtectStructs[battler1].quash || gProtectStructs[battler2].quash)
continue;
// We recalculate order only for action of the same priority. If any action other than switch/move has been taken, they should
// have been executed before. The only recalculation needed is for moves/switch. Mega evolution is handled in src/battle_main.c/TryChangeOrder
if((gActionsByTurnOrder[i] == B_ACTION_USE_MOVE && gActionsByTurnOrder[j] == B_ACTION_USE_MOVE))
{ {
if (GetWhoStrikesFirst(battler1, battler2, FALSE)) u8 battler1 = gBattlerByTurnOrder[i];
SwapTurnOrder(i, j); u8 battler2 = gBattlerByTurnOrder[j];
}
else if ((gActionsByTurnOrder[i] == B_ACTION_SWITCH && gActionsByTurnOrder[j] == B_ACTION_SWITCH)) if (gProtectStructs[battler1].quash || gProtectStructs[battler2].quash)
{ continue;
if (GetWhoStrikesFirst(battler1, battler2, TRUE)) // If the actions chosen are switching, we recalc order but ignoring the moves
SwapTurnOrder(i, j); // We recalculate order only for action of the same priority. If any action other than switch/move has been taken, they should
// have been executed before. The only recalculation needed is for moves/switch. Mega evolution is handled in src/battle_main.c/TryChangeOrder
if((gActionsByTurnOrder[i] == B_ACTION_USE_MOVE && gActionsByTurnOrder[j] == B_ACTION_USE_MOVE))
{
if (GetWhoStrikesFirst(battler1, battler2, FALSE))
SwapTurnOrder(i, j);
}
else if ((gActionsByTurnOrder[i] == B_ACTION_SWITCH && gActionsByTurnOrder[j] == B_ACTION_SWITCH))
{
if (GetWhoStrikesFirst(battler1, battler2, TRUE)) // If the actions chosen are switching, we recalc order but ignoring the moves
SwapTurnOrder(i, j);
}
} }
} }
} }

View file

@ -8,7 +8,6 @@ ASSUMPTIONS
DOUBLE_BATTLE_TEST("After You makes the target move after user") DOUBLE_BATTLE_TEST("After You makes the target move after user")
{ {
if (B_RECALC_TURN_AFTER_ACTIONS >= GEN_8) KNOWN_FAILING; // #2615.
GIVEN { GIVEN {
PLAYER(SPECIES_WOBBUFFET) { Speed(4); } PLAYER(SPECIES_WOBBUFFET) { Speed(4); }
PLAYER(SPECIES_WYNAUT) { Speed(1); } PLAYER(SPECIES_WYNAUT) { Speed(1); }