Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Teleport ending trainer battles #3166

Merged
merged 5 commits into from
Aug 7, 2023

Conversation

AlexOn1ine
Copy link
Collaborator

Description

Fix by redirecting to the Baton Pass script when it's a trainer battle.

Images

Issue(s) that this PR fixes

Fixes #3164

Discord contact info

@AsparagusEduardo
Copy link
Collaborator

Redirecting to Baton Pass' script will reduce PP twice

@LOuroboros
Copy link
Collaborator

LOuroboros commented Jul 27, 2023

You should update CanTeleport directly imo, @AlexOn1ine.

EDIT:

static bool32 CanTeleport(u8 battlerId)
{
    struct Pokemon *party = GetBattlerParty(battlerId);
    u32 species, count, i;

    for (i = 0; i < PARTY_SIZE; i++)
    {
        species = GetMonData(&party[i], MON_DATA_SPECIES_OR_EGG);
        if (species != SPECIES_NONE && species != SPECIES_EGG && GetMonData(&party[i], MON_DATA_HP) != 0)
            count++;
    }

    switch (GetBattlerSide(battlerId))
    {
    case B_SIDE_OPPONENT:
-       if (count == 1 || gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
+       if (count == 1 || gBattleTypeFlags & (BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TRAINER))
            return FALSE;
        break;
    case B_SIDE_PLAYER:
        if (count == 1 || (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && count <= 2))
            return FALSE;
        break;
    }

    return TRUE;
}

EDIT2: Also, I intended to do this at some point, but I guess I never ended up pushing it. canteleport and the subsequent jumpifbyte could be turned into a macro like jumpifcanteleport or something like that.

@AsparagusEduardo
Copy link
Collaborator

    switch (GetBattlerSide(battlerId))
    {
    case B_SIDE_OPPONENT:
-       if (count == 1 || gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
+       if (count == 1 || gBattleTypeFlags & (BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TRAINER))
            return FALSE;
        break;

This implies that Teleport fails in trainer battles for the opponent, which is not the case.

@AlexOn1ine
Copy link
Collaborator Author

Redirecting to Baton Pass' script will reduce PP twice

Fixed

EDIT2: Also, I intended to do this at some point, but I guess I never ended up pushing it. canteleport and the subsequent jumpifbyte could be turned into a macro like jumpifcanteleport or something like that.

I think canteleport isn't needed anymore so I removed it completely.

@LOuroboros
Copy link
Collaborator

Redirecting to Baton Pass' script will reduce PP twice

Fixed

EDIT2: Also, I intended to do this at some point, but I guess I never ended up pushing it. canteleport and the subsequent jumpifbyte could be turned into a macro like jumpifcanteleport or something like that.

I think canteleport isn't needed anymore so I removed it completely.

Noice!

The suggestion can still be applied to getbattlerside which could be used for a jumpifside macro to save a few lines in the file though 👀

@AlexOn1ine
Copy link
Collaborator Author

The suggestion can still be applied to getbattlerside which could be used for a jumpifside macro to save a few lines in the file though eyes

Something like this?

+	.macro jumpifside battler:req, side:req, jumpInstr:req
+	getbattlerside \battler
+	jumpifbyte CMP_EQUAL, gBattleCommunication, \side, \jumpInstr
+	.endm

-       getbattlerside BS_ATTACKER
-       jumpifbyte CMP_EQUAL, gBattleCommunication, B_SIDE_PLAYER, BattleScript_EffectBatonPass
+       jumpifside BS_ATTACKER, B_SIDE_PLAYER, BattleScript_EffectBatonPass
        jumpifbattletype BATTLE_TYPE_TRAINER, BattleScript_EffectBatonPass
-       jumpifbyte CMP_EQUAL, gBattleCommunication, B_SIDE_OPPONENT, BattleScript_EffectTeleportTryToRunAway
+       jumpifside BS_ATTACKER, B_SIDE_OPPONENT, BattleScript_EffectTeleportTryToRunAway

@LOuroboros
Copy link
Collaborator

Something like this?

Yup. I guess that adds a pointless function call to getbattlerside though, which could be worked around like this:

+	.macro jumpifside battler:req, side:req, equalJumpInstr:req, notEqualJumpInstr:req
+	getbattlerside \battler
+	jumpifbyte CMP_EQUAL, gBattleCommunication, \side, \equalJumpInstr
+	jumpifbyte CMP_NOT_EQUAL, gBattleCommunication, \side, \notEqualJumpInstr
+	.endm

-       getbattlerside BS_ATTACKER
-       jumpifbyte CMP_EQUAL, gBattleCommunication, B_SIDE_PLAYER, BattleScript_EffectBatonPass
+       jumpifside BS_ATTACKER, B_SIDE_PLAYER, BattleScript_EffectBatonPass, BattleScript_EffectTeleportTryToRunAway
        jumpifbattletype BATTLE_TYPE_TRAINER, BattleScript_EffectBatonPass
-       jumpifbyte CMP_EQUAL, gBattleCommunication, B_SIDE_OPPONENT, BattleScript_EffectTeleportTryToRunAway

@AlexOn1ine
Copy link
Collaborator Author

AlexOn1ine commented Jul 29, 2023

Yup. I guess that adds a pointless function call to getbattlerside though, which could be worked around like this:

Looks good, I like it but I think a small modification is needed to avoid the same issue the PR is trying to solve where Teleport would end a trainer battle.

+	.macro jumpifside battler:req, side:req, equalJumpInstr:req, notEqualJumpInstr:req
+	getbattlerside \battler
+	jumpifbyte CMP_EQUAL, gBattleCommunication, \side, \equalJumpInstr
+	jumpifbyte CMP_NOT_EQUAL, gBattleCommunication, \side, \notEqualJumpInstr
+	.endm

-       getbattlerside BS_ATTACKER
-       jumpifbyte CMP_EQUAL, gBattleCommunication, B_SIDE_PLAYER, BattleScript_EffectBatonPass
+       jumpifbattletype BATTLE_TYPE_TRAINER, BattleScript_EffectBatonPass
+       jumpifside BS_ATTACKER, B_SIDE_PLAYER, BattleScript_EffectBatonPass, BattleScript_EffectTeleportTryToRunAway
-       jumpifbattletype BATTLE_TYPE_TRAINER, BattleScript_EffectBatonPass
-       jumpifbyte CMP_EQUAL, gBattleCommunication, B_SIDE_OPPONENT, BattleScript_EffectTeleportTryToRunAway

@AlexOn1ine
Copy link
Collaborator Author

AlexOn1ine commented Jul 29, 2023

Added macro jumpifside as suggested by Lunos.

@AsparagusEduardo AsparagusEduardo merged commit 42992ca into rh-hideout:master Aug 7, 2023
HunarPG pushed a commit to HunarPG/pokeemerald-expansion that referenced this pull request Aug 12, 2023
@AlexOn1ine AlexOn1ine deleted the teleport branch August 31, 2023 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AI using Teleport in a trainer battle ends the battle
3 participants