diff --git a/data/battle_scripts_2.s b/data/battle_scripts_2.s index 9b26cbd0d..21a12d886 100644 --- a/data/battle_scripts_2.s +++ b/data/battle_scripts_2.s @@ -192,16 +192,30 @@ BattleScript_ActionWallyThrow: waitmessage B_WAIT_TIME_LONG end2 -BattleScript_TrainerSlideMsgRet:: +BattleScript_TrainerASlideMsgRet:: handletrainerslidemsg BS_SCRIPTING, 0 - trainerslidein 1 + trainerslidein B_POSITION_OPPONENT_LEFT handletrainerslidemsg BS_SCRIPTING, 1 waitstate - trainerslideout 1 - handletrainerslidemsg BS_SCRIPTING, 2 + trainerslideout B_POSITION_OPPONENT_LEFT waitstate + handletrainerslidemsg BS_SCRIPTING, 2 return -BattleScript_TrainerSlideMsgEnd2:: - call BattleScript_TrainerSlideMsgRet +BattleScript_TrainerASlideMsgEnd2:: + call BattleScript_TrainerASlideMsgRet + end2 + +BattleScript_TrainerBSlideMsgRet:: + handletrainerslidemsg BS_SCRIPTING, 0 + trainerslidein B_POSITION_OPPONENT_RIGHT + handletrainerslidemsg BS_SCRIPTING, 1 + waitstate + trainerslideout B_POSITION_OPPONENT_RIGHT + waitstate + handletrainerslidemsg BS_SCRIPTING, 2 + return + +BattleScript_TrainerBSlideMsgEnd2:: + call BattleScript_TrainerBSlideMsgRet end2 diff --git a/include/battle_message.h b/include/battle_message.h index 9f6905abd..19f8bc4ca 100644 --- a/include/battle_message.h +++ b/include/battle_message.h @@ -237,7 +237,7 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst); void BattlePutTextOnWindow(const u8 *text, u8 windowId); void SetPpNumbersPaletteInMoveSelection(void); u8 GetCurrentPpToMaxPpState(u8 currentPp, u8 maxPp); -bool32 ShouldDoTrainerSlide(u32 battlerId, u32 trainerId, u32 which); +u32 ShouldDoTrainerSlide(u32 battlerId, u32 which); // return 1 for TrainerA, 2 forTrainerB void ExpandBattleTextBuffPlaceholders(const u8 *src, u8 *dst); extern struct BattleMsgData *gBattleMsgDataPtr; diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 8c6b074c1..63c128ec5 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -295,8 +295,10 @@ extern const u8 BattleScript_MoveEffectClearSmog[]; extern const u8 BattleScript_SideStatusWoreOffReturn[]; extern const u8 BattleScript_MoveEffectSmackDown[]; extern const u8 BattleScript_MoveEffectFlameBurst[]; -extern const u8 BattleScript_TrainerSlideMsgRet[]; -extern const u8 BattleScript_TrainerSlideMsgEnd2[]; +extern const u8 BattleScript_TrainerASlideMsgRet[]; +extern const u8 BattleScript_TrainerASlideMsgEnd2[]; +extern const u8 BattleScript_TrainerBSlideMsgRet[]; +extern const u8 BattleScript_TrainerBSlideMsgEnd2[]; extern const u8 BattleScript_MoveEffectFeint[]; extern const u8 BattleScript_ProteanActivates[]; extern const u8 BattleScript_DazzlingProtected[]; diff --git a/src/battle_main.c b/src/battle_main.c index 6588d3c5e..96b2e90a5 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3866,8 +3866,8 @@ void BattleTurnPassed(void) BattleScriptExecute(BattleScript_PalacePrintFlavorText); else if (gBattleTypeFlags & BATTLE_TYPE_ARENA && gBattleStruct->arenaTurnCounter == 0) BattleScriptExecute(BattleScript_ArenaTurnBeginning); - else if (ShouldDoTrainerSlide(GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT), gTrainerBattleOpponent_A, TRAINER_SLIDE_LAST_LOW_HP)) - BattleScriptExecute(BattleScript_TrainerSlideMsgEnd2); + else if ((i = ShouldDoTrainerSlide(GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT), TRAINER_SLIDE_LAST_LOW_HP))) + BattleScriptExecute(i == 1 ? BattleScript_TrainerASlideMsgEnd2 : BattleScript_TrainerBSlideMsgEnd2); } u8 IsRunningFromBattleImpossible(void) diff --git a/src/battle_message.c b/src/battle_message.c index ec2527d84..4e49e39f1 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -3887,11 +3887,11 @@ static const struct TrainerSlide sTrainerSlides[] = */ }; -static u32 GetEnemyMonCount(bool32 onlyAlive) +static u32 GetEnemyMonCount(u32 firstId, u32 lastId, bool32 onlyAlive) { u32 i, count = 0; - for (i = 0; i < PARTY_SIZE; i++) + for (i = firstId; i < lastId; i++) { u32 species = GetMonData(&gEnemyParty[i], MON_DATA_SPECIES2, NULL); if (species != SPECIES_NONE @@ -3911,12 +3911,33 @@ static bool32 IsBattlerHpLow(u32 battler) return FALSE; } -bool32 ShouldDoTrainerSlide(u32 battlerId, u32 trainerId, u32 which) +u32 ShouldDoTrainerSlide(u32 battlerId, u32 which) { - s32 i; + u32 i, firstId, lastId, trainerId, retValue = 1; if (!(gBattleTypeFlags & BATTLE_TYPE_TRAINER) || GetBattlerSide(battlerId) != B_SIDE_OPPONENT) - return FALSE; + return 0; + + // Two opponents support. + if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) + { + if (gBattlerPartyIndexes[battlerId] >= 3) + { + firstId = 3, lastId = PARTY_SIZE; + trainerId = gTrainerBattleOpponent_B; + retValue = 2; + } + else + { + firstId = 0, lastId = 3; + trainerId = gTrainerBattleOpponent_A; + } + } + else + { + firstId = 0, lastId = PARTY_SIZE; + trainerId = gTrainerBattleOpponent_A; + } for (i = 0; i < ARRAY_COUNT(sTrainerSlides); i++) { @@ -3926,28 +3947,28 @@ bool32 ShouldDoTrainerSlide(u32 battlerId, u32 trainerId, u32 which) switch (which) { case TRAINER_SLIDE_LAST_SWITCHIN: - if (sTrainerSlides[i].msgLastSwitchIn != NULL && GetEnemyMonCount(TRUE) == 1) + if (sTrainerSlides[i].msgLastSwitchIn != NULL && !CanBattlerSwitch(battlerId)) { gBattleStruct->trainerSlideMsg = sTrainerSlides[i].msgLastSwitchIn; - return TRUE; + return retValue; } break; case TRAINER_SLIDE_LAST_LOW_HP: if (sTrainerSlides[i].msgLastLowHp != NULL - && GetEnemyMonCount(TRUE) == 1 + && GetEnemyMonCount(firstId, lastId, TRUE) == 1 && IsBattlerHpLow(battlerId) && !gBattleStruct->trainerSlideLowHpMsgDone) { gBattleStruct->trainerSlideLowHpMsgDone = TRUE; gBattleStruct->trainerSlideMsg = sTrainerSlides[i].msgLastLowHp; - return TRUE; + return retValue; } break; case TRAINER_SLIDE_FIRST_DOWN: - if (sTrainerSlides[i].msgFirstDown != NULL && GetEnemyMonCount(TRUE) == GetEnemyMonCount(FALSE) - 1) + if (sTrainerSlides[i].msgFirstDown != NULL && GetEnemyMonCount(firstId, lastId, TRUE) == GetEnemyMonCount(firstId, lastId, FALSE) - 1) { gBattleStruct->trainerSlideMsg = sTrainerSlides[i].msgFirstDown; - return TRUE; + return retValue; } break; } @@ -3955,5 +3976,5 @@ bool32 ShouldDoTrainerSlide(u32 battlerId, u32 trainerId, u32 which) } } - return FALSE; + return 0; } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 86db3c994..84a28804f 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -10109,7 +10109,8 @@ static void Cmd_various(void) VARIOUS_ARGS(u8 case_); if (cmd->case_ == 0) { - gBattleScripting.savedDmg = gBattlerSpriteIds[gActiveBattler]; + // Save sprite IDs, because trainer slide in will overwrite gBattlerSpriteIds variable. + gBattleScripting.savedDmg = (gBattlerSpriteIds[gActiveBattler] & 0xFF) | (gBattlerSpriteIds[BATTLE_PARTNER(gActiveBattler)] << 8); HideBattlerShadowSprite(gActiveBattler); } else if (cmd->case_ == 1) @@ -10119,12 +10120,19 @@ static void Cmd_various(void) } else { - gBattlerSpriteIds[gActiveBattler] = gBattleScripting.savedDmg; - if (gBattleMons[gActiveBattler].hp != 0) + gBattlerSpriteIds[BATTLE_PARTNER(gActiveBattler)] = gBattleScripting.savedDmg >> 8; + gBattlerSpriteIds[gActiveBattler] = gBattleScripting.savedDmg & 0xFF; + if (IsBattlerAlive(gActiveBattler)) { SetBattlerShadowSpriteCallback(gActiveBattler, gBattleMons[gActiveBattler].species); BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[gActiveBattler]], gActiveBattler); } + i = BATTLE_PARTNER(gActiveBattler); + if (IsBattlerAlive(i)) + { + SetBattlerShadowSpriteCallback(i, gBattleMons[i].species); + BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[i]], i); + } } gBattlescriptCurrInstr = cmd->nextInstr; return; @@ -10132,11 +10140,11 @@ static void Cmd_various(void) case VARIOUS_TRY_TRAINER_SLIDE_MSG_FIRST_OFF: { VARIOUS_ARGS(); - if (ShouldDoTrainerSlide(gActiveBattler, gTrainerBattleOpponent_A, TRAINER_SLIDE_FIRST_DOWN)) + if ((i = ShouldDoTrainerSlide(gActiveBattler, TRAINER_SLIDE_FIRST_DOWN))) { gBattleScripting.battler = gActiveBattler; BattleScriptPush(cmd->nextInstr); - gBattlescriptCurrInstr = BattleScript_TrainerSlideMsgRet; + gBattlescriptCurrInstr = (i == 1 ? BattleScript_TrainerASlideMsgRet : BattleScript_TrainerBSlideMsgRet); return; } break; @@ -10144,11 +10152,11 @@ static void Cmd_various(void) case VARIOUS_TRY_TRAINER_SLIDE_MSG_LAST_ON: { VARIOUS_ARGS(); - if (ShouldDoTrainerSlide(gActiveBattler, gTrainerBattleOpponent_A, TRAINER_SLIDE_LAST_SWITCHIN)) + if ((i = ShouldDoTrainerSlide(gActiveBattler, TRAINER_SLIDE_LAST_SWITCHIN))) { gBattleScripting.battler = gActiveBattler; BattleScriptPush(cmd->nextInstr); - gBattlescriptCurrInstr = BattleScript_TrainerSlideMsgRet; + gBattlescriptCurrInstr = (i == 1 ? BattleScript_TrainerASlideMsgRet : BattleScript_TrainerBSlideMsgRet); return; } break;