From 81d9faaaaa9ed394caf0766851088aaaf7c24c63 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 15 Feb 2023 12:35:09 +0100 Subject: [PATCH 1/4] Fix Explosion and Mind Blown --- data/battle_scripts_1.s | 40 +++++++++++++++++++++--------------- src/battle_script_commands.c | 23 ++++++++++----------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index c404dc37d7f0..3cfb3484a251 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -3370,15 +3370,14 @@ BattleScript_EffectExplosion:: ppreduce @ Below jumps to BattleScript_DampStopsExplosion if it fails (only way it can) tryexplosion - setatkhptozero waitstate - jumpifbyte CMP_NO_COMMON_BITS, gMoveResultFlags, MOVE_RESULT_MISSED, BattleScript_ExplosionDoAnimStartLoop + jumpifbyte CMP_NO_COMMON_BITS, gMoveResultFlags, MOVE_RESULT_MISSED, BattleScript_ExplosionAnim call BattleScript_PreserveMissedBitDoMoveAnim - goto BattleScript_ExplosionLoop -BattleScript_ExplosionDoAnimStartLoop: + goto BattleScript_ExplosionDmg +BattleScript_ExplosionAnim: attackanimation waitanimation -BattleScript_ExplosionLoop: +BattleScript_ExplosionDmg: movevaluescleanup critcalc damagecalc @@ -3394,32 +3393,41 @@ BattleScript_ExplosionLoop: resultmessage waitmessage B_WAIT_TIME_LONG tryfaintmon BS_TARGET - moveendto MOVEEND_NEXT_TARGET - jumpifnexttargetvalid BattleScript_ExplosionLoop +BattleScript_ExplosionEnd: + moveendall +@Because Mind Blown also uses this battlescript, we have to ignore the setting hp to zero command + jumpifmove MOVE_MIND_BLOWN BattleScript_ExplosionTryFaint + setatkhptozero +BattleScript_ExplosionTryFaint: tryfaintmon BS_ATTACKER - moveendcase MOVEEND_CLEAR_BITS end BattleScript_ExplosionMissed: effectivenesssound resultmessage waitmessage B_WAIT_TIME_LONG - moveendto MOVEEND_NEXT_TARGET - jumpifnexttargetvalid BattleScript_ExplosionLoop - tryfaintmon BS_ATTACKER - end + goto BattleScript_ExplosionEnd BattleScript_EffectMindBlown:: attackcanceler + jumpifword CMP_COMMON_BITS, gHitMarker, HITMARKER_NO_ATTACKSTRING | HITMARKER_NO_PPDEDUCT, BattleScript_MindBlownNoHpLoss attackstring ppreduce - tryexplosion + jumpifabilitypresent ABILITY_DAMP, BattleScript_MindBlownDump dmg_1_2_attackerhp healthbarupdate BS_ATTACKER datahpupdate BS_ATTACKER +BattleScript_MindBlownAfterHpLoss: waitstate - jumpifbyte CMP_NO_COMMON_BITS, gMoveResultFlags, MOVE_RESULT_MISSED, BattleScript_ExplosionDoAnimStartLoop + jumpifbyte CMP_NO_COMMON_BITS, gMoveResultFlags, MOVE_RESULT_MISSED, BattleScript_ExplosionAnim call BattleScript_PreserveMissedBitDoMoveAnim - goto BattleScript_ExplosionLoop + goto BattleScript_ExplosionDmg +BattleScript_MindBlownNoHpLoss: + attackstring + ppreduce + goto BattleScript_MindBlownAfterHpLoss +BattleScript_MindBlownDump: + copybyte gBattlerTarget, sBATTLER + goto BattleScript_DampStopsExplosion BattleScript_PreserveMissedBitDoMoveAnim: bichalfword gMoveResultFlags, MOVE_RESULT_MISSED @@ -8301,9 +8309,9 @@ BattleScript_AbilityRaisesDefenderStat:: BattleScript_AbilityPopUp: .if B_ABILITY_POP_UP == TRUE showabilitypopup BS_ABILITY_BATTLER - recordability BS_ABILITY_BATTLER pause 40 .endif + recordability BS_ABILITY_BATTLER sethword sABILITY_OVERWRITE, 0 return diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index d1c0a7c77314..b21561596966 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -4848,10 +4848,16 @@ static void Cmd_setroost(void) static void Cmd_jumpifabilitypresent(void) { - if (IsAbilityOnField(T1_READ_16(gBattlescriptCurrInstr + 1))) + u32 abilityBattler = IsAbilityOnField(T1_READ_16(gBattlescriptCurrInstr + 1)); + if (abilityBattler) + { gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); + gBattleScripting.battler = abilityBattler - 1; + } else + { gBattlescriptCurrInstr += 7; + } } static void Cmd_endselectionscript(void) @@ -10387,14 +10393,15 @@ static void Cmd_setprotectlike(void) static void Cmd_tryexplosion(void) { + u32 dampBattler; if (gBattleControllerExecFlags) return; - if ((gBattlerTarget = IsAbilityOnField(ABILITY_DAMP))) + if ((dampBattler = IsAbilityOnField(ABILITY_DAMP))) { // Failed, a battler has Damp gLastUsedAbility = ABILITY_DAMP; - RecordAbilityBattle(--gBattlerTarget, ABILITY_DAMP); + gBattlerTarget = --dampBattler; gBattlescriptCurrInstr = BattleScript_DampStopsExplosion; return; } @@ -10404,14 +10411,6 @@ static void Cmd_tryexplosion(void) BtlController_EmitHealthBarUpdate(BUFFER_A, INSTANT_HP_BAR_DROP); MarkBattlerForControllerExec(gActiveBattler); gBattlescriptCurrInstr++; - - for (gBattlerTarget = 0; gBattlerTarget < gBattlersCount; gBattlerTarget++) - { - if (gBattlerTarget == gBattlerAttacker) - continue; - if (IsBattlerAlive(gBattlerTarget)) - break; - } } static void Cmd_setatkhptozero(void) @@ -14965,7 +14964,7 @@ static void Cmd_callnative(void) func(); } -// Callnative Funcs +// Callnative Funcs void BS_CalcMetalBurstDmg(void) { u8 sideAttacker = GetBattlerSide(gBattlerAttacker); From 724251447787a54e0ca457429bca4112eeb49f3a Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 15 Feb 2023 23:49:02 +0100 Subject: [PATCH 2/4] use battler ability in jumpifabilitypresent --- data/battle_scripts_1.s | 5 +---- src/battle_script_commands.c | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 3cfb3484a251..d6bdbaaf6523 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -3412,7 +3412,7 @@ BattleScript_EffectMindBlown:: jumpifword CMP_COMMON_BITS, gHitMarker, HITMARKER_NO_ATTACKSTRING | HITMARKER_NO_PPDEDUCT, BattleScript_MindBlownNoHpLoss attackstring ppreduce - jumpifabilitypresent ABILITY_DAMP, BattleScript_MindBlownDump + jumpifabilitypresent ABILITY_DAMP, BattleScript_DampStopsExplosion dmg_1_2_attackerhp healthbarupdate BS_ATTACKER datahpupdate BS_ATTACKER @@ -3425,9 +3425,6 @@ BattleScript_MindBlownNoHpLoss: attackstring ppreduce goto BattleScript_MindBlownAfterHpLoss -BattleScript_MindBlownDump: - copybyte gBattlerTarget, sBATTLER - goto BattleScript_DampStopsExplosion BattleScript_PreserveMissedBitDoMoveAnim: bichalfword gMoveResultFlags, MOVE_RESULT_MISSED diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index b21561596966..58184d729ea0 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -4852,7 +4852,7 @@ static void Cmd_jumpifabilitypresent(void) if (abilityBattler) { gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); - gBattleScripting.battler = abilityBattler - 1; + gBattlerAbility = abilityBattler - 1; } else { From 8259468891deb556752f159a67da63106b37476f Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Thu, 16 Feb 2023 09:34:02 +0100 Subject: [PATCH 3/4] Fix pop-up on Mind Blown --- data/battle_scripts_1.s | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index d6bdbaaf6523..0cbd96b8ed82 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -3412,7 +3412,7 @@ BattleScript_EffectMindBlown:: jumpifword CMP_COMMON_BITS, gHitMarker, HITMARKER_NO_ATTACKSTRING | HITMARKER_NO_PPDEDUCT, BattleScript_MindBlownNoHpLoss attackstring ppreduce - jumpifabilitypresent ABILITY_DAMP, BattleScript_DampStopsExplosion + jumpifabilitypresent ABILITY_DAMP, BattleScript_MindBlownDamp dmg_1_2_attackerhp healthbarupdate BS_ATTACKER datahpupdate BS_ATTACKER @@ -3425,6 +3425,9 @@ BattleScript_MindBlownNoHpLoss: attackstring ppreduce goto BattleScript_MindBlownAfterHpLoss +BattleScript_MindBlownDamp: + copybyte gBattlerTarget, gBattlerAbility + goto BattleScript_DampStopsExplosion BattleScript_PreserveMissedBitDoMoveAnim: bichalfword gMoveResultFlags, MOVE_RESULT_MISSED From c4fe45ed35146bbc2542bcfa16d3374fdccb8f88 Mon Sep 17 00:00:00 2001 From: Martin Griffin Date: Tue, 21 Feb 2023 22:40:46 +0000 Subject: [PATCH 4/4] Apply suggestions from code review --- test/ability_damp.c | 2 +- test/ability_volt_absorb.c | 4 ++-- test/move_effect_explosion.c | 8 ++++---- test/move_effect_mind_blown.c | 24 ++++++++++++------------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/ability_damp.c b/test/ability_damp.c index b4adebbead24..c473660f5c74 100644 --- a/test/ability_damp.c +++ b/test/ability_damp.c @@ -27,7 +27,7 @@ DOUBLE_BATTLE_TEST("Damp prevents explosion-like moves from enemies in a double PARAMETRIZE { move = MOVE_MIND_BLOWN; } PARAMETRIZE { move = MOVE_MISTY_EXPLOSION; } GIVEN { - PLAYER(SPECIES_PARAS) { Ability(ABILITY_DAMP); }; + PLAYER(SPECIES_PARAS) { Ability(ABILITY_DAMP); } PLAYER(SPECIES_WOBBUFFET); OPPONENT(SPECIES_WOBBUFFET); OPPONENT(SPECIES_WOBBUFFET); diff --git a/test/ability_volt_absorb.c b/test/ability_volt_absorb.c index dc27f4cc7404..bef35e2b4b00 100644 --- a/test/ability_volt_absorb.c +++ b/test/ability_volt_absorb.c @@ -68,9 +68,9 @@ DOUBLE_BATTLE_TEST("Volt Absorb does not stop Electric Typed Explosion from dama GIVEN { ASSUME(gBattleMoves[MOVE_EXPLOSION].effect == EFFECT_EXPLOSION); ASSUME(gBattleMoves[MOVE_EXPLOSION].type == TYPE_NORMAL); - PLAYER(SPECIES_JOLTEON) { Ability(ABILITY_VOLT_ABSORB); HP(1); MaxHP(TEST_MAX_HP); }; + PLAYER(SPECIES_JOLTEON) { Ability(ABILITY_VOLT_ABSORB); HP(1); MaxHP(TEST_MAX_HP); } PLAYER(SPECIES_ABRA); - OPPONENT(SPECIES_GRAVELER_ALOLAN) { Ability(ABILITY_GALVANIZE); }; + OPPONENT(SPECIES_GRAVELER_ALOLAN) { Ability(ABILITY_GALVANIZE); } OPPONENT(SPECIES_WYNAUT); } WHEN { TURN { MOVE(opponentLeft, MOVE_EXPLOSION); } diff --git a/test/move_effect_explosion.c b/test/move_effect_explosion.c index 3cedd1d8711d..41e74044ba2b 100644 --- a/test/move_effect_explosion.c +++ b/test/move_effect_explosion.c @@ -24,7 +24,7 @@ SINGLE_BATTLE_TEST("Explosion causes the user & the target to faint") { GIVEN { PLAYER(SPECIES_WOBBUFFET); - OPPONENT(SPECIES_WOBBUFFET) { HP(1); } ; + OPPONENT(SPECIES_WOBBUFFET) { HP(1); } OPPONENT(SPECIES_WOBBUFFET); } WHEN { TURN { MOVE(player, MOVE_EXPLOSION); } @@ -73,9 +73,9 @@ DOUBLE_BATTLE_TEST("Explosion causes everyone to faint in a double battle") { GIVEN { PLAYER(SPECIES_WOBBUFFET); - PLAYER(SPECIES_WYNAUT) { HP(1); } ; - OPPONENT(SPECIES_ABRA) { HP(1); } ; - OPPONENT(SPECIES_KADABRA) { HP(1); } ; + PLAYER(SPECIES_WYNAUT) { HP(1); } + OPPONENT(SPECIES_ABRA) { HP(1); } + OPPONENT(SPECIES_KADABRA) { HP(1); } OPPONENT(SPECIES_KADABRA); } WHEN { TURN { MOVE(playerLeft, MOVE_EXPLOSION); } diff --git a/test/move_effect_mind_blown.c b/test/move_effect_mind_blown.c index 9a18b44e4ad3..6b053cfb5662 100644 --- a/test/move_effect_mind_blown.c +++ b/test/move_effect_mind_blown.c @@ -11,7 +11,7 @@ ASSUMPTIONS SINGLE_BATTLE_TEST("Mind Blown makes the user lose 1/2 of its HP") { GIVEN { - PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST) ; MaxHP(HP_TEST) ;} ; + PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST); MaxHP(HP_TEST); } OPPONENT(SPECIES_WOBBUFFET); } WHEN { TURN { MOVE(player, MOVE_MIND_BLOWN); } @@ -25,7 +25,7 @@ SINGLE_BATTLE_TEST("Mind Blown makes the user lose 1/2 of its HP") DOUBLE_BATTLE_TEST("Mind Blown makes the user lose 1/2 of its HP in a double battle") { GIVEN { - PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST) ; MaxHP(HP_TEST) ;} ; + PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST); MaxHP(HP_TEST); } PLAYER(SPECIES_WOBBUFFET); OPPONENT(SPECIES_WOBBUFFET); OPPONENT(SPECIES_WOBBUFFET); @@ -41,10 +41,10 @@ DOUBLE_BATTLE_TEST("Mind Blown makes the user lose 1/2 of its HP in a double bat SINGLE_BATTLE_TEST("Mind Blown causes the user to faint when below 1/2 of its HP") { GIVEN { - PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST / 2) ; MaxHP(HP_TEST) ;} ; + PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST / 2); MaxHP(HP_TEST); } OPPONENT(SPECIES_WOBBUFFET); } WHEN { - TURN { MOVE(player, MOVE_MIND_BLOWN);} + TURN { MOVE(player, MOVE_MIND_BLOWN); } } SCENE { HP_BAR(player, hp: 0); ANIMATION(ANIM_TYPE_MOVE, MOVE_MIND_BLOWN, player); @@ -55,7 +55,7 @@ SINGLE_BATTLE_TEST("Mind Blown causes the user to faint when below 1/2 of its HP DOUBLE_BATTLE_TEST("Mind Blown causes the user to faint when below 1/2 of its HP in a double battle") { GIVEN { - PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST / 2) ; MaxHP(HP_TEST) ;} ; + PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST / 2); MaxHP(HP_TEST); } PLAYER(SPECIES_WOBBUFFET); OPPONENT(SPECIES_WOBBUFFET); OPPONENT(SPECIES_WOBBUFFET); @@ -71,8 +71,8 @@ DOUBLE_BATTLE_TEST("Mind Blown causes the user to faint when below 1/2 of its HP SINGLE_BATTLE_TEST("Mind Blown causes the user & the target to faint when below 1/2 of its HP") { GIVEN { - PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST / 2) ; MaxHP(HP_TEST) ;} ; - OPPONENT(SPECIES_WOBBUFFET) { HP(1); } ; + PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST / 2) ; MaxHP(HP_TEST); } + OPPONENT(SPECIES_WOBBUFFET) { HP(1); } OPPONENT(SPECIES_WOBBUFFET); } WHEN { TURN { MOVE(player, MOVE_MIND_BLOWN);} @@ -88,13 +88,13 @@ SINGLE_BATTLE_TEST("Mind Blown causes the user & the target to faint when below DOUBLE_BATTLE_TEST("Mind Blown causes everyone to faint in a double battle") { GIVEN { - PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST / 2) ; MaxHP(HP_TEST) ;} ; - PLAYER(SPECIES_WYNAUT) { HP(1); } ; - OPPONENT(SPECIES_ABRA) { HP(1); } ; - OPPONENT(SPECIES_KADABRA) { HP(1); } ; + PLAYER(SPECIES_WOBBUFFET) { HP(HP_TEST / 2); MaxHP(HP_TEST); } + PLAYER(SPECIES_WYNAUT) { HP(1); } + OPPONENT(SPECIES_ABRA) { HP(1); } + OPPONENT(SPECIES_KADABRA) { HP(1); } OPPONENT(SPECIES_KADABRA); } WHEN { - TURN { MOVE(playerLeft, MOVE_MIND_BLOWN, criticalHit:FALSE); } + TURN { MOVE(playerLeft, MOVE_MIND_BLOWN, criticalHit: FALSE); } } SCENE { HP_BAR(playerLeft, hp: 0); ANIMATION(ANIM_TYPE_MOVE, MOVE_MIND_BLOWN, playerLeft);