From 6c8ca5e28ddede12a889df16c75b7d771b257da1 Mon Sep 17 00:00:00 2001 From: cawtds Date: Wed, 1 May 2024 17:07:57 +0200 Subject: [PATCH] updated up to Cmd_jumpifcantswitch --- asm/macros/battle_script.inc | 8 +-- include/battle_util.h | 1 + src/battle_script_commands.c | 98 ++++++++---------------------------- src/battle_util.c | 18 +++++++ 4 files changed, 43 insertions(+), 82 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 10d369b9c..e9cc984b9 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -475,16 +475,16 @@ .byte \battler .endm - .macro switchinanim battler:req, dontclearsubstitutebit:req + .macro switchinanim battler:req, dontClearSubstitute:req .byte 0x4e .byte \battler - .byte \dontclearsubstitutebit + .byte \dontClearSubstitute .endm - .macro jumpifcantswitch battler:req, ptr:req + .macro jumpifcantswitch battler:req, jumpInstr:req .byte 0x4f .byte \battler - .4byte \ptr + .4byte \jumpInstr .endm .macro openpartyscreen param0:req, param1:req diff --git a/include/battle_util.h b/include/battle_util.h index 2967251d4..1e1166d9a 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -226,6 +226,7 @@ bool32 HasEnoughHpToEatBerry(u32 battler, u32 hpFraction, u32 itemId); bool32 IsGen6ExpShareEnabled(void); void CopyMonLevelAndBaseStatsToBattleMon(u32 battler, struct Pokemon *mon); void SortBattlersBySpeed(u8 *battlers, bool32 slowToFast); +bool32 CanBattlerEscape(u32 battler); // no ability check // battle_ai_util.h bool32 IsHealingMove(u32 move); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 661ba1874..bd422c439 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -665,8 +665,8 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_returnatktoball, //0x4B // done Cmd_getswitchedmondata, //0x4C // done Cmd_switchindataupdate, //0x4D // done - Cmd_switchinanim, //0x4E - Cmd_jumpifcantswitch, //0x4F + Cmd_switchinanim, //0x4E // done + Cmd_jumpifcantswitch, //0x4F // done Cmd_openpartyscreen, //0x50 Cmd_switchhandleorder, //0x51 Cmd_switchineffects, //0x52 @@ -6741,26 +6741,30 @@ static void Cmd_switchindataupdate(void) static void Cmd_switchinanim(void) { + u32 battler; + + CMD_ARGS(u8 battler, bool8 dontClearSubstitute); + if (gBattleControllerExecFlags) return; - gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1]); + battler = gActiveBattler = GetBattlerForBattleScript(cmd->battler); - if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT + if (GetBattlerSide(battler) == B_SIDE_OPPONENT && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_LEGENDARY | BATTLE_TYPE_OLD_MAN_TUTORIAL | BATTLE_TYPE_POKEDUDE | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_GHOST))) - HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[gActiveBattler].species), FLAG_SET_SEEN, gBattleMons[gActiveBattler].personality); + HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[battler].species), FLAG_SET_SEEN, gBattleMons[battler].personality); - gAbsentBattlerFlags &= ~(gBitTable[gActiveBattler]); + gAbsentBattlerFlags &= ~(gBitTable[battler]); - BtlController_EmitSwitchInAnim(BUFFER_A, gBattlerPartyIndexes[gActiveBattler], gBattlescriptCurrInstr[2]); - MarkBattlerForControllerExec(gActiveBattler); + BtlController_EmitSwitchInAnim(BUFFER_A, gBattlerPartyIndexes[battler], cmd->dontClearSubstitute); + MarkBattlerForControllerExec(battler); - gBattlescriptCurrInstr += 3; + gBattlescriptCurrInstr = cmd->nextInstr; } bool32 CanBattlerSwitch(u32 battler) @@ -6908,81 +6912,19 @@ bool32 CanBattlerSwitch(u32 battler) static void Cmd_jumpifcantswitch(void) { - s32 i; - s32 lastMonId; - struct Pokemon *party; + CMD_ARGS(u8 battler:7, u8 ignoreEscapePrevention:1, const u8 *jumpInstr); - gActiveBattler = GetBattlerForBattleScript(gBattlescriptCurrInstr[1] & ~SWITCH_IGNORE_ESCAPE_PREVENTION); - if (!(gBattlescriptCurrInstr[1] & SWITCH_IGNORE_ESCAPE_PREVENTION) - && ((gBattleMons[gActiveBattler].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) - || (gStatuses3[gActiveBattler] & STATUS3_ROOTED))) + u32 battler = gActiveBattler = GetBattlerForBattleScript(cmd->battler); + if (!cmd->ignoreEscapePrevention && !CanBattlerEscape(battler)) { - gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2); - } - else if (gBattleTypeFlags & BATTLE_TYPE_MULTI) - { - if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT) - party = gEnemyParty; - else - party = gPlayerParty; - - i = 0; - if (GetLinkTrainerFlankId(GetBattlerMultiplayerId(gActiveBattler)) == TRUE) - i = 3; - for (lastMonId = i + 3; i < lastMonId; i++) - { - if (GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE - && !GetMonData(&party[i], MON_DATA_IS_EGG) - && GetMonData(&party[i], MON_DATA_HP) != 0 - && gBattlerPartyIndexes[gActiveBattler] != i) - break; - } - - if (i == lastMonId) - gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2); - else - gBattlescriptCurrInstr += 6; + gBattlescriptCurrInstr = cmd->jumpInstr; } else { - u8 battlerIn1, battlerIn2; - - if (GetBattlerSide(gActiveBattler) == B_SIDE_OPPONENT) - { - battlerIn1 = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - battlerIn2 = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); - else - battlerIn2 = battlerIn1; - - party = gEnemyParty; - } + if (CanBattlerSwitch(battler)) + gBattlescriptCurrInstr = cmd->nextInstr; else - { - battlerIn1 = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - battlerIn2 = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); - else - battlerIn2 = battlerIn1; - - party = gPlayerParty; - } - - for (i = 0; i < PARTY_SIZE; i++) - { - if (GetMonData(&party[i], MON_DATA_HP) != 0 - && GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE - && !GetMonData(&party[i], MON_DATA_IS_EGG) - && i != gBattlerPartyIndexes[battlerIn1] && i != gBattlerPartyIndexes[battlerIn2]) - break; - } - - if (i == PARTY_SIZE) - gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2); - else - gBattlescriptCurrInstr += 6; + gBattlescriptCurrInstr = cmd->jumpInstr; } } diff --git a/src/battle_util.c b/src/battle_util.c index 79e2e8f69..cac704598 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -9309,6 +9309,24 @@ void SortBattlersBySpeed(u8 *battlers, bool32 slowToFast) } } +bool32 CanBattlerEscape(u32 battler) // no ability check +{ + if (GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_SHED_SHELL) + return TRUE; + else if (B_GHOSTS_ESCAPE >= GEN_6 && IS_BATTLER_OF_TYPE(battler, TYPE_GHOST)) + return TRUE; + else if (gBattleMons[battler].status2 & (STATUS2_ESCAPE_PREVENTION | STATUS2_WRAPPED)) + return FALSE; + else if (gStatuses3[battler] & STATUS3_ROOTED) + return FALSE; + else if (gFieldStatuses & STATUS_FIELD_FAIRY_LOCK) + return FALSE; + else if (gStatuses3[battler] & STATUS3_SKY_DROPPED) + return FALSE; + else + return TRUE; +} + // battle_ai_util.c