diff --git a/include/battle_anim.h b/include/battle_anim.h index 455bf5f4cd84..cac5ce9f8183 100644 --- a/include/battle_anim.h +++ b/include/battle_anim.h @@ -62,7 +62,7 @@ void MoveBattlerSpriteToBG(u8 battlerId, bool8 toBG_2, bool8 setSpriteInvisible) bool8 IsContest(void); s8 BattleAnimAdjustPanning(s8 pan); s8 BattleAnimAdjustPanning2(s8 pan); -s16 KeepPanInRange(s16 panArg, int oldPan); +s16 KeepPanInRange(s16 pan); s16 CalculatePanIncrement(s16 sourcePan, s16 targetPan, s16 incrementPan); void RelocateBattleBgPal(u16 paletteNum, u16 *dest, u32 offset, bool8 largeScreen); void ResetBattleAnimBg(bool8); diff --git a/src/battle_anim.c b/src/battle_anim.c index e6e049c37051..111decbcb185 100644 --- a/src/battle_anim.c +++ b/src/battle_anim.c @@ -1319,10 +1319,8 @@ s8 BattleAnimAdjustPanning2(s8 pan) return pan; } -s16 KeepPanInRange(s16 panArg, int oldPan) +s16 KeepPanInRange(s16 pan) { - s16 pan = panArg; - if (pan > SOUND_PAN_TARGET) pan = SOUND_PAN_TARGET; else if (pan < SOUND_PAN_ATTACKER) @@ -1336,9 +1334,9 @@ s16 CalculatePanIncrement(s16 sourcePan, s16 targetPan, s16 incrementPan) s16 ret; if (sourcePan < targetPan) - ret = ((incrementPan < 0) ? -incrementPan : incrementPan); + ret = abs(incrementPan); else if (sourcePan > targetPan) - ret = -((incrementPan < 0) ? -incrementPan : incrementPan); + ret = -abs(incrementPan); else ret = 0; diff --git a/src/battle_anim_sound_tasks.c b/src/battle_anim_sound_tasks.c index 1fde3a982394..6d48465a1e95 100644 --- a/src/battle_anim_sound_tasks.c +++ b/src/battle_anim_sound_tasks.c @@ -57,7 +57,7 @@ static void SoundTask_FireBlast_Step1(u8 taskId) PlaySE12WithPanning(gTasks[taskId].data[0], pan); } pan += panIncrement; - gTasks[taskId].data[2] = KeepPanInRange(pan, panIncrement); + gTasks[taskId].data[2] = KeepPanInRange(pan); } } @@ -78,13 +78,14 @@ static void SoundTask_FireBlast_Step2(u8 taskId) void SoundTask_LoopSEAdjustPanning(u8 taskId) { u16 songId = gBattleAnimArgs[0]; + s8 sourcePan = gBattleAnimArgs[1]; s8 targetPan = gBattleAnimArgs[2]; s8 panIncrement = gBattleAnimArgs[3]; u8 r10 = gBattleAnimArgs[4]; u8 r7 = gBattleAnimArgs[5]; u8 r9 = gBattleAnimArgs[6]; - s8 sourcePan = BattleAnimAdjustPanning(gBattleAnimArgs[1]); + sourcePan = BattleAnimAdjustPanning(sourcePan); targetPan = BattleAnimAdjustPanning(targetPan); panIncrement = CalculatePanIncrement(sourcePan, targetPan, panIncrement); @@ -105,6 +106,8 @@ void SoundTask_LoopSEAdjustPanning(u8 taskId) static void SoundTask_LoopSEAdjustPanning_Step(u8 taskId) { + s8 unusedVar = gTasks[taskId].data[3]; + if (gTasks[taskId].data[12]++ == gTasks[taskId].data[6]) { gTasks[taskId].data[12] = 0; @@ -118,12 +121,9 @@ static void SoundTask_LoopSEAdjustPanning_Step(u8 taskId) if (gTasks[taskId].data[10]++ == gTasks[taskId].data[5]) { - u16 dPan, oldPan; gTasks[taskId].data[10] = 0; - dPan = gTasks[taskId].data[3]; - oldPan = gTasks[taskId].data[11]; - gTasks[taskId].data[11] = dPan + oldPan; - gTasks[taskId].data[11] = KeepPanInRange(gTasks[taskId].data[11], oldPan); + gTasks[taskId].data[11] += gTasks[taskId].data[3]; + gTasks[taskId].data[11] = KeepPanInRange(gTasks[taskId].data[11]); } } @@ -369,11 +369,12 @@ void SoundTask_PlaySE2WithPanning(u8 taskId) // Used by Confuse Ray and Will-O-Wisp (see uses of gAnimCustomPanning) void SoundTask_AdjustPanningVar(u8 taskId) { + s8 sourcePan = gBattleAnimArgs[0]; s8 targetPan = gBattleAnimArgs[1]; s8 panIncrement = gBattleAnimArgs[2]; - u16 r9 = gBattleAnimArgs[3]; - s8 sourcePan = BattleAnimAdjustPanning(gBattleAnimArgs[0]); + s16 r9 = gBattleAnimArgs[3]; + sourcePan = BattleAnimAdjustPanning(sourcePan); targetPan = BattleAnimAdjustPanning(targetPan); panIncrement = CalculatePanIncrement(sourcePan, targetPan, panIncrement); @@ -390,15 +391,13 @@ void SoundTask_AdjustPanningVar(u8 taskId) static void SoundTask_AdjustPanningVar_Step(u8 taskId) { - u16 panIncrement = gTasks[taskId].data[3]; + s8 unusedVar = gTasks[taskId].data[3]; if (gTasks[taskId].data[10]++ == gTasks[taskId].data[5]) { - u16 oldPan; gTasks[taskId].data[10] = 0; - oldPan = gTasks[taskId].data[11]; - gTasks[taskId].data[11] = panIncrement + oldPan; - gTasks[taskId].data[11] = KeepPanInRange(gTasks[taskId].data[11], oldPan); + gTasks[taskId].data[11] += gTasks[taskId].data[3]; + gTasks[taskId].data[11] = KeepPanInRange(gTasks[taskId].data[11]); } gAnimCustomPanning = gTasks[taskId].data[11];