diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 78d3037ae..7ca1c3d96 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2018,3 +2018,10 @@ setvar VAR_0x8002, \tryMultiple special TrySpecialOverworldEvo .endm + + .macro ai_vs_ai_battle trainer1:req, trainer2:req + setflag B_FLAG_AI_VS_AI_BATTLE + setvar VAR_0x8004, trainer1 + callnative CreateTrainerPartyForPlayer + trainerbattle_no_intro trainer2, NULL + .endm diff --git a/include/config/battle.h b/include/config/battle.h index 68cab28b6..3a173138b 100644 --- a/include/config/battle.h +++ b/include/config/battle.h @@ -156,6 +156,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_AI_VS_AI_BATTLE 0 // If this flag is set, the player's mons will be controlled by the ai next battles. // Var Settings // To use the following features in scripting, replace the 0s with the var ID you're assigning it to. diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index b9b0ef0cf..8d35e98ff 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -8,6 +8,7 @@ #include "battle_ai_switch_items.h" #include "battle_factory.h" #include "battle_setup.h" +#include "event_data.h" #include "data.h" #include "item.h" #include "pokemon.h" @@ -445,6 +446,8 @@ bool32 BattlerHasAi(u32 battlerId) switch (GetBattlerPosition(battlerId)) { case B_POSITION_PLAYER_LEFT: + if (FlagGet(B_FLAG_AI_VS_AI_BATTLE)) + return TRUE; default: return FALSE; case B_POSITION_OPPONENT_LEFT: diff --git a/src/battle_controllers.c b/src/battle_controllers.c index d7ca18c6a..8888249f2 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -6,6 +6,7 @@ #include "battle_message.h" #include "battle_setup.h" #include "cable_club.h" +#include "event_data.h" #include "link.h" #include "link_rfu.h" #include "party_menu.h" @@ -170,6 +171,8 @@ static void InitSinglePlayerBtlControllers(void) gBattlerControllerFuncs[0] = SetControllerToSafari; else if (gBattleTypeFlags & BATTLE_TYPE_WALLY_TUTORIAL) gBattlerControllerFuncs[0] = SetControllerToWally; + else if (FlagGet(B_FLAG_AI_VS_AI_BATTLE)) + gBattlerControllerFuncs[0] = SetControllerToPlayerPartner; else gBattlerControllerFuncs[0] = SetControllerToPlayer; @@ -221,13 +224,19 @@ static void InitSinglePlayerBtlControllers(void) { gBattleMainFunc = BeginBattleIntro; - gBattlerControllerFuncs[0] = SetControllerToPlayer; + if (FlagGet(B_FLAG_AI_VS_AI_BATTLE)) + gBattlerControllerFuncs[0] = SetControllerToPlayerPartner; + else + gBattlerControllerFuncs[0] = SetControllerToPlayer; gBattlerPositions[0] = B_POSITION_PLAYER_LEFT; gBattlerControllerFuncs[1] = SetControllerToOpponent; gBattlerPositions[1] = B_POSITION_OPPONENT_LEFT; - gBattlerControllerFuncs[2] = SetControllerToPlayer; + if (FlagGet(B_FLAG_AI_VS_AI_BATTLE)) + gBattlerControllerFuncs[2] = SetControllerToPlayerPartner; + else + gBattlerControllerFuncs[2] = SetControllerToPlayer; gBattlerPositions[2] = B_POSITION_PLAYER_RIGHT; gBattlerControllerFuncs[3] = SetControllerToOpponent; diff --git a/src/battle_main.c b/src/battle_main.c index ace56189c..17d741ee2 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -565,8 +565,8 @@ static void CB2_InitBattleInternal(void) gBattle_BG3_X = 0; gBattle_BG3_Y = 0; -#if DEBUG_OVERWORLD_MENU == FALSE - +#if DEBUG_OVERWORLD_MENU == FALSE + gBattleTerrain = BattleSetup_GetTerrainId(); #else if (!gIsDebugBattle) @@ -594,7 +594,7 @@ static void CB2_InitBattleInternal(void) else SetMainCallback2(CB2_HandleStartBattle); -#if DEBUG_OVERWORLD_MENU == FALSE +#if DEBUG_OVERWORLD_MENU == FALSE if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED))) { CreateNPCTrainerParty(&gEnemyParty[0], gTrainerBattleOpponent_A, TRUE); @@ -2145,6 +2145,12 @@ static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 fir return retVal; } +void CreateTrainerPartyForPlayer(void) +{ + ZeroPlayerPartyMons(); + CreateNPCTrainerPartyFromTrainer(gPlayerParty, &gTrainers[gSpecialVar_0x8004], TRUE, 0); +} + void VBlankCB_Battle(void) { // Change gRngSeed every vblank unless the battle could be recorded.