Skip to content

Commit

Permalink
Add battle flag that prevents running from wild Pokémon (#5502)
Browse files Browse the repository at this point in the history
* 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 <iasperbassoonian@gmail.com>

* Adjust for pre-Gen 8 Teleport

Addresses the edge case with Teleport when used with under Gen 8 mechanics.

---------

Co-authored-by: Bassoonian <iasperbassoonian@gmail.com>
  • Loading branch information
SarnPoke and Bassoonian authored Oct 11, 2024
1 parent 464c90a commit 2db1f07
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/config/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/overworld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 2db1f07

Please sign in to comment.