From 2db1f071fa1348959ccaae88c88bd80fbd8ef129 Mon Sep 17 00:00:00 2001 From: SarnPoke <77281351+SarnPoke@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:59:50 +0200 Subject: [PATCH] =?UTF-8?q?Add=20battle=20flag=20that=20prevents=20running?= =?UTF-8?q?=20from=20wild=20Pok=C3=A9mon=20(#5502)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add No Running Battle Flag Adds a flag that if set prevents the player from being able to run from wild battles. * Formatting battle_util.c Co-authored-by: Bassoonian * Adjust for pre-Gen 8 Teleport Addresses the edge case with Teleport when used with under Gen 8 mechanics. --------- Co-authored-by: Bassoonian --- include/config/battle.h | 1 + src/battle_main.c | 9 ++++++++- src/battle_script_commands.c | 3 +++ src/battle_util.c | 4 ++++ src/overworld.c | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/config/battle.h b/include/config/battle.h index ab2178eacc..14d2b47d32 100644 --- a/include/config/battle.h +++ b/include/config/battle.h @@ -187,6 +187,7 @@ #define B_SMART_WILD_AI_FLAG 0 // If not 0, you can set this flag in a script to enable smart wild pokemon #define B_FLAG_NO_BAG_USE 0 // If this flag is set, the ability to use the bag in battle is disabled. #define B_FLAG_NO_CATCHING 0 // If this flag is set, the ability to catch wild Pokémon is disabled. +#define B_FLAG_NO_RUNNING 0 // If this flag is set, the ability to escape from wild battles is disabled. Also makes Roar/Whirlwind and Teleport (under Gen8) fail. #define B_FLAG_AI_VS_AI_BATTLE 0 // If this flag is set, the player's mons will be controlled by the ai next battles. #define B_FLAG_DYNAMAX_BATTLE 0 // If this flag is set, the ability to Dynamax in battle is enabled for all trainers. #define B_FLAG_TERA_ORB_CHARGED 0 // If this flag is set, the Tera Orb is charged. It is automatically set upon healing and cleared upon Terastallizing once configured. diff --git a/src/battle_main.c b/src/battle_main.c index b2b6e14447..ab84ab9079 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -4073,6 +4073,12 @@ u8 IsRunningFromBattleImpossible(u32 battler) { u32 holdEffect, i; + if (FlagGet(B_FLAG_NO_RUNNING)) + { + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_CANT_ESCAPE; + return BATTLE_RUN_FORBIDDEN; + } + if (gBattleMons[battler].item == ITEM_ENIGMA_BERRY_E_READER) holdEffect = gEnigmaBerries[battler].holdEffect; else @@ -4430,8 +4436,9 @@ static void HandleTurnActionSelectionState(void) BattleScriptExecute(BattleScript_PrintCantRunFromTrainer); gBattleCommunication[battler] = STATE_BEFORE_ACTION_CHOSEN; } - else if (IsRunningFromBattleImpossible(battler) != BATTLE_RUN_SUCCESS + else if ((IsRunningFromBattleImpossible(battler) != BATTLE_RUN_SUCCESS && gBattleResources->bufferB[battler][1] == B_ACTION_RUN) + || (FlagGet(B_FLAG_NO_RUNNING) == TRUE && gBattleResources->bufferB[battler][1] == B_ACTION_RUN)) { gSelectionBattleScripts[battler] = BattleScript_PrintCantEscapeFromBattle; gBattleCommunication[battler] = STATE_SELECTION_SCRIPT; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index da1a8754e1..83f7bb4999 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -9076,6 +9076,7 @@ static void Cmd_various(void) { // Roar will fail in a double wild battle when used by the player against one of the two alive wild mons. // Also when an opposing wild mon uses it againt its partner. + // Also when B_FLAG_NO_RUNNING is enabled. case VARIOUS_JUMP_IF_ROAR_FAILS: { VARIOUS_ARGS(const u8 *jumpInstr); @@ -9088,6 +9089,8 @@ static void Cmd_various(void) && GetBattlerSide(gBattlerAttacker) == B_SIDE_OPPONENT && GetBattlerSide(gBattlerTarget) == B_SIDE_OPPONENT) gBattlescriptCurrInstr = cmd->jumpInstr; + else if (FlagGet(B_FLAG_NO_RUNNING)) + gBattlescriptCurrInstr = cmd->jumpInstr; else gBattlescriptCurrInstr = cmd->nextInstr; return; diff --git a/src/battle_util.c b/src/battle_util.c index 83ed114c07..03c3758684 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -450,6 +450,10 @@ bool32 TryRunFromBattle(u32 battler) u8 pyramidMultiplier; u8 speedVar; + // If this flag is set, running will never be successful under any circumstances. + if (FlagGet(B_FLAG_NO_RUNNING)) + return effect; + if (gBattleMons[battler].item == ITEM_ENIGMA_BERRY_E_READER) holdEffect = gEnigmaBerries[battler].holdEffect; else diff --git a/src/overworld.c b/src/overworld.c index 7dea410395..c06751f6f3 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -423,6 +423,7 @@ void Overworld_ResetBattleFlagsAndVars(void) FlagClear(B_SMART_WILD_AI_FLAG); FlagClear(B_FLAG_NO_BAG_USE); FlagClear(B_FLAG_NO_CATCHING); + FlagClear(B_FLAG_NO_RUNNING); FlagClear(B_FLAG_DYNAMAX_BATTLE); FlagClear(B_FLAG_SKY_BATTLE); }