From 95eb3ba1a7e36166e507a67ab2cdde3df3c59f70 Mon Sep 17 00:00:00 2001 From: hedara90 <90hedara@gmail.com> Date: Thu, 21 Aug 2025 14:43:41 +0200 Subject: [PATCH] Fix B_ANIMATE_MON_AFTER_KO with a new counter (#7531) Co-authored-by: Hedara Co-authored-by: Martin Griffin --- data/battle_scripts_1.s | 6 ++++++ include/battle.h | 2 +- src/battle_controllers.c | 2 ++ src/battle_script_commands.c | 2 +- src/pokemon_animation.c | 5 +++++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 2b086fd1d6..6d20887fb4 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -5232,6 +5232,7 @@ BattleScript_FaintAttacker:: dofaintanimation BS_ATTACKER printstring STRINGID_ATTACKERFAINTED cleareffectsonfaint BS_ATTACKER + waitanimation tryactivatesoulheart tryactivatereceiver BS_ATTACKER trytrainerslidefirstdownmsg BS_ATTACKER @@ -5246,6 +5247,7 @@ BattleScript_FaintTarget:: dofaintanimation BS_TARGET printstring STRINGID_TARGETFAINTED cleareffectsonfaint BS_TARGET + waitanimation tryactivatesoulheart tryactivatereceiver BS_TARGET trytrainerslidefirstdownmsg BS_TARGET @@ -8980,6 +8982,7 @@ BattleScript_ArenaDoJudgment:: waitcry BS_ATTACKER dofaintanimation BS_OPPONENT1 cleareffectsonfaint BS_OPPONENT1 + waitanimation arenaopponentmonlost end2 @@ -8994,6 +8997,7 @@ BattleScript_ArenaJudgmentPlayerLoses: waitcry BS_ATTACKER dofaintanimation BS_PLAYER1 cleareffectsonfaint BS_PLAYER1 + waitanimation arenaplayermonlost end2 @@ -9008,10 +9012,12 @@ BattleScript_ArenaJudgmentDraw: waitcry BS_ATTACKER dofaintanimation BS_PLAYER1 cleareffectsonfaint BS_PLAYER1 + waitanimation playfaintcry BS_OPPONENT1 waitcry BS_ATTACKER dofaintanimation BS_OPPONENT1 cleareffectsonfaint BS_OPPONENT1 + waitanimation arenabothmonlost end2 diff --git a/include/battle.h b/include/battle.h index cd3126ba6b..23002e91c5 100644 --- a/include/battle.h +++ b/include/battle.h @@ -687,7 +687,7 @@ struct BattleStruct u8 startingStatusDone:1; u8 terrainDone:1; u8 overworldWeatherDone:1; - u8 unused:3; + u8 battlerKOAnimsRunning:3; u8 isAtkCancelerForCalledMove:1; // Certain cases in atk canceler should only be checked once, when the original move is called, however others need to be checked the twice. u8 friskedAbility:1; // If identifies two mons, show the ability pop-up only once. u8 fickleBeamBoosted:1; diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 9bee760800..885b2a922a 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -3122,6 +3122,8 @@ static void LaunchKOAnimation(u32 battlerId, u16 animId, bool32 isFront) u32 species = GetBattlerVisualSpecies(battlerId); u32 spriteId = gBattlerSpriteIds[battlerId]; + gBattleStruct->battlerKOAnimsRunning++; + if (isFront) { LaunchAnimationTaskForFrontSprite(&gSprites[spriteId], animId); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 80a5ad664e..b1cab2f717 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -2558,7 +2558,7 @@ static void Cmd_waitanimation(void) { CMD_ARGS(); - if (gBattleControllerExecFlags == 0) + if (gBattleControllerExecFlags == 0 && gBattleStruct->battlerKOAnimsRunning == 0) gBattlescriptCurrInstr = cmd->nextInstr; } diff --git a/src/pokemon_animation.c b/src/pokemon_animation.c index 41bc400105..7f28bff4ce 100644 --- a/src/pokemon_animation.c +++ b/src/pokemon_animation.c @@ -523,6 +523,11 @@ static void Task_HandleMonAnimation(u8 taskId) sprite->data[2] = gTasks[taskId].tSpeciesId; sprite->data[1] = 0; + // Task_HandleMonAnimation handles more than just KO animations, + // but if the counter is non-zero then only KO animations are running. + // This assumption is not checked. + if (gBattleStruct->battlerKOAnimsRunning > 0) + gBattleStruct->battlerKOAnimsRunning--; DestroyTask(taskId); } }