Optimized Intimidate's code

This commit is contained in:
LOuroboros 2022-11-08 10:10:21 -03:00
parent e6ae0bd01e
commit 31a602f3b6
9 changed files with 40 additions and 92 deletions

View File

@ -1162,7 +1162,7 @@
.4byte \ptr .4byte \ptr
.endm .endm
.macro trygetintimidatetarget ptr:req .macro unused2 ptr:req
.byte 0xe1 .byte 0xe1
.4byte \ptr .4byte \ptr
.endm .endm
@ -1326,8 +1326,8 @@
various \battler, VARIOUS_GET_BATTLER_FAINTED various \battler, VARIOUS_GET_BATTLER_FAINTED
.endm .endm
.macro resetintimidatetracebits battler:req .macro resetswitchinabilitybits battler:req
various \battler, VARIOUS_RESET_INTIMIDATE_TRACE_BITS various \battler, VARIOUS_RESET_SWITCH_IN_ABILITY_BITS
.endm .endm
.macro updatechoicemoveonlvlup battler:req .macro updatechoicemoveonlvlup battler:req

View File

@ -6128,7 +6128,7 @@ BattleScript_FaintedMonTryChoose:
jumpifbyte CMP_EQUAL, gBattleCommunication, PARTY_SIZE, BattleScript_FaintedMonSendOutNew jumpifbyte CMP_EQUAL, gBattleCommunication, PARTY_SIZE, BattleScript_FaintedMonSendOutNew
@ Switch Pokémon before opponent @ Switch Pokémon before opponent
atknameinbuff1 atknameinbuff1
resetintimidatetracebits BS_ATTACKER resetswitchinabilitybits BS_ATTACKER
hpthresholds2 BS_ATTACKER hpthresholds2 BS_ATTACKER
printstring STRINGID_RETURNMON printstring STRINGID_RETURNMON
switchoutabilities BS_ATTACKER switchoutabilities BS_ATTACKER
@ -8198,19 +8198,15 @@ BattleScript_TryAdrenalineOrb:
BattleScript_TryAdrenalineOrbRet: BattleScript_TryAdrenalineOrbRet:
return return
BattleScript_IntimidateActivatesEnd3::
call BattleScript_PauseIntimidateActivates
end3
BattleScript_PauseIntimidateActivates:
pause B_WAIT_TIME_SHORT
BattleScript_IntimidateActivates:: BattleScript_IntimidateActivates::
showabilitypopup BS_ATTACKER
pause B_WAIT_TIME_LONG
destroyabilitypopup
setbyte gBattlerTarget, 0 setbyte gBattlerTarget, 0
call BattleScript_AbilityPopUp BattleScript_IntimidateLoop:
BattleScript_IntimidateActivatesLoop: jumpifbyteequal gBattlerTarget, gBattlerAttacker, BattleScript_IntimidateLoopIncrement
setstatchanger STAT_ATK, 1, TRUE jumpiftargetally BattleScript_IntimidateLoopIncrement
trygetintimidatetarget BattleScript_IntimidateActivatesReturn jumpifstatus2 BS_TARGET, STATUS2_SUBSTITUTE, BattleScript_IntimidateLoopIncrement
jumpifstatus2 BS_TARGET, STATUS2_SUBSTITUTE, BattleScript_IntimidateActivatesLoopIncrement
jumpifability BS_TARGET, ABILITY_CLEAR_BODY, BattleScript_IntimidatePrevented jumpifability BS_TARGET, ABILITY_CLEAR_BODY, BattleScript_IntimidatePrevented
jumpifability BS_TARGET, ABILITY_HYPER_CUTTER, BattleScript_IntimidatePrevented jumpifability BS_TARGET, ABILITY_HYPER_CUTTER, BattleScript_IntimidatePrevented
jumpifability BS_TARGET, ABILITY_WHITE_SMOKE, 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_OWN_TEMPO, BattleScript_IntimidatePrevented
jumpifability BS_TARGET, ABILITY_OBLIVIOUS, BattleScript_IntimidatePrevented jumpifability BS_TARGET, ABILITY_OBLIVIOUS, BattleScript_IntimidatePrevented
.endif .endif
statbuffchange STAT_CHANGE_NOT_PROTECT_AFFECTED | STAT_CHANGE_ALLOW_PTR, BattleScript_IntimidateActivatesLoopIncrement BattleScript_IntimidateEffect:
jumpifbyte CMP_GREATER_THAN, cMULTISTRING_CHOOSER, 1, BattleScript_IntimidateActivatesLoopIncrement statbuffchange STAT_CHANGE_NOT_PROTECT_AFFECTED | MOVE_EFFECT_CERTAIN, NULL
setgraphicalstatchangevalues setgraphicalstatchangevalues
playanimation BS_TARGET, B_ANIM_STATS_CHANGE, sB_ANIM_ARG1 playanimation BS_TARGET, B_ANIM_STATS_CHANGE, sB_ANIM_ARG1
printstring STRINGID_PKMNCUTSATTACKWITH printstring STRINGID_PKMNCUTSATTACKWITH
waitmessage B_WAIT_TIME_LONG waitmessage B_WAIT_TIME_LONG
call BattleScript_TryAdrenalineOrb @ Perform stat nerf
BattleScript_IntimidateActivatesLoopIncrement: BattleScript_IntimidateLoopIncrement:
addbyte gBattlerTarget, 1 addbyte gBattlerTarget, 1
goto BattleScript_IntimidateActivatesLoop jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_IntimidateLoop
BattleScript_IntimidateActivatesReturn: BattleScript_IntimidateEnd:
return destroyabilitypopup
pause B_WAIT_TIME_MED
end3
BattleScript_IntimidatePrevented: BattleScript_IntimidatePrevented:
pause B_WAIT_TIME_SHORT
call BattleScript_AbilityPopUp call BattleScript_AbilityPopUp
pause B_WAIT_TIME_LONG
setbyte gBattleCommunication STAT_ATK setbyte gBattleCommunication STAT_ATK
stattextbuffer BS_ATTACKER stattextbuffer BS_TARGET
printstring STRINGID_STATWASNOTLOWERED printstring STRINGID_STATWASNOTLOWERED
waitmessage B_WAIT_TIME_LONG waitmessage B_WAIT_TIME_LONG
call BattleScript_TryAdrenalineOrb call BattleScript_TryAdrenalineOrb
goto BattleScript_IntimidateActivatesLoopIncrement goto BattleScript_IntimidateLoopIncrement
BattleScript_DroughtActivates:: BattleScript_DroughtActivates::
pause B_WAIT_TIME_SHORT pause B_WAIT_TIME_SHORT

