From f317b542e22c734bff9d1f32001fcc16bef21c68 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Thu, 9 Dec 2021 20:11:35 -0300 Subject: [PATCH 1/4] Updated Teleport --- asm/macros/battle_script.inc | 8 +++++ data/battle_scripts_1.s | 30 ++++++++++++++++ include/constants/battle_config.h | 1 + include/constants/battle_script_commands.h | 2 ++ src/battle_script_commands.c | 40 ++++++++++++++++++++++ 5 files changed, 81 insertions(+) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 6ba63f916..c81a3f3b3 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1925,6 +1925,14 @@ various BS_ATTACKER, VARIOUS_SHELL_SIDE_ARM_CHECK .endm + .macro canteleport battler:req + various \battler, VARIOUS_CAN_TELEPORT + .endm + + .macro getbattlerside battler:req + various \battler, VARIOUS_GET_BATTLER_SIDE + .endm + @ helpful macros .macro setstatchanger stat:req, stages:req, down:req setbyte sSTATCHANGER \stat | \stages << 3 | \down << 7 diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index e9d019e43..8fe620460 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -4822,7 +4822,14 @@ BattleScript_EffectTeleport: attackcanceler attackstring ppreduce +.if B_TELEPORT_BEHAVIOR >= GEN_7 + canteleport BS_ATTACKER + jumpifbyte CMP_EQUAL, gBattleCommunication, TRUE, BattleScript_EffectTeleportNew + goto BattleScript_ButItFailed +.else jumpifbattletype BATTLE_TYPE_TRAINER, BattleScript_ButItFailed +.endif +BattleScript_EffectTeleportTryToRunAway: getifcantrunfrombattle BS_ATTACKER jumpifbyte CMP_EQUAL, gBattleCommunication, 1, BattleScript_ButItFailed jumpifbyte CMP_EQUAL, gBattleCommunication, 2, BattleScript_PrintAbilityMadeIneffective @@ -4833,6 +4840,29 @@ BattleScript_EffectTeleport: setoutcomeonteleport BS_ATTACKER goto BattleScript_MoveEnd +BattleScript_EffectTeleportNew: + getbattlerside BS_ATTACKER + jumpifbyte CMP_EQUAL, gBattleCommunication, B_SIDE_OPPONENT, BattleScript_EffectTeleportTryToRunAway + attackanimation + waitanimation + openpartyscreen BS_ATTACKER, BattleScript_EffectTeleportNewEnd + switchoutabilities BS_ATTACKER + waitstate + switchhandleorder BS_ATTACKER, 2 + returntoball BS_ATTACKER + getswitchedmondata BS_ATTACKER + switchindataupdate BS_ATTACKER + hpthresholds BS_ATTACKER + trytoclearprimalweather + printstring STRINGID_EMPTYSTRING3 + waitmessage 1 + printstring STRINGID_SWITCHINMON + switchinanim BS_ATTACKER, TRUE + waitstate + switchineffects BS_ATTACKER +BattleScript_EffectTeleportNewEnd: + goto BattleScript_MoveEnd + BattleScript_EffectBeatUp:: attackcanceler accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index 8f8d30b56..5b04ecef0 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -161,6 +161,7 @@ #define B_BRICK_BREAK GEN_7 // In Gen4+, you can destroy your own side's screens. In Gen 5+, screens are not removed if the target is immune. #define B_WISH_HP_SOURCE GEN_7 // In Gen5+, Wish heals half of the user's max HP instead of the target's. #define B_RAMPAGE_CANCELLING GEN_7 // In Gen5+, a failed Thrash, etc, will cancel except on its last turn. +#define B_TELEPORT_BEHAVIOR GEN_7 // In LGPE+, Teleport lets the user swap out with another party member. // Ability settings #define B_ABILITY_WEATHER GEN_7 // In Gen6+, ability-induced weather lasts 5 turns. Before, it lasted until the battle ended or until it was changed by a move or a different weather-affecting ability. diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index bd16f741b..dc9258096 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -208,6 +208,8 @@ #define VARIOUS_SET_OCTOLOCK 135 #define VARIOUS_CUT_1_3_HP_RAISE_STATS 136 #define VARIOUS_TRY_END_NEUTRALIZING_GAS 137 +#define VARIOUS_CAN_TELEPORT 138 +#define VARIOUS_GET_BATTLER_SIDE 139 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index fcac02894..3e80a124b 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -7505,6 +7505,37 @@ static bool32 IsRototillerAffected(u32 battlerId) return TRUE; } +static bool32 CanTeleport(u8 battlerId) +{ + struct Pokemon* party = NULL; + u32 species, count, i; + + if (GetBattlerSide(battlerId) == B_SIDE_PLAYER) + party = gPlayerParty; + else + party = gEnemyParty; + for (i = 0; i < PARTY_SIZE; i++) + { + species = GetMonData(&party[i], MON_DATA_SPECIES2); + if (species != SPECIES_NONE && species != SPECIES_EGG && GetMonData(&party[i], MON_DATA_HP) != 0) + count++; + } + + switch (GetBattlerSide(battlerId)) + { + case B_SIDE_OPPONENT: + if (WILD_DOUBLE_BATTLE || gBattleTypeFlags & BATTLE_TYPE_TRAINER) + return FALSE; + case B_SIDE_PLAYER: + if (((gBattleTypeFlags & BATTLE_TYPE_DOUBLE && count >= 3) || (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && count >= 2))) + return TRUE; + default: + break; + } + + return FALSE; +} + static void Cmd_various(void) { struct Pokemon *mon; @@ -9281,6 +9312,15 @@ static void Cmd_various(void) gBattlescriptCurrInstr += 7; return; } + case VARIOUS_CAN_TELEPORT: + gBattleCommunication[0] = CanTeleport(gActiveBattler); + break; + case VARIOUS_GET_BATTLER_SIDE: + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + gBattleCommunication[0] = B_SIDE_PLAYER; + else + gBattleCommunication[0] = B_SIDE_OPPONENT; + break; } // End of switch (gBattlescriptCurrInstr[2]) gBattlescriptCurrInstr += 3; From 195a290a98aba2bc287208b9de943e65b55c0822 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Fri, 6 May 2022 02:34:11 -0300 Subject: [PATCH 2/4] Small corrections --- src/battle_script_commands.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 2ea63b7bf..57dd58648 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -7720,6 +7720,7 @@ static bool32 CanTeleport(u8 battlerId) party = gPlayerParty; else party = gEnemyParty; + for (i = 0; i < PARTY_SIZE; i++) { species = GetMonData(&party[i], MON_DATA_SPECIES2); @@ -7730,16 +7731,16 @@ static bool32 CanTeleport(u8 battlerId) switch (GetBattlerSide(battlerId)) { case B_SIDE_OPPONENT: - if (WILD_DOUBLE_BATTLE || gBattleTypeFlags & BATTLE_TYPE_TRAINER) + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) return FALSE; case B_SIDE_PLAYER: - if (((gBattleTypeFlags & BATTLE_TYPE_DOUBLE && count >= 3) || (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && count >= 2))) - return TRUE; + if (count <= 2 && gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + return FALSE; default: break; } - return FALSE; + return TRUE; } static void Cmd_various(void) From c04f7d5e5bc9bff8a79b0943ba7fef9a5179c523 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Sun, 3 Jul 2022 13:50:42 -0300 Subject: [PATCH 3/4] Changed B_TELEPORT_BEHAVIOR's description comment --- include/constants/battle_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants/battle_config.h b/include/constants/battle_config.h index f3aec0326..798df94f6 100644 --- a/include/constants/battle_config.h +++ b/include/constants/battle_config.h @@ -178,7 +178,7 @@ // Draining abilities will not heal but will prevent damage. In Gen6+, Heal Block prevents the use of most HP-draining moves. #define B_ROOTED_GROUNDING GEN_7 // In Gen4+, Ingrain causes the affected Pokémon to become grounded. #define B_GROWTH_UNDER_SUN GEN_7 // In Gen5+, Growth's effects are doubled when under the effects of the sun. -#define B_TELEPORT_BEHAVIOR GEN_7 // In LGPE+, Teleport lets the user swap out with another party member. +#define B_TELEPORT_BEHAVIOR GEN_7 // In Gen7+, starting with Pokémon Let's Go P/E, Teleport allows the user to swap out with another party member. // Ability settings #define B_EXPANDED_ABILITY_NAMES TRUE // If TRUE, ability names are increased from 12 characters to 16 characters. From a1f921c33dc7843c3a4285b06ff52661ca4f8c23 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 4 Jul 2022 16:15:25 -0300 Subject: [PATCH 4/4] Fixed CanTeleport Also took the chance to correct the syntax inside its switch case. --- src/battle_script_commands.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 43aba0778..ae3acd987 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -7772,10 +7772,10 @@ static bool32 CanTeleport(u8 battlerId) case B_SIDE_OPPONENT: if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) return FALSE; + break; case B_SIDE_PLAYER: - if (count <= 2 && gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + if (count == 1 || (count <= 2 && gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) return FALSE; - default: break; }