From ef11706dc7f36699c07a0a1cd8f40b74d9c0f2be Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 14 Oct 2018 22:37:07 +0200 Subject: [PATCH] Begin wild double battles --- include/battle_setup.h | 1 + src/battle_script_commands.c | 30 ++++++++++++++++-------------- src/battle_setup.c | 13 ++++++++++--- src/item_use.c | 14 +++++++++++++- src/wild_encounter.c | 13 ++++++++++++- 5 files changed, 52 insertions(+), 19 deletions(-) diff --git a/include/battle_setup.h b/include/battle_setup.h index 0caa3df27c..88100cf4e0 100644 --- a/include/battle_setup.h +++ b/include/battle_setup.h @@ -37,6 +37,7 @@ extern u16 gTrainerBattleOpponent_B; extern u16 gPartnerTrainerId; void BattleSetup_StartWildBattle(void); +void BattleSetup_StartDoubleWildBattle(void); void BattleSetup_StartBattlePikeWildBattle(void); void BattleSetup_StartRoamerBattle(void); void StartWallyTutorialBattle(void); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 16192425cf..f4debb8fef 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -10489,6 +10489,8 @@ static void atkEF_handleballthrow(void) gActiveBattler = gBattlerAttacker; gBattlerTarget = gBattlerAttacker ^ BIT_SIDE; + if (!IsBattlerAlive(gBattlerTarget)) + gBattlerTarget ^= BIT_FLANK; if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) { @@ -10630,18 +10632,18 @@ static void atkEF_handleballthrow(void) static void atkF0_givecaughtmon(void) { - if (GiveMonToPlayer(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]]) != MON_GIVEN_TO_PARTY) + if (GiveMonToPlayer(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]]) != MON_GIVEN_TO_PARTY) { if (!sub_813B21C()) { gBattleCommunication[MULTISTRING_CHOOSER] = 0; StringCopy(gStringVar1, GetBoxNamePtr(VarGet(VAR_STORAGE_UNKNOWN))); - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_NICKNAME, gStringVar2); + GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_NICKNAME, gStringVar2); } else { StringCopy(gStringVar1, GetBoxNamePtr(VarGet(VAR_STORAGE_UNKNOWN))); - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_NICKNAME, gStringVar2); + GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_NICKNAME, gStringVar2); StringCopy(gStringVar3, GetBoxNamePtr(get_unknown_box_id())); gBattleCommunication[MULTISTRING_CHOOSER] = 2; } @@ -10650,17 +10652,17 @@ static void atkF0_givecaughtmon(void) gBattleCommunication[MULTISTRING_CHOOSER]++; } - gBattleResults.caughtMonSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_SPECIES, NULL); - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_NICKNAME, gBattleResults.caughtMonNick); - gBattleResults.caughtMonBall = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_POKEBALL, NULL); + gBattleResults.caughtMonSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_SPECIES, NULL); + GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_NICKNAME, gBattleResults.caughtMonNick); + gBattleResults.caughtMonBall = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_POKEBALL, NULL); gBattlescriptCurrInstr++; } static void atkF1_trysetcaughtmondexflags(void) { - u16 species = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, NULL); - u32 personality = GetMonData(&gEnemyParty[0], MON_DATA_PERSONALITY, NULL); + u16 species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_SPECIES, NULL); + u32 personality = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_PERSONALITY, NULL); if (GetSetPokedexFlag(SpeciesToNationalPokedexNum(species), FLAG_GET_CAUGHT)) { @@ -10675,7 +10677,7 @@ static void atkF1_trysetcaughtmondexflags(void) static void atkF2_displaydexinfo(void) { - u16 species = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, NULL); + u16 species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_SPECIES, NULL); switch (gBattleCommunication[0]) { @@ -10840,13 +10842,13 @@ static void atkF3_trygivecaughtmonnick(void) case 2: if (!gPaletteFade.active) { - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_NICKNAME, gBattleStruct->caughtMonNick); + GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_NICKNAME, gBattleStruct->caughtMonNick); FreeAllWindowBuffers(); DoNamingScreen(NAMING_SCREEN_CAUGHT_MON, gBattleStruct->caughtMonNick, - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_SPECIES), - GetMonGender(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]]), - GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_PERSONALITY, NULL), + GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_SPECIES), + GetMonGender(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]]), + GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_PERSONALITY, NULL), BattleMainCB2); gBattleCommunication[MULTIUSE_STATE]++; @@ -10855,7 +10857,7 @@ static void atkF3_trygivecaughtmonnick(void) case 3: if (gMain.callback2 == BattleMainCB2 && !gPaletteFade.active ) { - SetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker ^ BIT_SIDE]], MON_DATA_NICKNAME, gBattleStruct->caughtMonNick); + SetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattlerTarget]], MON_DATA_NICKNAME, gBattleStruct->caughtMonNick); gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1); } break; diff --git a/src/battle_setup.c b/src/battle_setup.c index f9fab3d172..96c2de5197 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -80,7 +80,7 @@ extern void CopyTrainerHillTrainerText(u8 a0, u16 arg1); // this file's functions static void DoBattlePikeWildBattle(void); static void DoSafariBattle(void); -static void DoStandardWildBattle(void); +static void DoStandardWildBattle(bool32 isDouble); static void CB2_EndWildBattle(void); static void CB2_EndScriptedWildBattle(void); static u8 GetWildBattleTransition(void); @@ -378,7 +378,12 @@ void BattleSetup_StartWildBattle(void) if (GetSafariZoneFlag()) DoSafariBattle(); else - DoStandardWildBattle(); + DoStandardWildBattle(FALSE); +} + +void BattleSetup_StartDoubleWildBattle(void) +{ + DoStandardWildBattle(TRUE); } void BattleSetup_StartBattlePikeWildBattle(void) @@ -386,13 +391,15 @@ void BattleSetup_StartBattlePikeWildBattle(void) DoBattlePikeWildBattle(); } -static void DoStandardWildBattle(void) +static void DoStandardWildBattle(bool32 isDouble) { ScriptContext2_Enable(); FreezeEventObjects(); sub_808BCF4(); gMain.savedCallback = CB2_EndWildBattle; gBattleTypeFlags = 0; + if (isDouble) + gBattleTypeFlags |= BATTLE_TYPE_DOUBLE; if (InBattlePyramid()) { VarSet(VAR_TEMP_E, 0); diff --git a/src/item_use.c b/src/item_use.c index 633d975a8c..6099c0b65c 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -931,7 +931,17 @@ void ItemUseOutOfBattle_EvolutionStone(u8 taskId) void ItemUseInBattle_PokeBall(u8 taskId) { - if (IsPlayerPartyAndPokemonStorageFull() == FALSE) // have room for mon? + if (IsBattlerAlive(GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT)) + && IsBattlerAlive(GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT))) // There are two present pokemon. + { + u8 textCantThrowPokeBall[] = _("Cannot throw a ball!\nThere are two pokemon out there!\p"); + + if (!InBattlePyramid()) + DisplayItemMessage(taskId, 1, textCantThrowPokeBall, bag_menu_inits_lists_menu); + else + DisplayItemMessageInBattlePyramid(taskId, textCantThrowPokeBall, sub_81C6714); + } + else if (IsPlayerPartyAndPokemonStorageFull() == FALSE) // have room for mon? { RemoveBagItem(gSpecialVar_ItemId, 1); if (!InBattlePyramid()) @@ -944,7 +954,9 @@ void ItemUseInBattle_PokeBall(u8 taskId) DisplayItemMessage(taskId, 1, gText_BoxFull, bag_menu_inits_lists_menu); } else + { DisplayItemMessageInBattlePyramid(taskId, gText_BoxFull, sub_81C6714); + } } void sub_80FE408(u8 taskId) diff --git a/src/wild_encounter.c b/src/wild_encounter.c index 9a22323ffc..8a3ee01488 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -18,6 +18,7 @@ #include "tv.h" #include "link.h" #include "script.h" +#include "battle_debug.h" #include "constants/items.h" #include "constants/maps.h" @@ -5146,7 +5147,17 @@ bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavi // try a regular wild land encounter if (TryGenerateWildMon(gWildMonHeaders[headerId].landMonsInfo, WILD_AREA_LAND, WILD_CHECK_REPEL | WILD_CHECK_KEEN_EYE) == TRUE) { - BattleSetup_StartWildBattle(); + if (USE_BATTLE_DEBUG && GetMonsStateToDoubles() == PLAYER_HAS_TWO_USABLE_MONS) + { + struct Pokemon mon1 = gEnemyParty[0]; + TryGenerateWildMon(gWildMonHeaders[headerId].landMonsInfo, WILD_AREA_LAND, WILD_CHECK_KEEN_EYE); + gEnemyParty[1] = mon1; + BattleSetup_StartDoubleWildBattle(); + } + else + { + BattleSetup_StartWildBattle(); + } return TRUE; }