From afb3472282c52746aaac52d1e361d0c9bdf31de3 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 30 Aug 2020 15:11:44 -0400 Subject: Minor battle_anim_throw cleanup --- src/battle_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index 935a53ffe..00ef33cf2 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -2978,7 +2978,7 @@ void sub_8039E60(struct Sprite *sprite) sprite->callback = SpriteCallbackDummy_3; } -void sub_8039E84(struct Sprite *sprite) +void SpriteCB_TrainerThrowObject(struct Sprite *sprite) { StartSpriteAnim(sprite, 1); sprite->callback = sub_8039E60; -- cgit v1.2.3 From a529bcf0b696eaad60806a676397aac7ca9226d1 Mon Sep 17 00:00:00 2001 From: Thomas Winwood Date: Wed, 2 Sep 2020 14:49:04 +0100 Subject: Tidy up naked functions --- src/battle_main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index 935a53ffe..99d48ef27 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3649,8 +3649,8 @@ static void BattleIntroOpponent1SendsOutMonAnimation(void) NAKED static void BattleIntroOpponent1SendsOutMonAnimation(void) { - asm(".syntax unified\n\ - push {r4-r6,lr}\n\ + asm_unified( + "push {r4-r6,lr}\n\ ldr r0, =gBattleTypeFlags\n\ ldr r2, [r0]\n\ movs r0, 0x80\n\ @@ -3728,8 +3728,7 @@ _0803B2F2:\n\ pop {r4-r6}\n\ pop {r0}\n\ bx r0\n\ - .pool\n\ - .syntax divided"); + .pool"); } #endif // NONMATCHING -- cgit v1.2.3 From 28ef2fb774bf596a3e7f81055453304e0d2ce066 Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Fri, 4 Sep 2020 21:11:55 -0400 Subject: Switch to button macros --- src/battle_main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index 2c3df2e34..193fffaf2 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -1854,7 +1854,7 @@ void BattleMainCB2(void) UpdatePaletteFade(); RunTasks(); - if (gMain.heldKeys & B_BUTTON && gBattleTypeFlags & BATTLE_TYPE_RECORDED && sub_8186450()) + if (JOY_HELD(B_BUTTON) && gBattleTypeFlags & BATTLE_TYPE_RECORDED && sub_8186450()) { gSpecialVar_Result = gBattleOutcome = B_OUTCOME_PLAYER_TELEPORTED; ResetPaletteFadeControl(); @@ -2510,7 +2510,7 @@ static void sub_803939C(void) } break; case 5: - if (gMain.newKeys & DPAD_UP) + if (JOY_NEW(DPAD_UP)) { if (gBattleCommunication[CURSOR_POSITION] != 0) { @@ -2520,7 +2520,7 @@ static void sub_803939C(void) BattleCreateYesNoCursorAt(0); } } - else if (gMain.newKeys & DPAD_DOWN) + else if (JOY_NEW(DPAD_DOWN)) { if (gBattleCommunication[CURSOR_POSITION] == 0) { @@ -2530,7 +2530,7 @@ static void sub_803939C(void) BattleCreateYesNoCursorAt(1); } } - else if (gMain.newKeys & A_BUTTON) + else if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); if (gBattleCommunication[CURSOR_POSITION] == 0) @@ -2544,7 +2544,7 @@ static void sub_803939C(void) gBattleCommunication[MULTIUSE_STATE]++; } } - else if (gMain.newKeys & B_BUTTON) + else if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); gBattleCommunication[MULTIUSE_STATE]++; -- cgit v1.2.3 From 0039542e19112ab9c31216cc087e3863cdeabb1e Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Sat, 5 Sep 2020 12:28:02 -0400 Subject: Match CheckBagHasSpace --- src/battle_main.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index 193fffaf2..7474ea1dd 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -655,19 +655,16 @@ static void CB2_InitBattleInternal(void) gBattle_WIN0V = 0x5051; ScanlineEffect_Clear(); - i = 0; - while (i < 80) + for (i = 0; i < 80; i++) { gScanlineEffectRegBuffers[0][i] = 0xF0; gScanlineEffectRegBuffers[1][i] = 0xF0; - i++; } - while (i < 160) + for (; i < 160; i++) { gScanlineEffectRegBuffers[0][i] = 0xFF10; gScanlineEffectRegBuffers[1][i] = 0xFF10; - i++; } ScanlineEffect_SetParams(sIntroScanlineParams16Bit); @@ -794,8 +791,7 @@ static void SetPlayerBerryDataInBattleStruct(void) static void SetAllPlayersBerryData(void) { - s32 i; - s32 j; + s32 i, j; if (!(gBattleTypeFlags & BATTLE_TYPE_LINK)) { @@ -3560,7 +3556,7 @@ static void BattleIntroPrintWildMonAttacked(void) static void BattleIntroPrintOpponentSendsOut(void) { - u32 position; + u8 position; if (gBattleControllerExecFlags) return; @@ -3583,7 +3579,7 @@ static void BattleIntroPrintOpponentSendsOut(void) static void BattleIntroOpponent2SendsOutMonAnimation(void) { - u32 position; + u8 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_OPPONENT_RIGHT; @@ -3612,7 +3608,7 @@ static void BattleIntroOpponent2SendsOutMonAnimation(void) #ifdef NONMATCHING static void BattleIntroOpponent1SendsOutMonAnimation(void) { - u32 position; + u8 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_OPPONENT_LEFT; @@ -3785,7 +3781,7 @@ static void BattleIntroPrintPlayerSendsOut(void) static void BattleIntroPlayer2SendsOutMonAnimation(void) { - u32 position; + u8 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_RIGHT; @@ -3817,7 +3813,7 @@ static void BattleIntroPlayer2SendsOutMonAnimation(void) static void BattleIntroPlayer1SendsOutMonAnimation(void) { - u32 position; + u8 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_LEFT; -- cgit v1.2.3 From 3ce29ee7bf9b104609cbfced8486884540021c00 Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Sat, 5 Sep 2020 17:36:10 -0400 Subject: Refactor Use Item --- src/battle_main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index 7474ea1dd..f118c52fd 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5556,11 +5556,9 @@ static void HandleAction_UseItem(void) break; case AI_ITEM_CURE_CONDITION: gBattleCommunication[MULTISTRING_CHOOSER] = 0; - if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1) - { - if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 0x3E) + if ((*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1) + && (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 0x3E)) gBattleCommunication[MULTISTRING_CHOOSER] = 5; - } else { while (!(*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1)) -- cgit v1.2.3 From fe9ab670630ea9458e59c4af991e743c44b3618c Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Sat, 5 Sep 2020 18:13:51 -0400 Subject: Change division to explicit shifts for consistency --- src/battle_main.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index f118c52fd..5bd98d25b 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3556,7 +3556,7 @@ static void BattleIntroPrintWildMonAttacked(void) static void BattleIntroPrintOpponentSendsOut(void) { - u8 position; + u32 position; if (gBattleControllerExecFlags) return; @@ -3579,7 +3579,7 @@ static void BattleIntroPrintOpponentSendsOut(void) static void BattleIntroOpponent2SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_OPPONENT_RIGHT; @@ -3608,7 +3608,7 @@ static void BattleIntroOpponent2SendsOutMonAnimation(void) #ifdef NONMATCHING static void BattleIntroOpponent1SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_OPPONENT_LEFT; @@ -3781,7 +3781,7 @@ static void BattleIntroPrintPlayerSendsOut(void) static void BattleIntroPlayer2SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_RIGHT; @@ -3813,7 +3813,7 @@ static void BattleIntroPlayer2SendsOutMonAnimation(void) static void BattleIntroPlayer1SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_LEFT; @@ -5556,14 +5556,16 @@ static void HandleAction_UseItem(void) break; case AI_ITEM_CURE_CONDITION: gBattleCommunication[MULTISTRING_CHOOSER] = 0; - if ((*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1) - && (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 0x3E)) + if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1) + { + if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 0x3E) gBattleCommunication[MULTISTRING_CHOOSER] = 5; + } else { - while (!(*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1)) + while (!(*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1)) { - *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; + *(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) >>= 1; gBattleCommunication[MULTISTRING_CHOOSER]++; } } @@ -5581,7 +5583,7 @@ static void HandleAction_UseItem(void) while (!((*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1))) & 1)) { - *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; + *(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) >>= 1; gBattleTextBuff1[2]++; } @@ -5597,7 +5599,7 @@ static void HandleAction_UseItem(void) break; } - gBattlescriptCurrInstr = gBattlescriptsForUsingItem[*(gBattleStruct->AI_itemType + gBattlerAttacker / 2)]; + gBattlescriptCurrInstr = gBattlescriptsForUsingItem[*(gBattleStruct->AI_itemType + (gBattlerAttacker >> 1))]; } gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; } -- cgit v1.2.3 From 8b729cf22583dbebfeffab60538ce69b1fcb113e Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Sat, 5 Sep 2020 18:15:53 -0400 Subject: While to do_while --- src/battle_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index 5bd98d25b..7fa59e6d4 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5563,11 +5563,11 @@ static void HandleAction_UseItem(void) } else { - while (!(*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1)) + do { *(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) >>= 1; gBattleCommunication[MULTISTRING_CHOOSER]++; - } + } while (!(*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1)); } break; case AI_ITEM_X_STAT: -- cgit v1.2.3 From 8200682b21fc6e9bb61e20a300fccb30970b995f Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Sun, 6 Sep 2020 19:02:30 -0400 Subject: u8 position --- src/battle_main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index 7fa59e6d4..2e280b4c8 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3556,7 +3556,7 @@ static void BattleIntroPrintWildMonAttacked(void) static void BattleIntroPrintOpponentSendsOut(void) { - u32 position; + u8 position; if (gBattleControllerExecFlags) return; @@ -3579,7 +3579,7 @@ static void BattleIntroPrintOpponentSendsOut(void) static void BattleIntroOpponent2SendsOutMonAnimation(void) { - u32 position; + u8 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_OPPONENT_RIGHT; @@ -3608,7 +3608,7 @@ static void BattleIntroOpponent2SendsOutMonAnimation(void) #ifdef NONMATCHING static void BattleIntroOpponent1SendsOutMonAnimation(void) { - u32 position; + u8 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_OPPONENT_LEFT; @@ -3781,7 +3781,7 @@ static void BattleIntroPrintPlayerSendsOut(void) static void BattleIntroPlayer2SendsOutMonAnimation(void) { - u32 position; + u8 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_RIGHT; @@ -3813,7 +3813,7 @@ static void BattleIntroPlayer2SendsOutMonAnimation(void) static void BattleIntroPlayer1SendsOutMonAnimation(void) { - u32 position; + u8 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_LEFT; -- cgit v1.2.3 From 5f7a410359ea4036c43cbe182a49c7b0f878e227 Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Sun, 6 Sep 2020 20:01:16 -0400 Subject: Preparation for matching BattleIntroOpponent1SendsOutMonAnimation --- src/battle_main.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index 2e280b4c8..e62513680 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3610,17 +3610,22 @@ static void BattleIntroOpponent1SendsOutMonAnimation(void) { u8 position; - if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) - position = B_POSITION_OPPONENT_LEFT; - else if (gBattleTypeFlags & BATTLE_TYPE_x2000000) + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) { - if (gBattleTypeFlags & BATTLE_TYPE_x80000000) - position = B_POSITION_OPPONENT_LEFT; + if (gBattleTypeFlags & BATTLE_TYPE_x2000000) + { + if (gBattleTypeFlags & BATTLE_TYPE_x80000000) + position = B_POSITION_OPPONENT_LEFT; + else + position = B_POSITION_PLAYER_LEFT; + } else - position = B_POSITION_PLAYER_LEFT; + position = B_POSITION_OPPONENT_LEFT; } else + { position = B_POSITION_OPPONENT_LEFT; + } if (gBattleControllerExecFlags) return; @@ -5099,15 +5104,15 @@ static void HandleEndTurn_RanFromBattle(void) { switch (gProtectStructs[gBattlerAttacker].fleeFlag) { - default: - gBattlescriptCurrInstr = BattleScript_GotAwaySafely; - break; case 1: gBattlescriptCurrInstr = BattleScript_SmokeBallEscape; break; case 2: gBattlescriptCurrInstr = BattleScript_RanAwayUsingMonAbility; break; + default: + gBattlescriptCurrInstr = BattleScript_GotAwaySafely; + break; } } @@ -5191,10 +5196,7 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void) gBattleMainFunc = ReturnFromBattleToOverworld; return; } - else - { - gBattleMainFunc = TryEvolvePokemon; - } + gBattleMainFunc = TryEvolvePokemon; } FreeAllWindowBuffers(); @@ -5530,7 +5532,9 @@ static void HandleAction_UseItem(void) gBattlerAttacker = gBattlerTarget = gBattlerByTurnOrder[gCurrentTurnActionNumber]; gBattle_BG0_X = 0; gBattle_BG0_Y = 0; + ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); + gLastUsedItem = gBattleBufferB[gBattlerAttacker][1] | (gBattleBufferB[gBattlerAttacker][2] << 8); if (gLastUsedItem <= LAST_BALL) // is ball -- cgit v1.2.3 From 3336eb341d4407a42115b52f6404ad921269b2af Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Tue, 8 Sep 2020 14:26:37 -0400 Subject: More adjustments --- src/battle_main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index e62513680..e2b3714fc 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3753,7 +3753,7 @@ static void BattleIntroRecordMonsToDex(void) } } -void sub_803B3AC(void) // unused +static void sub_803B3AC(void) // unused { if (gBattleControllerExecFlags == 0) gBattleMainFunc = BattleIntroPrintPlayerSendsOut; @@ -3856,7 +3856,7 @@ static void BattleIntroPlayer1SendsOutMonAnimation(void) gBattleMainFunc = TryDoEventsBeforeFirstTurn; } -void sub_803B598(void) // unused +static void sub_803B598(void) // unused { if (gBattleControllerExecFlags == 0) { @@ -3879,8 +3879,7 @@ void sub_803B598(void) // unused static void TryDoEventsBeforeFirstTurn(void) { - s32 i; - s32 j; + s32 i, j; u8 effect = 0; if (gBattleControllerExecFlags) -- cgit v1.2.3 From e84da39d8ad7228e731a55b2d6eaf58aa8acc96f Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Tue, 8 Sep 2020 16:44:04 -0400 Subject: Match BattleIntroOpponent1SendsOutMonAnimation --- src/battle_main.c | 705 +----------------------------------------------------- 1 file changed, 3 insertions(+), 702 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index e2b3714fc..66af8d07f 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -11,6 +11,7 @@ #include "battle_scripts.h" #include "battle_setup.h" #include "battle_tower.h" +#include "battle_util.h" #include "berry.h" #include "bg.h" #include "data.h" @@ -66,11 +67,6 @@ extern struct MusicPlayerInfo gMPlayInfo_SE2; extern const struct BgTemplate gBattleBgTemplates[]; extern const struct WindowTemplate *const gBattleWindowTemplates[]; -extern const u8 *const gBattleScriptsForMoveEffects[]; -extern const u8 *const gBattlescriptsForBallThrow[]; -extern const u8 *const gBattlescriptsForRunningByItem[]; -extern const u8 *const gBattlescriptsForUsingItem[]; -extern const u8 *const gBattlescriptsForSafariActions[]; // this file's functions #if !defined(NONMATCHING) && MODERN @@ -99,7 +95,6 @@ static void SpriteCB_AnimFaintOpponent(struct Sprite *sprite); static void SpriteCb_BlinkVisible(struct Sprite *sprite); static void SpriteCallbackDummy_3(struct Sprite *sprite); static void oac_poke_ally_(struct Sprite *sprite); -static void SpecialStatusesClear(void); static void TurnValuesCleanUp(bool8 var0); static void SpriteCB_BounceEffect(struct Sprite *sprite); static void BattleStartClearSetData(void); @@ -132,19 +127,7 @@ static void HandleEndTurn_BattleLost(void); static void HandleEndTurn_RanFromBattle(void); static void HandleEndTurn_MonFled(void); static void HandleEndTurn_FinishBattle(void); -static void HandleAction_UseMove(void); -static void HandleAction_Switch(void); -static void HandleAction_UseItem(void); -static void HandleAction_Run(void); -static void HandleAction_WatchesCarefully(void); -static void HandleAction_SafariZoneBallThrow(void); -static void HandleAction_ThrowPokeblock(void); -static void HandleAction_GoNear(void); -static void HandleAction_SafariZoneRun(void); -static void HandleAction_WallyBallThrow(void); -static void HandleAction_TryFinish(void); -static void HandleAction_NothingIsFainted(void); -static void HandleAction_ActionFinished(void); + // EWRAM vars EWRAM_DATA u16 gBattle_BG0_X = 0; @@ -591,10 +574,6 @@ const u8 * const gStatusConditionStringsTable[7][2] = {gStatusConditionString_LoveJpn, gText_Love} }; -static const u8 sPkblToEscapeFactor[][3] = {{0, 0, 0}, {3, 5, 0}, {2, 3, 0}, {1, 2, 0}, {1, 1, 0}}; -static const u8 sGoNearCounterToCatchFactor[] = {4, 3, 2, 1}; -static const u8 sGoNearCounterToEscapeFactor[] = {4, 4, 4, 4}; - // code void CB2_InitBattle(void) { @@ -3605,7 +3584,6 @@ static void BattleIntroOpponent2SendsOutMonAnimation(void) gBattleMainFunc = BattleIntroRecordMonsToDex; } -#ifdef NONMATCHING static void BattleIntroOpponent1SendsOutMonAnimation(void) { u8 position; @@ -3646,92 +3624,6 @@ static void BattleIntroOpponent1SendsOutMonAnimation(void) gBattleMainFunc = BattleIntroRecordMonsToDex; } -#else -NAKED -static void BattleIntroOpponent1SendsOutMonAnimation(void) -{ - asm_unified( - "push {r4-r6,lr}\n\ - ldr r0, =gBattleTypeFlags\n\ - ldr r2, [r0]\n\ - movs r0, 0x80\n\ - lsls r0, 17\n\ - ands r0, r2\n\ - cmp r0, 0\n\ - beq _0803B298\n\ - movs r0, 0x80\n\ - lsls r0, 18\n\ - ands r0, r2\n\ - cmp r0, 0\n\ - beq _0803B298\n\ - movs r1, 0x80\n\ - lsls r1, 24\n\ - ands r1, r2\n\ - negs r0, r1\n\ - orrs r0, r1\n\ - lsrs r5, r0, 31\n\ - b _0803B29A\n\ - .pool\n\ -_0803B288:\n\ - ldr r1, =gBattleMainFunc\n\ - ldr r0, =BattleIntroOpponent2SendsOutMonAnimation\n\ - b _0803B2F0\n\ - .pool\n\ -_0803B298:\n\ - movs r5, 0x1\n\ -_0803B29A:\n\ - ldr r0, =gBattleControllerExecFlags\n\ - ldr r2, [r0]\n\ - cmp r2, 0\n\ - bne _0803B2F2\n\ - ldr r0, =gActiveBattler\n\ - strb r2, [r0]\n\ - ldr r1, =gBattlersCount\n\ - adds r4, r0, 0\n\ - ldrb r1, [r1]\n\ - cmp r2, r1\n\ - bcs _0803B2EC\n\ - adds r6, r4, 0\n\ -_0803B2B2:\n\ - ldrb r0, [r4]\n\ - bl GetBattlerPosition\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - cmp r0, r5\n\ - bne _0803B2D8\n\ - movs r0, 0\n\ - bl BtlController_EmitIntroTrainerBallThrow\n\ - ldrb r0, [r4]\n\ - bl MarkBattlerForControllerExec\n\ - ldr r0, =gBattleTypeFlags\n\ - ldr r0, [r0]\n\ - ldr r1, =0x00008040\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - bne _0803B288\n\ -_0803B2D8:\n\ - ldrb r0, [r6]\n\ - adds r0, 0x1\n\ - strb r0, [r6]\n\ - ldr r1, =gBattlersCount\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - ldr r4, =gActiveBattler\n\ - ldrb r1, [r1]\n\ - cmp r0, r1\n\ - bcc _0803B2B2\n\ -_0803B2EC:\n\ - ldr r1, =gBattleMainFunc\n\ - ldr r0, =BattleIntroRecordMonsToDex\n\ -_0803B2F0:\n\ - str r0, [r1]\n\ -_0803B2F2:\n\ - pop {r4-r6}\n\ - pop {r0}\n\ - bx r0\n\ - .pool"); -} -#endif // NONMATCHING static void BattleIntroRecordMonsToDex(void) { @@ -4927,7 +4819,7 @@ static void TurnValuesCleanUp(bool8 var0) gSideTimers[1].followmeTimer = 0; } -static void SpecialStatusesClear(void) +void SpecialStatusesClear(void) { for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { @@ -5291,594 +5183,3 @@ void RunBattleScriptCommands(void) gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); } -static void HandleAction_UseMove(void) -{ - u8 side; - u8 var = 4; - - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - - if (*(&gBattleStruct->field_91) & gBitTable[gBattlerAttacker]) - { - gCurrentActionFuncId = B_ACTION_FINISHED; - return; - } - - gCritMultiplier = 1; - gBattleScripting.dmgMultiplier = 1; - gBattleStruct->atkCancellerTracker = 0; - gMoveResultFlags = 0; - gMultiHitCounter = 0; - gBattleCommunication[6] = 0; - gCurrMovePos = gChosenMovePos = *(gBattleStruct->chosenMovePositions + gBattlerAttacker); - - // choose move - if (gProtectStructs[gBattlerAttacker].noValidMoves) - { - gProtectStructs[gBattlerAttacker].noValidMoves = 0; - gCurrentMove = gChosenMove = MOVE_STRUGGLE; - gHitMarker |= HITMARKER_NO_PPDEDUCT; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(MOVE_STRUGGLE, 0); - } - else if (gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS || gBattleMons[gBattlerAttacker].status2 & STATUS2_RECHARGE) - { - gCurrentMove = gChosenMove = gLockedMoves[gBattlerAttacker]; - } - // encore forces you to use the same move - else if (gDisableStructs[gBattlerAttacker].encoredMove != MOVE_NONE - && gDisableStructs[gBattlerAttacker].encoredMove == gBattleMons[gBattlerAttacker].moves[gDisableStructs[gBattlerAttacker].encoredMovePos]) - { - gCurrentMove = gChosenMove = gDisableStructs[gBattlerAttacker].encoredMove; - gCurrMovePos = gChosenMovePos = gDisableStructs[gBattlerAttacker].encoredMovePos; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); - } - // check if the encored move wasn't overwritten - else if (gDisableStructs[gBattlerAttacker].encoredMove != MOVE_NONE - && gDisableStructs[gBattlerAttacker].encoredMove != gBattleMons[gBattlerAttacker].moves[gDisableStructs[gBattlerAttacker].encoredMovePos]) - { - gCurrMovePos = gChosenMovePos = gDisableStructs[gBattlerAttacker].encoredMovePos; - gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; - gDisableStructs[gBattlerAttacker].encoredMove = MOVE_NONE; - gDisableStructs[gBattlerAttacker].encoredMovePos = 0; - gDisableStructs[gBattlerAttacker].encoreTimer = 0; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); - } - else if (gBattleMons[gBattlerAttacker].moves[gCurrMovePos] != gChosenMoveByBattler[gBattlerAttacker]) - { - gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); - } - else - { - gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; - } - - if (gBattleMons[gBattlerAttacker].hp != 0) - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - gBattleResults.lastUsedMovePlayer = gCurrentMove; - else - gBattleResults.lastUsedMoveOpponent = gCurrentMove; - } - - // choose target - side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; - if (gSideTimers[side].followmeTimer != 0 - && gBattleMoves[gCurrentMove].target == MOVE_TARGET_SELECTED - && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gSideTimers[side].followmeTarget) - && gBattleMons[gSideTimers[side].followmeTarget].hp != 0) - { - gBattlerTarget = gSideTimers[side].followmeTarget; - } - else if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - && gSideTimers[side].followmeTimer == 0 - && (gBattleMoves[gCurrentMove].power != 0 - || gBattleMoves[gCurrentMove].target != MOVE_TARGET_USER) - && gBattleMons[*(gBattleStruct->moveTarget + gBattlerAttacker)].ability != ABILITY_LIGHTNING_ROD - && gBattleMoves[gCurrentMove].type == TYPE_ELECTRIC) - { - side = GetBattlerSide(gBattlerAttacker); - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) - { - if (side != GetBattlerSide(gActiveBattler) - && *(gBattleStruct->moveTarget + gBattlerAttacker) != gActiveBattler - && gBattleMons[gActiveBattler].ability == ABILITY_LIGHTNING_ROD - && GetBattlerTurnOrderNum(gActiveBattler) < var) - { - var = GetBattlerTurnOrderNum(gActiveBattler); - } - } - if (var == 4) - { - if (gBattleMoves[gChosenMove].target & MOVE_TARGET_RANDOM) - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); - } - else - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); - } - } - else - { - gBattlerTarget = *(gBattleStruct->moveTarget + gBattlerAttacker); - } - - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - { - if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - else - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - } - } - else - { - gActiveBattler = gBattlerByTurnOrder[var]; - RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); - gSpecialStatuses[gActiveBattler].lightningRodRedirected = 1; - gBattlerTarget = gActiveBattler; - } - } - else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE - && gBattleMoves[gChosenMove].target & MOVE_TARGET_RANDOM) - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); - } - else - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); - } - - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget] - && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - } - else - { - gBattlerTarget = *(gBattleStruct->moveTarget + gBattlerAttacker); - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - { - if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - else - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - } - } - - // choose battlescript - if (gBattleTypeFlags & BATTLE_TYPE_PALACE - && gProtectStructs[gBattlerAttacker].palaceUnableToUseMove) - { - if (gBattleMons[gBattlerAttacker].hp == 0) - { - gCurrentActionFuncId = B_ACTION_FINISHED; - return; - } - else if (gPalaceSelectionBattleScripts[gBattlerAttacker] != NULL) - { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - gBattlescriptCurrInstr = gPalaceSelectionBattleScripts[gBattlerAttacker]; - gPalaceSelectionBattleScripts[gBattlerAttacker] = NULL; - } - else - { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - gBattlescriptCurrInstr = BattleScript_MoveUsedLoafingAround; - } - } - else - { - gBattlescriptCurrInstr = gBattleScriptsForMoveEffects[gBattleMoves[gCurrentMove].effect]; - } - - if (gBattleTypeFlags & BATTLE_TYPE_ARENA) - BattleArena_AddMindPoints(gBattlerAttacker); - - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -static void HandleAction_Switch(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gActionSelectionCursor[gBattlerAttacker] = 0; - gMoveSelectionCursor[gBattlerAttacker] = 0; - - PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, *(gBattleStruct->field_58 + gBattlerAttacker)) - - gBattleScripting.battler = gBattlerAttacker; - gBattlescriptCurrInstr = BattleScript_ActionSwitch; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - - if (gBattleResults.playerSwitchesCounter < 255) - gBattleResults.playerSwitchesCounter++; -} - -static void HandleAction_UseItem(void) -{ - gBattlerAttacker = gBattlerTarget = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - - ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); - - gLastUsedItem = gBattleBufferB[gBattlerAttacker][1] | (gBattleBufferB[gBattlerAttacker][2] << 8); - - if (gLastUsedItem <= LAST_BALL) // is ball - { - gBattlescriptCurrInstr = gBattlescriptsForBallThrow[gLastUsedItem]; - } - else if (gLastUsedItem == ITEM_POKE_DOLL || gLastUsedItem == ITEM_FLUFFY_TAIL) - { - gBattlescriptCurrInstr = gBattlescriptsForRunningByItem[0]; - } - else if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - gBattlescriptCurrInstr = gBattlescriptsForUsingItem[0]; - } - else - { - gBattleScripting.battler = gBattlerAttacker; - - switch (*(gBattleStruct->AI_itemType + (gBattlerAttacker >> 1))) - { - case AI_ITEM_FULL_RESTORE: - case AI_ITEM_HEAL_HP: - break; - case AI_ITEM_CURE_CONDITION: - gBattleCommunication[MULTISTRING_CHOOSER] = 0; - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1) - { - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 0x3E) - gBattleCommunication[MULTISTRING_CHOOSER] = 5; - } - else - { - do - { - *(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) >>= 1; - gBattleCommunication[MULTISTRING_CHOOSER]++; - } while (!(*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1)); - } - break; - case AI_ITEM_X_STAT: - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 0x80) - { - gBattleCommunication[MULTISTRING_CHOOSER] = 5; - } - else - { - PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_ATK) - PREPARE_STRING_BUFFER(gBattleTextBuff2, CHAR_X) - - while (!((*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1))) & 1)) - { - *(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) >>= 1; - gBattleTextBuff1[2]++; - } - - gBattleScripting.animArg1 = gBattleTextBuff1[2] + 14; - gBattleScripting.animArg2 = 0; - } - break; - case AI_ITEM_GUARD_SPECS: - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - gBattleCommunication[MULTISTRING_CHOOSER] = 2; - else - gBattleCommunication[MULTISTRING_CHOOSER] = 0; - break; - } - - gBattlescriptCurrInstr = gBattlescriptsForUsingItem[*(gBattleStruct->AI_itemType + (gBattlerAttacker >> 1))]; - } - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -bool8 TryRunFromBattle(u8 battler) -{ - bool8 effect = FALSE; - u8 holdEffect; - u8 pyramidMultiplier; - u8 speedVar; - - if (gBattleMons[battler].item == ITEM_ENIGMA_BERRY) - holdEffect = gEnigmaBerries[battler].holdEffect; - else - holdEffect = ItemId_GetHoldEffect(gBattleMons[battler].item); - - gPotentialItemEffectBattler = battler; - - if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) - { - gLastUsedItem = gBattleMons[battler].item; - gProtectStructs[battler].fleeFlag = 1; - effect++; - } - else if (gBattleMons[battler].ability == ABILITY_RUN_AWAY) - { - if (InBattlePyramid()) - { - gBattleStruct->runTries++; - pyramidMultiplier = GetPyramidRunMultiplier(); - speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); - if (speedVar > (Random() & 0xFF)) - { - gLastUsedAbility = ABILITY_RUN_AWAY; - gProtectStructs[battler].fleeFlag = 2; - effect++; - } - } - else - { - gLastUsedAbility = ABILITY_RUN_AWAY; - gProtectStructs[battler].fleeFlag = 2; - effect++; - } - } - else if (gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_TRAINER_HILL) && gBattleTypeFlags & BATTLE_TYPE_TRAINER) - { - effect++; - } - else - { - if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) - { - if (InBattlePyramid()) - { - pyramidMultiplier = GetPyramidRunMultiplier(); - speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); - if (speedVar > (Random() & 0xFF)) - effect++; - } - else if (gBattleMons[battler].speed < gBattleMons[BATTLE_OPPOSITE(battler)].speed) - { - speedVar = (gBattleMons[battler].speed * 128) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); - if (speedVar > (Random() & 0xFF)) - effect++; - } - else // same speed or faster - { - effect++; - } - } - - gBattleStruct->runTries++; - } - - if (effect) - { - gCurrentTurnActionNumber = gBattlersCount; - gBattleOutcome = B_OUTCOME_RAN; - } - - return effect; -} - -static void HandleAction_Run(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - - if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) - { - gCurrentTurnActionNumber = gBattlersCount; - - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) - { - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) - { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) - gBattleOutcome |= B_OUTCOME_LOST; - } - else - { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) - gBattleOutcome |= B_OUTCOME_WON; - } - } - - gBattleOutcome |= B_OUTCOME_LINK_BATTLE_RAN; - gSaveBlock2Ptr->frontier.disableRecordBattle = TRUE; - } - else - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - if (!TryRunFromBattle(gBattlerAttacker)) // failed to run away - { - ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); - gBattleCommunication[MULTISTRING_CHOOSER] = 3; - gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - } - } - else - { - if (gBattleMons[gBattlerAttacker].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) - { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - } - else - { - gCurrentTurnActionNumber = gBattlersCount; - gBattleOutcome = B_OUTCOME_MON_FLED; - } - } - } -} - -static void HandleAction_WatchesCarefully(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[0]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -static void HandleAction_SafariZoneBallThrow(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gNumSafariBalls--; - gLastUsedItem = ITEM_SAFARI_BALL; - gBattlescriptCurrInstr = gBattlescriptsForBallThrow[ITEM_SAFARI_BALL]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -static void HandleAction_ThrowPokeblock(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gBattleCommunication[MULTISTRING_CHOOSER] = gBattleBufferB[gBattlerAttacker][1] - 1; - gLastUsedItem = gBattleBufferB[gBattlerAttacker][2]; - - if (gBattleResults.pokeblockThrows < 0xFF) - gBattleResults.pokeblockThrows++; - if (gBattleStruct->safariPkblThrowCounter < 3) - gBattleStruct->safariPkblThrowCounter++; - if (gBattleStruct->safariEscapeFactor > 1) - { - if (gBattleStruct->safariEscapeFactor < sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]) - gBattleStruct->safariEscapeFactor = 1; - else - gBattleStruct->safariEscapeFactor -= sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]; - } - - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[2]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -static void HandleAction_GoNear(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - - gBattleStruct->safariCatchFactor += sGoNearCounterToCatchFactor[gBattleStruct->safariGoNearCounter]; - if (gBattleStruct->safariCatchFactor > 20) - gBattleStruct->safariCatchFactor = 20; - - gBattleStruct->safariEscapeFactor += sGoNearCounterToEscapeFactor[gBattleStruct->safariGoNearCounter]; - if (gBattleStruct->safariEscapeFactor > 20) - gBattleStruct->safariEscapeFactor = 20; - - if (gBattleStruct->safariGoNearCounter < 3) - { - gBattleStruct->safariGoNearCounter++; - gBattleCommunication[MULTISTRING_CHOOSER] = 0; - } - else - { - gBattleCommunication[MULTISTRING_CHOOSER] = 1; // Can't get closer. - } - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[1]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -static void HandleAction_SafariZoneRun(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - PlaySE(SE_FLEE); - gCurrentTurnActionNumber = gBattlersCount; - gBattleOutcome = B_OUTCOME_RAN; -} - -static void HandleAction_WallyBallThrow(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - - PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, gBattlerPartyIndexes[gBattlerAttacker]) - - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[3]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - gActionsByTurnOrder[1] = B_ACTION_FINISHED; -} - -static void HandleAction_TryFinish(void) -{ - if (!HandleFaintedMonActions()) - { - gBattleStruct->faintedActionsState = 0; - gCurrentActionFuncId = B_ACTION_FINISHED; - } -} - -static void HandleAction_NothingIsFainted(void) -{ - gCurrentTurnActionNumber++; - gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; - gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED - | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR - | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 - | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT - | HITMARKER_CHARGING | HITMARKER_x4000000); -} - -static void HandleAction_ActionFinished(void) -{ - *(gBattleStruct->monToSwitchIntoId + gBattlerByTurnOrder[gCurrentTurnActionNumber]) = 6; - gCurrentTurnActionNumber++; - gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; - SpecialStatusesClear(); - gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED - | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR - | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 - | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT - | HITMARKER_CHARGING | HITMARKER_x4000000); - - gCurrentMove = 0; - gBattleMoveDamage = 0; - gMoveResultFlags = 0; - gBattleScripting.animTurn = 0; - gBattleScripting.animTargetsHit = 0; - gLastLandedMoves[gBattlerAttacker] = 0; - gLastHitByType[gBattlerAttacker] = 0; - gBattleStruct->dynamicMoveType = 0; - gDynamicBasePower = 0; - gBattleScripting.moveendState = 0; - gBattleCommunication[3] = 0; - gBattleCommunication[4] = 0; - gBattleScripting.multihitMoveEffect = 0; - gBattleResources->battleScriptsStack->size = 0; -} - - -- cgit v1.2.3 From bb5da949f22f0825fa2e75f63dc45a13572686ef Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Tue, 8 Sep 2020 19:44:33 -0400 Subject: Fix build --- src/battle_main.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index 66af8d07f..bf0fdc1aa 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -2686,8 +2686,7 @@ static void sub_80398BC(struct Sprite *sprite) // unused? static void sub_80398D0(struct Sprite *sprite) { - sprite->data[4]--; - if (sprite->data[4] == 0) + if (--sprite->data[4] == 0) { sprite->data[4] = 8; sprite->invisible ^= 1; @@ -3418,17 +3417,13 @@ static void BattleIntroDrawTrainersOrMonsSprites(void) } } - if (gBattleTypeFlags & BATTLE_TYPE_MULTI) + if ((gBattleTypeFlags & BATTLE_TYPE_MULTI) && (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT || GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT)) { - if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT - || GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT) - { - BtlController_EmitDrawTrainerPic(0); - MarkBattlerForControllerExec(gActiveBattler); - } + BtlController_EmitDrawTrainerPic(0); + MarkBattlerForControllerExec(gActiveBattler); } - if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT) + if ((gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) && (GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT)) { BtlController_EmitDrawTrainerPic(0); MarkBattlerForControllerExec(gActiveBattler); @@ -3961,11 +3956,7 @@ u8 IsRunningFromBattleImpossible(void) gPotentialItemEffectBattler = gActiveBattler; - if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) - return 0; - if (gBattleTypeFlags & BATTLE_TYPE_LINK) - return 0; - if (gBattleMons[gActiveBattler].ability == ABILITY_RUN_AWAY) + if ((holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) || (gBattleTypeFlags & BATTLE_TYPE_LINK) || (gBattleMons[gActiveBattler].ability == ABILITY_RUN_AWAY)) return 0; side = GetBattlerSide(gActiveBattler); -- cgit v1.2.3 From 7dc95a0103af08c95c9093b6efa6c77af77a2538 Mon Sep 17 00:00:00 2001 From: aaaaaa123456789 Date: Sun, 13 Sep 2020 04:22:50 -0300 Subject: Undo PokeCodec's PRs This commit undoes most of PokeCodec's PRs after the debate in chat. Some harmless or completely superseded PRs have been left alone, as there is not much benefit in attempting to undo them. Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136, #1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179, #1180, #1181, #1182 and #1183. --- src/battle_main.c | 858 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 788 insertions(+), 70 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index bf0fdc1aa..0c3e84c1e 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -11,7 +11,6 @@ #include "battle_scripts.h" #include "battle_setup.h" #include "battle_tower.h" -#include "battle_util.h" #include "berry.h" #include "bg.h" #include "data.h" @@ -67,6 +66,11 @@ extern struct MusicPlayerInfo gMPlayInfo_SE2; extern const struct BgTemplate gBattleBgTemplates[]; extern const struct WindowTemplate *const gBattleWindowTemplates[]; +extern const u8 *const gBattleScriptsForMoveEffects[]; +extern const u8 *const gBattlescriptsForBallThrow[]; +extern const u8 *const gBattlescriptsForRunningByItem[]; +extern const u8 *const gBattlescriptsForUsingItem[]; +extern const u8 *const gBattlescriptsForSafariActions[]; // this file's functions #if !defined(NONMATCHING) && MODERN @@ -95,6 +99,7 @@ static void SpriteCB_AnimFaintOpponent(struct Sprite *sprite); static void SpriteCb_BlinkVisible(struct Sprite *sprite); static void SpriteCallbackDummy_3(struct Sprite *sprite); static void oac_poke_ally_(struct Sprite *sprite); +static void SpecialStatusesClear(void); static void TurnValuesCleanUp(bool8 var0); static void SpriteCB_BounceEffect(struct Sprite *sprite); static void BattleStartClearSetData(void); @@ -127,7 +132,19 @@ static void HandleEndTurn_BattleLost(void); static void HandleEndTurn_RanFromBattle(void); static void HandleEndTurn_MonFled(void); static void HandleEndTurn_FinishBattle(void); - +static void HandleAction_UseMove(void); +static void HandleAction_Switch(void); +static void HandleAction_UseItem(void); +static void HandleAction_Run(void); +static void HandleAction_WatchesCarefully(void); +static void HandleAction_SafariZoneBallThrow(void); +static void HandleAction_ThrowPokeblock(void); +static void HandleAction_GoNear(void); +static void HandleAction_SafariZoneRun(void); +static void HandleAction_WallyBallThrow(void); +static void HandleAction_TryFinish(void); +static void HandleAction_NothingIsFainted(void); +static void HandleAction_ActionFinished(void); // EWRAM vars EWRAM_DATA u16 gBattle_BG0_X = 0; @@ -574,6 +591,10 @@ const u8 * const gStatusConditionStringsTable[7][2] = {gStatusConditionString_LoveJpn, gText_Love} }; +static const u8 sPkblToEscapeFactor[][3] = {{0, 0, 0}, {3, 5, 0}, {2, 3, 0}, {1, 2, 0}, {1, 1, 0}}; +static const u8 sGoNearCounterToCatchFactor[] = {4, 3, 2, 1}; +static const u8 sGoNearCounterToEscapeFactor[] = {4, 4, 4, 4}; + // code void CB2_InitBattle(void) { @@ -634,16 +655,19 @@ static void CB2_InitBattleInternal(void) gBattle_WIN0V = 0x5051; ScanlineEffect_Clear(); - for (i = 0; i < 80; i++) + i = 0; + while (i < 80) { gScanlineEffectRegBuffers[0][i] = 0xF0; gScanlineEffectRegBuffers[1][i] = 0xF0; + i++; } - for (; i < 160; i++) + while (i < 160) { gScanlineEffectRegBuffers[0][i] = 0xFF10; gScanlineEffectRegBuffers[1][i] = 0xFF10; + i++; } ScanlineEffect_SetParams(sIntroScanlineParams16Bit); @@ -770,7 +794,8 @@ static void SetPlayerBerryDataInBattleStruct(void) static void SetAllPlayersBerryData(void) { - s32 i, j; + s32 i; + s32 j; if (!(gBattleTypeFlags & BATTLE_TYPE_LINK)) { @@ -1829,7 +1854,7 @@ void BattleMainCB2(void) UpdatePaletteFade(); RunTasks(); - if (JOY_HELD(B_BUTTON) && gBattleTypeFlags & BATTLE_TYPE_RECORDED && sub_8186450()) + if (gMain.heldKeys & B_BUTTON && gBattleTypeFlags & BATTLE_TYPE_RECORDED && sub_8186450()) { gSpecialVar_Result = gBattleOutcome = B_OUTCOME_PLAYER_TELEPORTED; ResetPaletteFadeControl(); @@ -2485,7 +2510,7 @@ static void sub_803939C(void) } break; case 5: - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { if (gBattleCommunication[CURSOR_POSITION] != 0) { @@ -2495,7 +2520,7 @@ static void sub_803939C(void) BattleCreateYesNoCursorAt(0); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (gBattleCommunication[CURSOR_POSITION] == 0) { @@ -2505,7 +2530,7 @@ static void sub_803939C(void) BattleCreateYesNoCursorAt(1); } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (gBattleCommunication[CURSOR_POSITION] == 0) @@ -2519,7 +2544,7 @@ static void sub_803939C(void) gBattleCommunication[MULTIUSE_STATE]++; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gBattleCommunication[MULTIUSE_STATE]++; @@ -2686,7 +2711,8 @@ static void sub_80398BC(struct Sprite *sprite) // unused? static void sub_80398D0(struct Sprite *sprite) { - if (--sprite->data[4] == 0) + sprite->data[4]--; + if (sprite->data[4] == 0) { sprite->data[4] = 8; sprite->invisible ^= 1; @@ -3417,13 +3443,17 @@ static void BattleIntroDrawTrainersOrMonsSprites(void) } } - if ((gBattleTypeFlags & BATTLE_TYPE_MULTI) && (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT || GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT)) + if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { - BtlController_EmitDrawTrainerPic(0); - MarkBattlerForControllerExec(gActiveBattler); + if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT + || GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT) + { + BtlController_EmitDrawTrainerPic(0); + MarkBattlerForControllerExec(gActiveBattler); + } } - if ((gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) && (GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT)) + if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT) { BtlController_EmitDrawTrainerPic(0); MarkBattlerForControllerExec(gActiveBattler); @@ -3530,7 +3560,7 @@ static void BattleIntroPrintWildMonAttacked(void) static void BattleIntroPrintOpponentSendsOut(void) { - u8 position; + u32 position; if (gBattleControllerExecFlags) return; @@ -3553,7 +3583,7 @@ static void BattleIntroPrintOpponentSendsOut(void) static void BattleIntroOpponent2SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_OPPONENT_RIGHT; @@ -3579,26 +3609,22 @@ static void BattleIntroOpponent2SendsOutMonAnimation(void) gBattleMainFunc = BattleIntroRecordMonsToDex; } +#ifdef NONMATCHING static void BattleIntroOpponent1SendsOutMonAnimation(void) { - u8 position; + u32 position; - if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) + position = B_POSITION_OPPONENT_LEFT; + else if (gBattleTypeFlags & BATTLE_TYPE_x2000000) { - if (gBattleTypeFlags & BATTLE_TYPE_x2000000) - { - if (gBattleTypeFlags & BATTLE_TYPE_x80000000) - position = B_POSITION_OPPONENT_LEFT; - else - position = B_POSITION_PLAYER_LEFT; - } - else + if (gBattleTypeFlags & BATTLE_TYPE_x80000000) position = B_POSITION_OPPONENT_LEFT; + else + position = B_POSITION_PLAYER_LEFT; } else - { position = B_POSITION_OPPONENT_LEFT; - } if (gBattleControllerExecFlags) return; @@ -3619,6 +3645,92 @@ static void BattleIntroOpponent1SendsOutMonAnimation(void) gBattleMainFunc = BattleIntroRecordMonsToDex; } +#else +NAKED +static void BattleIntroOpponent1SendsOutMonAnimation(void) +{ + asm_unified( + "push {r4-r6,lr}\n\ + ldr r0, =gBattleTypeFlags\n\ + ldr r2, [r0]\n\ + movs r0, 0x80\n\ + lsls r0, 17\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _0803B298\n\ + movs r0, 0x80\n\ + lsls r0, 18\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _0803B298\n\ + movs r1, 0x80\n\ + lsls r1, 24\n\ + ands r1, r2\n\ + negs r0, r1\n\ + orrs r0, r1\n\ + lsrs r5, r0, 31\n\ + b _0803B29A\n\ + .pool\n\ +_0803B288:\n\ + ldr r1, =gBattleMainFunc\n\ + ldr r0, =BattleIntroOpponent2SendsOutMonAnimation\n\ + b _0803B2F0\n\ + .pool\n\ +_0803B298:\n\ + movs r5, 0x1\n\ +_0803B29A:\n\ + ldr r0, =gBattleControllerExecFlags\n\ + ldr r2, [r0]\n\ + cmp r2, 0\n\ + bne _0803B2F2\n\ + ldr r0, =gActiveBattler\n\ + strb r2, [r0]\n\ + ldr r1, =gBattlersCount\n\ + adds r4, r0, 0\n\ + ldrb r1, [r1]\n\ + cmp r2, r1\n\ + bcs _0803B2EC\n\ + adds r6, r4, 0\n\ +_0803B2B2:\n\ + ldrb r0, [r4]\n\ + bl GetBattlerPosition\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + cmp r0, r5\n\ + bne _0803B2D8\n\ + movs r0, 0\n\ + bl BtlController_EmitIntroTrainerBallThrow\n\ + ldrb r0, [r4]\n\ + bl MarkBattlerForControllerExec\n\ + ldr r0, =gBattleTypeFlags\n\ + ldr r0, [r0]\n\ + ldr r1, =0x00008040\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _0803B288\n\ +_0803B2D8:\n\ + ldrb r0, [r6]\n\ + adds r0, 0x1\n\ + strb r0, [r6]\n\ + ldr r1, =gBattlersCount\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + ldr r4, =gActiveBattler\n\ + ldrb r1, [r1]\n\ + cmp r0, r1\n\ + bcc _0803B2B2\n\ +_0803B2EC:\n\ + ldr r1, =gBattleMainFunc\n\ + ldr r0, =BattleIntroRecordMonsToDex\n\ +_0803B2F0:\n\ + str r0, [r1]\n\ +_0803B2F2:\n\ + pop {r4-r6}\n\ + pop {r0}\n\ + bx r0\n\ + .pool"); +} +#endif // NONMATCHING static void BattleIntroRecordMonsToDex(void) { @@ -3640,7 +3752,7 @@ static void BattleIntroRecordMonsToDex(void) } } -static void sub_803B3AC(void) // unused +void sub_803B3AC(void) // unused { if (gBattleControllerExecFlags == 0) gBattleMainFunc = BattleIntroPrintPlayerSendsOut; @@ -3673,7 +3785,7 @@ static void BattleIntroPrintPlayerSendsOut(void) static void BattleIntroPlayer2SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_RIGHT; @@ -3705,7 +3817,7 @@ static void BattleIntroPlayer2SendsOutMonAnimation(void) static void BattleIntroPlayer1SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_LEFT; @@ -3743,7 +3855,7 @@ static void BattleIntroPlayer1SendsOutMonAnimation(void) gBattleMainFunc = TryDoEventsBeforeFirstTurn; } -static void sub_803B598(void) // unused +void sub_803B598(void) // unused { if (gBattleControllerExecFlags == 0) { @@ -3766,7 +3878,8 @@ static void sub_803B598(void) // unused static void TryDoEventsBeforeFirstTurn(void) { - s32 i, j; + s32 i; + s32 j; u8 effect = 0; if (gBattleControllerExecFlags) @@ -3956,7 +4069,11 @@ u8 IsRunningFromBattleImpossible(void) gPotentialItemEffectBattler = gActiveBattler; - if ((holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) || (gBattleTypeFlags & BATTLE_TYPE_LINK) || (gBattleMons[gActiveBattler].ability == ABILITY_RUN_AWAY)) + if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) + return 0; + if (gBattleTypeFlags & BATTLE_TYPE_LINK) + return 0; + if (gBattleMons[gActiveBattler].ability == ABILITY_RUN_AWAY) return 0; side = GetBattlerSide(gActiveBattler); @@ -4733,38 +4850,40 @@ static void SetActionsAndBattlersTurnOrder(void) gBattleStruct->focusPunchBattlerId = 0; return; } - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + else { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_USE_ITEM || gChosenActionByBattler[gActiveBattler] == B_ACTION_SWITCH) + for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { - gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; - gBattlerByTurnOrder[turnOrderId] = gActiveBattler; - turnOrderId++; + if (gChosenActionByBattler[gActiveBattler] == B_ACTION_USE_ITEM || gChosenActionByBattler[gActiveBattler] == B_ACTION_SWITCH) + { + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; + gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + turnOrderId++; + } } - } - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) - { - if (gChosenActionByBattler[gActiveBattler] != B_ACTION_USE_ITEM && gChosenActionByBattler[gActiveBattler] != B_ACTION_SWITCH) + for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { - gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; - gBattlerByTurnOrder[turnOrderId] = gActiveBattler; - turnOrderId++; + if (gChosenActionByBattler[gActiveBattler] != B_ACTION_USE_ITEM && gChosenActionByBattler[gActiveBattler] != B_ACTION_SWITCH) + { + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; + gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + turnOrderId++; + } } - } - for (i = 0; i < gBattlersCount - 1; i++) - { - for (j = i + 1; j < gBattlersCount; j++) + for (i = 0; i < gBattlersCount - 1; i++) { - u8 battler1 = gBattlerByTurnOrder[i]; - u8 battler2 = gBattlerByTurnOrder[j]; - - if (gActionsByTurnOrder[i] != B_ACTION_USE_ITEM - && gActionsByTurnOrder[j] != B_ACTION_USE_ITEM - && gActionsByTurnOrder[i] != B_ACTION_SWITCH - && gActionsByTurnOrder[j] != B_ACTION_SWITCH) + for (j = i + 1; j < gBattlersCount; j++) { - if (GetWhoStrikesFirst(battler1, battler2, FALSE)) - SwapTurnOrder(i, j); + u8 battler1 = gBattlerByTurnOrder[i]; + u8 battler2 = gBattlerByTurnOrder[j]; + if (gActionsByTurnOrder[i] != B_ACTION_USE_ITEM + && gActionsByTurnOrder[j] != B_ACTION_USE_ITEM + && gActionsByTurnOrder[i] != B_ACTION_SWITCH + && gActionsByTurnOrder[j] != B_ACTION_SWITCH) + { + if (GetWhoStrikesFirst(battler1, battler2, FALSE)) + SwapTurnOrder(i, j); + } } } } @@ -4810,7 +4929,7 @@ static void TurnValuesCleanUp(bool8 var0) gSideTimers[1].followmeTimer = 0; } -void SpecialStatusesClear(void) +static void SpecialStatusesClear(void) { for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { @@ -4842,8 +4961,12 @@ static void CheckFocusPunch_ClearVarsBeforeTurnStarts(void) } TryClearRageStatuses(); - gCurrentTurnActionNumber = 0; //See comment underneath - gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; //Should be gActionsByTurnOrder[(gCurrentTurnActionNumber = 0)], but that doesn't match + gCurrentTurnActionNumber = 0; +{ + // something stupid needed to match + u8 zero; + gCurrentActionFuncId = gActionsByTurnOrder[(zero = 0)]; +} gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gBattleMainFunc = RunTurnActionsFunctions; @@ -4866,10 +4989,13 @@ static void RunTurnActionsFunctions(void) gHitMarker &= ~(HITMARKER_x100000); gBattleMainFunc = sEndTurnFuncsTable[gBattleOutcome & 0x7F]; } - else if (gBattleStruct->savedTurnActionNumber != gCurrentTurnActionNumber) // action turn has been done, clear hitmarker bits for another battlerId + else { - gHitMarker &= ~(HITMARKER_NO_ATTACKSTRING); - gHitMarker &= ~(HITMARKER_UNABLE_TO_USE_MOVE); + if (gBattleStruct->savedTurnActionNumber != gCurrentTurnActionNumber) // action turn has been done, clear hitmarker bits for another battlerId + { + gHitMarker &= ~(HITMARKER_NO_ATTACKSTRING); + gHitMarker &= ~(HITMARKER_UNABLE_TO_USE_MOVE); + } } } @@ -4986,15 +5112,15 @@ static void HandleEndTurn_RanFromBattle(void) { switch (gProtectStructs[gBattlerAttacker].fleeFlag) { + default: + gBattlescriptCurrInstr = BattleScript_GotAwaySafely; + break; case 1: gBattlescriptCurrInstr = BattleScript_SmokeBallEscape; break; case 2: gBattlescriptCurrInstr = BattleScript_RanAwayUsingMonAbility; break; - default: - gBattlescriptCurrInstr = BattleScript_GotAwaySafely; - break; } } @@ -5078,7 +5204,10 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void) gBattleMainFunc = ReturnFromBattleToOverworld; return; } - gBattleMainFunc = TryEvolvePokemon; + else + { + gBattleMainFunc = TryEvolvePokemon; + } } FreeAllWindowBuffers(); @@ -5174,3 +5303,592 @@ void RunBattleScriptCommands(void) gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); } +static void HandleAction_UseMove(void) +{ + u8 side; + u8 var = 4; + + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + + if (*(&gBattleStruct->field_91) & gBitTable[gBattlerAttacker]) + { + gCurrentActionFuncId = B_ACTION_FINISHED; + return; + } + + gCritMultiplier = 1; + gBattleScripting.dmgMultiplier = 1; + gBattleStruct->atkCancellerTracker = 0; + gMoveResultFlags = 0; + gMultiHitCounter = 0; + gBattleCommunication[6] = 0; + gCurrMovePos = gChosenMovePos = *(gBattleStruct->chosenMovePositions + gBattlerAttacker); + + // choose move + if (gProtectStructs[gBattlerAttacker].noValidMoves) + { + gProtectStructs[gBattlerAttacker].noValidMoves = 0; + gCurrentMove = gChosenMove = MOVE_STRUGGLE; + gHitMarker |= HITMARKER_NO_PPDEDUCT; + *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(MOVE_STRUGGLE, 0); + } + else if (gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS || gBattleMons[gBattlerAttacker].status2 & STATUS2_RECHARGE) + { + gCurrentMove = gChosenMove = gLockedMoves[gBattlerAttacker]; + } + // encore forces you to use the same move + else if (gDisableStructs[gBattlerAttacker].encoredMove != MOVE_NONE + && gDisableStructs[gBattlerAttacker].encoredMove == gBattleMons[gBattlerAttacker].moves[gDisableStructs[gBattlerAttacker].encoredMovePos]) + { + gCurrentMove = gChosenMove = gDisableStructs[gBattlerAttacker].encoredMove; + gCurrMovePos = gChosenMovePos = gDisableStructs[gBattlerAttacker].encoredMovePos; + *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); + } + // check if the encored move wasn't overwritten + else if (gDisableStructs[gBattlerAttacker].encoredMove != MOVE_NONE + && gDisableStructs[gBattlerAttacker].encoredMove != gBattleMons[gBattlerAttacker].moves[gDisableStructs[gBattlerAttacker].encoredMovePos]) + { + gCurrMovePos = gChosenMovePos = gDisableStructs[gBattlerAttacker].encoredMovePos; + gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; + gDisableStructs[gBattlerAttacker].encoredMove = MOVE_NONE; + gDisableStructs[gBattlerAttacker].encoredMovePos = 0; + gDisableStructs[gBattlerAttacker].encoreTimer = 0; + *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); + } + else if (gBattleMons[gBattlerAttacker].moves[gCurrMovePos] != gChosenMoveByBattler[gBattlerAttacker]) + { + gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; + *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); + } + else + { + gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; + } + + if (gBattleMons[gBattlerAttacker].hp != 0) + { + if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) + gBattleResults.lastUsedMovePlayer = gCurrentMove; + else + gBattleResults.lastUsedMoveOpponent = gCurrentMove; + } + + // choose target + side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; + if (gSideTimers[side].followmeTimer != 0 + && gBattleMoves[gCurrentMove].target == MOVE_TARGET_SELECTED + && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gSideTimers[side].followmeTarget) + && gBattleMons[gSideTimers[side].followmeTarget].hp != 0) + { + gBattlerTarget = gSideTimers[side].followmeTarget; + } + else if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + && gSideTimers[side].followmeTimer == 0 + && (gBattleMoves[gCurrentMove].power != 0 + || gBattleMoves[gCurrentMove].target != MOVE_TARGET_USER) + && gBattleMons[*(gBattleStruct->moveTarget + gBattlerAttacker)].ability != ABILITY_LIGHTNING_ROD + && gBattleMoves[gCurrentMove].type == TYPE_ELECTRIC) + { + side = GetBattlerSide(gBattlerAttacker); + for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + { + if (side != GetBattlerSide(gActiveBattler) + && *(gBattleStruct->moveTarget + gBattlerAttacker) != gActiveBattler + && gBattleMons[gActiveBattler].ability == ABILITY_LIGHTNING_ROD + && GetBattlerTurnOrderNum(gActiveBattler) < var) + { + var = GetBattlerTurnOrderNum(gActiveBattler); + } + } + if (var == 4) + { + if (gBattleMoves[gChosenMove].target & MOVE_TARGET_RANDOM) + { + if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) + { + if (Random() & 1) + gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + else + gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); + } + else + { + if (Random() & 1) + gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + else + gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); + } + } + else + { + gBattlerTarget = *(gBattleStruct->moveTarget + gBattlerAttacker); + } + + if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) + { + if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) + { + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + } + else + { + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); + if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + } + } + } + else + { + gActiveBattler = gBattlerByTurnOrder[var]; + RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); + gSpecialStatuses[gActiveBattler].lightningRodRedirected = 1; + gBattlerTarget = gActiveBattler; + } + } + else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE + && gBattleMoves[gChosenMove].target & MOVE_TARGET_RANDOM) + { + if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) + { + if (Random() & 1) + gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + else + gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); + } + else + { + if (Random() & 1) + gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + else + gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); + } + + if (gAbsentBattlerFlags & gBitTable[gBattlerTarget] + && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) + { + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + } + } + else + { + gBattlerTarget = *(gBattleStruct->moveTarget + gBattlerAttacker); + if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) + { + if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) + { + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + } + else + { + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); + if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + } + } + } + + // choose battlescript + if (gBattleTypeFlags & BATTLE_TYPE_PALACE + && gProtectStructs[gBattlerAttacker].palaceUnableToUseMove) + { + if (gBattleMons[gBattlerAttacker].hp == 0) + { + gCurrentActionFuncId = B_ACTION_FINISHED; + return; + } + else if (gPalaceSelectionBattleScripts[gBattlerAttacker] != NULL) + { + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattlescriptCurrInstr = gPalaceSelectionBattleScripts[gBattlerAttacker]; + gPalaceSelectionBattleScripts[gBattlerAttacker] = NULL; + } + else + { + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattlescriptCurrInstr = BattleScript_MoveUsedLoafingAround; + } + } + else + { + gBattlescriptCurrInstr = gBattleScriptsForMoveEffects[gBattleMoves[gCurrentMove].effect]; + } + + if (gBattleTypeFlags & BATTLE_TYPE_ARENA) + BattleArena_AddMindPoints(gBattlerAttacker); + + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +static void HandleAction_Switch(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gActionSelectionCursor[gBattlerAttacker] = 0; + gMoveSelectionCursor[gBattlerAttacker] = 0; + + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, *(gBattleStruct->field_58 + gBattlerAttacker)) + + gBattleScripting.battler = gBattlerAttacker; + gBattlescriptCurrInstr = BattleScript_ActionSwitch; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; + + if (gBattleResults.playerSwitchesCounter < 255) + gBattleResults.playerSwitchesCounter++; +} + +static void HandleAction_UseItem(void) +{ + gBattlerAttacker = gBattlerTarget = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); + gLastUsedItem = gBattleBufferB[gBattlerAttacker][1] | (gBattleBufferB[gBattlerAttacker][2] << 8); + + if (gLastUsedItem <= LAST_BALL) // is ball + { + gBattlescriptCurrInstr = gBattlescriptsForBallThrow[gLastUsedItem]; + } + else if (gLastUsedItem == ITEM_POKE_DOLL || gLastUsedItem == ITEM_FLUFFY_TAIL) + { + gBattlescriptCurrInstr = gBattlescriptsForRunningByItem[0]; + } + else if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) + { + gBattlescriptCurrInstr = gBattlescriptsForUsingItem[0]; + } + else + { + gBattleScripting.battler = gBattlerAttacker; + + switch (*(gBattleStruct->AI_itemType + (gBattlerAttacker >> 1))) + { + case AI_ITEM_FULL_RESTORE: + case AI_ITEM_HEAL_HP: + break; + case AI_ITEM_CURE_CONDITION: + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1) + { + if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 0x3E) + gBattleCommunication[MULTISTRING_CHOOSER] = 5; + } + else + { + while (!(*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1)) + { + *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; + gBattleCommunication[MULTISTRING_CHOOSER]++; + } + } + break; + case AI_ITEM_X_STAT: + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 0x80) + { + gBattleCommunication[MULTISTRING_CHOOSER] = 5; + } + else + { + PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_ATK) + PREPARE_STRING_BUFFER(gBattleTextBuff2, CHAR_X) + + while (!((*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1))) & 1)) + { + *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; + gBattleTextBuff1[2]++; + } + + gBattleScripting.animArg1 = gBattleTextBuff1[2] + 14; + gBattleScripting.animArg2 = 0; + } + break; + case AI_ITEM_GUARD_SPECS: + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + gBattleCommunication[MULTISTRING_CHOOSER] = 2; + else + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + break; + } + + gBattlescriptCurrInstr = gBattlescriptsForUsingItem[*(gBattleStruct->AI_itemType + gBattlerAttacker / 2)]; + } + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +bool8 TryRunFromBattle(u8 battler) +{ + bool8 effect = FALSE; + u8 holdEffect; + u8 pyramidMultiplier; + u8 speedVar; + + if (gBattleMons[battler].item == ITEM_ENIGMA_BERRY) + holdEffect = gEnigmaBerries[battler].holdEffect; + else + holdEffect = ItemId_GetHoldEffect(gBattleMons[battler].item); + + gPotentialItemEffectBattler = battler; + + if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) + { + gLastUsedItem = gBattleMons[battler].item; + gProtectStructs[battler].fleeFlag = 1; + effect++; + } + else if (gBattleMons[battler].ability == ABILITY_RUN_AWAY) + { + if (InBattlePyramid()) + { + gBattleStruct->runTries++; + pyramidMultiplier = GetPyramidRunMultiplier(); + speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); + if (speedVar > (Random() & 0xFF)) + { + gLastUsedAbility = ABILITY_RUN_AWAY; + gProtectStructs[battler].fleeFlag = 2; + effect++; + } + } + else + { + gLastUsedAbility = ABILITY_RUN_AWAY; + gProtectStructs[battler].fleeFlag = 2; + effect++; + } + } + else if (gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_TRAINER_HILL) && gBattleTypeFlags & BATTLE_TYPE_TRAINER) + { + effect++; + } + else + { + if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) + { + if (InBattlePyramid()) + { + pyramidMultiplier = GetPyramidRunMultiplier(); + speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); + if (speedVar > (Random() & 0xFF)) + effect++; + } + else if (gBattleMons[battler].speed < gBattleMons[BATTLE_OPPOSITE(battler)].speed) + { + speedVar = (gBattleMons[battler].speed * 128) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); + if (speedVar > (Random() & 0xFF)) + effect++; + } + else // same speed or faster + { + effect++; + } + } + + gBattleStruct->runTries++; + } + + if (effect) + { + gCurrentTurnActionNumber = gBattlersCount; + gBattleOutcome = B_OUTCOME_RAN; + } + + return effect; +} + +static void HandleAction_Run(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) + { + gCurrentTurnActionNumber = gBattlersCount; + + for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + { + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + { + if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) + gBattleOutcome |= B_OUTCOME_LOST; + } + else + { + if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) + gBattleOutcome |= B_OUTCOME_WON; + } + } + + gBattleOutcome |= B_OUTCOME_LINK_BATTLE_RAN; + gSaveBlock2Ptr->frontier.disableRecordBattle = TRUE; + } + else + { + if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) + { + if (!TryRunFromBattle(gBattlerAttacker)) // failed to run away + { + ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); + gBattleCommunication[MULTISTRING_CHOOSER] = 3; + gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; + } + } + else + { + if (gBattleMons[gBattlerAttacker].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) + { + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; + } + else + { + gCurrentTurnActionNumber = gBattlersCount; + gBattleOutcome = B_OUTCOME_MON_FLED; + } + } + } +} + +static void HandleAction_WatchesCarefully(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[0]; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +static void HandleAction_SafariZoneBallThrow(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gNumSafariBalls--; + gLastUsedItem = ITEM_SAFARI_BALL; + gBattlescriptCurrInstr = gBattlescriptsForBallThrow[ITEM_SAFARI_BALL]; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +static void HandleAction_ThrowPokeblock(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = gBattleBufferB[gBattlerAttacker][1] - 1; + gLastUsedItem = gBattleBufferB[gBattlerAttacker][2]; + + if (gBattleResults.pokeblockThrows < 0xFF) + gBattleResults.pokeblockThrows++; + if (gBattleStruct->safariPkblThrowCounter < 3) + gBattleStruct->safariPkblThrowCounter++; + if (gBattleStruct->safariEscapeFactor > 1) + { + if (gBattleStruct->safariEscapeFactor < sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]) + gBattleStruct->safariEscapeFactor = 1; + else + gBattleStruct->safariEscapeFactor -= sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]; + } + + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[2]; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +static void HandleAction_GoNear(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + + gBattleStruct->safariCatchFactor += sGoNearCounterToCatchFactor[gBattleStruct->safariGoNearCounter]; + if (gBattleStruct->safariCatchFactor > 20) + gBattleStruct->safariCatchFactor = 20; + + gBattleStruct->safariEscapeFactor += sGoNearCounterToEscapeFactor[gBattleStruct->safariGoNearCounter]; + if (gBattleStruct->safariEscapeFactor > 20) + gBattleStruct->safariEscapeFactor = 20; + + if (gBattleStruct->safariGoNearCounter < 3) + { + gBattleStruct->safariGoNearCounter++; + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + } + else + { + gBattleCommunication[MULTISTRING_CHOOSER] = 1; // Can't get closer. + } + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[1]; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +static void HandleAction_SafariZoneRun(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + PlaySE(SE_FLEE); + gCurrentTurnActionNumber = gBattlersCount; + gBattleOutcome = B_OUTCOME_RAN; +} + +static void HandleAction_WallyBallThrow(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, gBattlerPartyIndexes[gBattlerAttacker]) + + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[3]; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; + gActionsByTurnOrder[1] = B_ACTION_FINISHED; +} + +static void HandleAction_TryFinish(void) +{ + if (!HandleFaintedMonActions()) + { + gBattleStruct->faintedActionsState = 0; + gCurrentActionFuncId = B_ACTION_FINISHED; + } +} + +static void HandleAction_NothingIsFainted(void) +{ + gCurrentTurnActionNumber++; + gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; + gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED + | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR + | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 + | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT + | HITMARKER_CHARGING | HITMARKER_x4000000); +} + +static void HandleAction_ActionFinished(void) +{ + *(gBattleStruct->monToSwitchIntoId + gBattlerByTurnOrder[gCurrentTurnActionNumber]) = 6; + gCurrentTurnActionNumber++; + gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; + SpecialStatusesClear(); + gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED + | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR + | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 + | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT + | HITMARKER_CHARGING | HITMARKER_x4000000); + + gCurrentMove = 0; + gBattleMoveDamage = 0; + gMoveResultFlags = 0; + gBattleScripting.animTurn = 0; + gBattleScripting.animTargetsHit = 0; + gLastLandedMoves[gBattlerAttacker] = 0; + gLastHitByType[gBattlerAttacker] = 0; + gBattleStruct->dynamicMoveType = 0; + gDynamicBasePower = 0; + gBattleScripting.moveendState = 0; + gBattleCommunication[3] = 0; + gBattleCommunication[4] = 0; + gBattleScripting.multihitMoveEffect = 0; + gBattleResources->battleScriptsStack->size = 0; +} + + -- cgit v1.2.3 From 847878eae9a9f0ac4a722c27c1cdf1a2d3ff1d67 Mon Sep 17 00:00:00 2001 From: Kaz Date: Sat, 19 Sep 2020 13:37:24 -0400 Subject: battle_gfx_sfx_util.c: Very annoying fakematch fix. daycare.c: -g eliminates the need for the brace hack. battle_transition.c: Fix Phase2_Ripple_Func2...? --- src/battle_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index bf0fdc1aa..f0fedbd13 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -2762,7 +2762,7 @@ static void SpriteCB_AnimFaintOpponent(struct Sprite *sprite) } else // Erase bottom part of the sprite to create a smooth illusion of mon falling down. { - u8 *dst = (u8 *)gMonSpritesGfxPtr->sprites[GetBattlerPosition(sprite->sBattler)] + (gBattleMonForms[sprite->sBattler] << 11) + (sprite->data[3] << 8); + u8* dst = gMonSpritesGfxPtr->sprites.byte[GetBattlerPosition(sprite->sBattler)] + (gBattleMonForms[sprite->sBattler] << 11) + (sprite->data[3] << 8); for (i = 0; i < 0x100; i++) *(dst++) = 0; -- cgit v1.2.3 From 52598983250fd8ad7b66ff2b9d77046859f169c8 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 1 Oct 2020 17:20:38 -0400 Subject: Replace POKEMON_SLOTS_NUMBER --- src/battle_main.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index bf0fdc1aa..bdde96be2 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -58,7 +58,6 @@ #include "constants/party_menu.h" #include "constants/rgb.h" #include "constants/songs.h" -#include "constants/species.h" #include "constants/trainers.h" #include "cable_club.h" -- cgit v1.2.3 From 64ba8c806111ab6baa6bde485f64925c07378f89 Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Thu, 22 Oct 2020 05:45:53 -0400 Subject: port fakematch fixes from #1155 --- src/battle_main.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index 0c3e84c1e..d2763b000 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -4962,11 +4962,7 @@ static void CheckFocusPunch_ClearVarsBeforeTurnStarts(void) TryClearRageStatuses(); gCurrentTurnActionNumber = 0; -{ - // something stupid needed to match - u8 zero; - gCurrentActionFuncId = gActionsByTurnOrder[(zero = 0)]; -} + gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gBattleMainFunc = RunTurnActionsFunctions; -- cgit v1.2.3 From fe40c0c4663d732c8ba9ca5f5e00b3c14a17d304 Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Mon, 26 Oct 2020 05:52:00 -0400 Subject: re-match BattleIntroOpponent1SendsOutMonAnimation a lot of functions and a bit of data had to be moved from battle_main.c to battle_util.c; I have added a note to battle_util.c stating the reason for this --- src/battle_main.c | 718 +----------------------------------------------------- 1 file changed, 11 insertions(+), 707 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index d2763b000..11ed29ac8 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -11,6 +11,7 @@ #include "battle_scripts.h" #include "battle_setup.h" #include "battle_tower.h" +#include "battle_util.h" #include "berry.h" #include "bg.h" #include "data.h" @@ -66,11 +67,6 @@ extern struct MusicPlayerInfo gMPlayInfo_SE2; extern const struct BgTemplate gBattleBgTemplates[]; extern const struct WindowTemplate *const gBattleWindowTemplates[]; -extern const u8 *const gBattleScriptsForMoveEffects[]; -extern const u8 *const gBattlescriptsForBallThrow[]; -extern const u8 *const gBattlescriptsForRunningByItem[]; -extern const u8 *const gBattlescriptsForUsingItem[]; -extern const u8 *const gBattlescriptsForSafariActions[]; // this file's functions #if !defined(NONMATCHING) && MODERN @@ -99,7 +95,6 @@ static void SpriteCB_AnimFaintOpponent(struct Sprite *sprite); static void SpriteCb_BlinkVisible(struct Sprite *sprite); static void SpriteCallbackDummy_3(struct Sprite *sprite); static void oac_poke_ally_(struct Sprite *sprite); -static void SpecialStatusesClear(void); static void TurnValuesCleanUp(bool8 var0); static void SpriteCB_BounceEffect(struct Sprite *sprite); static void BattleStartClearSetData(void); @@ -132,19 +127,6 @@ static void HandleEndTurn_BattleLost(void); static void HandleEndTurn_RanFromBattle(void); static void HandleEndTurn_MonFled(void); static void HandleEndTurn_FinishBattle(void); -static void HandleAction_UseMove(void); -static void HandleAction_Switch(void); -static void HandleAction_UseItem(void); -static void HandleAction_Run(void); -static void HandleAction_WatchesCarefully(void); -static void HandleAction_SafariZoneBallThrow(void); -static void HandleAction_ThrowPokeblock(void); -static void HandleAction_GoNear(void); -static void HandleAction_SafariZoneRun(void); -static void HandleAction_WallyBallThrow(void); -static void HandleAction_TryFinish(void); -static void HandleAction_NothingIsFainted(void); -static void HandleAction_ActionFinished(void); // EWRAM vars EWRAM_DATA u16 gBattle_BG0_X = 0; @@ -591,10 +573,6 @@ const u8 * const gStatusConditionStringsTable[7][2] = {gStatusConditionString_LoveJpn, gText_Love} }; -static const u8 sPkblToEscapeFactor[][3] = {{0, 0, 0}, {3, 5, 0}, {2, 3, 0}, {1, 2, 0}, {1, 1, 0}}; -static const u8 sGoNearCounterToCatchFactor[] = {4, 3, 2, 1}; -static const u8 sGoNearCounterToEscapeFactor[] = {4, 4, 4, 4}; - // code void CB2_InitBattle(void) { @@ -3609,19 +3587,21 @@ static void BattleIntroOpponent2SendsOutMonAnimation(void) gBattleMainFunc = BattleIntroRecordMonsToDex; } -#ifdef NONMATCHING static void BattleIntroOpponent1SendsOutMonAnimation(void) { u32 position; - if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) - position = B_POSITION_OPPONENT_LEFT; - else if (gBattleTypeFlags & BATTLE_TYPE_x2000000) + if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) { - if (gBattleTypeFlags & BATTLE_TYPE_x80000000) - position = B_POSITION_OPPONENT_LEFT; + if (gBattleTypeFlags & BATTLE_TYPE_x2000000) + { + if (gBattleTypeFlags & BATTLE_TYPE_x80000000) + position = B_POSITION_OPPONENT_LEFT; + else + position = B_POSITION_PLAYER_LEFT; + } else - position = B_POSITION_PLAYER_LEFT; + position = B_POSITION_OPPONENT_LEFT; } else position = B_POSITION_OPPONENT_LEFT; @@ -3645,92 +3625,6 @@ static void BattleIntroOpponent1SendsOutMonAnimation(void) gBattleMainFunc = BattleIntroRecordMonsToDex; } -#else -NAKED -static void BattleIntroOpponent1SendsOutMonAnimation(void) -{ - asm_unified( - "push {r4-r6,lr}\n\ - ldr r0, =gBattleTypeFlags\n\ - ldr r2, [r0]\n\ - movs r0, 0x80\n\ - lsls r0, 17\n\ - ands r0, r2\n\ - cmp r0, 0\n\ - beq _0803B298\n\ - movs r0, 0x80\n\ - lsls r0, 18\n\ - ands r0, r2\n\ - cmp r0, 0\n\ - beq _0803B298\n\ - movs r1, 0x80\n\ - lsls r1, 24\n\ - ands r1, r2\n\ - negs r0, r1\n\ - orrs r0, r1\n\ - lsrs r5, r0, 31\n\ - b _0803B29A\n\ - .pool\n\ -_0803B288:\n\ - ldr r1, =gBattleMainFunc\n\ - ldr r0, =BattleIntroOpponent2SendsOutMonAnimation\n\ - b _0803B2F0\n\ - .pool\n\ -_0803B298:\n\ - movs r5, 0x1\n\ -_0803B29A:\n\ - ldr r0, =gBattleControllerExecFlags\n\ - ldr r2, [r0]\n\ - cmp r2, 0\n\ - bne _0803B2F2\n\ - ldr r0, =gActiveBattler\n\ - strb r2, [r0]\n\ - ldr r1, =gBattlersCount\n\ - adds r4, r0, 0\n\ - ldrb r1, [r1]\n\ - cmp r2, r1\n\ - bcs _0803B2EC\n\ - adds r6, r4, 0\n\ -_0803B2B2:\n\ - ldrb r0, [r4]\n\ - bl GetBattlerPosition\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - cmp r0, r5\n\ - bne _0803B2D8\n\ - movs r0, 0\n\ - bl BtlController_EmitIntroTrainerBallThrow\n\ - ldrb r0, [r4]\n\ - bl MarkBattlerForControllerExec\n\ - ldr r0, =gBattleTypeFlags\n\ - ldr r0, [r0]\n\ - ldr r1, =0x00008040\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - bne _0803B288\n\ -_0803B2D8:\n\ - ldrb r0, [r6]\n\ - adds r0, 0x1\n\ - strb r0, [r6]\n\ - ldr r1, =gBattlersCount\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - ldr r4, =gActiveBattler\n\ - ldrb r1, [r1]\n\ - cmp r0, r1\n\ - bcc _0803B2B2\n\ -_0803B2EC:\n\ - ldr r1, =gBattleMainFunc\n\ - ldr r0, =BattleIntroRecordMonsToDex\n\ -_0803B2F0:\n\ - str r0, [r1]\n\ -_0803B2F2:\n\ - pop {r4-r6}\n\ - pop {r0}\n\ - bx r0\n\ - .pool"); -} -#endif // NONMATCHING static void BattleIntroRecordMonsToDex(void) { @@ -4929,7 +4823,7 @@ static void TurnValuesCleanUp(bool8 var0) gSideTimers[1].followmeTimer = 0; } -static void SpecialStatusesClear(void) +void SpecialStatusesClear(void) { for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { @@ -5298,593 +5192,3 @@ void RunBattleScriptCommands(void) if (gBattleControllerExecFlags == 0) gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); } - -static void HandleAction_UseMove(void) -{ - u8 side; - u8 var = 4; - - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - - if (*(&gBattleStruct->field_91) & gBitTable[gBattlerAttacker]) - { - gCurrentActionFuncId = B_ACTION_FINISHED; - return; - } - - gCritMultiplier = 1; - gBattleScripting.dmgMultiplier = 1; - gBattleStruct->atkCancellerTracker = 0; - gMoveResultFlags = 0; - gMultiHitCounter = 0; - gBattleCommunication[6] = 0; - gCurrMovePos = gChosenMovePos = *(gBattleStruct->chosenMovePositions + gBattlerAttacker); - - // choose move - if (gProtectStructs[gBattlerAttacker].noValidMoves) - { - gProtectStructs[gBattlerAttacker].noValidMoves = 0; - gCurrentMove = gChosenMove = MOVE_STRUGGLE; - gHitMarker |= HITMARKER_NO_PPDEDUCT; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(MOVE_STRUGGLE, 0); - } - else if (gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS || gBattleMons[gBattlerAttacker].status2 & STATUS2_RECHARGE) - { - gCurrentMove = gChosenMove = gLockedMoves[gBattlerAttacker]; - } - // encore forces you to use the same move - else if (gDisableStructs[gBattlerAttacker].encoredMove != MOVE_NONE - && gDisableStructs[gBattlerAttacker].encoredMove == gBattleMons[gBattlerAttacker].moves[gDisableStructs[gBattlerAttacker].encoredMovePos]) - { - gCurrentMove = gChosenMove = gDisableStructs[gBattlerAttacker].encoredMove; - gCurrMovePos = gChosenMovePos = gDisableStructs[gBattlerAttacker].encoredMovePos; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); - } - // check if the encored move wasn't overwritten - else if (gDisableStructs[gBattlerAttacker].encoredMove != MOVE_NONE - && gDisableStructs[gBattlerAttacker].encoredMove != gBattleMons[gBattlerAttacker].moves[gDisableStructs[gBattlerAttacker].encoredMovePos]) - { - gCurrMovePos = gChosenMovePos = gDisableStructs[gBattlerAttacker].encoredMovePos; - gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; - gDisableStructs[gBattlerAttacker].encoredMove = MOVE_NONE; - gDisableStructs[gBattlerAttacker].encoredMovePos = 0; - gDisableStructs[gBattlerAttacker].encoreTimer = 0; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); - } - else if (gBattleMons[gBattlerAttacker].moves[gCurrMovePos] != gChosenMoveByBattler[gBattlerAttacker]) - { - gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); - } - else - { - gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; - } - - if (gBattleMons[gBattlerAttacker].hp != 0) - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - gBattleResults.lastUsedMovePlayer = gCurrentMove; - else - gBattleResults.lastUsedMoveOpponent = gCurrentMove; - } - - // choose target - side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; - if (gSideTimers[side].followmeTimer != 0 - && gBattleMoves[gCurrentMove].target == MOVE_TARGET_SELECTED - && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gSideTimers[side].followmeTarget) - && gBattleMons[gSideTimers[side].followmeTarget].hp != 0) - { - gBattlerTarget = gSideTimers[side].followmeTarget; - } - else if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - && gSideTimers[side].followmeTimer == 0 - && (gBattleMoves[gCurrentMove].power != 0 - || gBattleMoves[gCurrentMove].target != MOVE_TARGET_USER) - && gBattleMons[*(gBattleStruct->moveTarget + gBattlerAttacker)].ability != ABILITY_LIGHTNING_ROD - && gBattleMoves[gCurrentMove].type == TYPE_ELECTRIC) - { - side = GetBattlerSide(gBattlerAttacker); - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) - { - if (side != GetBattlerSide(gActiveBattler) - && *(gBattleStruct->moveTarget + gBattlerAttacker) != gActiveBattler - && gBattleMons[gActiveBattler].ability == ABILITY_LIGHTNING_ROD - && GetBattlerTurnOrderNum(gActiveBattler) < var) - { - var = GetBattlerTurnOrderNum(gActiveBattler); - } - } - if (var == 4) - { - if (gBattleMoves[gChosenMove].target & MOVE_TARGET_RANDOM) - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); - } - else - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); - } - } - else - { - gBattlerTarget = *(gBattleStruct->moveTarget + gBattlerAttacker); - } - - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - { - if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - else - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - } - } - else - { - gActiveBattler = gBattlerByTurnOrder[var]; - RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); - gSpecialStatuses[gActiveBattler].lightningRodRedirected = 1; - gBattlerTarget = gActiveBattler; - } - } - else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE - && gBattleMoves[gChosenMove].target & MOVE_TARGET_RANDOM) - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); - } - else - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); - } - - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget] - && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - } - else - { - gBattlerTarget = *(gBattleStruct->moveTarget + gBattlerAttacker); - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - { - if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - else - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - } - } - - // choose battlescript - if (gBattleTypeFlags & BATTLE_TYPE_PALACE - && gProtectStructs[gBattlerAttacker].palaceUnableToUseMove) - { - if (gBattleMons[gBattlerAttacker].hp == 0) - { - gCurrentActionFuncId = B_ACTION_FINISHED; - return; - } - else if (gPalaceSelectionBattleScripts[gBattlerAttacker] != NULL) - { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - gBattlescriptCurrInstr = gPalaceSelectionBattleScripts[gBattlerAttacker]; - gPalaceSelectionBattleScripts[gBattlerAttacker] = NULL; - } - else - { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - gBattlescriptCurrInstr = BattleScript_MoveUsedLoafingAround; - } - } - else - { - gBattlescriptCurrInstr = gBattleScriptsForMoveEffects[gBattleMoves[gCurrentMove].effect]; - } - - if (gBattleTypeFlags & BATTLE_TYPE_ARENA) - BattleArena_AddMindPoints(gBattlerAttacker); - - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -static void HandleAction_Switch(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gActionSelectionCursor[gBattlerAttacker] = 0; - gMoveSelectionCursor[gBattlerAttacker] = 0; - - PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, *(gBattleStruct->field_58 + gBattlerAttacker)) - - gBattleScripting.battler = gBattlerAttacker; - gBattlescriptCurrInstr = BattleScript_ActionSwitch; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - - if (gBattleResults.playerSwitchesCounter < 255) - gBattleResults.playerSwitchesCounter++; -} - -static void HandleAction_UseItem(void) -{ - gBattlerAttacker = gBattlerTarget = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); - gLastUsedItem = gBattleBufferB[gBattlerAttacker][1] | (gBattleBufferB[gBattlerAttacker][2] << 8); - - if (gLastUsedItem <= LAST_BALL) // is ball - { - gBattlescriptCurrInstr = gBattlescriptsForBallThrow[gLastUsedItem]; - } - else if (gLastUsedItem == ITEM_POKE_DOLL || gLastUsedItem == ITEM_FLUFFY_TAIL) - { - gBattlescriptCurrInstr = gBattlescriptsForRunningByItem[0]; - } - else if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - gBattlescriptCurrInstr = gBattlescriptsForUsingItem[0]; - } - else - { - gBattleScripting.battler = gBattlerAttacker; - - switch (*(gBattleStruct->AI_itemType + (gBattlerAttacker >> 1))) - { - case AI_ITEM_FULL_RESTORE: - case AI_ITEM_HEAL_HP: - break; - case AI_ITEM_CURE_CONDITION: - gBattleCommunication[MULTISTRING_CHOOSER] = 0; - if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1) - { - if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 0x3E) - gBattleCommunication[MULTISTRING_CHOOSER] = 5; - } - else - { - while (!(*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1)) - { - *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; - gBattleCommunication[MULTISTRING_CHOOSER]++; - } - } - break; - case AI_ITEM_X_STAT: - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 0x80) - { - gBattleCommunication[MULTISTRING_CHOOSER] = 5; - } - else - { - PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_ATK) - PREPARE_STRING_BUFFER(gBattleTextBuff2, CHAR_X) - - while (!((*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1))) & 1)) - { - *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; - gBattleTextBuff1[2]++; - } - - gBattleScripting.animArg1 = gBattleTextBuff1[2] + 14; - gBattleScripting.animArg2 = 0; - } - break; - case AI_ITEM_GUARD_SPECS: - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - gBattleCommunication[MULTISTRING_CHOOSER] = 2; - else - gBattleCommunication[MULTISTRING_CHOOSER] = 0; - break; - } - - gBattlescriptCurrInstr = gBattlescriptsForUsingItem[*(gBattleStruct->AI_itemType + gBattlerAttacker / 2)]; - } - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -bool8 TryRunFromBattle(u8 battler) -{ - bool8 effect = FALSE; - u8 holdEffect; - u8 pyramidMultiplier; - u8 speedVar; - - if (gBattleMons[battler].item == ITEM_ENIGMA_BERRY) - holdEffect = gEnigmaBerries[battler].holdEffect; - else - holdEffect = ItemId_GetHoldEffect(gBattleMons[battler].item); - - gPotentialItemEffectBattler = battler; - - if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) - { - gLastUsedItem = gBattleMons[battler].item; - gProtectStructs[battler].fleeFlag = 1; - effect++; - } - else if (gBattleMons[battler].ability == ABILITY_RUN_AWAY) - { - if (InBattlePyramid()) - { - gBattleStruct->runTries++; - pyramidMultiplier = GetPyramidRunMultiplier(); - speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); - if (speedVar > (Random() & 0xFF)) - { - gLastUsedAbility = ABILITY_RUN_AWAY; - gProtectStructs[battler].fleeFlag = 2; - effect++; - } - } - else - { - gLastUsedAbility = ABILITY_RUN_AWAY; - gProtectStructs[battler].fleeFlag = 2; - effect++; - } - } - else if (gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_TRAINER_HILL) && gBattleTypeFlags & BATTLE_TYPE_TRAINER) - { - effect++; - } - else - { - if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) - { - if (InBattlePyramid()) - { - pyramidMultiplier = GetPyramidRunMultiplier(); - speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); - if (speedVar > (Random() & 0xFF)) - effect++; - } - else if (gBattleMons[battler].speed < gBattleMons[BATTLE_OPPOSITE(battler)].speed) - { - speedVar = (gBattleMons[battler].speed * 128) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); - if (speedVar > (Random() & 0xFF)) - effect++; - } - else // same speed or faster - { - effect++; - } - } - - gBattleStruct->runTries++; - } - - if (effect) - { - gCurrentTurnActionNumber = gBattlersCount; - gBattleOutcome = B_OUTCOME_RAN; - } - - return effect; -} - -static void HandleAction_Run(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - - if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) - { - gCurrentTurnActionNumber = gBattlersCount; - - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) - { - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) - { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) - gBattleOutcome |= B_OUTCOME_LOST; - } - else - { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) - gBattleOutcome |= B_OUTCOME_WON; - } - } - - gBattleOutcome |= B_OUTCOME_LINK_BATTLE_RAN; - gSaveBlock2Ptr->frontier.disableRecordBattle = TRUE; - } - else - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - if (!TryRunFromBattle(gBattlerAttacker)) // failed to run away - { - ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); - gBattleCommunication[MULTISTRING_CHOOSER] = 3; - gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - } - } - else - { - if (gBattleMons[gBattlerAttacker].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) - { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - } - else - { - gCurrentTurnActionNumber = gBattlersCount; - gBattleOutcome = B_OUTCOME_MON_FLED; - } - } - } -} - -static void HandleAction_WatchesCarefully(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[0]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -static void HandleAction_SafariZoneBallThrow(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gNumSafariBalls--; - gLastUsedItem = ITEM_SAFARI_BALL; - gBattlescriptCurrInstr = gBattlescriptsForBallThrow[ITEM_SAFARI_BALL]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -static void HandleAction_ThrowPokeblock(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gBattleCommunication[MULTISTRING_CHOOSER] = gBattleBufferB[gBattlerAttacker][1] - 1; - gLastUsedItem = gBattleBufferB[gBattlerAttacker][2]; - - if (gBattleResults.pokeblockThrows < 0xFF) - gBattleResults.pokeblockThrows++; - if (gBattleStruct->safariPkblThrowCounter < 3) - gBattleStruct->safariPkblThrowCounter++; - if (gBattleStruct->safariEscapeFactor > 1) - { - if (gBattleStruct->safariEscapeFactor < sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]) - gBattleStruct->safariEscapeFactor = 1; - else - gBattleStruct->safariEscapeFactor -= sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]; - } - - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[2]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -static void HandleAction_GoNear(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - - gBattleStruct->safariCatchFactor += sGoNearCounterToCatchFactor[gBattleStruct->safariGoNearCounter]; - if (gBattleStruct->safariCatchFactor > 20) - gBattleStruct->safariCatchFactor = 20; - - gBattleStruct->safariEscapeFactor += sGoNearCounterToEscapeFactor[gBattleStruct->safariGoNearCounter]; - if (gBattleStruct->safariEscapeFactor > 20) - gBattleStruct->safariEscapeFactor = 20; - - if (gBattleStruct->safariGoNearCounter < 3) - { - gBattleStruct->safariGoNearCounter++; - gBattleCommunication[MULTISTRING_CHOOSER] = 0; - } - else - { - gBattleCommunication[MULTISTRING_CHOOSER] = 1; // Can't get closer. - } - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[1]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -static void HandleAction_SafariZoneRun(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - PlaySE(SE_FLEE); - gCurrentTurnActionNumber = gBattlersCount; - gBattleOutcome = B_OUTCOME_RAN; -} - -static void HandleAction_WallyBallThrow(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - - PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, gBattlerPartyIndexes[gBattlerAttacker]) - - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[3]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - gActionsByTurnOrder[1] = B_ACTION_FINISHED; -} - -static void HandleAction_TryFinish(void) -{ - if (!HandleFaintedMonActions()) - { - gBattleStruct->faintedActionsState = 0; - gCurrentActionFuncId = B_ACTION_FINISHED; - } -} - -static void HandleAction_NothingIsFainted(void) -{ - gCurrentTurnActionNumber++; - gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; - gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED - | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR - | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 - | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT - | HITMARKER_CHARGING | HITMARKER_x4000000); -} - -static void HandleAction_ActionFinished(void) -{ - *(gBattleStruct->monToSwitchIntoId + gBattlerByTurnOrder[gCurrentTurnActionNumber]) = 6; - gCurrentTurnActionNumber++; - gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; - SpecialStatusesClear(); - gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED - | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR - | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 - | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT - | HITMARKER_CHARGING | HITMARKER_x4000000); - - gCurrentMove = 0; - gBattleMoveDamage = 0; - gMoveResultFlags = 0; - gBattleScripting.animTurn = 0; - gBattleScripting.animTargetsHit = 0; - gLastLandedMoves[gBattlerAttacker] = 0; - gLastHitByType[gBattlerAttacker] = 0; - gBattleStruct->dynamicMoveType = 0; - gDynamicBasePower = 0; - gBattleScripting.moveendState = 0; - gBattleCommunication[3] = 0; - gBattleCommunication[4] = 0; - gBattleScripting.multihitMoveEffect = 0; - gBattleResources->battleScriptsStack->size = 0; -} - - -- cgit v1.2.3 From bacc831aa91d059936bd7c852bf0a0fb44d8f27a Mon Sep 17 00:00:00 2001 From: aaaaaa123456789 Date: Mon, 2 Nov 2020 22:02:39 -0300 Subject: Re-apply joypad macros (minus merge conflicts) --- src/battle_main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index ec4c651f0..acc65008e 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -1831,7 +1831,7 @@ void BattleMainCB2(void) UpdatePaletteFade(); RunTasks(); - if (gMain.heldKeys & B_BUTTON && gBattleTypeFlags & BATTLE_TYPE_RECORDED && sub_8186450()) + if (JOY_HELD(B_BUTTON) && gBattleTypeFlags & BATTLE_TYPE_RECORDED && sub_8186450()) { gSpecialVar_Result = gBattleOutcome = B_OUTCOME_PLAYER_TELEPORTED; ResetPaletteFadeControl(); @@ -2487,7 +2487,7 @@ static void sub_803939C(void) } break; case 5: - if (gMain.newKeys & DPAD_UP) + if (JOY_NEW(DPAD_UP)) { if (gBattleCommunication[CURSOR_POSITION] != 0) { @@ -2497,7 +2497,7 @@ static void sub_803939C(void) BattleCreateYesNoCursorAt(0); } } - else if (gMain.newKeys & DPAD_DOWN) + else if (JOY_NEW(DPAD_DOWN)) { if (gBattleCommunication[CURSOR_POSITION] == 0) { @@ -2507,7 +2507,7 @@ static void sub_803939C(void) BattleCreateYesNoCursorAt(1); } } - else if (gMain.newKeys & A_BUTTON) + else if (JOY_NEW(A_BUTTON)) { PlaySE(SE_SELECT); if (gBattleCommunication[CURSOR_POSITION] == 0) @@ -2521,7 +2521,7 @@ static void sub_803939C(void) gBattleCommunication[MULTIUSE_STATE]++; } } - else if (gMain.newKeys & B_BUTTON) + else if (JOY_NEW(B_BUTTON)) { PlaySE(SE_SELECT); gBattleCommunication[MULTIUSE_STATE]++; -- cgit v1.2.3 From 769ddf22c266c2bf41d3353c5972bca8fa49c085 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 24 Dec 2020 16:18:47 -0500 Subject: Label remaining subs in battle_tower.c --- src/battle_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/battle_main.c') diff --git a/src/battle_main.c b/src/battle_main.c index 5bc80f61e..29a8f560a 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -1357,7 +1357,7 @@ static void CB2_HandleStartMultiPartnerBattle(void) case 16: if (BattleInitAllSprites(&gBattleCommunication[SPRITES_INIT_STATE1], &gBattleCommunication[SPRITES_INIT_STATE2])) { - sub_8166188(); + TrySetLinkBattleTowerEnemyPartyLevel(); gPreBattleCallback1 = gMain.callback1; gMain.callback1 = BattleMainCB1; SetMainCallback2(BattleMainCB2); -- cgit v1.2.3