From 31a602f3b64eb58efaf8065614f13abfaa4048e9 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Tue, 8 Nov 2022 10:10:21 -0300 Subject: [PATCH 1/3] Optimized Intimidate's code --- asm/macros/battle_script.inc | 6 +-- data/battle_scripts_1.s | 43 +++++++++++----------- include/battle.h | 4 +- include/battle_scripts.h | 1 - include/battle_util.h | 12 +++--- include/constants/battle_script_commands.h | 2 +- src/battle_main.c | 2 - src/battle_script_commands.c | 30 ++------------- src/battle_util.c | 32 +++------------- 9 files changed, 40 insertions(+), 92 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 1a6641e76..0e3aab037 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1162,7 +1162,7 @@ .4byte \ptr .endm - .macro trygetintimidatetarget ptr:req + .macro unused2 ptr:req .byte 0xe1 .4byte \ptr .endm @@ -1326,8 +1326,8 @@ various \battler, VARIOUS_GET_BATTLER_FAINTED .endm - .macro resetintimidatetracebits battler:req - various \battler, VARIOUS_RESET_INTIMIDATE_TRACE_BITS + .macro resetswitchinabilitybits battler:req + various \battler, VARIOUS_RESET_SWITCH_IN_ABILITY_BITS .endm .macro updatechoicemoveonlvlup battler:req diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 63719e2b6..4514de868 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -6128,7 +6128,7 @@ BattleScript_FaintedMonTryChoose: jumpifbyte CMP_EQUAL, gBattleCommunication, PARTY_SIZE, BattleScript_FaintedMonSendOutNew @ Switch Pokémon before opponent atknameinbuff1 - resetintimidatetracebits BS_ATTACKER + resetswitchinabilitybits BS_ATTACKER hpthresholds2 BS_ATTACKER printstring STRINGID_RETURNMON switchoutabilities BS_ATTACKER @@ -8198,19 +8198,15 @@ BattleScript_TryAdrenalineOrb: BattleScript_TryAdrenalineOrbRet: return -BattleScript_IntimidateActivatesEnd3:: - call BattleScript_PauseIntimidateActivates - end3 - -BattleScript_PauseIntimidateActivates: - pause B_WAIT_TIME_SHORT BattleScript_IntimidateActivates:: + showabilitypopup BS_ATTACKER + pause B_WAIT_TIME_LONG + destroyabilitypopup setbyte gBattlerTarget, 0 - call BattleScript_AbilityPopUp -BattleScript_IntimidateActivatesLoop: - setstatchanger STAT_ATK, 1, TRUE - trygetintimidatetarget BattleScript_IntimidateActivatesReturn - jumpifstatus2 BS_TARGET, STATUS2_SUBSTITUTE, BattleScript_IntimidateActivatesLoopIncrement +BattleScript_IntimidateLoop: + jumpifbyteequal gBattlerTarget, gBattlerAttacker, BattleScript_IntimidateLoopIncrement + jumpiftargetally BattleScript_IntimidateLoopIncrement + jumpifstatus2 BS_TARGET, STATUS2_SUBSTITUTE, BattleScript_IntimidateLoopIncrement jumpifability BS_TARGET, ABILITY_CLEAR_BODY, BattleScript_IntimidatePrevented jumpifability BS_TARGET, ABILITY_HYPER_CUTTER, BattleScript_IntimidatePrevented jumpifability BS_TARGET, ABILITY_WHITE_SMOKE, BattleScript_IntimidatePrevented @@ -8220,27 +8216,30 @@ BattleScript_IntimidateActivatesLoop: jumpifability BS_TARGET, ABILITY_OWN_TEMPO, BattleScript_IntimidatePrevented jumpifability BS_TARGET, ABILITY_OBLIVIOUS, BattleScript_IntimidatePrevented .endif - statbuffchange STAT_CHANGE_NOT_PROTECT_AFFECTED | STAT_CHANGE_ALLOW_PTR, BattleScript_IntimidateActivatesLoopIncrement - jumpifbyte CMP_GREATER_THAN, cMULTISTRING_CHOOSER, 1, BattleScript_IntimidateActivatesLoopIncrement +BattleScript_IntimidateEffect: + statbuffchange STAT_CHANGE_NOT_PROTECT_AFFECTED | MOVE_EFFECT_CERTAIN, NULL setgraphicalstatchangevalues playanimation BS_TARGET, B_ANIM_STATS_CHANGE, sB_ANIM_ARG1 printstring STRINGID_PKMNCUTSATTACKWITH waitmessage B_WAIT_TIME_LONG - call BattleScript_TryAdrenalineOrb -BattleScript_IntimidateActivatesLoopIncrement: +@ Perform stat nerf +BattleScript_IntimidateLoopIncrement: addbyte gBattlerTarget, 1 - goto BattleScript_IntimidateActivatesLoop -BattleScript_IntimidateActivatesReturn: - return + jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_IntimidateLoop +BattleScript_IntimidateEnd: + destroyabilitypopup + pause B_WAIT_TIME_MED + end3 + BattleScript_IntimidatePrevented: - pause B_WAIT_TIME_SHORT call BattleScript_AbilityPopUp + pause B_WAIT_TIME_LONG setbyte gBattleCommunication STAT_ATK - stattextbuffer BS_ATTACKER + stattextbuffer BS_TARGET printstring STRINGID_STATWASNOTLOWERED waitmessage B_WAIT_TIME_LONG call BattleScript_TryAdrenalineOrb - goto BattleScript_IntimidateActivatesLoopIncrement + goto BattleScript_IntimidateLoopIncrement BattleScript_DroughtActivates:: pause B_WAIT_TIME_SHORT diff --git a/include/battle.h b/include/battle.h index 5d9f57e43..9670aa4e6 100644 --- a/include/battle.h +++ b/include/battle.h @@ -53,7 +53,7 @@ struct ResourceFlags #define RESOURCE_FLAG_FLASH_FIRE 0x1 #define RESOURCE_FLAG_ROOST 0x2 #define RESOURCE_FLAG_UNBURDEN 0x4 -#define RESOURCE_FLAG_INTIMIDATED 0x8 +#define RESOURCE_FLAG_UNUSED 0x8 #define RESOURCE_FLAG_TRACED 0x10 #define RESOURCE_FLAG_EMERGENCY_EXIT 0x20 #define RESOURCE_FLAG_NEUTRALIZING_GAS 0x40 @@ -158,7 +158,6 @@ struct SpecialStatus u8 statLowered:1; u8 lightningRodRedirected:1; u8 restoredBattlerSprite: 1; - u8 intimidatedMon:1; u8 traced:1; u8 ppNotAffectedByPressure:1; u8 faintedHasReplacement:1; @@ -583,7 +582,6 @@ struct BattleStruct u8 AI_itemFlags[2]; u16 choicedMove[MAX_BATTLERS_COUNT]; u16 changedItems[MAX_BATTLERS_COUNT]; - u8 intimidateBattler; u8 switchInItemsCounter; u8 arenaTurnCounter; u8 turnSideTracker; diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 23f18e3be..7fdc5758c 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -152,7 +152,6 @@ extern const u8 BattleScript_ShedSkinActivates[]; extern const u8 BattleScript_WeatherFormChanges[]; extern const u8 BattleScript_WeatherFormChangesLoop[]; extern const u8 BattleScript_WeatherFormChange[]; -extern const u8 BattleScript_IntimidateActivatesEnd3[]; extern const u8 BattleScript_IntimidateActivates[]; extern const u8 BattleScript_DroughtActivates[]; extern const u8 BattleScript_TookAttack[]; diff --git a/include/battle_util.h b/include/battle_util.h index 3f516daba..257b5a743 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -29,13 +29,11 @@ #define ABILITYEFFECT_WEATHER_FORM 7 #define ABILITYEFFECT_SYNCHRONIZE 8 #define ABILITYEFFECT_ATK_SYNCHRONIZE 9 -#define ABILITYEFFECT_INTIMIDATE1 10 -#define ABILITYEFFECT_INTIMIDATE2 11 -#define ABILITYEFFECT_TRACE1 12 -#define ABILITYEFFECT_TRACE2 13 -#define ABILITYEFFECT_MOVE_END_OTHER 14 -#define ABILITYEFFECT_NEUTRALIZINGGAS 15 -#define ABILITYEFFECT_FIELD_SPORT 16 // Only used if B_SPORT_TURNS < GEN_6 +#define ABILITYEFFECT_TRACE1 10 +#define ABILITYEFFECT_TRACE2 11 +#define ABILITYEFFECT_MOVE_END_OTHER 12 +#define ABILITYEFFECT_NEUTRALIZINGGAS 13 +#define ABILITYEFFECT_FIELD_SPORT 14 // Only used if B_SPORT_TURNS < GEN_6 // Special cases #define ABILITYEFFECT_MUD_SPORT 252 // Only used if B_SPORT_TURNS < GEN_6 #define ABILITYEFFECT_WATER_SPORT 253 // Only used if B_SPORT_TURNS < GEN_6 diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 06a09fc17..2d6db1fbb 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -93,7 +93,7 @@ #define VARIOUS_IS_RUNNING_IMPOSSIBLE 2 #define VARIOUS_GET_MOVE_TARGET 3 #define VARIOUS_GET_BATTLER_FAINTED 4 -#define VARIOUS_RESET_INTIMIDATE_TRACE_BITS 5 +#define VARIOUS_RESET_SWITCH_IN_ABILITY_BITS 5 #define VARIOUS_UPDATE_CHOICE_MOVE_ON_LVL_UP 6 #define VARIOUS_RESET_PLAYER_FAINTED 7 #define VARIOUS_PALACE_FLAVOR_TEXT 8 diff --git a/src/battle_main.c b/src/battle_main.c index 9790810a1..74b844012 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3721,8 +3721,6 @@ static void TryDoEventsBeforeFirstTurn(void) if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gBattlerAttacker, 0, 0, 0) != 0) return; } - if (AbilityBattleEffects(ABILITYEFFECT_INTIMIDATE1, 0, 0, 0, 0) != 0) - return; if (AbilityBattleEffects(ABILITYEFFECT_TRACE1, 0, 0, 0, 0) != 0) return; // Check all switch in items having effect from the fastest mon to slowest. diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 3e52aa618..036ac3bd1 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -545,7 +545,7 @@ static void Cmd_setuserstatus3(void); static void Cmd_assistattackselect(void); static void Cmd_trysetmagiccoat(void); static void Cmd_trysetsnatch(void); -static void Cmd_trygetintimidatetarget(void); +static void Cmd_unused2(void); static void Cmd_switchoutabilities(void); static void Cmd_jumpifhasnohp(void); static void Cmd_getsecretpowereffect(void); @@ -804,7 +804,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_assistattackselect, //0xDE Cmd_trysetmagiccoat, //0xDF Cmd_trysetsnatch, //0xE0 - Cmd_trygetintimidatetarget, //0xE1 + Cmd_unused2, //0xE1 Cmd_switchoutabilities, //0xE2 Cmd_jumpifhasnohp, //0xE3 Cmd_getsecretpowereffect, //0xE4 @@ -6783,7 +6783,6 @@ static void Cmd_switchineffects(void) if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gActiveBattler, 0, 0, 0) || ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, gActiveBattler, FALSE) - || AbilityBattleEffects(ABILITYEFFECT_INTIMIDATE2, 0, 0, 0, 0) || AbilityBattleEffects(ABILITYEFFECT_TRACE2, 0, 0, 0, 0) || AbilityBattleEffects(ABILITYEFFECT_WEATHER_FORM, 0, 0, 0, 0)) return; @@ -8469,8 +8468,7 @@ static void Cmd_various(void) else gBattleCommunication[0] = FALSE; break; - case VARIOUS_RESET_INTIMIDATE_TRACE_BITS: - gSpecialStatuses[gActiveBattler].intimidatedMon = FALSE; + case VARIOUS_RESET_SWITCH_IN_ABILITY_BITS: gSpecialStatuses[gActiveBattler].traced = FALSE; gSpecialStatuses[gActiveBattler].switchInAbilityDone = FALSE; break; @@ -8634,7 +8632,6 @@ static void Cmd_various(void) gBattlescriptCurrInstr += 3; AbilityBattleEffects(ABILITYEFFECT_NEUTRALIZINGGAS, gActiveBattler, 0, 0, 0); AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gActiveBattler, 0, 0, 0); - AbilityBattleEffects(ABILITYEFFECT_INTIMIDATE2, gActiveBattler, 0, 0, 0); AbilityBattleEffects(ABILITYEFFECT_TRACE2, gActiveBattler, 0, 0, 0); return; case VARIOUS_SAVE_TARGET: @@ -13533,27 +13530,8 @@ static void Cmd_trysetsnatch(void) } } -static void Cmd_trygetintimidatetarget(void) +static void Cmd_unused2(void) { - u8 side; - - gBattleScripting.battler = gBattleStruct->intimidateBattler; - side = GetBattlerSide(gBattleScripting.battler); - - PREPARE_ABILITY_BUFFER(gBattleTextBuff1, gBattleMons[gBattleScripting.battler].ability) - - for (;gBattlerTarget < gBattlersCount; gBattlerTarget++) - { - if (GetBattlerSide(gBattlerTarget) == side) - continue; - if (!(gAbsentBattlerFlags & gBitTable[gBattlerTarget])) - break; - } - - if (gBattlerTarget >= gBattlersCount) - gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1); - else - gBattlescriptCurrInstr += 5; } static void Cmd_switchoutabilities(void) diff --git a/src/battle_util.c b/src/battle_util.c index 9c3e189d7..bc5037abd 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -4780,10 +4780,12 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move } break; case ABILITY_INTIMIDATE: - if (!(gSpecialStatuses[battler].intimidatedMon)) + if (!gSpecialStatuses[battler].switchInAbilityDone) { - gBattleResources->flags->flags[battler] |= RESOURCE_FLAG_INTIMIDATED; - gSpecialStatuses[battler].intimidatedMon = TRUE; + gSpecialStatuses[battler].switchInAbilityDone = TRUE; + SET_STATCHANGER(STAT_ATK, 1, TRUE); + BattleScriptPushCursorAndCallback(BattleScript_IntimidateActivates); + effect++; } break; case ABILITY_FORECAST: @@ -5958,30 +5960,6 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move } } break; - case ABILITYEFFECT_INTIMIDATE1: - case ABILITYEFFECT_INTIMIDATE2: - for (i = 0; i < gBattlersCount; i++) - { - if (GetBattlerAbility(i) == ABILITY_INTIMIDATE && gBattleResources->flags->flags[i] & RESOURCE_FLAG_INTIMIDATED - && (IsBattlerAlive(BATTLE_OPPOSITE(i)) || IsBattlerAlive(BATTLE_PARTNER(BATTLE_OPPOSITE(i))))) // At least one opposing mon has to be alive. - { - gBattleResources->flags->flags[i] &= ~RESOURCE_FLAG_INTIMIDATED; - gLastUsedAbility = ABILITY_INTIMIDATE; - if (caseID == ABILITYEFFECT_INTIMIDATE1) - { - BattleScriptPushCursorAndCallback(BattleScript_IntimidateActivatesEnd3); - } - else - { - BattleScriptPushCursor(); - gBattlescriptCurrInstr = BattleScript_IntimidateActivates; - } - battler = gBattlerAbility = gBattleStruct->intimidateBattler = i; - effect++; - break; - } - } - break; case ABILITYEFFECT_TRACE1: case ABILITYEFFECT_TRACE2: for (i = 0; i < gBattlersCount; i++) From e6a3396b0f5e28f7e92ebf33a1fa5914d6126d68 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Sun, 11 Dec 2022 19:24:36 -0300 Subject: [PATCH 2/3] Added Adrenaline Orb check and removed silly comment --- data/battle_scripts_1.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 4514de868..c3c490712 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -8222,7 +8222,7 @@ BattleScript_IntimidateEffect: playanimation BS_TARGET, B_ANIM_STATS_CHANGE, sB_ANIM_ARG1 printstring STRINGID_PKMNCUTSATTACKWITH waitmessage B_WAIT_TIME_LONG -@ Perform stat nerf + call BattleScript_TryAdrenalineOrb BattleScript_IntimidateLoopIncrement: addbyte gBattlerTarget, 1 jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_IntimidateLoop From 8eff1a13c1e51fa032900c9dcfdb872f1c0f3e49 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Sun, 11 Dec 2022 23:17:59 -0300 Subject: [PATCH 3/3] Updated BattleScript_IntimidateEffect to comply with BattleScript_TryAdrenalineOrb's demands --- data/battle_scripts_1.s | 1 + 1 file changed, 1 insertion(+) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index c3c490712..f30bccaaa 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -8217,6 +8217,7 @@ BattleScript_IntimidateLoop: jumpifability BS_TARGET, ABILITY_OBLIVIOUS, BattleScript_IntimidatePrevented .endif BattleScript_IntimidateEffect: + copybyte sBATTLER, gBattlerTarget statbuffchange STAT_CHANGE_NOT_PROTECT_AFFECTED | MOVE_EFFECT_CERTAIN, NULL setgraphicalstatchangevalues playanimation BS_TARGET, B_ANIM_STATS_CHANGE, sB_ANIM_ARG1