diff --git a/include/config/battle.h b/include/config/battle.h index ab2178eacc59..14d2b47d32ca 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 b2b6e14447a8..ab84ab90792f 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 da1a8754e106..83f7bb4999ce 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 83ed114c0778..03c375868496 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 7dea410395eb..c06751f6f3e3 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); }