From 5a740c7461fd7652dea077f1e6894b7e0a878ef0 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Mon, 27 Feb 2023 22:18:42 -0500 Subject: [PATCH 1/2] dont overwrite gbattlerAttacker in TryChangeBattleTerrain, update BattleScript_ActivateTerrainAbilities loop iterator --- data/battle_scripts_1.s | 10 +++++----- src/battle_util.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index e8b751777bd1..f8e24cb91ac7 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -8803,14 +8803,14 @@ BattleScript_ActivateSwitchInAbilities_Increment: return BattleScript_ActivateTerrainAbilities: - copybyte sBATTLER, gBattlerAttacker - setbyte gBattlerAttacker, 0 + savetarget + setbyte gBattlerTarget, 0 BattleScript_ActivateTerrainAbilities_Loop: activateterrainchangeabilities BS_ATTACKER BattleScript_ActivateTerrainAbilities_Increment: - addbyte gBattlerAttacker, 1 - jumpifbytenotequal gBattlerAttacker, gBattlersCount, BattleScript_ActivateTerrainAbilities_Loop - copybyte gBattlerAttacker, sBATTLER + addbyte gBattlerTarget, 1 + jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_ActivateTerrainAbilities_Loop + restoretarget return BattleScript_ElectricSurgeActivates:: diff --git a/src/battle_util.c b/src/battle_util.c index 1625ff919c3f..fc30547e6079 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -4205,7 +4205,7 @@ static bool32 TryChangeBattleTerrain(u32 battler, u32 statusFlag, u8 *timer) else *timer = 5; - gBattlerAttacker = gBattleScripting.battler = battler; + gBattleScripting.battler = battler; return TRUE; } From b399d1e8c5529fc311c93c281a4a8eea51ccfd77 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Mon, 27 Feb 2023 22:29:23 -0500 Subject: [PATCH 2/2] fix ABILITYEFFECT_ON_TERRAIN battler Id settings --- src/battle_util.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/battle_util.c b/src/battle_util.c index fc30547e6079..ddc3eaa1a2f1 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -6230,7 +6230,6 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move } break; case ABILITYEFFECT_ON_TERRAIN: // For ability effects that activate when the field terrain changes. - battler = gBattlerAbility = gBattleScripting.battler; gLastUsedAbility = GetBattlerAbility(battler); switch (gLastUsedAbility) { @@ -6239,6 +6238,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move { gSpecialStatuses[battler].terrainAbilityDone = TRUE; ChangeTypeBasedOnTerrain(battler); + gBattlerAbility = gBattleScripting.battler = battler; BattleScriptPushCursorAndCallback(BattleScript_MimicryActivates_End3); effect++; } @@ -6247,6 +6247,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move if (!gSpecialStatuses[battler].terrainAbilityDone && IsBattlerTerrainAffected(battler, STATUS_FIELD_ELECTRIC_TERRAIN)) { gSpecialStatuses[battler].terrainAbilityDone = TRUE; + gBattlerAbility = gBattleScripting.battler = battler; PREPARE_STAT_BUFFER(gBattleTextBuff1, GetHighestStatId(battler)); BattleScriptPushCursorAndCallback(BattleScript_QuarkDriveActivates); effect++;