From f317b542e22c734bff9d1f32001fcc16bef21c68 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Thu, 9 Dec 2021 20:11:35 -0300 Subject: [PATCH] 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 6ba63f916f..c81a3f3b39 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 e9d019e430..8fe6204600 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 8f8d30b568..5b04ecef08 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 bd16f741be..dc92580964 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 fcac028945..3e80a124ba 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;