From de0f94406a2cf235e833c0b3aeb7ebf038a5c80a Mon Sep 17 00:00:00 2001 From: Nopinou <140268269+Nopinou@users.noreply.github.com> Date: Sun, 11 Feb 2024 21:36:35 +0100 Subject: [PATCH] Add shouldDynamax & shouldTerastal bits to TrainerMon (#4169) --- include/data.h | 2 ++ src/battle_controller_opponent.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/data.h b/include/data.h index e80768f68c..4727dc605b 100644 --- a/include/data.h +++ b/include/data.h @@ -71,6 +71,8 @@ struct TrainerMon bool8 isShiny : 1; u8 dynamaxLevel : 4; bool8 gigantamaxFactor : 1; + bool8 shouldDynamax : 1; + bool8 shouldTerastal : 1; }; #define TRAINER_PARTY(partyArray) partyArray, .partySize = ARRAY_COUNT(partyArray) diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index aeb13ec9a5..c299b61c72 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -547,6 +547,9 @@ static void OpponentHandleChooseMove(u32 battler) default: { u16 chosenMove = moveInfo->moves[chosenMoveId]; + bool32 isSecondTrainer = (GetBattlerPosition(battler) == B_POSITION_OPPONENT_RIGHT) && (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) && !BATTLE_TWO_VS_ONE_OPPONENT; + u16 trainerId = isSecondTrainer ? gTrainerBattleOpponent_B : gTrainerBattleOpponent_A; + const struct TrainerMon *party = gTrainers[trainerId].party; if (GetBattlerMoveTargetType(battler, chosenMove) & (MOVE_TARGET_USER_OR_SELECTED | MOVE_TARGET_USER)) gBattlerTarget = battler; @@ -564,8 +567,8 @@ static void OpponentHandleChooseMove(u32 battler) // If opponent can Ultra Burst, do it. else if (CanUltraBurst(battler)) BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (RET_ULTRA_BURST) | (gBattlerTarget << 8)); - // If opponent can Dynamax and is on final Pokemon, do it. - else if (CanDynamax(battler) && CountAIAliveNonEggMonsExcept(gBattlerPartyIndexes[battler]) == 0) + // If opponent can Dynamax and is allowed in the partydata, do it. + else if (CanDynamax(battler) && party[isSecondTrainer ? gBattlerPartyIndexes[battler] - MULTI_PARTY_SIZE : gBattlerPartyIndexes[battler]].shouldDynamax) BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (RET_DYNAMAX) | (gBattlerTarget << 8)); else BtlController_EmitTwoReturnValues(battler, BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8));