diff --git a/asm/macros/battle_ai_script.inc b/asm/macros/battle_ai_script.inc index f3e243619..4d0cd23af 100644 --- a/asm/macros/battle_ai_script.inc +++ b/asm/macros/battle_ai_script.inc @@ -581,6 +581,19 @@ .4byte \ptr .endm + .macro if_share_type battler1:req, battler2:req, ptr:req + .byte 0x67 + .byte \battler1 + .byte \battler2 + .4byte \ptr + .endm + + .macro if_cant_use_last_resort battler:req, ptr:req + .byte 0x68 + .byte \battler + .4byte \ptr + .endm + @ useful script macros .macro if_holds_no_item battler, ptr:req if_holds_item \battler, 0, \ptr diff --git a/data/battle_ai_scripts.s b/data/battle_ai_scripts.s index b1b9f795f..c58b87a4e 100644 --- a/data/battle_ai_scripts.s +++ b/data/battle_ai_scripts.s @@ -234,8 +234,89 @@ AI_CheckBadMove_CheckEffect: @ 82DC045 if_effect EFFECT_ATTACK_ACCURACY_UP, AI_CBM_AtkAccUp if_effect EFFECT_ATTACK_SPATK_UP, AI_CBM_AtkSpAtkUp if_effect EFFECT_GROWTH, AI_CBM_AtkSpAtkUp + if_effect EFFECT_AROMATIC_MIST, AI_CBM_AromaticMist + if_effect EFFECT_ACUPRESSURE, AI_CBM_Acupressure + if_effect EFFECT_BESTOW, AI_CBM_Bestow + if_effect EFFECT_PSYCHO_SHIFT, AI_CBM_PsychicShift + if_effect EFFECT_DEFOG, AI_CBM_Defog + if_effect EFFECT_SYNCHRONOISE, AI_CBM_Synchronoise + if_effect EFFECT_AUTONOMIZE, AI_CBM_SpeedUp + if_effect EFFECT_TOXIC_THREAD, AI_CBM_ToxicThread + if_effect EFFECT_VENOM_DRENCH, AI_CBM_VenomDrench + if_effect EFFECT_DEFENSE_UP_3, AI_CBM_DefenseUp + if_effect EFFECT_SHIFT_GEAR, AI_CBM_DragonDance + if_effect EFFECT_NOBLE_ROAR, AI_CBM_NobleRoar + if_effect EFFECT_SHELL_SMASH, AI_CBM_ShellSmash + if_effect EFFECT_LAST_RESORT, AI_CBM_LastResort end +AI_CBM_LastResort: + if_cant_use_last_resort AI_USER, Score_Minus10 + end + +AI_CBM_ShellSmash: + if_ability AI_USER, ABILITY_CONTRARY, AI_CBM_ShellSmashContrary + if_stat_level_not_equal AI_USER, STAT_SPATK, 12, AI_Ret + if_stat_level_not_equal AI_USER, STAT_SPEED, 12, AI_Ret + if_stat_level_equal AI_USER, STAT_ATK, 12, Score_Minus10 + end +AI_CBM_ShellSmashContrary: + if_stat_level_not_equal AI_USER, STAT_DEF, 12, AI_Ret + if_stat_level_equal AI_USER, STAT_SPDEF, 12, Score_Minus10 + end + +AI_CBM_NobleRoar: + if_stat_level_not_equal AI_TARGET, STAT_SPATK, 12, AI_Ret + if_stat_level_equal AI_TARGET, STAT_ATK, 12, Score_Minus10 + end + +AI_CBM_VenomDrench: + if_not_status AI_TARGET, STATUS1_PSN_ANY, Score_Minus10 + if_stat_level_not_equal AI_TARGET, STAT_SPEED, 12, AI_Ret + if_stat_level_not_equal AI_TARGET, STAT_SPATK, 12, AI_Ret + if_stat_level_equal AI_TARGET, STAT_ATK, 12, Score_Minus10 + end + +AI_CBM_ToxicThread: + if_stat_level_not_equal AI_TARGET, STAT_SPEED, 12, AI_Ret + goto AI_CBM_Toxic + +AI_CBM_Synchronoise: + if_share_type AI_USER, AI_TARGET AI_Ret + goto Score_Minus10 + +AI_CBM_Defog: + if_side_affecting AI_USER, SIDE_STATUS_SPIKES | SIDE_STATUS_STEALTH_ROCK | SIDE_STATUS_TOXIC_SPIKES | SIDE_STATUS_STICKY_WEB, AI_Ret + goto AI_CBM_EvasionDown + +AI_CBM_PsychicShift: + if_not_status AI_USER, STATUS1_ANY, Score_Minus10 + if_status AI_TARGET, STATUS1_ANY, Score_Minus10 + if_status AI_USER, STATUS1_PARALYSIS, AI_CBM_Paralyze + if_status AI_USER, STATUS1_PSN_ANY, AI_CBM_Toxic + if_status AI_USER, STATUS1_BURN, AI_CBM_WillOWisp + if_status AI_USER, STATUS1_SLEEP, AI_CBM_Sleep + end + +AI_CBM_Bestow: + if_holds_no_item AI_USER, Score_Minus10 + end + +AI_CBM_Acupressure: + if_double_battle AI_Ret + if_stat_level_not_equal AI_USER, STAT_ATK, 12, AI_Ret + if_stat_level_not_equal AI_USER, STAT_DEF, 12, AI_Ret + if_stat_level_not_equal AI_USER, STAT_SPATK, 12, AI_Ret + if_stat_level_not_equal AI_USER, STAT_SPDEF, 12, AI_Ret + if_stat_level_not_equal AI_USER, STAT_SPEED, 12, AI_Ret + if_stat_level_not_equal AI_USER, STAT_ACC, 12, AI_Ret + if_stat_level_equal AI_USER, STAT_EVASION, 12, Score_Minus10 + end + +AI_CBM_AromaticMist: + if_target_is_ally AI_Ret + goto Score_Minus10 + AI_CBM_AtkAccUp: if_stat_level_not_equal AI_USER, STAT_ATK, 12, AI_Ret if_stat_level_equal AI_USER, STAT_ACC, 12, Score_Minus10 diff --git a/include/battle_script_commands.h b/include/battle_script_commands.h index 92593e4a6..4c3841d1f 100644 --- a/include/battle_script_commands.h +++ b/include/battle_script_commands.h @@ -13,6 +13,7 @@ void BufferMoveToLearnIntoBattleTextBuff2(void); void HandleBattleWindow(u8 xStart, u8 yStart, u8 xEnd, u8 yEnd, u8 flags); bool8 UproarWakeUpCheck(u8 battlerId); bool32 DoesSubstituteBlockMove(u8 battlerAtk, u8 battlerDef, u32 move); +bool32 CanUseLastResort(u8 battlerId); extern void (* const gBattleScriptingCommandsTable[])(void); extern const u8 gUnknown_0831C494[][4]; diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index db63a5c68..75cc8ccf2 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -156,6 +156,8 @@ static void BattleAICmd_get_ally_chosen_move(void); static void BattleAICmd_if_has_no_attacking_moves(void); static void BattleAICmd_get_hazards_count(void); static void BattleAICmd_if_doesnt_hold_berry(void); +static void BattleAICmd_if_share_type(void); +static void BattleAICmd_if_cant_use_last_resort(void); // ewram EWRAM_DATA const u8 *gAIScriptPtr = NULL; @@ -269,6 +271,8 @@ static const BattleAICmdFunc sBattleAICmdTable[] = BattleAICmd_if_has_no_attacking_moves, // 0x64 BattleAICmd_get_hazards_count, // 0x65 BattleAICmd_if_doesnt_hold_berry, // 0x66 + BattleAICmd_if_share_type, // 0x67 + BattleAICmd_if_cant_use_last_resort, // 0x68 }; static const u16 sDiscouragedPowerfulMoveEffects[] = @@ -2526,3 +2530,24 @@ static void BattleAICmd_if_doesnt_hold_berry(void) else gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); } + +static void BattleAICmd_if_share_type(void) +{ + u8 battler1 = BattleAI_GetWantedBattler(gAIScriptPtr[1]); + u8 battler2 = BattleAI_GetWantedBattler(gAIScriptPtr[2]); + + if (DoBattlersShareType(battler1, battler2)) + gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 3); + else + gAIScriptPtr += 7; +} + +static void BattleAICmd_if_cant_use_last_resort(void) +{ + u8 battler = BattleAI_GetWantedBattler(gAIScriptPtr[1]); + + if (CanUseLastResort(battler)) + gAIScriptPtr += 6; + else + gAIScriptPtr = T1_READ_PTR(gAIScriptPtr + 2); +}