View File

@ -53,7 +53,7 @@ struct ResourceFlags
#define RESOURCE_FLAG_FLASH_FIRE 0x1 #define RESOURCE_FLAG_FLASH_FIRE 0x1
#define RESOURCE_FLAG_ROOST 0x2 #define RESOURCE_FLAG_ROOST 0x2
#define RESOURCE_FLAG_UNBURDEN 0x4 #define RESOURCE_FLAG_UNBURDEN 0x4
#define RESOURCE_FLAG_INTIMIDATED 0x8 #define RESOURCE_FLAG_UNUSED 0x8
#define RESOURCE_FLAG_TRACED 0x10 #define RESOURCE_FLAG_TRACED 0x10
#define RESOURCE_FLAG_EMERGENCY_EXIT 0x20 #define RESOURCE_FLAG_EMERGENCY_EXIT 0x20
#define RESOURCE_FLAG_NEUTRALIZING_GAS 0x40 #define RESOURCE_FLAG_NEUTRALIZING_GAS 0x40
@ -158,7 +158,6 @@ struct SpecialStatus
u8 statLowered:1; u8 statLowered:1;
u8 lightningRodRedirected:1; u8 lightningRodRedirected:1;
u8 restoredBattlerSprite: 1; u8 restoredBattlerSprite: 1;
u8 intimidatedMon:1;
u8 traced:1; u8 traced:1;
u8 ppNotAffectedByPressure:1; u8 ppNotAffectedByPressure:1;
u8 faintedHasReplacement:1; u8 faintedHasReplacement:1;
@ -583,7 +582,6 @@ struct BattleStruct
u8 AI_itemFlags[2]; u8 AI_itemFlags[2];
u16 choicedMove[MAX_BATTLERS_COUNT]; u16 choicedMove[MAX_BATTLERS_COUNT];
u16 changedItems[MAX_BATTLERS_COUNT]; u16 changedItems[MAX_BATTLERS_COUNT];
u8 intimidateBattler;
u8 switchInItemsCounter; u8 switchInItemsCounter;
u8 arenaTurnCounter; u8 arenaTurnCounter;
u8 turnSideTracker; u8 turnSideTracker;

View File

@ -152,7 +152,6 @@ extern const u8 BattleScript_ShedSkinActivates[];
extern const u8 BattleScript_WeatherFormChanges[]; extern const u8 BattleScript_WeatherFormChanges[];
extern const u8 BattleScript_WeatherFormChangesLoop[]; extern const u8 BattleScript_WeatherFormChangesLoop[];
extern const u8 BattleScript_WeatherFormChange[]; extern const u8 BattleScript_WeatherFormChange[];
extern const u8 BattleScript_IntimidateActivatesEnd3[];
extern const u8 BattleScript_IntimidateActivates[]; extern const u8 BattleScript_IntimidateActivates[];
extern const u8 BattleScript_DroughtActivates[]; extern const u8 BattleScript_DroughtActivates[];
extern const u8 BattleScript_TookAttack[]; extern const u8 BattleScript_TookAttack[];

View File

@ -29,13 +29,11 @@
#define ABILITYEFFECT_WEATHER_FORM 7 #define ABILITYEFFECT_WEATHER_FORM 7
#define ABILITYEFFECT_SYNCHRONIZE 8 #define ABILITYEFFECT_SYNCHRONIZE 8
#define ABILITYEFFECT_ATK_SYNCHRONIZE 9 #define ABILITYEFFECT_ATK_SYNCHRONIZE 9
#define ABILITYEFFECT_INTIMIDATE1 10 #define ABILITYEFFECT_TRACE1 10
#define ABILITYEFFECT_INTIMIDATE2 11 #define ABILITYEFFECT_TRACE2 11
#define ABILITYEFFECT_TRACE1 12 #define ABILITYEFFECT_MOVE_END_OTHER 12
#define ABILITYEFFECT_TRACE2 13 #define ABILITYEFFECT_NEUTRALIZINGGAS 13
#define ABILITYEFFECT_MOVE_END_OTHER 14 #define ABILITYEFFECT_FIELD_SPORT 14 // Only used if B_SPORT_TURNS < GEN_6
#define ABILITYEFFECT_NEUTRALIZINGGAS 15
#define ABILITYEFFECT_FIELD_SPORT 16 // Only used if B_SPORT_TURNS < GEN_6
// Special cases // Special cases
#define ABILITYEFFECT_MUD_SPORT 252 // Only used if B_SPORT_TURNS < GEN_6 #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 #define ABILITYEFFECT_WATER_SPORT 253 // Only used if B_SPORT_TURNS < GEN_6

View File

@ -93,7 +93,7 @@
#define VARIOUS_IS_RUNNING_IMPOSSIBLE 2 #define VARIOUS_IS_RUNNING_IMPOSSIBLE 2
#define VARIOUS_GET_MOVE_TARGET 3 #define VARIOUS_GET_MOVE_TARGET 3
#define VARIOUS_GET_BATTLER_FAINTED 4 #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_UPDATE_CHOICE_MOVE_ON_LVL_UP 6
#define VARIOUS_RESET_PLAYER_FAINTED 7 #define VARIOUS_RESET_PLAYER_FAINTED 7
#define VARIOUS_PALACE_FLAVOR_TEXT 8 #define VARIOUS_PALACE_FLAVOR_TEXT 8

View File

@ -3721,8 +3721,6 @@ static void TryDoEventsBeforeFirstTurn(void)
if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gBattlerAttacker, 0, 0, 0) != 0) if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gBattlerAttacker, 0, 0, 0) != 0)
return; return;
} }
if (AbilityBattleEffects(ABILITYEFFECT_INTIMIDATE1, 0, 0, 0, 0) != 0)
return;
if (AbilityBattleEffects(ABILITYEFFECT_TRACE1, 0, 0, 0, 0) != 0) if (AbilityBattleEffects(ABILITYEFFECT_TRACE1, 0, 0, 0, 0) != 0)
return; return;
// Check all switch in items having effect from the fastest mon to slowest. // Check all switch in items having effect from the fastest mon to slowest.

View File

@ -545,7 +545,7 @@ static void Cmd_setuserstatus3(void);
static void Cmd_assistattackselect(void); static void Cmd_assistattackselect(void);
static void Cmd_trysetmagiccoat(void); static void Cmd_trysetmagiccoat(void);
static void Cmd_trysetsnatch(void); static void Cmd_trysetsnatch(void);
static void Cmd_trygetintimidatetarget(void); static void Cmd_unused2(void);
static void Cmd_switchoutabilities(void); static void Cmd_switchoutabilities(void);
static void Cmd_jumpifhasnohp(void); static void Cmd_jumpifhasnohp(void);
static void Cmd_getsecretpowereffect(void); static void Cmd_getsecretpowereffect(void);
@ -804,7 +804,7 @@ void (* const gBattleScriptingCommandsTable[])(void) =
Cmd_assistattackselect, //0xDE Cmd_assistattackselect, //0xDE
Cmd_trysetmagiccoat, //0xDF Cmd_trysetmagiccoat, //0xDF
Cmd_trysetsnatch, //0xE0 Cmd_trysetsnatch, //0xE0
Cmd_trygetintimidatetarget, //0xE1 Cmd_unused2, //0xE1
Cmd_switchoutabilities, //0xE2 Cmd_switchoutabilities, //0xE2
Cmd_jumpifhasnohp, //0xE3 Cmd_jumpifhasnohp, //0xE3
Cmd_getsecretpowereffect, //0xE4 Cmd_getsecretpowereffect, //0xE4
@ -6783,7 +6783,6 @@ static void Cmd_switchineffects(void)
if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gActiveBattler, 0, 0, 0) if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gActiveBattler, 0, 0, 0)
|| ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, gActiveBattler, FALSE) || ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, gActiveBattler, FALSE)
|| AbilityBattleEffects(ABILITYEFFECT_INTIMIDATE2, 0, 0, 0, 0)
|| AbilityBattleEffects(ABILITYEFFECT_TRACE2, 0, 0, 0, 0) || AbilityBattleEffects(ABILITYEFFECT_TRACE2, 0, 0, 0, 0)
|| AbilityBattleEffects(ABILITYEFFECT_WEATHER_FORM, 0, 0, 0, 0)) || AbilityBattleEffects(ABILITYEFFECT_WEATHER_FORM, 0, 0, 0, 0))
return; return;
@ -8469,8 +8468,7 @@ static void Cmd_various(void)
else else
gBattleCommunication[0] = FALSE; gBattleCommunication[0] = FALSE;
break; break;
case VARIOUS_RESET_INTIMIDATE_TRACE_BITS: case VARIOUS_RESET_SWITCH_IN_ABILITY_BITS:
gSpecialStatuses[gActiveBattler].intimidatedMon = FALSE;
gSpecialStatuses[gActiveBattler].traced = FALSE; gSpecialStatuses[gActiveBattler].traced = FALSE;
gSpecialStatuses[gActiveBattler].switchInAbilityDone = FALSE; gSpecialStatuses[gActiveBattler].switchInAbilityDone = FALSE;
break; break;
@ -8634,7 +8632,6 @@ static void Cmd_various(void)
gBattlescriptCurrInstr += 3; gBattlescriptCurrInstr += 3;
AbilityBattleEffects(ABILITYEFFECT_NEUTRALIZINGGAS, gActiveBattler, 0, 0, 0); AbilityBattleEffects(ABILITYEFFECT_NEUTRALIZINGGAS, gActiveBattler, 0, 0, 0);
AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, 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); AbilityBattleEffects(ABILITYEFFECT_TRACE2, gActiveBattler, 0, 0, 0);
return; return;
case VARIOUS_SAVE_TARGET: 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) static void Cmd_switchoutabilities(void)

View File

@ -4780,10 +4780,12 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move
} }
break; break;
case ABILITY_INTIMIDATE: case ABILITY_INTIMIDATE:
if (!(gSpecialStatuses[battler].intimidatedMon)) if (!gSpecialStatuses[battler].switchInAbilityDone)
{ {
gBattleResources->flags->flags[battler] |= RESOURCE_FLAG_INTIMIDATED; gSpecialStatuses[battler].switchInAbilityDone = TRUE;
gSpecialStatuses[battler].intimidatedMon = TRUE; SET_STATCHANGER(STAT_ATK, 1, TRUE);
BattleScriptPushCursorAndCallback(BattleScript_IntimidateActivates);
effect++;
} }
break; break;
case ABILITY_FORECAST: case ABILITY_FORECAST:
@ -5958,30 +5960,6 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move
} }
} }
break; 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_TRACE1:
case ABILITYEFFECT_TRACE2: case ABILITYEFFECT_TRACE2:
for (i = 0; i < gBattlersCount; i++) for (i = 0; i < gBattlersCount; i++)