From f56df74576e00bad04eae031b6f119dfd06178c7 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Fri, 4 Nov 2022 11:51:34 -0300 Subject: [PATCH] Optimized Bad Dreams' code Misc: -Made the ability pop up stick around until the ability's effect ends just like in ORAS. -Updated sText_BadDreamsDmg accordingly while I was at it. --- asm/macros/battle_script.inc | 2 +- data/battle_scripts_1.s | 31 ++++++++++++++++++++----------- src/battle_message.c | 2 +- src/battle_script_commands.c | 20 +++----------------- src/battle_util.c | 10 ++-------- 5 files changed, 27 insertions(+), 38 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 23884f6e4..e4e5af2e2 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1290,7 +1290,7 @@ .4byte \ptr .endm - .macro trygetbaddreamstarget ptr:req + .macro unused ptr:req .byte 0xfd .4byte \ptr .endm diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index f213b52e1..890cd9c54 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -8358,24 +8358,33 @@ BattleScript_PsychicSurgeActivates:: call BattleScript_TerrainSeedLoop end3 -BattleScript_BadDreamsActivates:: - setbyte gBattlerTarget, 0 - call BattleScript_AbilityPopUp -BattleScript_BadDreamsLoop: - trygetbaddreamstarget BattleScript_BadDreamsEnd - dmg_1_8_targethp +BattleScript_HurtTarget_NoString: orword gHitMarker, HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_PASSIVE_DAMAGE - printstring STRINGID_BADDREAMSDMG - waitmessage B_WAIT_TIME_LONG - jumpifability BS_TARGET, ABILITY_MAGIC_GUARD, BattleScript_BadDreamsIncrement healthbarupdate BS_TARGET datahpupdate BS_TARGET tryfaintmon BS_TARGET - checkteamslost BattleScript_BadDreamsIncrement + return + +BattleScript_BadDreamsActivates:: + call BattleScript_AbilityPopUp + setbyte sFIXED_ABILITY_POPUP, TRUE + setbyte gBattlerTarget, 0 +BattleScript_BadDreamsLoop: + jumpiftargetally BattleScript_BadDreamsIncrement + jumpifability BS_TARGET, ABILITY_MAGIC_GUARD, BattleScript_BadDreamsIncrement + jumpifability BS_TARGET, ABILITY_COMATOSE, BattleScript_BadDreams_Dmg + jumpifstatus BS_TARGET, STATUS1_SLEEP, BattleScript_BadDreams_Dmg + goto BattleScript_BadDreamsIncrement +BattleScript_BadDreams_Dmg: + printstring STRINGID_BADDREAMSDMG + waitmessage B_WAIT_TIME_LONG + dmg_1_8_targethp + call BattleScript_HurtTarget_NoString BattleScript_BadDreamsIncrement: addbyte gBattlerTarget, 1 - goto BattleScript_BadDreamsLoop + jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_BadDreamsLoop BattleScript_BadDreamsEnd: + destroyabilitypopup end3 BattleScript_TookAttack:: diff --git a/src/battle_message.c b/src/battle_message.c index 568aac774..9503fbaaf 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -589,7 +589,7 @@ static const u8 sText_PsychicTerrainEnds[] = _("The weirdness disappeared\nfrom static const u8 sText_GrassyTerrainEnds[] = _("The grass disappeared\nfrom the battlefield."); static const u8 sText_TargetsStatWasMaxedOut[] = _("{B_DEF_NAME_WITH_PREFIX}'s {B_DEF_ABILITY} maxed\nits {B_BUFF1}!"); static const u8 sText_PoisonHealHpUp[] = _("The poisoning healed {B_ATK_NAME_WITH_PREFIX}\na little bit!"); -static const u8 sText_BadDreamsDmg[] = _("{B_DEF_NAME_WITH_PREFIX} is tormented\nby {B_ATK_ABILITY}!"); +static const u8 sText_BadDreamsDmg[] = _("{B_DEF_NAME_WITH_PREFIX} is tormented!"); static const u8 sText_MoldBreakerEnters[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} breaks the mold!"); static const u8 sText_TeravoltEnters[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} is radiating \na bursting aura!"); static const u8 sText_TurboblazeEnters[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} is radiating\na blazing aura!"); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 9646b59b6..5504bfe03 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -573,7 +573,7 @@ static void Cmd_settelekinesis(void); static void Cmd_swapstatstages(void); static void Cmd_averagestats(void); static void Cmd_jumpifoppositegenders(void); -static void Cmd_trygetbaddreamstarget(void); +static void Cmd_unused(void); static void Cmd_tryworryseed(void); static void Cmd_metalburstdamagecalculator(void); @@ -832,7 +832,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_swapstatstages, //0xFA Cmd_averagestats, //0xFB Cmd_jumpifoppositegenders, //0xFC - Cmd_trygetbaddreamstarget, //0xFD + Cmd_unused, //0xFD Cmd_tryworryseed, //0xFE Cmd_metalburstdamagecalculator, //0xFF }; @@ -14730,22 +14730,8 @@ static void Cmd_jumpifoppositegenders(void) gBattlescriptCurrInstr += 5; } -static void Cmd_trygetbaddreamstarget(void) +static void Cmd_unused(void) { - u8 badDreamsMonSide = GetBattlerSide(gBattlerAttacker); - for (;gBattlerTarget < gBattlersCount; gBattlerTarget++) - { - if (GetBattlerSide(gBattlerTarget) == badDreamsMonSide) - continue; - if ((gBattleMons[gBattlerTarget].status1 & STATUS1_SLEEP || GetBattlerAbility(gBattlerTarget) == ABILITY_COMATOSE) - && IsBattlerAlive(gBattlerTarget)) - break; - } - - if (gBattlerTarget >= gBattlersCount) - gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1); - else - gBattlescriptCurrInstr += 5; } static void Cmd_tryworryseed(void) diff --git a/src/battle_util.c b/src/battle_util.c index 98e8bbfd2..5c5a35a38 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -5003,14 +5003,8 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move gDisableStructs[gBattlerAttacker].truantCounter ^= 1; break; case ABILITY_BAD_DREAMS: - if (gBattleMons[BATTLE_PARTNER(BATTLE_OPPOSITE(battler))].status1 & STATUS1_SLEEP - || gBattleMons[BATTLE_OPPOSITE(battler)].status1 & STATUS1_SLEEP - || GetBattlerAbility(BATTLE_PARTNER(BATTLE_OPPOSITE(battler))) == ABILITY_COMATOSE - || GetBattlerAbility(BATTLE_OPPOSITE(battler)) == ABILITY_COMATOSE) - { - BattleScriptPushCursorAndCallback(BattleScript_BadDreamsActivates); - effect++; - } + BattleScriptPushCursorAndCallback(BattleScript_BadDreamsActivates); + effect++; break; SOLAR_POWER_HP_DROP: case ABILITY_SOLAR_POWER: