From 342e616d4b49d1772628947782a931964d36e167 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 6 Oct 2017 00:12:01 +0200 Subject: [PATCH] battle2 more and more and more --- asm/battle_2.s | 2623 +--------------------------------- asm/evolution_scene.s | 14 +- asm/party_menu.s | 2 +- asm/pokemon_item_effect.s | 2 +- data/battle_scripts_1.s | 22 +- data/battle_scripts_2.s | 8 +- data/data2b.s | 4 +- include/battle.h | 54 +- include/evolution_scene.h | 10 + include/pokemon.h | 6 + include/recorded_battle.h | 1 + include/songs.h | 84 +- src/battle_2.c | 896 +++++++++++- src/battle_3.c | 16 +- src/battle_script_commands.c | 54 +- sym_ewram.txt | 4 +- 16 files changed, 1046 insertions(+), 2754 deletions(-) create mode 100644 include/evolution_scene.h diff --git a/asm/battle_2.s b/asm/battle_2.s index 673a0a8331..c0d8fd72a1 100644 --- a/asm/battle_2.s +++ b/asm/battle_2.s @@ -6,2591 +6,12 @@ .text - thumb_func_start TurnValuesCleanUp -TurnValuesCleanUp: @ 803D580 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - ldr r1, =gActiveBank - movs r0, 0 - strb r0, [r1] - ldr r0, =gNoOfAllBanks - ldrb r2, [r0] - adds r5, r1, 0 - cmp r2, 0 - beq _0803D678 - ldr r7, =gProtectStructs - adds r6, r5, 0 - ldr r0, =gBattleMons + 0x50 - mov r12, r0 - ldr r1, =gDisableStructs - mov r8, r1 - mov r10, r8 -_0803D5AE: - mov r2, r9 - cmp r2, 0 - beq _0803D5EC - ldrb r1, [r6] - lsls r1, 4 - adds r1, r7 - ldrb r2, [r1] - movs r0, 0x2 - negs r0, r0 - ands r0, r2 - strb r0, [r1] - ldrb r1, [r6] - lsls r1, 4 - adds r1, r7 - ldrb r2, [r1] - movs r0, 0x3 - negs r0, r0 - ands r0, r2 - strb r0, [r1] - b _0803D648 - .pool -_0803D5EC: - ldrb r0, [r6] - lsls r0, 4 - adds r2, r0, r7 - movs r1, 0 - mov r4, r10 - movs r3, 0 -_0803D5F8: - adds r0, r2, r1 - strb r3, [r0] - adds r1, 0x1 - cmp r1, 0xF - bls _0803D5F8 - ldrb r1, [r5] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r1, r0, r4 - ldrb r0, [r1, 0x16] - cmp r0, 0 - beq _0803D616 - subs r0, 0x1 - strb r0, [r1, 0x16] -_0803D616: - ldrb r1, [r5] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r1, r0, r4 - ldrb r0, [r1, 0x19] - cmp r0, 0 - beq _0803D648 - subs r0, 0x1 - strb r0, [r1, 0x19] - ldrb r2, [r5] - lsls r0, r2, 3 - subs r0, r2 - lsls r0, 2 - adds r0, r4 - ldrb r0, [r0, 0x19] - cmp r0, 0 - bne _0803D648 - movs r0, 0x58 - muls r2, r0 - add r2, r12 - ldr r0, [r2] - ldr r1, =0xffbfffff - ands r0, r1 - str r0, [r2] -_0803D648: - ldrb r2, [r5] - lsls r0, r2, 3 - subs r0, r2 - lsls r0, 2 - add r0, r8 - ldrb r0, [r0, 0xA] - cmp r0, 0 - bne _0803D666 - movs r0, 0x58 - muls r2, r0 - add r2, r12 - ldr r0, [r2] - ldr r1, =0xfeffffff - ands r0, r1 - str r0, [r2] -_0803D666: - ldrb r0, [r5] - adds r0, 0x1 - strb r0, [r5] - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gNoOfAllBanks - ldrb r1, [r1] - cmp r0, r1 - bcc _0803D5AE -_0803D678: - movs r0, 0 - ldr r2, =gSideTimers - strb r0, [r2, 0x8] - strb r0, [r2, 0x14] - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end TurnValuesCleanUp - - thumb_func_start SpecialStatusesClear -SpecialStatusesClear: @ 803D6A0 - push {r4-r6,lr} - ldr r2, =gActiveBank - movs r0, 0 - strb r0, [r2] - ldr r0, =gNoOfAllBanks - ldrb r1, [r0] - adds r6, r0, 0 - cmp r1, 0 - beq _0803D6DE - adds r3, r2, 0 - movs r4, 0 - ldr r5, =gSpecialStatuses -_0803D6B8: - ldrb r1, [r3] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 2 - adds r2, r0, r5 - movs r1, 0 -_0803D6C4: - adds r0, r2, r1 - strb r4, [r0] - adds r1, 0x1 - cmp r1, 0x13 - bls _0803D6C4 - ldrb r0, [r3] - adds r0, 0x1 - strb r0, [r3] - lsls r0, 24 - lsrs r0, 24 - ldrb r1, [r6] - cmp r0, r1 - bcc _0803D6B8 -_0803D6DE: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end SpecialStatusesClear - - thumb_func_start bc_80154A0 -bc_80154A0: @ 803D6F0 - push {r4-r7,lr} - ldr r0, =gHitMarker - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 8 - ands r0, r1 - cmp r0, 0 - bne _0803D7AE - ldr r2, =gBattleStruct - ldr r0, [r2] - adds r0, 0x48 - ldr r1, =gNoOfAllBanks - ldrb r0, [r0] - mov r12, r2 - adds r6, r1, 0 - ldrb r1, [r6] - cmp r0, r1 - bcs _0803D7AE - ldr r5, =gActiveBank - ldr r4, =gBankAttacker - movs r7, 0x84 - lsls r7, 1 -_0803D71C: - ldr r1, [r2] - adds r1, 0x48 - ldrb r0, [r1] - strb r0, [r4] - strb r0, [r5] - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - ldr r1, =gChosenMovesByBanks - ldrb r3, [r5] - lsls r0, r3, 1 - adds r0, r1 - ldrh r0, [r0] - cmp r0, r7 - bne _0803D7A0 - ldr r1, =gBattleMons - movs r0, 0x58 - muls r0, r3 - adds r1, 0x4C - adds r0, r1 - ldr r0, [r0] - movs r1, 0x7 - ands r0, r1 - cmp r0, 0 - bne _0803D7A0 - ldr r2, =gDisableStructs - ldrb r1, [r4] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r0, [r0, 0x18] - lsls r0, 31 - cmp r0, 0 - bne _0803D7A0 - ldr r0, =gProtectStructs - lsls r1, r3, 4 - adds r1, r0 - ldrb r0, [r1] - lsls r0, 29 - cmp r0, 0 - blt _0803D7A0 - ldr r0, =gUnknown_082DB1FF - bl BattleScriptExecute - b _0803D7E8 - .pool -_0803D7A0: - mov r2, r12 - ldr r0, [r2] - adds r0, 0x48 - ldrb r0, [r0] - ldrb r1, [r6] - cmp r0, r1 - bcc _0803D71C -_0803D7AE: - bl b_clear_atk_up_if_hit_flag_unless_enraged - ldr r1, =gCurrentMoveTurn - movs r0, 0 - strb r0, [r1] - ldr r1, =gFightStateTracker - ldr r0, =gActionsByTurnOrder - movs r3, 0 - ldrb r0, [r0] - strb r0, [r1] - ldr r0, =gDynamicBasePower - movs r2, 0 - strh r3, [r0] - ldr r0, =gBattleStruct - ldr r0, [r0] - strb r2, [r0, 0x13] - ldr r1, =gBattleMainFunc - ldr r0, =bc_bs_exec - str r0, [r1] - ldr r0, =gBattleCommunication - strb r2, [r0, 0x3] - strb r2, [r0, 0x4] - ldr r0, =gBattleScripting - strb r2, [r0, 0x16] - ldr r0, =gBattleResources - ldr r0, [r0] - ldr r0, [r0, 0x8] - adds r0, 0x20 - strb r2, [r0] -_0803D7E8: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end bc_80154A0 - - thumb_func_start bc_bs_exec -bc_bs_exec: @ 803D818 - push {r4-r6,lr} - ldr r6, =gBattleOutcome - ldrb r0, [r6] - ldr r2, =gFightStateTracker - cmp r0, 0 - beq _0803D828 - movs r0, 0xC - strb r0, [r2] -_0803D828: - ldr r5, =gBattleStruct - ldr r0, [r5] - adds r0, 0x4B - ldr r4, =gCurrentMoveTurn - ldrb r1, [r4] - strb r1, [r0] - ldr r1, =gUnknown_0831BC0C - ldrb r0, [r2] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - bl _call_via_r0 - ldr r0, =gNoOfAllBanks - ldrb r1, [r4] - ldrb r0, [r0] - cmp r1, r0 - bcc _0803D894 - ldr r2, =gHitMarker - ldr r0, [r2] - ldr r1, =0xffefffff - ands r0, r1 - str r0, [r2] - ldr r3, =gBattleMainFunc - ldr r2, =gUnknown_0831BC44 - ldrb r1, [r6] - movs r0, 0x7F - ands r0, r1 - lsls r0, 2 - adds r0, r2 - ldr r0, [r0] - str r0, [r3] - b _0803D8AC - .pool -_0803D894: - ldr r0, [r5] - adds r0, 0x4B - ldrb r0, [r0] - cmp r0, r1 - beq _0803D8AC - ldr r2, =gHitMarker - ldr r0, [r2] - ldr r1, =0xfffffdff - ands r0, r1 - ldr r1, =0xfff7ffff - ands r0, r1 - str r0, [r2] -_0803D8AC: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end bc_bs_exec - - thumb_func_start HandleEndTurn_BattleWon -HandleEndTurn_BattleWon: @ 803D8C0 - push {r4,lr} - ldr r1, =gFightStateTracker - movs r0, 0 - strb r0, [r1] - ldr r1, =gBattleTypeFlags - ldr r2, [r1] - ldr r0, =0x02000002 - ands r0, r2 - cmp r0, 0 - beq _0803D920 - ldr r1, =gScriptResult - ldr r4, =gBattleOutcome - ldrb r0, [r4] - strh r0, [r1] - ldr r1, =gBattleTextBuff1 - ldrb r0, [r4] - strb r0, [r1] - movs r0, 0 - bl GetBankByIdentity - ldr r1, =gBankAttacker - strb r0, [r1] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DAA35 - str r0, [r1] - ldrb r1, [r4] - movs r0, 0x7F - ands r0, r1 - strb r0, [r4] - b _0803DAA4 - .pool -_0803D920: - movs r0, 0x8 - ands r0, r2 - cmp r0, 0 - beq _0803D95C - ldr r0, =0x043f0900 - ands r2, r0 - cmp r2, 0 - beq _0803D95C - bl BattleMusicStop - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DAA87 - str r0, [r1] - ldr r0, =gTrainerBattleOpponent_A - ldrh r1, [r0] - ldr r0, =0x000003fe - cmp r1, r0 - bne _0803D946 - b _0803DA8A -_0803D946: - b _0803DA94 - .pool -_0803D95C: - ldr r0, [r1] - movs r1, 0xA - ands r0, r1 - cmp r0, 0x8 - beq _0803D968 - b _0803DA9E -_0803D968: - bl BattleMusicStop - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DA92D - str r0, [r1] - ldr r2, =gTrainers - ldr r0, =gTrainerBattleOpponent_A - ldrh r1, [r0] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r2 - ldrb r0, [r0, 0x1] - subs r0, 0x3 - cmp r0, 0x32 - bls _0803D98A - b _0803DA94 -_0803D98A: - lsls r0, 2 - ldr r1, =_0803D9A8 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0803D9A8: - .4byte _0803DA80 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA80 - .4byte _0803DA94 - .4byte _0803DA80 - .4byte _0803DA94 - .4byte _0803DA80 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA74 - .4byte _0803DA8A - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA74 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA80 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA94 - .4byte _0803DA80 -_0803DA74: - ldr r0, =0x00000163 - bl PlayBGM - b _0803DAA4 - .pool -_0803DA80: - movs r0, 0xD4 - lsls r0, 1 - bl PlayBGM - b _0803DAA4 -_0803DA8A: - movs r0, 0xB1 - lsls r0, 1 - bl PlayBGM - b _0803DAA4 -_0803DA94: - movs r0, 0xCE - lsls r0, 1 - bl PlayBGM - b _0803DAA4 -_0803DA9E: - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DA96A - str r0, [r1] -_0803DAA4: - ldr r1, =gBattleMainFunc - ldr r0, =HandleEndTurn_FinishBattle - str r0, [r1] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end HandleEndTurn_BattleWon - - thumb_func_start HandleEndTurn_BattleLost -HandleEndTurn_BattleLost: @ 803DAC0 - push {r4,lr} - ldr r1, =gFightStateTracker - movs r0, 0 - strb r0, [r1] - ldr r0, =gBattleTypeFlags - ldr r1, [r0] - ldr r0, =0x02000002 - ands r0, r1 - cmp r0, 0 - beq _0803DB7C - ldr r0, =0x003f0100 - ands r1, r0 - cmp r1, 0 - beq _0803DB44 - ldr r3, =gBattleOutcome - ldrb r2, [r3] - movs r0, 0x80 - ands r0, r2 - cmp r0, 0 - beq _0803DB2C - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DB9C8 - str r0, [r1] - movs r0, 0x7F - ands r0, r2 - strb r0, [r3] - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0x00000ca9 - adds r1, r0 - ldrb r0, [r1] - movs r2, 0x8 - orrs r0, r2 - strb r0, [r1] - b _0803DB82 - .pool -_0803DB2C: - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DAA0B - str r0, [r1] - movs r0, 0x7F - ands r0, r2 - strb r0, [r3] - b _0803DB82 - .pool -_0803DB44: - ldr r1, =gBattleTextBuff1 - ldr r4, =gBattleOutcome - ldrb r0, [r4] - strb r0, [r1] - movs r0, 0 - bl GetBankByIdentity - ldr r1, =gBankAttacker - strb r0, [r1] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DAA35 - str r0, [r1] - ldrb r1, [r4] - movs r0, 0x7F - ands r0, r1 - strb r0, [r4] - b _0803DB82 - .pool -_0803DB7C: - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DA96D - str r0, [r1] -_0803DB82: - ldr r1, =gBattleMainFunc - ldr r0, =HandleEndTurn_FinishBattle - str r0, [r1] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end HandleEndTurn_BattleLost - - thumb_func_start HandleEndTurn_RanFromBattle -HandleEndTurn_RanFromBattle: @ 803DBA0 - push {lr} - ldr r1, =gFightStateTracker - movs r0, 0 - strb r0, [r1] - ldr r1, =gBattleTypeFlags - ldr r2, [r1] - ldr r0, =0x003f0100 - ands r0, r2 - cmp r0, 0 - beq _0803DBFC - movs r0, 0x8 - ands r2, r0 - cmp r2, 0 - beq _0803DBFC - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DB9C1 - str r0, [r1] - ldr r1, =gBattleOutcome - movs r0, 0x9 - strb r0, [r1] - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0x00000ca9 - adds r1, r0 - ldrb r0, [r1] - movs r2, 0x8 - orrs r0, r2 - strb r0, [r1] - b _0803DC6A - .pool -_0803DBFC: - ldr r0, [r1] - movs r1, 0x80 - lsls r1, 19 - ands r0, r1 - cmp r0, 0 - beq _0803DC24 - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DB9C1 - str r0, [r1] - ldr r1, =gBattleOutcome - movs r0, 0x9 - strb r0, [r1] - b _0803DC6A - .pool -_0803DC24: - ldr r1, =gProtectStructs - ldr r0, =gBankAttacker - ldrb r0, [r0] - lsls r0, 4 - adds r0, r1 - ldrb r0, [r0, 0x1] - lsls r0, 27 - lsrs r0, 30 - cmp r0, 0x1 - beq _0803DC54 - cmp r0, 0x2 - beq _0803DC64 - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DAAF0 - b _0803DC68 - .pool -_0803DC54: - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DAADB - b _0803DC68 - .pool -_0803DC64: - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DAAE9 -_0803DC68: - str r0, [r1] -_0803DC6A: - ldr r1, =gBattleMainFunc - ldr r0, =HandleEndTurn_FinishBattle - str r0, [r1] - pop {r0} - bx r0 - .pool - thumb_func_end HandleEndTurn_RanFromBattle - - thumb_func_start HandleEndTurn_MonFled -HandleEndTurn_MonFled: @ 803DC84 - ldr r1, =gFightStateTracker - movs r0, 0 - strb r0, [r1] - ldr r1, =gBattleTextBuff1 - movs r0, 0xFD - strb r0, [r1] - movs r0, 0x7 - strb r0, [r1, 0x1] - ldr r2, =gBankAttacker - ldrb r0, [r2] - strb r0, [r1, 0x2] - ldr r3, =gBattlePartyID - ldrb r0, [r2] - lsls r0, 1 - adds r0, r3 - ldrh r0, [r0] - strb r0, [r1, 0x3] - movs r0, 0xFF - strb r0, [r1, 0x4] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DAAF7 - str r0, [r1] - ldr r1, =gBattleMainFunc - ldr r0, =HandleEndTurn_FinishBattle - str r0, [r1] - bx lr - .pool - thumb_func_end HandleEndTurn_MonFled - - thumb_func_start HandleEndTurn_FinishBattle -HandleEndTurn_FinishBattle: @ 803DCD8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - ldr r0, =gFightStateTracker - ldrb r0, [r0] - subs r0, 0xB - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bls _0803DCEE - b _0803DE10 -_0803DCEE: - ldr r0, =gBattleTypeFlags - ldr r1, [r0] - ldr r0, =0x023f0b92 - ands r1, r0 - cmp r1, 0 - bne _0803DDB6 - ldr r2, =gActiveBank - strb r1, [r2] - ldr r0, =gNoOfAllBanks - ldrb r0, [r0] - cmp r1, r0 - bcs _0803DDB2 - adds r5, r2, 0 - ldr r0, =gBattlePartyID - mov r8, r0 - movs r7, 0x64 - ldr r6, =gPlayerParty -_0803DD10: - ldrb r0, [r5] - bl GetBankSide - lsls r0, 24 - cmp r0, 0 - bne _0803DDA0 - ldr r4, =gBattleResults - ldrh r0, [r4, 0x6] - cmp r0, 0 - bne _0803DD74 - ldrb r0, [r5] - lsls r0, 1 - add r0, r8 - ldrh r0, [r0] - muls r0, r7 - adds r0, r6 - movs r1, 0xB - movs r2, 0 - bl GetMonData - strh r0, [r4, 0x6] - ldrb r0, [r5] - lsls r0, 1 - add r0, r8 - ldrh r0, [r0] - muls r0, r7 - adds r0, r6 - movs r1, 0x2 - adds r2, r4, 0 - adds r2, 0x8 - bl GetMonData - b _0803DDA0 - .pool -_0803DD74: - ldrb r0, [r5] - lsls r0, 1 - add r0, r8 - ldrh r0, [r0] - muls r0, r7 - adds r0, r6 - movs r1, 0xB - movs r2, 0 - bl GetMonData - strh r0, [r4, 0x26] - ldrb r0, [r5] - lsls r0, 1 - add r0, r8 - ldrh r0, [r0] - muls r0, r7 - adds r0, r6 - movs r1, 0x2 - adds r2, r4, 0 - adds r2, 0x14 - bl GetMonData -_0803DDA0: - ldrb r0, [r5] - adds r0, 0x1 - strb r0, [r5] - ldr r1, =gNoOfAllBanks - lsls r0, 24 - lsrs r0, 24 - ldrb r1, [r1] - cmp r0, r1 - bcc _0803DD10 -_0803DDB2: - bl sub_80EC728 -_0803DDB6: - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - ldr r1, =0x023f0b9a - ands r0, r1 - cmp r0, 0 - bne _0803DDD2 - ldr r0, =gBattleResults - ldrb r1, [r0, 0x5] - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - beq _0803DDD2 - bl sub_80EE184 -_0803DDD2: - bl sub_8186444 - movs r0, 0x3 - bl BeginFastPaletteFade - movs r0, 0x5 - bl FadeOutMapMusic - ldr r1, =gBattleMainFunc - ldr r0, =sub_803DE40 - str r0, [r1] - ldr r1, =gUnknown_030061E8 - ldr r0, =BattleMainCB2 - str r0, [r1] - b _0803DE2A - .pool -_0803DE10: - ldr r0, =gBattleExecBuffer - ldr r0, [r0] - cmp r0, 0 - bne _0803DE2A - ldr r1, =gBattleScriptingCommandsTable - ldr r0, =gBattlescriptCurrInstr - ldr r0, [r0] - ldrb r0, [r0] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - bl _call_via_r0 -_0803DE2A: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end HandleEndTurn_FinishBattle - - thumb_func_start sub_803DE40 -sub_803DE40: @ 803DE40 - push {lr} - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _0803DE86 - bl ResetSpriteData - ldr r0, =gLeveledUpInBattle - ldrb r0, [r0] - cmp r0, 0 - beq _0803DE62 - ldr r0, =gBattleOutcome - ldrb r0, [r0] - cmp r0, 0x1 - beq _0803DE80 -_0803DE62: - ldr r1, =gBattleMainFunc - ldr r0, =c4_overworld - str r0, [r1] - b _0803DEA2 - .pool -_0803DE80: - ldr r1, =gBattleMainFunc - ldr r0, =bc_evolution_cutscene - str r0, [r1] -_0803DE86: - bl FreeAllWindowBuffers - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x2 - ands r0, r1 - cmp r0, 0 - bne _0803DEA2 - bl FreeMonSpritesGfx - bl FreeBattleResources - bl FreeBattleSpritesData -_0803DEA2: - pop {r0} - bx r0 - .pool - thumb_func_end sub_803DE40 - - thumb_func_start bc_evolution_cutscene -bc_evolution_cutscene: @ 803DEB4 - push {r4-r6,lr} - ldr r0, =gLeveledUpInBattle - ldrb r1, [r0] - adds r3, r0, 0 - cmp r1, 0 - beq _0803DF2E -_0803DEC0: - movs r6, 0 -_0803DEC2: - ldrb r2, [r3] - ldr r0, =gBitTable - lsls r1, r6, 2 - adds r1, r0 - ldr r1, [r1] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0 - beq _0803DF20 - bics r2, r1 - strb r2, [r3] - movs r0, 0x64 - adds r1, r6, 0 - muls r1, r0 - ldr r0, =gPlayerParty - adds r5, r1, r0 - adds r0, r5, 0 - movs r1, 0 - bl GetEvolutionTargetSpecies - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0 - beq _0803DF20 - bl FreeAllWindowBuffers - ldr r0, =gBattleMainFunc - ldr r1, =sub_803DF48 - str r1, [r0] - lsls r3, r6, 24 - lsrs r3, 24 - adds r0, r5, 0 - adds r1, r4, 0 - movs r2, 0x1 - bl evolution_cutscene - b _0803DF34 - .pool -_0803DF20: - adds r6, 0x1 - ldr r3, =gLeveledUpInBattle - cmp r6, 0x5 - ble _0803DEC2 - ldrb r0, [r3] - cmp r0, 0 - bne _0803DEC0 -_0803DF2E: - ldr r1, =gBattleMainFunc - ldr r0, =c4_overworld - str r0, [r1] -_0803DF34: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end bc_evolution_cutscene - - thumb_func_start sub_803DF48 -sub_803DF48: @ 803DF48 - push {lr} - ldr r0, =gMain - ldr r1, [r0, 0x4] - ldr r0, =BattleMainCB2 - cmp r1, r0 - bne _0803DF5A - ldr r1, =gBattleMainFunc - ldr r0, =bc_evolution_cutscene - str r0, [r1] -_0803DF5A: - pop {r0} - bx r0 - .pool - thumb_func_end sub_803DF48 - - thumb_func_start c4_overworld -c4_overworld: @ 803DF70 - push {r4-r6,lr} - ldr r6, =gBattleTypeFlags - ldr r0, [r6] - movs r5, 0x2 - ands r0, r5 - cmp r0, 0 - bne _0803DF8C - ldr r4, =gPlayerParty - adds r0, r4, 0 - bl RandomlyGivePartyPokerus - adds r0, r4, 0 - bl PartySpreadPokerus -_0803DF8C: - ldr r4, [r6] - adds r0, r4, 0 - ands r0, r5 - cmp r0, 0 - beq _0803DF9E - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r0, [r0] - cmp r0, 0 - bne _0803DFEC -_0803DF9E: - ldr r1, =gScriptResult - ldr r5, =gBattleOutcome - ldrb r0, [r5] - strh r0, [r1] - ldr r3, =gMain - ldr r0, =0x00000439 - adds r2, r3, r0 - ldrb r1, [r2] - movs r0, 0x3 - negs r0, r0 - ands r0, r1 - strb r0, [r2] - ldr r0, =gPreBattleCallback1 - ldr r0, [r0] - str r0, [r3] - movs r0, 0x80 - lsls r0, 3 - ands r4, r0 - cmp r4, 0 - beq _0803DFDE - ldr r0, =gEnemyParty - bl UpdateRoamerHPStatus - ldrb r1, [r5] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _0803DFDA - cmp r1, 0x7 - bne _0803DFDE -_0803DFDA: - bl SetRoamerInactive -_0803DFDE: - movs r0, 0x5A - bl m4aSongNumStop - ldr r0, =gMain - ldr r0, [r0, 0x8] - bl SetMainCallback2 -_0803DFEC: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end c4_overworld - - thumb_func_start bc_move_exec_returning -bc_move_exec_returning: @ 803E018 - push {lr} - ldr r0, =gFightStateTracker - ldrb r0, [r0] - subs r0, 0xB - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bhi _0803E060 - ldr r3, =gBattleResources - ldr r0, [r3] - ldr r0, [r0, 0xC] - adds r1, r0, 0 - adds r1, 0x20 - ldrb r0, [r1] - cmp r0, 0 - beq _0803E03C - subs r0, 0x1 - strb r0, [r1] -_0803E03C: - ldr r2, =gBattleMainFunc - ldr r0, [r3] - ldr r1, [r0, 0xC] - adds r0, r1, 0 - adds r0, 0x20 - ldrb r0, [r0] - lsls r0, 2 - adds r1, r0 - ldr r0, [r1] - str r0, [r2] - b _0803E07A - .pool -_0803E060: - ldr r0, =gBattleExecBuffer - ldr r0, [r0] - cmp r0, 0 - bne _0803E07A - ldr r1, =gBattleScriptingCommandsTable - ldr r0, =gBattlescriptCurrInstr - ldr r0, [r0] - ldrb r0, [r0] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - bl _call_via_r0 -_0803E07A: - pop {r0} - bx r0 - .pool - thumb_func_end bc_move_exec_returning - - thumb_func_start sub_803E08C -sub_803E08C: @ 803E08C - push {lr} - ldr r0, =gBattleExecBuffer - ldr r0, [r0] - cmp r0, 0 - bne _0803E0A8 - ldr r1, =gBattleScriptingCommandsTable - ldr r0, =gBattlescriptCurrInstr - ldr r0, [r0] - ldrb r0, [r0] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - bl _call_via_r0 -_0803E0A8: - pop {r0} - bx r0 - .pool - thumb_func_end sub_803E08C - - thumb_func_start sub_803E0B8 -sub_803E0B8: @ 803E0B8 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - movs r0, 0x4 - str r0, [sp] - ldr r6, =gBankAttacker - ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentMoveTurn - ldrb r0, [r0] - adds r0, r1 - ldrb r0, [r0] - strb r0, [r6] - ldr r1, =gBattleStruct - ldr r3, [r1] - adds r0, r3, 0 - adds r0, 0x91 - ldrb r2, [r0] - ldr r1, =gBitTable - ldrb r0, [r6] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - ands r2, r0 - cmp r2, 0 - beq _0803E110 - ldr r1, =gFightStateTracker - movs r0, 0xC - b _0803E83C - .pool -_0803E110: - ldr r1, =gCritMultiplier - movs r0, 0x1 - strb r0, [r1] - ldr r1, =gBattleScripting - movs r0, 0x1 - strb r0, [r1, 0xE] - ldr r5, =0x000001a3 - adds r0, r3, r5 - strb r2, [r0] - ldr r0, =gBattleMoveFlags - strb r2, [r0] - ldr r0, =gMultiHitCounter - strb r2, [r0] - ldr r0, =gBattleCommunication - strb r2, [r0, 0x6] - ldr r2, =gCurrMovePos - ldr r0, =gUnknown_020241E9 - mov r9, r0 - ldrb r0, [r6] - ldr r3, =gBattleStruct - ldr r1, [r3] - adds r0, r1 - adds r0, 0x80 - ldrb r0, [r0] - mov r5, r9 - strb r0, [r5] - strb r0, [r2] - ldr r1, =gProtectStructs - ldrb r4, [r6] - lsls r0, r4, 4 - adds r3, r0, r1 - ldrb r1, [r3] - lsls r0, r1, 29 - mov r8, r2 - cmp r0, 0 - bge _0803E1BC - movs r0, 0x5 - negs r0, r0 - ands r0, r1 - strb r0, [r3] - ldr r2, =gCurrentMove - ldr r1, =gLastUsedMove - movs r0, 0xA5 - strh r0, [r1] - strh r0, [r2] - ldr r2, =gHitMarker - ldr r0, [r2] - movs r1, 0x80 - lsls r1, 4 - orrs r0, r1 - str r0, [r2] - movs r0, 0xA5 - movs r1, 0 - bl GetMoveTarget - ldrb r1, [r6] - ldr r3, =gBattleStruct - ldr r2, [r3] - b _0803E316 - .pool -_0803E1BC: - ldr r5, =gBattleMons - mov r10, r5 - movs r0, 0x58 - adds r5, r4, 0 - muls r5, r0 - mov r0, r10 - adds r0, 0x50 - adds r0, r5, r0 - ldr r1, [r0] - movs r0, 0x80 - lsls r0, 5 - ands r0, r1 - cmp r0, 0 - bne _0803E1E2 - movs r7, 0x80 - lsls r7, 15 - ands r7, r1 - cmp r7, 0 - beq _0803E204 -_0803E1E2: - ldr r3, =gCurrentMove - ldr r2, =gLastUsedMove - ldr r1, =gLockedMoves - lsls r0, r4, 1 - adds r0, r1 - ldrh r0, [r0] - strh r0, [r2] - strh r0, [r3] - b _0803E33C - .pool -_0803E204: - ldr r1, =gDisableStructs - mov r12, r1 - lsls r0, r4, 3 - subs r0, r4 - lsls r0, 2 - add r0, r12 - ldrh r3, [r0, 0x6] - adds r1, r3, 0 - cmp r1, 0 - beq _0803E2DC - ldrb r2, [r0, 0xC] - lsls r0, r2, 1 - adds r0, r5 - mov r4, r10 - adds r4, 0xC - adds r0, r4 - ldrh r0, [r0] - cmp r1, r0 - bne _0803E268 - ldr r2, =gCurrentMove - ldr r0, =gLastUsedMove - strh r3, [r0] - strh r3, [r2] - ldrb r1, [r6] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - add r0, r12 - ldrb r0, [r0, 0xC] - mov r3, r9 - strb r0, [r3] - mov r5, r8 - strb r0, [r5] - ldrh r0, [r2] - movs r1, 0 - bl GetMoveTarget - ldrb r1, [r6] - ldr r3, =gBattleStruct - ldr r2, [r3] - b _0803E316 - .pool -_0803E268: - cmp r1, 0 - beq _0803E2DC - cmp r1, r0 - beq _0803E2DC - mov r5, r9 - strb r2, [r5] - mov r0, r8 - strb r2, [r0] - ldr r3, =gCurrentMove - ldr r2, =gLastUsedMove - ldrb r0, [r0] - lsls r0, 1 - ldrb r1, [r6] - movs r5, 0x58 - muls r1, r5 - adds r0, r1 - adds r0, r4 - ldrh r0, [r0] - strh r0, [r2] - strh r0, [r3] - ldrb r1, [r6] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - add r0, r12 - movs r2, 0 - strh r7, [r0, 0x6] - ldrb r1, [r6] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - add r0, r12 - strb r2, [r0, 0xC] - ldrb r0, [r6] - lsls r1, r0, 3 - subs r1, r0 - lsls r1, 2 - add r1, r12 - ldrb r2, [r1, 0xE] - movs r0, 0x10 - negs r0, r0 - ands r0, r2 - strb r0, [r1, 0xE] - ldrh r0, [r3] - movs r1, 0 - bl GetMoveTarget - ldrb r1, [r6] - ldr r3, =gBattleStruct - ldr r2, [r3] - b _0803E316 - .pool -_0803E2DC: - ldr r3, =gBattleMons - mov r5, r8 - ldrb r0, [r5] - lsls r0, 1 - ldr r4, =gBankAttacker - ldrb r2, [r4] - movs r1, 0x58 - muls r1, r2 - adds r0, r1 - adds r3, 0xC - adds r0, r3 - ldr r1, =gChosenMovesByBanks - lsls r2, 1 - adds r2, r1 - ldrh r3, [r0] - ldrh r2, [r2] - cmp r3, r2 - beq _0803E334 - ldr r1, =gCurrentMove - ldr r0, =gLastUsedMove - strh r3, [r0] - strh r3, [r1] - ldrh r0, [r1] - movs r1, 0 - bl GetMoveTarget - ldrb r1, [r4] - ldr r2, =gBattleStruct - ldr r2, [r2] -_0803E316: - adds r1, r2 - strb r0, [r1, 0xC] - b _0803E33C - .pool -_0803E334: - ldr r1, =gCurrentMove - ldr r0, =gLastUsedMove - strh r3, [r0] - strh r3, [r1] -_0803E33C: - ldr r2, =gBattleMons - ldr r1, =gBankAttacker - ldrb r3, [r1] - movs r0, 0x58 - muls r0, r3 - adds r0, r2 - ldrh r0, [r0, 0x28] - mov r8, r1 - cmp r0, 0 - beq _0803E384 - adds r0, r3, 0 - bl GetBankSide - lsls r0, 24 - cmp r0, 0 - bne _0803E37C - ldr r0, =gBattleResults - ldr r1, =gCurrentMove - ldrh r1, [r1] - strh r1, [r0, 0x22] - b _0803E384 - .pool -_0803E37C: - ldr r0, =gBattleResults - ldr r1, =gCurrentMove - ldrh r1, [r1] - strh r1, [r0, 0x24] -_0803E384: - mov r1, r8 - ldrb r0, [r1] - bl GetBankSide - movs r1, 0x1 - eors r0, r1 - lsls r0, 24 - lsrs r6, r0, 24 - ldr r1, =gSideTimers - lsls r0, r6, 1 - adds r0, r6 - lsls r0, 2 - adds r5, r0, r1 - ldrb r0, [r5, 0x8] - cmp r0, 0 - beq _0803E400 - ldr r2, =gBattleMoves - ldr r0, =gCurrentMove - ldrh r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r0, [r0, 0x6] - cmp r0, 0 - bne _0803E400 - mov r3, r8 - ldrb r0, [r3] - bl GetBankSide - adds r4, r0, 0 - ldrb r0, [r5, 0x9] - bl GetBankSide - lsls r4, 24 - lsls r0, 24 - cmp r4, r0 - beq _0803E400 - ldr r1, =gBattleMons - ldrb r2, [r5, 0x9] - movs r0, 0x58 - muls r0, r2 - adds r0, r1 - ldrh r0, [r0, 0x28] - cmp r0, 0 - beq _0803E400 - ldr r0, =gBankTarget - strb r2, [r0] - b _0803E76A - .pool -_0803E400: - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x1 - ands r0, r1 - ldr r5, =gBankAttacker - mov r8, r5 - cmp r0, 0 - bne _0803E412 - b _0803E6E0 -_0803E412: - ldr r1, =gSideTimers - lsls r0, r6, 1 - adds r0, r6 - lsls r0, 2 - adds r0, r1 - ldrb r5, [r0, 0x8] - cmp r5, 0 - beq _0803E424 - b _0803E630 -_0803E424: - ldr r2, =gBattleMoves - ldr r0, =gCurrentMove - ldrh r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r4, r0, r2 - ldrb r0, [r4, 0x1] - cmp r0, 0 - bne _0803E440 - ldrb r0, [r4, 0x6] - cmp r0, 0x10 - bne _0803E440 - b _0803E630 -_0803E440: - ldr r3, =gBattleMons - ldr r2, =gBankAttacker - ldrb r6, [r2] - ldr r0, =gBattleStruct - ldr r0, [r0] - adds r0, r6, r0 - ldrb r1, [r0, 0xC] - movs r0, 0x58 - muls r0, r1 - adds r0, r3 - adds r0, 0x20 - ldrb r0, [r0] - mov r8, r2 - cmp r0, 0x1F - bne _0803E460 - b _0803E630 -_0803E460: - ldrb r0, [r4, 0x2] - cmp r0, 0xD - beq _0803E468 - b _0803E630 -_0803E468: - adds r0, r6, 0 - bl GetBankSide - lsls r0, 24 - lsrs r6, r0, 24 - ldr r1, =gActiveBank - strb r5, [r1] - ldr r0, =gNoOfAllBanks - ldrb r0, [r0] - cmp r5, r0 - bcs _0803E4E0 - adds r4, r1, 0 -_0803E480: - ldrb r0, [r4] - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - cmp r6, r0 - beq _0803E4CE - ldr r0, =gBankAttacker - ldrb r1, [r0] - ldr r0, =gBattleStruct - ldr r0, [r0] - adds r1, r0 - ldrb r0, [r1, 0xC] - ldrb r1, [r4] - cmp r0, r1 - beq _0803E4CE - ldr r1, =gBattleMons - ldrb r2, [r4] - movs r0, 0x58 - muls r0, r2 - adds r0, r1 - adds r0, 0x20 - ldrb r0, [r0] - cmp r0, 0x1F - bne _0803E4CE - adds r0, r2, 0 - bl BankGetTurnOrder - lsls r0, 24 - lsrs r0, 24 - ldr r3, [sp] - cmp r0, r3 - bcs _0803E4CE - ldrb r0, [r4] - bl BankGetTurnOrder - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] -_0803E4CE: - ldrb r0, [r4] - adds r0, 0x1 - strb r0, [r4] - ldr r1, =gNoOfAllBanks - lsls r0, 24 - lsrs r0, 24 - ldrb r1, [r1] - cmp r0, r1 - bcc _0803E480 -_0803E4E0: - ldr r5, [sp] - cmp r5, 0x4 - beq _0803E4E8 - b _0803E5E2 -_0803E4E8: - ldr r2, =gBattleMoves - ldr r0, =gLastUsedMove - ldrh r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r0, [r0, 0x6] - ands r5, r0 - cmp r5, 0 - beq _0803E568 - ldr r0, =gBankAttacker - ldrb r0, [r0] - bl GetBankSide - lsls r0, 24 - cmp r0, 0 - bne _0803E548 - bl Random - movs r1, 0x1 - ands r1, r0 - cmp r1, 0 - beq _0803E544 - movs r0, 0x1 - b _0803E55A - .pool -_0803E544: - movs r0, 0x3 - b _0803E55A -_0803E548: - bl Random - movs r1, 0x1 - ands r1, r0 - cmp r1, 0 - beq _0803E558 - movs r0, 0 - b _0803E55A -_0803E558: - movs r0, 0x2 -_0803E55A: - bl GetBankByIdentity - ldr r1, =gBankTarget - strb r0, [r1] - b _0803E578 - .pool -_0803E568: - ldr r2, =gBankTarget - ldr r0, =gBankAttacker - ldrb r0, [r0] - ldr r1, =gBattleStruct - ldr r1, [r1] - adds r0, r1 - ldrb r0, [r0, 0xC] - strb r0, [r2] -_0803E578: - ldr r7, =gAbsentBankFlags - ldrb r0, [r7] - ldr r1, =gBitTable - mov r8, r1 - ldr r5, =gBankTarget - ldrb r1, [r5] - lsls r1, 2 - add r1, r8 - ldr r1, [r1] - ands r0, r1 - cmp r0, 0 - bne _0803E592 - b _0803E76A -_0803E592: - ldr r6, =gBankAttacker - ldrb r0, [r6] - bl GetBankSide - adds r4, r0, 0 - ldrb r0, [r5] - bl GetBankSide - lsls r4, 24 - lsls r0, 24 - cmp r4, r0 - beq _0803E5C4 - ldrb r0, [r5] - b _0803E758 - .pool -_0803E5C4: - ldrb r0, [r6] - bl GetBankIdentity - movs r1, 0x1 - eors r0, r1 - lsls r0, 24 - lsrs r0, 24 - bl GetBankByIdentity - strb r0, [r5] - ldrb r1, [r7] - ldrb r2, [r5] - lsls r0, r2, 2 - add r0, r8 - b _0803E74E -_0803E5E2: - ldr r4, =gActiveBank - ldr r0, =gBanksByTurnOrder - ldr r3, [sp] - adds r0, r3, r0 - ldrb r0, [r0] - strb r0, [r4] - ldrb r0, [r4] - ldr r2, =gBattleMons - movs r1, 0x58 - muls r1, r0 - adds r1, r2 - adds r1, 0x20 - ldrb r1, [r1] - bl RecordAbilityBattle - ldr r2, =gSpecialStatuses - ldrb r1, [r4] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r1, [r0] - movs r2, 0x2 - orrs r1, r2 - strb r1, [r0] - ldr r1, =gBankTarget - ldrb r0, [r4] - strb r0, [r1] - b _0803E76A - .pool -_0803E630: - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r4, 0x1 - ands r0, r4 - cmp r0, 0 - beq _0803E6E0 - ldr r2, =gBattleMoves - ldr r0, =gLastUsedMove - ldrh r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r1, [r0, 0x6] - movs r0, 0x4 - ands r0, r1 - cmp r0, 0 - beq _0803E6E0 - mov r5, r8 - ldrb r0, [r5] - bl GetBankSide - lsls r0, 24 - cmp r0, 0 - bne _0803E684 - bl Random - adds r1, r4, 0 - ands r1, r0 - cmp r1, 0 - beq _0803E680 - movs r0, 0x1 - b _0803E696 - .pool -_0803E680: - movs r0, 0x3 - b _0803E696 -_0803E684: - bl Random - adds r1, r4, 0 - ands r1, r0 - cmp r1, 0 - beq _0803E694 - movs r0, 0 - b _0803E696 -_0803E694: - movs r0, 0x2 -_0803E696: - bl GetBankByIdentity - ldr r1, =gBankTarget - strb r0, [r1] - ldr r0, =gAbsentBankFlags - ldrb r1, [r0] - ldr r2, =gBitTable - ldr r5, =gBankTarget - ldrb r0, [r5] - lsls r0, 2 - adds r0, r2 - ldr r0, [r0] - ands r1, r0 - cmp r1, 0 - beq _0803E76A - ldr r0, =gBankAttacker - ldrb r0, [r0] - bl GetBankSide - adds r4, r0, 0 - ldrb r0, [r5] - bl GetBankSide - lsls r4, 24 - lsls r0, 24 - cmp r4, r0 - beq _0803E76A - ldrb r0, [r5] - b _0803E758 - .pool -_0803E6E0: - ldr r5, =gBankTarget - mov r2, r8 - ldrb r0, [r2] - ldr r1, =gBattleStruct - ldr r1, [r1] - adds r0, r1 - ldrb r0, [r0, 0xC] - strb r0, [r5] - ldr r6, =gAbsentBankFlags - ldrb r1, [r6] - ldr r7, =gBitTable - ldrb r0, [r5] - lsls r0, 2 - adds r0, r7 - ldr r0, [r0] - ands r1, r0 - cmp r1, 0 - beq _0803E76A - ldrb r0, [r2] - bl GetBankSide - adds r4, r0, 0 - ldrb r0, [r5] - bl GetBankSide - lsls r4, 24 - lsls r0, 24 - cmp r4, r0 - beq _0803E730 - ldrb r0, [r5] - b _0803E758 - .pool -_0803E730: - mov r1, r8 - ldrb r0, [r1] - bl GetBankIdentity - movs r1, 0x1 - eors r0, r1 - lsls r0, 24 - lsrs r0, 24 - bl GetBankByIdentity - strb r0, [r5] - ldrb r1, [r6] - ldrb r2, [r5] - lsls r0, r2, 2 - adds r0, r7 -_0803E74E: - ldr r0, [r0] - ands r1, r0 - cmp r1, 0 - beq _0803E76A - adds r0, r2, 0 -_0803E758: - bl GetBankIdentity - movs r1, 0x2 - eors r0, r1 - lsls r0, 24 - lsrs r0, 24 - bl GetBankByIdentity - strb r0, [r5] -_0803E76A: - ldr r0, =gBattleTypeFlags - ldr r1, [r0] - movs r2, 0x80 - lsls r2, 10 - ands r1, r2 - adds r5, r0, 0 - cmp r1, 0 - beq _0803E808 - ldr r0, =gProtectStructs - ldr r4, =gBankAttacker - ldrb r2, [r4] - lsls r1, r2, 4 - adds r1, r0 - ldrb r0, [r1, 0x2] - lsls r0, 27 - cmp r0, 0 - bge _0803E808 - ldr r1, =gBattleMons - movs r0, 0x58 - muls r0, r2 - adds r0, r1 - ldrh r0, [r0, 0x28] - cmp r0, 0 - bne _0803E7B4 - ldr r1, =gFightStateTracker - movs r0, 0xC - b _0803E83C - .pool -_0803E7B4: - ldr r3, =gUnknown_02024230 - lsls r0, r2, 2 - adds r0, r3 - ldr r0, [r0] - cmp r0, 0 - beq _0803E7EC - ldr r1, =gBattleCommunication - movs r2, 0 - movs r0, 0x4 - strb r0, [r1, 0x5] - ldr r1, =gBattlescriptCurrInstr - ldrb r0, [r4] - lsls r0, 2 - adds r0, r3 - ldr r0, [r0] - str r0, [r1] - ldrb r0, [r4] - lsls r0, 2 - adds r0, r3 - str r2, [r0] - b _0803E824 - .pool -_0803E7EC: - ldr r1, =gBattleCommunication - movs r0, 0x4 - strb r0, [r1, 0x5] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =BattleScript_MoveUsedLoafingAround - str r0, [r1] - b _0803E824 - .pool -_0803E808: - ldr r4, =gBattlescriptCurrInstr - ldr r3, =gBattleScriptsForMoveEffects - ldr r2, =gBattleMoves - ldr r0, =gCurrentMove - ldrh r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 2 - adds r0, r3 - ldr r0, [r0] - str r0, [r4] -_0803E824: - ldr r0, [r5] - movs r1, 0x80 - lsls r1, 11 - ands r0, r1 - cmp r0, 0 - beq _0803E838 - ldr r0, =gBankAttacker - ldrb r0, [r0] - bl sub_81A56E8 -_0803E838: - ldr r1, =gFightStateTracker - movs r0, 0xA -_0803E83C: - strb r0, [r1] - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_803E0B8 - - thumb_func_start bs2_8016374 -bs2_8016374: @ 803E868 - push {r4,lr} - ldr r3, =gBankAttacker - ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentMoveTurn - ldrb r0, [r0] - adds r0, r1 - ldrb r0, [r0] - strb r0, [r3] - ldr r0, =gBattle_BG0_X - movs r2, 0 - strh r2, [r0] - ldr r0, =gBattle_BG0_Y - strh r2, [r0] - ldr r1, =gActionSelectionCursor - ldrb r0, [r3] - adds r0, r1 - strb r2, [r0] - ldr r1, =gMoveSelectionCursor - ldrb r0, [r3] - adds r0, r1 - strb r2, [r0] - ldr r2, =gBattleTextBuff1 - movs r0, 0xFD - strb r0, [r2] - movs r0, 0x7 - strb r0, [r2, 0x1] - ldrb r4, [r3] - strb r4, [r2, 0x2] - ldrb r0, [r3] - ldr r1, =gBattleStruct - ldr r1, [r1] - adds r0, r1 - adds r0, 0x58 - ldrb r0, [r0] - strb r0, [r2, 0x3] - movs r0, 0xFF - strb r0, [r2, 0x4] - ldr r0, =gBattleScripting - strb r4, [r0, 0x17] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DAB15 - str r0, [r1] - ldr r1, =gFightStateTracker - movs r0, 0xA - strb r0, [r1] - ldr r1, =gBattleResults - ldrb r0, [r1, 0x2] - cmp r0, 0xFE - bhi _0803E8CE - adds r0, 0x1 - strb r0, [r1, 0x2] -_0803E8CE: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end bs2_8016374 - - thumb_func_start sub_803E90C -sub_803E90C: @ 803E90C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - ldr r4, =gBankAttacker - ldr r2, =gBankTarget - ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentMoveTurn - ldrb r0, [r0] - adds r0, r1 - ldrb r0, [r0] - strb r0, [r2] - strb r0, [r4] - ldr r0, =gBattle_BG0_X - movs r1, 0 - strh r1, [r0] - ldr r0, =gBattle_BG0_Y - strh r1, [r0] - ldrb r0, [r4] - bl sub_8045868 - ldr r5, =gLastUsedItem - ldr r2, =gBattleBufferB - ldrb r1, [r4] - lsls r1, 9 - adds r0, r2, 0x1 - adds r0, r1, r0 - ldrb r3, [r0] - adds r2, 0x2 - adds r1, r2 - ldrb r0, [r1] - lsls r0, 8 - orrs r3, r0 - strh r3, [r5] - cmp r3, 0xC - bhi _0803E998 - ldr r2, =gBattlescriptCurrInstr - ldr r1, =gUnknown_082DBD08 - ldrh r0, [r5] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - str r0, [r2] - ldr r0, =gFightStateTracker - mov r10, r0 - b _0803EBF6 - .pool -_0803E998: - adds r0, r3, 0 - subs r0, 0x50 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x1 - bhi _0803E9C0 - ldr r0, =gBattlescriptCurrInstr - ldr r1, =gUnknown_082DBD54 - ldr r1, [r1] - str r1, [r0] - ldr r1, =gFightStateTracker - mov r10, r1 - b _0803EBF6 - .pool -_0803E9C0: - ldrb r0, [r4] - bl GetBankSide - lsls r0, 24 - cmp r0, 0 - bne _0803E9E8 - ldr r0, =gBattlescriptCurrInstr - ldr r1, =gUnknown_082DBD3C - ldr r1, [r1] - str r1, [r0] - ldr r2, =gFightStateTracker - mov r10, r2 - b _0803EBF6 - .pool -_0803E9E8: - ldr r3, =gBattleScripting - ldrb r0, [r4] - strb r0, [r3, 0x17] - lsls r0, 24 - lsrs r0, 25 - ldr r2, =gBattleStruct - ldr r1, [r2] - adds r0, r1 - adds r0, 0xC4 - ldrb r0, [r0] - subs r0, 0x1 - mov r8, r4 - ldr r1, =gBattlescriptCurrInstr - mov r9, r1 - ldr r6, =gUnknown_082DBD3C - mov r12, r3 - adds r7, r2, 0 - ldr r2, =gFightStateTracker - mov r10, r2 - cmp r0, 0x4 - bls _0803EA14 - b _0803EBDE -_0803EA14: - lsls r0, 2 - ldr r1, =_0803EA38 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0803EA38: - .4byte _0803EBDE - .4byte _0803EBDE - .4byte _0803EA4C - .4byte _0803EAE0 - .4byte _0803EBB0 -_0803EA4C: - ldr r5, =gBattleCommunication - movs r0, 0 - strb r0, [r5, 0x5] - ldr r2, =gBankAttacker - ldrb r0, [r2] - lsrs r0, 1 - ldr r1, [r7] - adds r0, r1 - adds r0, 0xC6 - ldrb r1, [r0] - movs r0, 0x1 - ands r0, r1 - mov r8, r2 - cmp r0, 0 - beq _0803EA98 - movs r0, 0x3E - ands r0, r1 - ldr r1, =gBattlescriptCurrInstr - mov r9, r1 - ldr r6, =gUnknown_082DBD3C - ldr r2, =gFightStateTracker - mov r10, r2 - cmp r0, 0 - bne _0803EA7E - b _0803EBDE -_0803EA7E: - movs r0, 0x5 - strb r0, [r5, 0x5] - b _0803EBDE - .pool -_0803EA98: - ldr r0, =gBattlescriptCurrInstr - mov r9, r0 - ldr r6, =gUnknown_082DBD3C - ldr r1, =gFightStateTracker - mov r10, r1 - mov r4, r8 - adds r3, r7, 0 - adds r2, r5, 0 -_0803EAA8: - ldrb r1, [r4] - lsrs r1, 1 - ldr r0, [r3] - adds r1, r0 - adds r1, 0xC6 - ldrb r0, [r1] - lsrs r0, 1 - strb r0, [r1] - ldrb r0, [r2, 0x5] - adds r0, 0x1 - strb r0, [r2, 0x5] - ldrb r0, [r4] - lsrs r0, 1 - ldr r1, [r3] - adds r0, r1 - adds r0, 0xC6 - ldrb r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _0803EAA8 - b _0803EBDE - .pool -_0803EAE0: - ldr r3, =gBattleCommunication - movs r0, 0x4 - strb r0, [r3, 0x5] - ldr r2, =gBankAttacker - ldrb r0, [r2] - lsrs r0, 1 - ldr r1, [r7] - adds r0, r1 - adds r6, r0, 0 - adds r6, 0xC6 - ldrb r1, [r6] - movs r0, 0x80 - ands r0, r1 - lsls r0, 24 - lsrs r5, r0, 24 - mov r8, r2 - cmp r5, 0 - beq _0803EB28 - movs r0, 0x5 - strb r0, [r3, 0x5] - ldr r2, =gBattlescriptCurrInstr - mov r9, r2 - ldr r6, =gUnknown_082DBD3C - ldr r0, =gFightStateTracker - mov r10, r0 - b _0803EBDE - .pool -_0803EB28: - ldr r3, =gBattleTextBuff1 - movs r4, 0xFD - strb r4, [r3] - movs r0, 0x5 - strb r0, [r3, 0x1] - movs r2, 0x1 - strb r2, [r3, 0x2] - movs r0, 0xFF - strb r0, [r3, 0x3] - ldr r1, =gBattleTextBuff2 - strb r4, [r1] - strb r5, [r1, 0x1] - movs r0, 0xD2 - strb r0, [r1, 0x2] - strb r5, [r1, 0x3] - subs r0, 0xD3 - strb r0, [r1, 0x4] - ldrb r0, [r6] - ands r2, r0 - ldr r1, =gBattlescriptCurrInstr - mov r9, r1 - ldr r6, =gUnknown_082DBD3C - ldr r0, =gFightStateTracker - mov r10, r0 - cmp r2, 0 - bne _0803EB8C - mov r5, r8 - adds r4, r7, 0 - adds r2, r3, 0 -_0803EB62: - ldrb r1, [r5] - lsrs r1, 1 - ldr r0, [r4] - adds r1, r0 - adds r1, 0xC6 - ldrb r0, [r1] - lsrs r0, 1 - strb r0, [r1] - ldrb r0, [r2, 0x2] - adds r0, 0x1 - strb r0, [r2, 0x2] - ldrb r0, [r5] - lsrs r0, 1 - ldr r1, [r4] - adds r0, r1 - adds r0, 0xC6 - ldrb r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _0803EB62 -_0803EB8C: - ldrb r0, [r3, 0x2] - adds r0, 0xE - movs r1, 0 - mov r2, r12 - strb r0, [r2, 0x10] - strb r1, [r2, 0x11] - b _0803EBDE - .pool -_0803EBB0: - ldr r0, =gBattleTypeFlags - ldr r1, [r0] - movs r0, 0x1 - ands r1, r0 - cmp r1, 0 - beq _0803EBCC - ldr r1, =gBattleCommunication - movs r0, 0x2 - strb r0, [r1, 0x5] - b _0803EBD0 - .pool -_0803EBCC: - ldr r0, =gBattleCommunication - strb r1, [r0, 0x5] -_0803EBD0: - ldr r0, =gBankAttacker - mov r8, r0 - ldr r1, =gBattlescriptCurrInstr - mov r9, r1 - ldr r6, =gUnknown_082DBD3C - ldr r2, =gFightStateTracker - mov r10, r2 -_0803EBDE: - mov r1, r8 - ldrb r0, [r1] - lsrs r0, 1 - ldr r1, [r7] - adds r0, r1 - adds r0, 0xC4 - ldrb r0, [r0] - lsls r0, 2 - adds r0, r6 - ldr r0, [r0] - mov r2, r9 - str r0, [r2] -_0803EBF6: - movs r0, 0xA - mov r1, r10 - strb r0, [r1] - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_803E90C - - thumb_func_start CanRunFromBattle -CanRunFromBattle: @ 803EC20 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - lsls r0, 24 - lsrs r5, r0, 24 - movs r7, 0 - ldr r1, =gBattleMons - movs r0, 0x58 - muls r0, r5 - adds r1, r0, r1 - ldrh r0, [r1, 0x2E] - cmp r0, 0xAF - bne _0803EC54 - ldr r1, =gEnigmaBerries - lsls r0, r5, 3 - subs r0, r5 - lsls r0, 2 - adds r0, r1 - ldrb r1, [r0, 0x7] - b _0803EC5E - .pool -_0803EC54: - ldrh r0, [r1, 0x2E] - bl ItemId_GetHoldEffect - lsls r0, 24 - lsrs r1, r0, 24 -_0803EC5E: - ldr r0, =gStringBank - strb r5, [r0] - cmp r1, 0x25 - bne _0803EC9C - ldr r2, =gLastUsedItem - ldr r1, =gBattleMons - movs r0, 0x58 - muls r0, r5 - adds r0, r1 - ldrh r0, [r0, 0x2E] - strh r0, [r2] - ldr r0, =gProtectStructs - lsls r2, r5, 4 - adds r2, r0 - ldrb r1, [r2, 0x1] - movs r0, 0x19 - negs r0, r0 - ands r0, r1 - movs r1, 0x8 - orrs r0, r1 - strb r0, [r2, 0x1] - b _0803ED70 - .pool -_0803EC9C: - ldr r0, =gBattleMons - mov r10, r0 - movs r2, 0x58 - mov r9, r2 - mov r0, r9 - muls r0, r5 - add r0, r10 - mov r8, r0 - adds r0, 0x20 - ldrb r6, [r0] - cmp r6, 0x32 - bne _0803ED5C - bl InBattlePyramid - lsls r0, 24 - cmp r0, 0 - beq _0803ED38 - ldr r4, =gBattleStruct - ldr r1, [r4] - adds r1, 0x6C - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - bl sub_81A9E28 - lsls r0, 24 - lsrs r1, r0, 24 - mov r2, r8 - ldrh r0, [r2, 0x6] - muls r0, r1 - movs r2, 0x1 - adds r1, r5, 0 - eors r1, r2 - mov r2, r9 - muls r2, r1 - adds r1, r2, 0 - add r1, r10 - ldrh r1, [r1, 0x6] - bl __divsi3 - ldr r1, [r4] - adds r1, 0x6C - ldrb r2, [r1] - lsls r1, r2, 4 - subs r1, r2 - lsls r1, 1 - adds r0, r1 - lsls r0, 24 - lsrs r4, r0, 24 - bl Random - movs r1, 0xFF - ands r1, r0 - cmp r4, r1 - bhi _0803ED0C - b _0803EE12 -_0803ED0C: - ldr r0, =gLastUsedAbility - strb r6, [r0] - ldr r0, =gProtectStructs - lsls r2, r5, 4 - adds r2, r0 - ldrb r1, [r2, 0x1] - movs r0, 0x19 - negs r0, r0 - ands r0, r1 - movs r1, 0x10 - orrs r0, r1 - strb r0, [r2, 0x1] - b _0803ED70 - .pool -_0803ED38: - ldr r0, =gLastUsedAbility - strb r6, [r0] - ldr r0, =gProtectStructs - lsls r2, r5, 4 - adds r2, r0 - ldrb r1, [r2, 0x1] - movs r0, 0x19 - negs r0, r0 - ands r0, r1 - movs r1, 0x10 - orrs r0, r1 - strb r0, [r2, 0x1] - b _0803ED70 - .pool -_0803ED5C: - ldr r1, =gBattleTypeFlags - ldr r2, [r1] - ldr r0, =0x043f0100 - ands r0, r2 - cmp r0, 0 - beq _0803ED80 - movs r0, 0x8 - ands r2, r0 - cmp r2, 0 - beq _0803ED80 -_0803ED70: - adds r0, r7, 0x1 - lsls r0, 24 - lsrs r7, r0, 24 - b _0803EE12 - .pool -_0803ED80: - ldr r0, [r1] - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - bne _0803EE06 - bl InBattlePyramid - lsls r0, 24 - cmp r0, 0 - beq _0803EDBC - bl sub_81A9E28 - lsls r0, 24 - lsrs r1, r0, 24 - ldr r4, =gBattleMons - movs r3, 0x58 - adds r0, r5, 0 - muls r0, r3 - adds r0, r4 - ldrh r0, [r0, 0x6] - muls r0, r1 - movs r2, 0x1 - adds r1, r5, 0 - eors r1, r2 - muls r1, r3 - adds r1, r4 - b _0803EDDA - .pool -_0803EDBC: - ldr r3, =gBattleMons - movs r2, 0x58 - adds r0, r5, 0 - muls r0, r2 - adds r4, r0, r3 - movs r1, 0x1 - adds r0, r5, 0 - eors r0, r1 - muls r0, r2 - adds r1, r0, r3 - ldrh r0, [r4, 0x6] - ldrh r2, [r1, 0x6] - cmp r0, r2 - bcs _0803EE00 - lsls r0, 7 -_0803EDDA: - ldrh r1, [r1, 0x6] - bl __divsi3 - ldr r1, =gBattleStruct - ldr r1, [r1] - adds r1, 0x6C - ldrb r2, [r1] - lsls r1, r2, 4 - subs r1, r2 - lsls r1, 1 - adds r0, r1 - lsls r0, 24 - lsrs r4, r0, 24 - bl Random - movs r1, 0xFF - ands r1, r0 - cmp r4, r1 - bls _0803EE06 -_0803EE00: - adds r0, r7, 0x1 - lsls r0, 24 - lsrs r7, r0, 24 -_0803EE06: - ldr r0, =gBattleStruct - ldr r1, [r0] - adds r1, 0x6C - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] -_0803EE12: - cmp r7, 0 - beq _0803EE24 - ldr r1, =gCurrentMoveTurn - ldr r0, =gNoOfAllBanks - ldrb r0, [r0] - strb r0, [r1] - ldr r1, =gBattleOutcome - movs r0, 0x4 - strb r0, [r1] -_0803EE24: - adds r0, r7, 0 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end CanRunFromBattle - thumb_func_start sub_803EE48 sub_803EE48: @ 803EE48 push {r4-r6,lr} ldr r4, =gBankAttacker ldr r1, =gBanksByTurnOrder - ldr r5, =gCurrentMoveTurn + ldr r5, =gCurrentTurnActionNumber ldrb r0, [r5] adds r0, r1 ldrb r0, [r0] @@ -2671,19 +92,19 @@ _0803EF0C: cmp r0, 0 bne _0803EF4C ldrb r0, [r4] - bl CanRunFromBattle + bl TryRunFromBattle lsls r0, 24 cmp r0, 0 bne _0803EF98 ldrb r0, [r4] - bl sub_8045868 + bl ClearFuryCutterDestinyBondGrudge ldr r1, =gBattleCommunication movs r0, 0x3 strb r0, [r1, 0x5] ldr r1, =gBattlescriptCurrInstr ldr r0, =gUnknown_082DAB02 str r0, [r1] - ldr r1, =gFightStateTracker + ldr r1, =gCurrentActionFuncId movs r0, 0xA b _0803EF96 .pool @@ -2705,7 +126,7 @@ _0803EF4C: ldr r1, =gBattlescriptCurrInstr ldr r0, =gUnknown_082DAB02 str r0, [r1] - ldr r1, =gFightStateTracker + ldr r1, =gCurrentActionFuncId movs r0, 0xA b _0803EF96 .pool @@ -2728,7 +149,7 @@ _0803EF98: sub_803EFA8: @ 803EFA8 ldr r2, =gBankAttacker ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentMoveTurn + ldr r0, =gCurrentTurnActionNumber ldrb r0, [r0] adds r0, r1 ldrb r0, [r0] @@ -2742,7 +163,7 @@ sub_803EFA8: @ 803EFA8 ldr r0, =gUnknown_082DBD58 ldr r0, [r0] str r0, [r1] - ldr r1, =gFightStateTracker + ldr r1, =gCurrentActionFuncId movs r0, 0xA strb r0, [r1] bx lr @@ -2753,7 +174,7 @@ sub_803EFA8: @ 803EFA8 bs5_8016AC0: @ 803EFF0 ldr r2, =gBankAttacker ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentMoveTurn + ldr r0, =gCurrentTurnActionNumber ldrb r0, [r0] adds r0, r1 ldrb r0, [r0] @@ -2771,10 +192,10 @@ bs5_8016AC0: @ 803EFF0 movs r0, 0x5 strh r0, [r1] ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DBD08 + ldr r0, =gBattlescriptsForBallThrow ldr r0, [r0, 0x14] str r0, [r1] - ldr r1, =gFightStateTracker + ldr r1, =gCurrentActionFuncId movs r0, 0xA strb r0, [r1] bx lr @@ -2786,7 +207,7 @@ sub_803F050: @ 803F050 push {r4-r6,lr} ldr r3, =gBankAttacker ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentMoveTurn + ldr r0, =gCurrentTurnActionNumber ldrb r0, [r0] adds r0, r1 ldrb r0, [r0] @@ -2859,7 +280,7 @@ _0803F100: ldr r0, =gUnknown_082DBD58 ldr r0, [r0, 0x8] str r0, [r1] - ldr r1, =gFightStateTracker + ldr r1, =gCurrentActionFuncId movs r0, 0xA strb r0, [r1] pop {r4-r6} @@ -2873,7 +294,7 @@ sub_803F120: @ 803F120 push {r4,lr} ldr r2, =gBankAttacker ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentMoveTurn + ldr r0, =gCurrentTurnActionNumber ldrb r0, [r0] adds r0, r1 ldrb r0, [r0] @@ -2945,7 +366,7 @@ _0803F1CA: ldr r0, =gUnknown_082DBD58 ldr r0, [r0, 0x4] str r0, [r1] - ldr r1, =gFightStateTracker + ldr r1, =gCurrentActionFuncId movs r0, 0xA strb r0, [r1] pop {r4} @@ -2959,7 +380,7 @@ bs8_exit_by_flight: @ 803F1F0 push {r4,lr} ldr r2, =gBankAttacker ldr r1, =gBanksByTurnOrder - ldr r4, =gCurrentMoveTurn + ldr r4, =gCurrentTurnActionNumber ldrb r0, [r4] adds r0, r1 ldrb r0, [r0] @@ -2982,7 +403,7 @@ bs8_exit_by_flight: @ 803F1F0 bs9_8016C9C: @ 803F22C ldr r3, =gBankAttacker ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentMoveTurn + ldr r0, =gCurrentTurnActionNumber ldrb r0, [r0] adds r0, r1 ldrb r2, [r0] @@ -3010,7 +431,7 @@ bs9_8016C9C: @ 803F22C ldr r0, =gUnknown_082DBD58 ldr r0, [r0, 0xC] str r0, [r1] - ldr r1, =gFightStateTracker + ldr r1, =gCurrentActionFuncId movs r0, 0xA strb r0, [r1] ldr r1, =gActionsByTurnOrder @@ -3032,7 +453,7 @@ bsB_exit_by_move: @ 803F2A4 ldr r0, [r0] adds r0, 0x4D strb r1, [r0] - ldr r1, =gFightStateTracker + ldr r1, =gCurrentActionFuncId movs r0, 0xC strb r0, [r1] _0803F2C0: @@ -3043,11 +464,11 @@ _0803F2C0: thumb_func_start bsD_proceed bsD_proceed: @ 803F2CC - ldr r1, =gCurrentMoveTurn + ldr r1, =gCurrentTurnActionNumber ldrb r0, [r1] adds r0, 0x1 strb r0, [r1] - ldr r3, =gFightStateTracker + ldr r3, =gCurrentActionFuncId ldr r2, =gActionsByTurnOrder ldrb r0, [r1] adds r0, r2 @@ -3066,7 +487,7 @@ bsD_proceed: @ 803F2CC bsC_8016D70: @ 803F300 push {r4-r6,lr} ldr r1, =gBanksByTurnOrder - ldr r2, =gCurrentMoveTurn + ldr r2, =gCurrentTurnActionNumber ldrb r0, [r2] adds r0, r1 ldrb r0, [r0] @@ -3079,7 +500,7 @@ bsC_8016D70: @ 803F300 ldrb r0, [r2] adds r0, 0x1 strb r0, [r2] - ldr r3, =gFightStateTracker + ldr r3, =gCurrentActionFuncId ldr r1, =gActionsByTurnOrder ldrb r0, [r2] adds r0, r1 diff --git a/asm/evolution_scene.s b/asm/evolution_scene.s index 8894037877..e5e9aaab9e 100644 --- a/asm/evolution_scene.s +++ b/asm/evolution_scene.s @@ -68,7 +68,7 @@ _0813DA00: adds r1, r4, 0 adds r2, r5, 0 adds r3, r6, 0 - bl evolution_cutscene + bl EvolutionScene _0813DA30: add sp, 0x4 pop {r4-r7} @@ -77,8 +77,8 @@ _0813DA30: .pool thumb_func_end sub_813D9C0 - thumb_func_start sub_813DA40 -sub_813DA40: @ 813DA40 + thumb_func_start BeginEvolutionScene +BeginEvolutionScene: @ 813DA40 push {r4-r6,lr} adds r4, r1, 0 adds r5, r2, 0 @@ -110,10 +110,10 @@ sub_813DA40: @ 813DA40 pop {r0} bx r0 .pool - thumb_func_end sub_813DA40 + thumb_func_end BeginEvolutionScene - thumb_func_start evolution_cutscene -evolution_cutscene: @ 813DA8C + thumb_func_start EvolutionScene +EvolutionScene: @ 813DA8C push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -393,7 +393,7 @@ evolution_cutscene: @ 813DA8C pop {r0} bx r0 .pool - thumb_func_end evolution_cutscene + thumb_func_end EvolutionScene thumb_func_start sub_813DD7C sub_813DD7C: @ 813DD7C diff --git a/asm/party_menu.s b/asm/party_menu.s index 4eb080b136..a881d45890 100755 --- a/asm/party_menu.s +++ b/asm/party_menu.s @@ -13868,7 +13868,7 @@ sub_81B7810: @ 81B7810 adds r0, r7, 0 adds r1, r4, 0 movs r2, 0x1 - bl sub_813DA40 + bl BeginEvolutionScene adds r0, r5, 0 bl DestroyTask b _081B786E diff --git a/asm/pokemon_item_effect.s b/asm/pokemon_item_effect.s index 5dc6452e9c..49b2059671 100644 --- a/asm/pokemon_item_effect.s +++ b/asm/pokemon_item_effect.s @@ -221,7 +221,7 @@ _0806BEE0: mov r0, r8 movs r2, 0 ldr r3, [sp, 0x10] - bl sub_813DA40 + bl BeginEvolutionScene movs r0, 0 bl _0806CD5C _0806BEF0: diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 0b797feef6..faa945bddb 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -45,34 +45,34 @@ gUnknown_082DA7C4:: @ 82DA7C4 gUnknown_082DA7CD:: @ 82DA7CD .incbin "baserom.gba", 0x2da7cd, 0x160 -gUnknown_082DA92D:: @ 82DA92D +BattleScript_LocalTrainerBattleWon:: @ 82DA92D .incbin "baserom.gba", 0x2da92d, 0x3d -gUnknown_082DA96A:: @ 82DA96A +BattleScript_PayDayMoneyAndPickUpItems:: @ 82DA96A .incbin "baserom.gba", 0x2da96a, 0x3 -gUnknown_082DA96D:: @ 82DA96D +BattleScript_LocalBattleLost:: @ 82DA96D .incbin "baserom.gba", 0x2da96d, 0x9e gUnknown_082DAA0B:: @ 82DAA0B .incbin "baserom.gba", 0x2daa0b, 0x2a -gUnknown_082DAA35:: @ 82DAA35 +BattleScript_LinkBattleWonOrLost:: @ 82DAA35 .incbin "baserom.gba", 0x2daa35, 0x52 -gUnknown_082DAA87:: @ 82DAA87 +BattleScript_FrontierTrainerBattleWon:: @ 82DAA87 .incbin "baserom.gba", 0x2daa87, 0x54 -gUnknown_082DAADB:: @ 82DAADB +BattleScript_SmokeBallEscape:: @ 82DAADB .incbin "baserom.gba", 0x2daadb, 0xe -gUnknown_082DAAE9:: @ 82DAAE9 +BattleScript_RanAwayUsingMonAbility:: @ 82DAAE9 .incbin "baserom.gba", 0x2daae9, 0x7 -gUnknown_082DAAF0:: @ 82DAAF0 +BattleScript_GotAwaySafely:: @ 82DAAF0 .incbin "baserom.gba", 0x2daaf0, 0x7 -gUnknown_082DAAF7:: @ 82DAAF7 +BattleScript_WildMonFled:: @ 82DAAF7 .incbin "baserom.gba", 0x2daaf7, 0x7 gUnknown_082DAAFE:: @ 82DAAFE @@ -87,7 +87,7 @@ gUnknown_082DAB0B:: @ 82DAB0B gUnknown_082DAB11:: @ 82DAB11 .incbin "baserom.gba", 0x2dab11, 0x4 -gUnknown_082DAB15:: @ 82DAB15 +BattleScript_ActionSwitch:: @ 82DAB15 .incbin "baserom.gba", 0x2dab15, 0xa4 BattleScript_Pausex20:: @ 82DABB9 @@ -255,7 +255,7 @@ BattleScript_OneHitKOMsg:: @ 82DB1CE BattleScript_SAtkDown2:: @ 82DB1D5 .incbin "baserom.gba", 0x2db1d5, 0x2a -gUnknown_082DB1FF:: @ 82DB1FF +BattleScript_FocusPunchSetUp:: @ 82DB1FF .incbin "baserom.gba", 0x2db1ff, 0x14 BattleScript_MoveUsedIsAsleep:: @ 82DB213 diff --git a/data/battle_scripts_2.s b/data/battle_scripts_2.s index adabccb88c..985c09b23c 100644 --- a/data/battle_scripts_2.s +++ b/data/battle_scripts_2.s @@ -4,7 +4,7 @@ .section script_data, "aw", %progbits .align 2 -gUnknown_082DBD08:: @ 82DBD08 +gBattlescriptsForBallThrow:: @ 82DBD08 .4byte gUnknown_082DBD68 .4byte gUnknown_082DBD68 .4byte gUnknown_082DBD68 @@ -29,8 +29,8 @@ gUnknown_082DBD3C:: @ 82DBD3C .4byte gUnknown_082DBE91 .align 2 -gUnknown_082DBD54:: @ 82DBD54 - .4byte gUnknown_082DBEB3 +gBattlescriptsForRunningByItem:: @ 82DBD54 + .4byte BattleScript_RunByUsingItem .align 2 gUnknown_082DBD58:: @ 82DBD58 @@ -72,7 +72,7 @@ gUnknown_082DBE6F:: @ 82DBE6F gUnknown_082DBE91:: @ 82DBE91 .incbin "baserom.gba", 0x2dbe91, 0x22 -gUnknown_082DBEB3:: @ 82DBEB3 +BattleScript_RunByUsingItem:: @ 82DBEB3 .incbin "baserom.gba", 0x2dbeb3, 0xA gUnknown_082DBEBD:: @ 82DBEBD diff --git a/data/data2b.s b/data/data2b.s index 96d56c820c..717b70d4dc 100644 --- a/data/data2b.s +++ b/data/data2b.s @@ -226,10 +226,10 @@ gTrainerMoneyTable:: @ 831AEB8 @ 831BAD4 .include "data/text/ability_description_pointers.inc" -gUnknown_0831BC0C:: @ 831BC0C +gTurnActionsFuncsTable:: @ 831BC0C .incbin "baserom.gba", 0x31bc0c, 0x38 -gUnknown_0831BC44:: @ 831BC44 +gEndTurnFuncsTable:: @ 831BC44 .incbin "baserom.gba", 0x31bc44, 0x2c gStatusConditionString_PoisonJpn:: @ 831BC70 diff --git a/include/battle.h b/include/battle.h index 7c8d89e57b..639558e60b 100644 --- a/include/battle.h +++ b/include/battle.h @@ -56,6 +56,7 @@ #define BATTLE_TYPE_RAYQUAZA 0x40000000 #define BATTLE_TYPE_x80000000 0x80000000 +#define TRAINER_OPPONENT_3FE 0x3FE #define TRAINER_OPPONENT_C00 0xC00 #define TRAINER_OPPONENT_800 0x800 #define STEVEN_PARTNER_ID 0xC03 @@ -71,8 +72,11 @@ #define BATTLE_PLAYER_TELEPORTED 0x5 #define BATTLE_POKE_FLED 0x6 #define BATTLE_CAUGHT 0x7 +#define BATTLE_FORFEITED 0x9 #define BATTLE_OPPONENT_TELEPORTED 0xA +#define BATTLE_OUTCOME_BIT_x80 0x80 + #define STATUS_SLEEP 0x7 #define STATUS_POISON 0x8 #define STATUS_BURN 0x10 @@ -171,8 +175,10 @@ #define ACTION_GO_NEAR 7 #define ACTION_SAFARI_ZONE_RUN 8 #define ACTION_9 9 -#define ACTION_CANCEL_PARTNER 12 -#define ACTION_NOTHING_FAINTED 13 +#define ACTION_RUN_BATTLESCRIPT 10 // when executing an action +#define ACTION_CANCEL_PARTNER 12 // when choosing an action +#define ACTION_FINISHED 12 // when executing an action +#define ACTION_NOTHING_FAINTED 13 // when choosing an action #define ACTION_INIT_VALUE 0xFF #define ABILITYEFFECT_ON_SWITCHIN 0x0 @@ -559,22 +565,19 @@ struct BattleResults u8 playerSwitchesCounter; // 0x2 u8 unk3; // 0x3 u8 unk4; // 0x4 - u8 unk5_0:1; // 0x5 - u8 unk5_1:1; // 0x5 - u8 caughtMonBall:4; // 0x5 - u8 unk5_6:1; // 0x5 - u8 unk5_7:1; // 0x5 - u16 poke1Species; // 0x6 - u8 pokeString1[10]; // 0x8 - u8 unk12; + u8 unk5_0:1; // 0x5 , 0x1 + u8 unk5_1:1; // 0x5 , 0x2 + u8 caughtMonBall:4; // 0x5 , 0x4/0x8/0x10/0x20 + u8 unk5_6:1; // 0x5 , 0x40 + u8 unk5_7:1; // 0x5 , 0x80 + u16 playerMon1Species; // 0x6 + u8 playerMon1Name[11]; // 0x8 u8 battleTurnCounter; // 0x13 - u8 pokeString2[10]; // 0x14 - u8 field_1E; // 0x1E - u8 field_1F; // 0x1F + u8 playerMon2Name[11]; // 0x14 u16 lastOpponentSpecies; // 0x20 - u16 lastUsedMove; // 0x22 - u16 opponentMove; // 0x24 - u16 opponentSpecies; // 0x26 + u16 lastUsedMovePlayer; // 0x22 + u16 lastUsedMoveOpponent; // 0x24 + u16 playerMon2Species; // 0x26 u16 caughtMonSpecies; // 0x28 u8 caughtMonNick[10]; // 0x2A u8 filler34[2]; @@ -605,7 +608,7 @@ struct BattleStruct u8 field_45; u8 field_46; u8 field_47; - u8 field_48; + u8 focusPunchBank; u8 field_49; u8 moneyMultiplier; u8 field_4B; @@ -620,7 +623,7 @@ struct BattleStruct u8 field_58[4]; u8 field_5C[4]; u8 field_60[4][3]; - u8 field_6C; + u8 runTries; u8 caughtMonNick[11]; u8 field_78; u8 field_79; @@ -630,7 +633,7 @@ struct BattleStruct u8 field_7D; u8 field_7E; u8 formToChangeInto; - u8 chosenMovesIds[BATTLE_BANKS_COUNT]; + u8 chosenMovePositions[BATTLE_BANKS_COUNT]; u8 stateIdAfterSelScript[BATTLE_BANKS_COUNT]; u8 field_88; u8 field_89; @@ -665,7 +668,9 @@ struct BattleStruct u8 field_B3; void (*savedCallback)(void); u16 usedHeldItems[BATTLE_BANKS_COUNT]; - u8 field_C0[8]; + u8 field_C0[4]; + u8 field_C4[2]; + u8 field_C6[2]; u16 choicedMove[BATTLE_BANKS_COUNT]; u16 changedItems[BATTLE_BANKS_COUNT]; u8 intimidateBank; @@ -818,6 +823,7 @@ extern struct BattleStruct* gBattleStruct; #define VARIOUS_CANCEL_MULTI_TURN_MOVES 0 #define VARIOUS_SET_MAGIC_COAT_TARGET 1 +#define VARIOUS_CAN_RUN_FROM_BATTLE 2 #define VARIOUS_GET_MOVE_TARGET 3 #define VARIOUS_RESET_INTIMIDATE_TRACE_BITS 5 #define VARIOUS_UPDATE_CHOICE_MOVE_ON_LVL_UP 6 @@ -901,13 +907,15 @@ void sub_803FA70(u8 bank); void BattleMainCB2(void); void VBlankCB_Battle(void); void ResetSentPokesToOpponentValue(void); -bool8 CanRunFromBattle(u8 bank); +bool8 TryRunFromBattle(u8 bank); bool8 IsRunningFromBattleImpossible(void); void PressurePPLoseOnUsingPerishSong(u8 bankAtk); void PressurePPLoseOnUsingImprision(u8 bankAtk); u8 GetWhoStrikesFirst(u8 bank1, u8 bank2, bool8 ignoreChosenMoves); void SwapTurnOrder(u8, u8); void BattleTurnPassed(void); +void RunBattleScriptCommands_PopCallbacksStack(void); +void RunBattleScriptCommands(void); // battle_3 #define MOVE_LIMITATION_ZEROMOVE (1 << 0) @@ -928,7 +936,7 @@ u8 UpdateTurnCounters(void); u8 TurnBasedEffects(void); bool8 sub_8041364(void); bool8 sub_8041728(void); -void b_clear_atk_up_if_hit_flag_unless_enraged(void); +void TryClearRageStatuses(void); u8 AtkCanceller_UnableToUseMove(void); bool8 sub_80423F4(u8 bank, u8 r1, u8 r2); u8 CastformDataTypeChange(u8 bank); @@ -936,7 +944,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 bank, u8 ability, u8 special, u16 moveArg) void BattleScriptExecute(const u8* BS_ptr); void BattleScriptPushCursorAndCallback(const u8* BS_ptr); u8 ItemBattleEffects(u8 caseID, u8 bank, bool8 moveTurn); -void sub_8045868(u8 bank); +void ClearFuryCutterDestinyBondGrudge(u8 bank); void sub_80458B4(void); u8 GetMoveTarget(u16 move, u8 useMoveTarget); u8 IsPokeDisobedient(void); diff --git a/include/evolution_scene.h b/include/evolution_scene.h new file mode 100644 index 0000000000..48bd6ebe1d --- /dev/null +++ b/include/evolution_scene.h @@ -0,0 +1,10 @@ +#ifndef GUARD_EVOLUTION_SCENE_H +#define GUARD_EVOLUTION_SCENE_H + +void EvolutionScene(struct Pokemon* mon, u16 speciesToEvolve, bool8 canStopEvo, u8 partyID); +void BeginEvolutionScene(struct Pokemon* mon, u16 speciesToEvolve, bool8 canStopEvo, u8 partyID); +void TradeEvolutionScene(struct Pokemon* mon, u16 speciesToEvolve, u8 preEvoSpriteID, u8 partyID); + +extern void (*gCB2_AfterEvolution)(void); + +#endif // GUARD_EVOLUTION_SCENE_H diff --git a/include/pokemon.h b/include/pokemon.h index 5d97c16665..c41099b095 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -634,6 +634,12 @@ bool16 sub_806D82C(u8 id); u16 MonTryLearningNewMove(struct Pokemon* mon, bool8); void sub_8068AA4(void); // sets stats for deoxys bool8 HasTwoFramesAnimation(u16 species); +u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem); +void RandomlyGivePartyPokerus(struct Pokemon *party); +u8 CheckPartyPokerus(struct Pokemon *party, u8 selection); +u8 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection); +void UpdatePartyPokerusTime(u16 days); +void PartySpreadPokerus(struct Pokemon *party); #include "sprite.h" diff --git a/include/recorded_battle.h b/include/recorded_battle.h index 2df1620e40..65ad998e6a 100644 --- a/include/recorded_battle.h +++ b/include/recorded_battle.h @@ -14,5 +14,6 @@ u8 sub_8185FB8(void); u8 MoveRecordedBattleToSaveData(void); void sub_818603C(u8); void sub_8185FD0(void); +void sub_8186444(void); #endif // GUARD_RECORDED_BATTLE_H diff --git a/include/songs.h b/include/songs.h index d828e40688..5a1fff00cb 100644 --- a/include/songs.h +++ b/include/songs.h @@ -252,23 +252,23 @@ enum SE_W114, SE_W063B, BGM_STOP = 349, - BGM_TETSUJI, - BGM_FIELD13, - BGM_KACHI22, - BGM_KACHI2, - BGM_KACHI3, - BGM_KACHI5, - BGM_PCC, - BGM_NIBI, - BGM_SUIKUN, - BGM_DOORO1, - BGM_DOORO_X1, - BGM_DOORO_X3, - BGM_MACHI_S2, - BGM_MACHI_S4, - BGM_GIM, - BGM_NAMINORI, - BGM_DAN01, + /*0x15E*/ BGM_TETSUJI, + /*0x15F*/ BGM_FIELD13, + /*0x160*/ BGM_KACHI22, + /*0x161*/ BGM_KACHI2, + /*0x162*/ BGM_KACHI3, + /*0x163*/ BGM_KACHI5, + /*0x164*/ BGM_PCC, + /*0x165*/ BGM_NIBI, + /*0x166*/ BGM_SUIKUN, + /*0x167*/ BGM_DOORO1, + /*0x168*/ BGM_DOORO_X1, + /*0x169*/ BGM_DOORO_X3, + /*0x16A*/ BGM_MACHI_S2, + /*0x16B*/ BGM_MACHI_S4, + /*0x16C*/ BGM_GIM, + /*0x16D*/ BGM_NAMINORI, + /*0x16E*/ BGM_DAN01, /*0x16F*/ BGM_FANFA1, /*0x170*/ BGM_ME_ASA, /*0x171*/ BGM_ME_BACHI, @@ -306,31 +306,31 @@ enum /*0x191*/ BGM_NEXTROAD, /*0x192*/ BGM_GRANROAD, /*0x193*/ BGM_CYCLING, - BGM_FRIENDLY, - BGM_MISHIRO, - BGM_TOZAN, - BGM_GIRLEYE, - BGM_MINAMO, - BGM_ASHROAD, - BGM_EVENT0, - BGM_DEEPDEEP, - BGM_KACHI1, - BGM_TITLE3, - BGM_DEMO1, - BGM_GIRL_SUP, - BGM_HAGESHII, - BGM_KAKKOII, - BGM_KAZANBAI, - BGM_AQA_0, - BGM_TSURETEK, - BGM_BOY_SUP, - BGM_RAINBOW, - BGM_AYASII, - BGM_KACHI4, - BGM_ROPEWAY, - BGM_CASINO, - BGM_HIGHTOWN, - BGM_SAFARI, + /*0x194*/ BGM_FRIENDLY, + /*0x195*/ BGM_MISHIRO, + /*0x196*/ BGM_TOZAN, + /*0x197*/ BGM_GIRLEYE, + /*0x198*/ BGM_MINAMO, + /*0x199*/ BGM_ASHROAD, + /*0x19A*/ BGM_EVENT0, + /*0x19B*/ BGM_DEEPDEEP, + /*0x19C*/ BGM_KACHI1, + /*0x19D*/ BGM_TITLE3, + /*0x19E*/ BGM_DEMO1, + /*0x19F*/ BGM_GIRL_SUP, + /*0x1A0*/ BGM_HAGESHII, + /*0x1A1*/ BGM_KAKKOII, + /*0x1A2*/ BGM_KAZANBAI, + /*0x1A3*/ BGM_AQA_0, + /*0x1A4*/ BGM_TSURETEK, + /*0x1A5*/ BGM_BOY_SUP, + /*0x1A6*/ BGM_RAINBOW, + /*0x1A7*/ BGM_AYASII, + /*0x1A8*/ BGM_KACHI4, + /*0x1A9*/ BGM_ROPEWAY, + /*0x1AA*/ BGM_CASINO, + /*0x1AB*/ BGM_HIGHTOWN, + /*0x1AC*/ BGM_SAFARI, BGM_C_ROAD, BGM_AJITO, BGM_M_BOAT, diff --git a/src/battle_2.c b/src/battle_2.c index 04907d0c0c..ab1aae7477 100644 --- a/src/battle_2.c +++ b/src/battle_2.c @@ -37,6 +37,9 @@ #include "pokedex.h" #include "abilities.h" #include "moves.h" +#include "trainer_classes.h" +#include "evolution_scene.h" +#include "roamer.h" struct UnknownStruct6 { @@ -80,6 +83,7 @@ extern u16 gTrainerBattleOpponent_B; extern struct BattleEnigmaBerry gEnigmaBerries[BATTLE_BANKS_COUNT]; extern void (*gPreBattleCallback1)(void); extern void (*gBattleMainFunc)(void); +extern void (*gUnknown_030061E8)(void); extern struct UnknownPokemonStruct2 gUnknown_02022FF8[3]; // what is it used for? extern struct UnknownPokemonStruct2* gUnknown_02023058; // what is it used for? extern u8 gBattleOutcome; @@ -131,13 +135,20 @@ extern struct BattlePokemon gBattleMons[BATTLE_BANKS_COUNT]; extern u8 gBanksByTurnOrder[BATTLE_BANKS_COUNT]; extern u8 gActionForBanks[BATTLE_BANKS_COUNT]; extern u16 gChosenMovesByBanks[BATTLE_BANKS_COUNT]; -extern u8 gFightStateTracker; +extern u8 gCurrentActionFuncId; extern u8 gLastUsedAbility; extern u16 gLastUsedItem; extern u8 gUnknown_0203CF00[]; extern const u8* gBattlescriptPtrsForSelection[BATTLE_BANKS_COUNT]; extern const u8* gBattlescriptCurrInstr; extern u32 gBattlePalaceMoveSelectionRngValue; +extern u8 gActionsByTurnOrder[BATTLE_BANKS_COUNT]; +extern u8 gCurrentTurnActionNumber; +extern u16 gDynamicBasePower; +extern u8 gCritMultiplier; +extern u8 gCurrMovePos; +extern u8 gUnknown_020241E9; +extern u16 gLastUsedMove; extern const u8 gSpeciesNames[][POKEMON_NAME_LENGTH + 1]; extern const struct BattleMove gBattleMoves[]; @@ -145,6 +156,7 @@ extern const u16 gUnknown_08C004E0[]; // battle textbox palette extern const struct BgTemplate gUnknown_0831AA08[]; extern const struct WindowTemplate * const gUnknown_0831ABA0[]; extern const u8 gUnknown_0831ACE0[]; +extern const u8 gStatStageRatios[][2]; // strings extern const u8 gText_LinkStandby3[]; @@ -163,7 +175,23 @@ extern const u8 gUnknown_082DAB11[]; extern const u8 gUnknown_082DB9BA[]; extern const u8 gUnknown_082DAAFE[]; extern const u8 gUnknown_082DAB0B[]; +extern const u8 BattleScript_FocusPunchSetUp[]; +extern const u8 BattleScript_LinkBattleWonOrLost[]; +extern const u8 BattleScript_FrontierTrainerBattleWon[]; +extern const u8 BattleScript_LocalTrainerBattleWon[]; +extern const u8 BattleScript_PayDayMoneyAndPickUpItems[]; +extern const u8 BattleScript_LocalBattleLost[]; +extern const u8 gUnknown_082DB9C8[]; +extern const u8 gUnknown_082DAA0B[]; +extern const u8 gUnknown_082DB9C1[]; +extern const u8 BattleScript_RanAwayUsingMonAbility[]; +extern const u8 BattleScript_SmokeBallEscape[]; +extern const u8 BattleScript_GotAwaySafely[]; +extern const u8 BattleScript_WildMonFled[]; +extern const u8 BattleScript_MoveUsedLoafingAround[]; +extern const u8 BattleScript_ActionSwitch[]; +// functions extern void HandleLinkBattleSetup(void); // rom_3 extern void SetUpBattleVarsAndBirchZigzagoon(void); // rom_3 extern void sub_8032768(void); // rom_3 @@ -179,8 +207,13 @@ extern void sub_80B3AF8(u8 taskId); // cable club extern void sub_8076918(u8 bank); extern void sub_80729D0(u8 healthoxSpriteId); extern void sub_81A56B4(void); // battle frontier 2 +extern u8 sub_81A9E28(void); // battle frontier 2 +extern void sub_81A56E8(u8 bank); // battle frontier 2 extern void sub_81B8FB0(u8, u8); // party menu extern u8 pokemon_order_func(u8); // party menu +extern void sub_80EC728(void); // tv +extern void sub_80EE184(void); // tv +extern bool8 InBattlePyramid(void); // this file's functions static void CB2_InitBattleInternal(void); @@ -209,7 +242,7 @@ void sub_8039E9C(struct Sprite *sprite); void SpriteCallbackDummy_3(struct Sprite *sprite); void oac_poke_ally_(struct Sprite *sprite); void SpecialStatusesClear(void); -void TurnValuesCleanUp(u8); +void TurnValuesCleanUp(bool8 var0); static void SpriteCB_HealthBoxBounce(struct Sprite *sprite); static void BattleStartClearSetData(void); static void BattleIntroGetMonsData(void); @@ -226,11 +259,16 @@ static void BattleIntroRecordMonsToDex(void); static void BattleIntroPlayer1SendsOutMonAnimation(void); static void TryDoEventsBeforeFirstTurn(void); void HandleTurnActionSelectionState(void); -void bc_bs_exec(void); +static void RunTurnActionsFunctions(void); static void SetActionsAndBanksTurnOrder(void); void sub_803CDF8(void); bool8 sub_803CDB8(void); -void bc_80154A0(void); +static void CheckFocusPunch_ClearVarsBeforeTurnStarts(void); +void HandleEndTurn_FinishBattle(void); +static void FreeResetData_ReturnToOvOrDoEvolutions(void); +static void ReturnFromBattleToOverworld(void); +static void TryEvolvePokemon(void); +static void WaitForEvoSceneToFinish(void); void CB2_InitBattle(void) { @@ -2645,7 +2683,7 @@ static void BattleStartClearSetData(void) u32 j; u8 *dataPtr; - TurnValuesCleanUp(0); + TurnValuesCleanUp(FALSE); SpecialStatusesClear(); for (i = 0; i < BATTLE_BANKS_COUNT; i++) @@ -2715,7 +2753,7 @@ static void BattleStartClearSetData(void) gBattleScripting.animTargetsHit = 0; gLeveledUpInBattle = 0; gAbsentBankFlags = 0; - gBattleStruct->field_6C = 0; + gBattleStruct->runTries = 0; gBattleStruct->field_79 = 0; gBattleStruct->field_7A = 0; *(&gBattleStruct->field_7C) = gBaseStats[GetMonData(&gEnemyParty[0], MON_DATA_SPECIES)].catchRate * 100 / 1275; @@ -3568,7 +3606,7 @@ static void TryDoEventsBeforeFirstTurn(void) gActionForBanks[i] = ACTION_INIT_VALUE; gChosenMovesByBanks[i] = MOVE_NONE; } - TurnValuesCleanUp(0); + TurnValuesCleanUp(FALSE); SpecialStatusesClear(); *(&gBattleStruct->field_91) = gAbsentBankFlags; sub_814F9EC(gText_EmptyString3, 0); @@ -3627,7 +3665,7 @@ void BattleTurnPassed(void) { s32 i; - TurnValuesCleanUp(1); + TurnValuesCleanUp(TRUE); if (gBattleOutcome == 0) { if (UpdateTurnCounters() != 0) @@ -3641,7 +3679,7 @@ void BattleTurnPassed(void) if (sub_8041364() != 0) return; - TurnValuesCleanUp(0); + TurnValuesCleanUp(FALSE); gHitMarker &= ~(HITMARKER_NO_ATTACKSTRING); gHitMarker &= ~(HITMARKER_UNABLE_TO_USE_MOVE); gHitMarker &= ~(HITMARKER_x400000); @@ -3657,8 +3695,8 @@ void BattleTurnPassed(void) if (gBattleOutcome != 0) { - gFightStateTracker = 12; - gBattleMainFunc = bc_bs_exec; + gCurrentActionFuncId = 12; + gBattleMainFunc = RunTurnActionsFunctions; return; } @@ -3862,7 +3900,7 @@ void HandleTurnActionSelectionState(void) else if (gDisableStructs[gActiveBank].encoredMove != 0) { gChosenMovesByBanks[gActiveBank] = gDisableStructs[gActiveBank].encoredMove; - *(gBattleStruct->chosenMovesIds + gActiveBank) = gDisableStructs[gActiveBank].encoredMovePos; + *(gBattleStruct->chosenMovePositions + gActiveBank) = gDisableStructs[gActiveBank].encoredMovePos; gBattleCommunication[gActiveBank] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; return; } @@ -4067,8 +4105,8 @@ void HandleTurnActionSelectionState(void) RecordedBattle_SetBankAction(gActiveBank, gBattleBufferB[gActiveBank][2]); RecordedBattle_SetBankAction(gActiveBank, gBattleBufferB[gActiveBank][3]); } - *(gBattleStruct->chosenMovesIds + gActiveBank) = gBattleBufferB[gActiveBank][2]; - gChosenMovesByBanks[gActiveBank] = gBattleMons[gActiveBank].moves[*(gBattleStruct->chosenMovesIds + gActiveBank)]; + *(gBattleStruct->chosenMovePositions + gActiveBank) = gBattleBufferB[gActiveBank][2]; + gChosenMovesByBanks[gActiveBank] = gBattleMons[gActiveBank].moves[*(gBattleStruct->chosenMovePositions + gActiveBank)]; *(gBattleStruct->moveTarget + gActiveBank) = gBattleBufferB[gActiveBank][3]; gBattleCommunication[gActiveBank]++; } @@ -4257,8 +4295,6 @@ void sub_803CDF8(void) } } -extern u8 gActionsByTurnOrder[BATTLE_BANKS_COUNT]; - void SwapTurnOrder(u8 id1, u8 id2) { u32 temp = gActionsByTurnOrder[id1]; @@ -4270,8 +4306,6 @@ void SwapTurnOrder(u8 id1, u8 id2) gBanksByTurnOrder[id2] = temp; } -extern const u8 gStatStageRatios[][2]; - u8 GetWhoStrikesFirst(u8 bank1, u8 bank2, bool8 ignoreChosenMoves) { u8 strikesFirst = 0; @@ -4379,7 +4413,7 @@ u8 GetWhoStrikesFirst(u8 bank1, u8 bank2, bool8 ignoreChosenMoves) if (gProtectStructs[bank1].onlyStruggle) moveBank1 = MOVE_STRUGGLE; else - moveBank1 = gBattleMons[bank1].moves[*(gBattleStruct->chosenMovesIds + bank1)]; + moveBank1 = gBattleMons[bank1].moves[*(gBattleStruct->chosenMovePositions + bank1)]; } else moveBank1 = MOVE_NONE; @@ -4389,7 +4423,7 @@ u8 GetWhoStrikesFirst(u8 bank1, u8 bank2, bool8 ignoreChosenMoves) if (gProtectStructs[bank2].onlyStruggle) moveBank2 = MOVE_STRUGGLE; else - moveBank2 = gBattleMons[bank2].moves[*(gBattleStruct->chosenMovesIds + bank2)]; + moveBank2 = gBattleMons[bank2].moves[*(gBattleStruct->chosenMovePositions + bank2)]; } else moveBank2 = MOVE_NONE; @@ -4482,8 +4516,8 @@ static void SetActionsAndBanksTurnOrder(void) var++; } } - gBattleMainFunc = bc_80154A0; - gBattleStruct->field_48 = 0; + gBattleMainFunc = CheckFocusPunch_ClearVarsBeforeTurnStarts; + gBattleStruct->focusPunchBank = 0; return; } else @@ -4524,6 +4558,820 @@ static void SetActionsAndBanksTurnOrder(void) } } } - gBattleMainFunc = bc_80154A0; - gBattleStruct->field_48 = 0; + gBattleMainFunc = CheckFocusPunch_ClearVarsBeforeTurnStarts; + gBattleStruct->focusPunchBank = 0; +} + +void TurnValuesCleanUp(bool8 var0) +{ + s32 i; + u8 *dataPtr; + + for (gActiveBank = 0; gActiveBank < gNoOfAllBanks; gActiveBank++) + { + if (var0) + { + gProtectStructs[gActiveBank].protected = 0; + gProtectStructs[gActiveBank].endured = 0; + } + else + { + dataPtr = (u8*)(&gProtectStructs[gActiveBank]); + for (i = 0; i < sizeof(struct ProtectStruct); i++) + dataPtr[i] = 0; + + if (gDisableStructs[gActiveBank].isFirstTurn) + gDisableStructs[gActiveBank].isFirstTurn--; + + if (gDisableStructs[gActiveBank].rechargeCounter) + { + gDisableStructs[gActiveBank].rechargeCounter--; + if (gDisableStructs[gActiveBank].rechargeCounter == 0) + gBattleMons[gActiveBank].status2 &= ~(STATUS2_RECHARGE); + } + } + + if (gDisableStructs[gActiveBank].substituteHP == 0) + gBattleMons[gActiveBank].status2 &= ~(STATUS2_SUBSTITUTE); + } + + gSideTimers[0].followmeTimer = 0; + gSideTimers[1].followmeTimer = 0; +} + +void SpecialStatusesClear(void) +{ + for (gActiveBank = 0; gActiveBank < gNoOfAllBanks; gActiveBank++) + { + s32 i; + u8 *dataPtr = (u8*)(&gSpecialStatuses[gActiveBank]); + + for (i = 0; i < sizeof(struct SpecialStatus); i++) + dataPtr[i] = 0; + } +} + +static void CheckFocusPunch_ClearVarsBeforeTurnStarts(void) +{ + if (!(gHitMarker & HITMARKER_x8000)) + { + while (gBattleStruct->focusPunchBank < gNoOfAllBanks) + { + gActiveBank = gBankAttacker = gBattleStruct->focusPunchBank; + gBattleStruct->focusPunchBank++; + if (gChosenMovesByBanks[gActiveBank] == MOVE_FOCUS_PUNCH + && !(gBattleMons[gActiveBank].status1 & STATUS_SLEEP) + && !(gDisableStructs[gBankAttacker].truantCounter) + && !(gProtectStructs[gActiveBank].onlyStruggle)) + { + BattleScriptExecute(BattleScript_FocusPunchSetUp); + return; + } + } + } + + TryClearRageStatuses(); + gCurrentTurnActionNumber = 0; +{ + // something stupid needed to match + u8 zero; + gCurrentActionFuncId = gActionsByTurnOrder[(zero = 0)]; +} + gDynamicBasePower = 0; + gBattleStruct->dynamicMoveType = 0; + gBattleMainFunc = RunTurnActionsFunctions; + gBattleCommunication[3] = 0; + gBattleCommunication[4] = 0; + gBattleScripting.field_16 = 0; + gBattleResources->battleScriptsStack->size = 0; +} + +extern void (* const gTurnActionsFuncsTable[])(void); +extern void (* const gEndTurnFuncsTable[])(void); + +static void RunTurnActionsFunctions(void) +{ + if (gBattleOutcome != 0) + gCurrentActionFuncId = 12; + + *(&gBattleStruct->field_4B) = gCurrentTurnActionNumber; + gTurnActionsFuncsTable[gCurrentActionFuncId](); + + if (gCurrentTurnActionNumber >= gNoOfAllBanks) // everyone did their actions, turn finished + { + gHitMarker &= ~(HITMARKER_x100000); + gBattleMainFunc = gEndTurnFuncsTable[gBattleOutcome & 0x7F]; + } + else + { + if (gBattleStruct->field_4B != gCurrentTurnActionNumber) // action turn has been done, clear hitmarker bits for another bank + { + gHitMarker &= ~(HITMARKER_NO_ATTACKSTRING); + gHitMarker &= ~(HITMARKER_UNABLE_TO_USE_MOVE); + } + } +} + +void HandleEndTurn_BattleWon(void) +{ + gCurrentActionFuncId = 0; + + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) + { + gScriptResult = gBattleOutcome; + gBattleTextBuff1[0] = gBattleOutcome; + gBankAttacker = GetBankByIdentity(IDENTITY_PLAYER_MON1); + gBattlescriptCurrInstr = BattleScript_LinkBattleWonOrLost; + gBattleOutcome &= ~(BATTLE_OUTCOME_BIT_x80); + } + else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER + && gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_x4000000 | BATTLE_TYPE_EREADER_TRAINER)) + { + BattleMusicStop(); + gBattlescriptCurrInstr = BattleScript_FrontierTrainerBattleWon; + + if (gTrainerBattleOpponent_A == TRAINER_OPPONENT_3FE) + PlayBGM(BGM_KACHI3); + else + PlayBGM(BGM_KACHI1); + } + else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && !(gBattleTypeFlags & BATTLE_TYPE_LINK)) + { + BattleMusicStop(); + gBattlescriptCurrInstr = BattleScript_LocalTrainerBattleWon; + + switch (gTrainers[gTrainerBattleOpponent_A].trainerClass) + { + case CLASS_ELITE_FOUR: + case CLASS_CHAMPION: + PlayBGM(BGM_KACHI5); + break; + case CLASS_TEAM_AQUA: + case CLASS_TEAM_MAGMA: + case CLASS_AQUA_ADMIN: + case CLASS_AQUA_LEADER: + case CLASS_MAGMA_ADMIN: + case CLASS_MAGMA_LEADER: + PlayBGM(BGM_KACHI4); + break; + case CLASS_LEADER: + PlayBGM(BGM_KACHI3); + break; + default: + PlayBGM(BGM_KACHI1); + break; + } + } + else + { + gBattlescriptCurrInstr = BattleScript_PayDayMoneyAndPickUpItems; + } + + gBattleMainFunc = HandleEndTurn_FinishBattle; +} + +void HandleEndTurn_BattleLost(void) +{ + gCurrentActionFuncId = 0; + + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) + { + if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) + { + if (gBattleOutcome & BATTLE_OUTCOME_BIT_x80) + { + gBattlescriptCurrInstr = gUnknown_082DB9C8; + gBattleOutcome &= ~(BATTLE_OUTCOME_BIT_x80); + gSaveBlock2Ptr->field_CA9_b = 1; + } + else + { + gBattlescriptCurrInstr = gUnknown_082DAA0B; + gBattleOutcome &= ~(BATTLE_OUTCOME_BIT_x80); + } + } + else + { + gBattleTextBuff1[0] = gBattleOutcome; + gBankAttacker = GetBankByIdentity(IDENTITY_PLAYER_MON1); + gBattlescriptCurrInstr = BattleScript_LinkBattleWonOrLost; + gBattleOutcome &= ~(BATTLE_OUTCOME_BIT_x80); + } + } + else + { + gBattlescriptCurrInstr = BattleScript_LocalBattleLost; + } + + gBattleMainFunc = HandleEndTurn_FinishBattle; +} + +void HandleEndTurn_RanFromBattle(void) +{ + gCurrentActionFuncId = 0; + + if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER && gBattleTypeFlags & BATTLE_TYPE_TRAINER) + { + gBattlescriptCurrInstr = gUnknown_082DB9C1; + gBattleOutcome = BATTLE_FORFEITED; + gSaveBlock2Ptr->field_CA9_b = 1; + } + else if (gBattleTypeFlags & BATTLE_TYPE_x4000000) + { + gBattlescriptCurrInstr = gUnknown_082DB9C1; + gBattleOutcome = BATTLE_FORFEITED; + } + else + { + switch (gProtectStructs[gBankAttacker].fleeFlag) + { + default: + gBattlescriptCurrInstr = BattleScript_GotAwaySafely; + break; + case 1: + gBattlescriptCurrInstr = BattleScript_SmokeBallEscape; + break; + case 2: + gBattlescriptCurrInstr = BattleScript_RanAwayUsingMonAbility; + break; + } + } + + gBattleMainFunc = HandleEndTurn_FinishBattle; +} + +void HandleEndTurn_MonFled(void) +{ + gCurrentActionFuncId = 0; + + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBankAttacker, gBattlePartyID[gBankAttacker]); + gBattlescriptCurrInstr = BattleScript_WildMonFled; + + gBattleMainFunc = HandleEndTurn_FinishBattle; +} + +void HandleEndTurn_FinishBattle(void) +{ + if (gCurrentActionFuncId == 0xB || gCurrentActionFuncId == 0xC) + { + if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK + | BATTLE_TYPE_x2000000 + | BATTLE_TYPE_FIRST_BATTLE + | BATTLE_TYPE_SAFARI + | BATTLE_TYPE_EREADER_TRAINER + | BATTLE_TYPE_WALLY_TUTORIAL + | BATTLE_TYPE_FRONTIER))) + { + for (gActiveBank = 0; gActiveBank < gNoOfAllBanks; gActiveBank++) + { + if (GetBankSide(gActiveBank) == SIDE_PLAYER) + { + if (gBattleResults.playerMon1Species == SPECIES_NONE) + { + gBattleResults.playerMon1Species = GetMonData(&gPlayerParty[gBattlePartyID[gActiveBank]], MON_DATA_SPECIES, NULL); + GetMonData(&gPlayerParty[gBattlePartyID[gActiveBank]], MON_DATA_NICKNAME, gBattleResults.playerMon1Name); + } + else + { + gBattleResults.playerMon2Species = GetMonData(&gPlayerParty[gBattlePartyID[gActiveBank]], MON_DATA_SPECIES, NULL); + GetMonData(&gPlayerParty[gBattlePartyID[gActiveBank]], MON_DATA_NICKNAME, gBattleResults.playerMon2Name); + } + } + } + sub_80EC728(); + } + + if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK + | BATTLE_TYPE_x2000000 + | BATTLE_TYPE_TRAINER + | BATTLE_TYPE_FIRST_BATTLE + | BATTLE_TYPE_SAFARI + | BATTLE_TYPE_FRONTIER + | BATTLE_TYPE_EREADER_TRAINER + | BATTLE_TYPE_WALLY_TUTORIAL)) + && gBattleResults.unk5_6) + { + sub_80EE184(); + } + + sub_8186444(); + BeginFastPaletteFade(3); + FadeOutMapMusic(5); + gBattleMainFunc = FreeResetData_ReturnToOvOrDoEvolutions; + gUnknown_030061E8 = BattleMainCB2; + } + else + { + if (gBattleExecBuffer == 0) + gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); + } +} + +static void FreeResetData_ReturnToOvOrDoEvolutions(void) +{ + if (!gPaletteFade.active) + { + ResetSpriteData(); + if (gLeveledUpInBattle == 0 || gBattleOutcome != BATTLE_WON) + { + gBattleMainFunc = ReturnFromBattleToOverworld; + return; + } + else + { + gBattleMainFunc = TryEvolvePokemon; + } + } + + FreeAllWindowBuffers(); + if (!(gBattleTypeFlags & BATTLE_TYPE_LINK)) + { + FreeMonSpritesGfx(); + FreeBattleResources(); + FreeBattleSpritesData(); + } +} + +static void TryEvolvePokemon(void) +{ + s32 i; + + while (gLeveledUpInBattle != 0) + { + for (i = 0; i < 6; i++) + { + if (gLeveledUpInBattle & gBitTable[i]) + { + u16 species; + u8 levelUpBits = gLeveledUpInBattle; + + levelUpBits &= ~(gBitTable[i]); + gLeveledUpInBattle = levelUpBits; + + species = GetEvolutionTargetSpecies(&gPlayerParty[i], 0, levelUpBits); + if (species != SPECIES_NONE) + { + FreeAllWindowBuffers(); + gBattleMainFunc = WaitForEvoSceneToFinish; + EvolutionScene(&gPlayerParty[i], species, TRUE, i); + return; + } + } + } + } + + gBattleMainFunc = ReturnFromBattleToOverworld; +} + +static void WaitForEvoSceneToFinish(void) +{ + if (gMain.callback2 == BattleMainCB2) + gBattleMainFunc = TryEvolvePokemon; +} + +static void ReturnFromBattleToOverworld(void) +{ + if (!(gBattleTypeFlags & BATTLE_TYPE_LINK)) + { + RandomlyGivePartyPokerus(gPlayerParty); + PartySpreadPokerus(gPlayerParty); + } + + if (gBattleTypeFlags & BATTLE_TYPE_LINK && gReceivedRemoteLinkPlayers != 0) + return; + + gScriptResult = gBattleOutcome; + gMain.inBattle = 0; + gMain.callback1 = gPreBattleCallback1; + + if (gBattleTypeFlags & BATTLE_TYPE_ROAMER) + { + UpdateRoamerHPStatus(&gEnemyParty[0]); + if ((gBattleOutcome & BATTLE_WON) || gBattleOutcome == BATTLE_CAUGHT) + SetRoamerInactive(); + } + + m4aSongNumStop(0x5A); + SetMainCallback2(gMain.savedCallback); +} + +void RunBattleScriptCommands_PopCallbacksStack(void) +{ + if (gCurrentActionFuncId == 0xB || gCurrentActionFuncId == 0xC) + { + if (BATTLE_CALLBACKS_STACK->size != 0) + BATTLE_CALLBACKS_STACK->size--; + gBattleMainFunc = BATTLE_CALLBACKS_STACK->function[BATTLE_CALLBACKS_STACK->size]; + } + else + { + if (gBattleExecBuffer == 0) + gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); + } +} + +void RunBattleScriptCommands(void) +{ + if (gBattleExecBuffer == 0) + gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); +} + +extern const u8 * const gBattleScriptsForMoveEffects[]; + +void HandleAction_UseMove(void) +{ + u8 side; + u8 var = 4; + + gBankAttacker = gBanksByTurnOrder[gCurrentTurnActionNumber]; + + if (*(&gBattleStruct->field_91) & gBitTable[gBankAttacker]) + { + gCurrentActionFuncId = ACTION_FINISHED; + return; + } + + gCritMultiplier = 1; + gBattleScripting.dmgMultiplier = 1; + gBattleStruct->atkCancellerTracker = 0; + gBattleMoveFlags = 0; + gMultiHitCounter = 0; + gBattleCommunication[6] = 0; + gCurrMovePos = gUnknown_020241E9 = *(gBattleStruct->chosenMovePositions + gBankAttacker); + + // choose move + if (gProtectStructs[gBankAttacker].onlyStruggle) + { + gProtectStructs[gBankAttacker].onlyStruggle = 0; + gCurrentMove = gLastUsedMove = MOVE_STRUGGLE; + gHitMarker |= HITMARKER_NO_PPDEDUCT; + *(gBattleStruct->moveTarget + gBankAttacker) = GetMoveTarget(MOVE_STRUGGLE, 0); + } + else if (gBattleMons[gBankAttacker].status2 & STATUS2_MULTIPLETURNS || gBattleMons[gBankAttacker].status2 & STATUS2_RECHARGE) + { + gCurrentMove = gLastUsedMove = gLockedMoves[gBankAttacker]; + } + // encore forces you to use the same move + else if (gDisableStructs[gBankAttacker].encoredMove != MOVE_NONE + && gDisableStructs[gBankAttacker].encoredMove == gBattleMons[gBankAttacker].moves[gDisableStructs[gBankAttacker].encoredMovePos]) + { + gCurrentMove = gLastUsedMove = gDisableStructs[gBankAttacker].encoredMove; + gCurrMovePos = gUnknown_020241E9 = gDisableStructs[gBankAttacker].encoredMovePos; + *(gBattleStruct->moveTarget + gBankAttacker) = GetMoveTarget(gCurrentMove, 0); + } + // check if the encored move wasn't overwritten + else if (gDisableStructs[gBankAttacker].encoredMove != MOVE_NONE + && gDisableStructs[gBankAttacker].encoredMove != gBattleMons[gBankAttacker].moves[gDisableStructs[gBankAttacker].encoredMovePos]) + { + gCurrMovePos = gUnknown_020241E9 = gDisableStructs[gBankAttacker].encoredMovePos; + gCurrentMove = gLastUsedMove = gBattleMons[gBankAttacker].moves[gCurrMovePos]; + gDisableStructs[gBankAttacker].encoredMove = MOVE_NONE; + gDisableStructs[gBankAttacker].encoredMovePos = 0; + gDisableStructs[gBankAttacker].encoreTimer1 = 0; + *(gBattleStruct->moveTarget + gBankAttacker) = GetMoveTarget(gCurrentMove, 0); + } + else if (gBattleMons[gBankAttacker].moves[gCurrMovePos] != gChosenMovesByBanks[gBankAttacker]) + { + gCurrentMove = gLastUsedMove = gBattleMons[gBankAttacker].moves[gCurrMovePos]; + *(gBattleStruct->moveTarget + gBankAttacker) = GetMoveTarget(gCurrentMove, 0); + } + else + { + gCurrentMove = gLastUsedMove = gBattleMons[gBankAttacker].moves[gCurrMovePos]; + } + + if (gBattleMons[gBankAttacker].hp != 0) + { + if (GetBankSide(gBankAttacker) == SIDE_PLAYER) + gBattleResults.lastUsedMovePlayer = gCurrentMove; + else + gBattleResults.lastUsedMoveOpponent = gCurrentMove; + } + + // choose target + side = GetBankSide(gBankAttacker) ^ BIT_SIDE; + if (gSideTimers[side].followmeTimer != 0 + && gBattleMoves[gCurrentMove].target == MOVE_TARGET_SELECTED + && GetBankSide(gBankAttacker) != GetBankSide(gSideTimers[side].followmeTarget) + && gBattleMons[gSideTimers[side].followmeTarget].hp != 0) + { + gBankTarget = gSideTimers[side].followmeTarget; + } + else if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + && gSideTimers[side].followmeTimer == 0 + && (gBattleMoves[gCurrentMove].power != 0 + || gBattleMoves[gCurrentMove].target != MOVE_TARGET_x10) + && gBattleMons[*(gBattleStruct->moveTarget + gBankAttacker)].ability != ABILITY_LIGHTNING_ROD + && gBattleMoves[gCurrentMove].type == TYPE_ELECTRIC) + { + side = GetBankSide(gBankAttacker); + for (gActiveBank = 0; gActiveBank < gNoOfAllBanks; gActiveBank++) + { + if (side != GetBankSide(gActiveBank) + && *(gBattleStruct->moveTarget + gBankAttacker) != gActiveBank + && gBattleMons[gActiveBank].ability == ABILITY_LIGHTNING_ROD + && BankGetTurnOrder(gActiveBank) < var) + { + var = BankGetTurnOrder(gActiveBank); + } + } + if (var == 4) + { + if (gBattleMoves[gLastUsedMove].target & MOVE_TARGET_RANDOM) + { + if (GetBankSide(gBankAttacker) == SIDE_PLAYER) + { + if (Random() & 1) + gBankTarget = GetBankByIdentity(IDENTITY_OPPONENT_MON1); + else + gBankTarget = GetBankByIdentity(IDENTITY_OPPONENT_MON2); + } + else + { + if (Random() & 1) + gBankTarget = GetBankByIdentity(IDENTITY_PLAYER_MON1); + else + gBankTarget = GetBankByIdentity(IDENTITY_PLAYER_MON2); + } + } + else + { + gBankTarget = *(gBattleStruct->moveTarget + gBankAttacker); + } + + if (gAbsentBankFlags & gBitTable[gBankTarget]) + { + if (GetBankSide(gBankAttacker) != GetBankSide(gBankTarget)) + { + gBankTarget = GetBankByIdentity(GetBankIdentity(gBankTarget) ^ BIT_MON); + } + else + { + gBankTarget = GetBankByIdentity(GetBankIdentity(gBankAttacker) ^ BIT_SIDE); + if (gAbsentBankFlags & gBitTable[gBankTarget]) + gBankTarget = GetBankByIdentity(GetBankIdentity(gBankTarget) ^ BIT_MON); + } + } + } + else + { + gActiveBank = gBanksByTurnOrder[var]; + RecordAbilityBattle(gActiveBank, gBattleMons[gActiveBank].ability); + gSpecialStatuses[gActiveBank].lightningRodRedirected = 1; + gBankTarget = gActiveBank; + } + } + else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE + && gBattleMoves[gLastUsedMove].target & MOVE_TARGET_RANDOM) + { + if (GetBankSide(gBankAttacker) == SIDE_PLAYER) + { + if (Random() & 1) + gBankTarget = GetBankByIdentity(IDENTITY_OPPONENT_MON1); + else + gBankTarget = GetBankByIdentity(IDENTITY_OPPONENT_MON2); + } + else + { + if (Random() & 1) + gBankTarget = GetBankByIdentity(IDENTITY_PLAYER_MON1); + else + gBankTarget = GetBankByIdentity(IDENTITY_PLAYER_MON2); + } + + if (gAbsentBankFlags & gBitTable[gBankTarget] + && GetBankSide(gBankAttacker) != GetBankSide(gBankTarget)) + { + gBankTarget = GetBankByIdentity(GetBankIdentity(gBankTarget) ^ BIT_MON); + } + } + else + { + gBankTarget = *(gBattleStruct->moveTarget + gBankAttacker); + if (gAbsentBankFlags & gBitTable[gBankTarget]) + { + if (GetBankSide(gBankAttacker) != GetBankSide(gBankTarget)) + { + gBankTarget = GetBankByIdentity(GetBankIdentity(gBankTarget) ^ BIT_MON); + } + else + { + gBankTarget = GetBankByIdentity(GetBankIdentity(gBankAttacker) ^ BIT_SIDE); + if (gAbsentBankFlags & gBitTable[gBankTarget]) + gBankTarget = GetBankByIdentity(GetBankIdentity(gBankTarget) ^ BIT_MON); + } + } + } + + // choose battlescript + if (gBattleTypeFlags & BATTLE_TYPE_PALACE + && gProtectStructs[gBankAttacker].flag_x10) + { + if (gBattleMons[gBankAttacker].hp == 0) + { + gCurrentActionFuncId = 12; + return; + } + else if (gUnknown_02024230[gBankAttacker] != NULL) + { + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattlescriptCurrInstr = gUnknown_02024230[gBankAttacker]; + gUnknown_02024230[gBankAttacker] = NULL; + } + else + { + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattlescriptCurrInstr = BattleScript_MoveUsedLoafingAround; + } + } + else + { + gBattlescriptCurrInstr = gBattleScriptsForMoveEffects[gBattleMoves[gCurrentMove].effect]; + } + + if (gBattleTypeFlags & BATTLE_TYPE_ARENA) + sub_81A56E8(gBankAttacker); + + gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT; +} + +void HandleAction_Switch(void) +{ + gBankAttacker = gBanksByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gActionSelectionCursor[gBankAttacker] = 0; + gMoveSelectionCursor[gBankAttacker] = 0; + + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBankAttacker, *(gBattleStruct->field_58 + gBankAttacker)) + + gBattleScripting.bank = gBankAttacker; + gBattlescriptCurrInstr = BattleScript_ActionSwitch; + gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT; + + if (gBattleResults.playerSwitchesCounter < 255) + gBattleResults.playerSwitchesCounter++; +} + +extern const u8 * const gBattlescriptsForBallThrow[]; +extern const u8 * const gBattlescriptsForRunningByItem[]; +extern const u8 * const gUnknown_082DBD3C[]; + +void HandleAction_UseItem(void) +{ + gBankAttacker = gBankTarget = gBanksByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + ClearFuryCutterDestinyBondGrudge(gBankAttacker); + gLastUsedItem = gBattleBufferB[gBankAttacker][1] | (gBattleBufferB[gBankAttacker][2] << 8); + + if (gLastUsedItem <= ITEM_PREMIER_BALL) // is ball + { + gBattlescriptCurrInstr = gBattlescriptsForBallThrow[gLastUsedItem]; + } + else if (gLastUsedItem == ITEM_POKE_DOLL || gLastUsedItem == ITEM_FLUFFY_TAIL) + { + gBattlescriptCurrInstr = gBattlescriptsForRunningByItem[0]; + } + else if (GetBankSide(gBankAttacker) == SIDE_PLAYER) + { + gBattlescriptCurrInstr = gUnknown_082DBD3C[0]; + } + else + { + gBattleScripting.bank = gBankAttacker; + + switch (*(gBattleStruct->field_C4 + (gBankAttacker >> 1))) + { + case 1: + case 2: + break; + case 3: + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + if (*(gBattleStruct->field_C6 + gBankAttacker / 2) & 1) + { + if (*(gBattleStruct->field_C6 + gBankAttacker / 2) & 0x3E) + gBattleCommunication[MULTISTRING_CHOOSER] = 5; + } + else + { + while (!(*(gBattleStruct->field_C6 + gBankAttacker / 2) & 1)) + { + *(gBattleStruct->field_C6 + gBankAttacker / 2) >>= 1; + gBattleCommunication[MULTISTRING_CHOOSER]++; + } + } + break; + case 4: + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + if (*(gBattleStruct->field_C6 + (gBankAttacker >> 1)) & 0x80) + { + gBattleCommunication[MULTISTRING_CHOOSER] = 5; + } + else + { + PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_ATK) + PREPARE_STRING_BUFFER(gBattleTextBuff2, 0xD2) + + while (!((*(gBattleStruct->field_C6 + (gBankAttacker >> 1))) & 1)) + { + *(gBattleStruct->field_C6 + gBankAttacker / 2) >>= 1; + gBattleTextBuff1[2]++; + } + + gBattleScripting.animArg1 = gBattleTextBuff1[2] + 14; + gBattleScripting.animArg2 = 0; + } + break; + case 5: + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + gBattleCommunication[MULTISTRING_CHOOSER] = 2; + else + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + break; + } + + gBattlescriptCurrInstr = gUnknown_082DBD3C[*(gBattleStruct->field_C4 + gBankAttacker / 2)]; + } + gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT; +} + +bool8 TryRunFromBattle(u8 bank) +{ + bool8 effect = FALSE; + u8 holdEffect; + u8 pyramidMultiplier; + u8 speedVar; + + if (gBattleMons[bank].item == ITEM_ENIGMA_BERRY) + holdEffect = gEnigmaBerries[bank].holdEffect; + else + holdEffect = ItemId_GetHoldEffect(gBattleMons[bank].item); + + gStringBank = bank; + + if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) + { + gLastUsedItem = gBattleMons[bank].item ; + gProtectStructs[bank].fleeFlag = 1; + effect++; + } + else if (gBattleMons[bank].ability == ABILITY_RUN_AWAY) + { + if (InBattlePyramid()) + { + gBattleStruct->runTries++; + pyramidMultiplier = sub_81A9E28(); + speedVar = (gBattleMons[bank].speed * pyramidMultiplier) / (gBattleMons[bank ^ BIT_SIDE].speed) + (gBattleStruct->runTries * 30); + if (speedVar > (Random() & 0xFF)) + { + gLastUsedAbility = ABILITY_RUN_AWAY; + gProtectStructs[bank].fleeFlag = 2; + effect++; + } + } + else + { + gLastUsedAbility = ABILITY_RUN_AWAY; + gProtectStructs[bank].fleeFlag = 2; + effect++; + } + } + else if (gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_x4000000) && gBattleTypeFlags & BATTLE_TYPE_TRAINER) + { + effect++; + } + else + { + if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) + { + if (InBattlePyramid()) + { + pyramidMultiplier = sub_81A9E28(); + speedVar = (gBattleMons[bank].speed * pyramidMultiplier) / (gBattleMons[bank ^ BIT_SIDE].speed) + (gBattleStruct->runTries * 30); + if (speedVar > (Random() & 0xFF)) + effect++; + } + else if (gBattleMons[bank].speed < gBattleMons[bank ^ BIT_SIDE].speed) + { + speedVar = (gBattleMons[bank].speed * 128) / (gBattleMons[bank ^ BIT_SIDE].speed) + (gBattleStruct->runTries * 30); + if (speedVar > (Random() & 0xFF)) + effect++; + } + else // same speed or faster + { + effect++; + } + } + + gBattleStruct->runTries++; + } + + if (effect) + { + gCurrentTurnActionNumber = gNoOfAllBanks; + gBattleOutcome = BATTLE_RAN; + } + + return effect; } diff --git a/src/battle_3.c b/src/battle_3.c index c20d361a4f..58e0a05c7e 100644 --- a/src/battle_3.c +++ b/src/battle_3.c @@ -50,7 +50,7 @@ extern u8 gBattleMoveFlags; extern s32 gTakenDmg[BATTLE_BANKS_COUNT]; extern u8 gTakenDmgBanks[BATTLE_BANKS_COUNT]; extern u8 gLastUsedAbility; -extern u8 gFightStateTracker; +extern u8 gCurrentActionFuncId; extern u32 gBattleExecBuffer; extern u16 gRandomMove; extern u8 gCurrMovePos; @@ -181,8 +181,6 @@ extern const u16 gSoundMovesTable[]; extern void sub_803F9EC(); extern bool8 sub_80423F4(u8 bank, u8, u8); extern u8 weather_get_current(void); -extern void sub_803E08C(void); -extern void bc_move_exec_returning(void); extern s8 GetFlavourRelationByPersonality(u32 personality, u8 flavor); void BattleScriptPush(const u8* bsPtr) @@ -1156,7 +1154,7 @@ bool8 sub_8041728(void) return FALSE; } -void b_clear_atk_up_if_hit_flag_unless_enraged(void) +void TryClearRageStatuses(void) { int i; for (i = 0; i < gNoOfAllBanks; i++) @@ -5441,8 +5439,8 @@ void BattleScriptExecute(const u8* BS_ptr) { gBattlescriptCurrInstr = BS_ptr; BATTLE_CALLBACKS_STACK->function[BATTLE_CALLBACKS_STACK->size++] = gBattleMainFunc; - gBattleMainFunc = bc_move_exec_returning; - gFightStateTracker = 0; + gBattleMainFunc = RunBattleScriptCommands_PopCallbacksStack; + gCurrentActionFuncId = 0; } void BattleScriptPushCursorAndCallback(const u8* BS_ptr) @@ -5450,7 +5448,7 @@ void BattleScriptPushCursorAndCallback(const u8* BS_ptr) BattleScriptPushCursor(); gBattlescriptCurrInstr = BS_ptr; BATTLE_CALLBACKS_STACK->function[BATTLE_CALLBACKS_STACK->size++] = gBattleMainFunc; - gBattleMainFunc = sub_803E08C; + gBattleMainFunc = RunBattleScriptCommands; } enum @@ -5520,7 +5518,7 @@ u8 ItemBattleEffects(u8 caseID, u8 bank, bool8 moveTurn) switch (caseID) { - case 0: + case ITEMEFFECT_ON_SWITCH_IN: switch (bankHoldEffect) { case HOLD_EFFECT_DOUBLE_PRIZE: @@ -6185,7 +6183,7 @@ u8 ItemBattleEffects(u8 caseID, u8 bank, bool8 moveTurn) return effect; } -void sub_8045868(u8 bank) +void ClearFuryCutterDestinyBondGrudge(u8 bank) { gDisableStructs[bank].furyCutterCounter = 0; gBattleMons[bank].status2 &= ~(STATUS2_DESTINY_BOND); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 380f9ec40d..e68137c479 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -67,7 +67,7 @@ extern u8 gBankAttacker; extern u8 gBankTarget; extern const u8* gBattlescriptCurrInstr; extern u8 gCurrMovePos; -extern u8 gFightStateTracker; +extern u8 gCurrentActionFuncId; extern u32 gHitMarker; extern u8 gBattleMoveFlags; extern u8 gBattleCommunication[]; @@ -92,7 +92,7 @@ extern u16 gMoveToLearn; extern u16 gRandomMove; extern u8 gBankInMenu; extern u8 gActionForBanks[BATTLE_BANKS_COUNT]; -extern u8 gCurrentMoveTurn; +extern u8 gCurrentTurnActionNumber; extern u8 gBattleBufferB[BATTLE_BANKS_COUNT][0x200]; extern u16 gLockedMoves[BATTLE_BANKS_COUNT]; extern u16 gPartnerTrainerId; @@ -377,7 +377,7 @@ static void atk6E_set_atk_to_player0(void); static void atk6F_set_visible(void); static void atk70_record_last_used_ability(void); static void atk71_buffer_move_to_learn(void); -static void atk72_jump_if_can_run_frombattle(void); +static void atk72_jump_if_run_attempt_success(void); static void atk73_hp_thresholds(void); static void atk74_hp_thresholds2(void); static void atk75_item_effect_on_opponent(void); @@ -509,8 +509,8 @@ static void atkF2_display_dex_info(void); static void atkF3_nickname_caught_poke(void); static void atkF4_subattackerhpbydmg(void); static void atkF5_removeattackerstatus1(void); -static void atkF6_802BF48(void); -static void atkF7_802BF54(void); +static void atkF6_action_finished(void); +static void atkF7_turn_finished(void); static void atkF8_trainer_slide_back(void); void (* const gBattleScriptingCommandsTable[])(void) = @@ -629,7 +629,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = atk6F_set_visible, atk70_record_last_used_ability, atk71_buffer_move_to_learn, - atk72_jump_if_can_run_frombattle, + atk72_jump_if_run_attempt_success, atk73_hp_thresholds, atk74_hp_thresholds2, atk75_item_effect_on_opponent, @@ -761,8 +761,8 @@ void (* const gBattleScriptingCommandsTable[])(void) = atkF3_nickname_caught_poke, atkF4_subattackerhpbydmg, atkF5_removeattackerstatus1, - atkF6_802BF48, - atkF7_802BF54, + atkF6_action_finished, + atkF7_turn_finished, atkF8_trainer_slide_back }; @@ -1097,9 +1097,9 @@ static void atk00_attackcanceler(void) { s32 i; - if (gBattleOutcome) + if (gBattleOutcome != 0) { - gFightStateTracker = 0xC; + gCurrentActionFuncId = ACTION_FINISHED; return; } if (gBattleMons[gBankAttacker].hp == 0 && !(gHitMarker & HITMARKER_NO_ATTACKSTRING)) @@ -2736,7 +2736,7 @@ void SetMoveEffect(bool8 primary, u8 certain) } else { - if (BankGetTurnOrder(gEffectBank) > gCurrentMoveTurn) + if (BankGetTurnOrder(gEffectBank) > gCurrentTurnActionNumber) gBattleMons[gEffectBank].status2 |= sStatusFlagsForMoveEffects[gBattleCommunication[MOVE_EFFECT_BYTE]]; gBattlescriptCurrInstr++; } @@ -3208,7 +3208,7 @@ static void atk19_faint_pokemon(void) && gBattleMons[gBankAttacker].hp != 0 && gCurrentMove != MOVE_STRUGGLE) { - u8 moveIndex = *(gBattleStruct->chosenMovesIds + gBankAttacker); + u8 moveIndex = *(gBattleStruct->chosenMovePositions + gBankAttacker); gBattleMons[gBankAttacker].pp[moveIndex] = 0; BattleScriptPush(gBattlescriptCurrInstr); @@ -4421,13 +4421,13 @@ static void atk3D_end(void) gBattleMoveFlags = 0; gActiveBank = 0; - gFightStateTracker = 0xB; + gCurrentActionFuncId = 0xB; } static void atk3E_end2(void) { gActiveBank = 0; - gFightStateTracker = 0xB; + gCurrentActionFuncId = 0xB; } static void atk3F_end3(void) // pops the main function stack @@ -6956,9 +6956,9 @@ static void atk71_buffer_move_to_learn(void) gBattlescriptCurrInstr++; } -static void atk72_jump_if_can_run_frombattle(void) +static void atk72_jump_if_run_attempt_success(void) { - if (CanRunFromBattle(gBank1)) + if (TryRunFromBattle(gBank1)) gBattlescriptCurrInstr = BSScriptReadPtr(gBattlescriptCurrInstr + 1); else gBattlescriptCurrInstr += 5; @@ -7045,7 +7045,7 @@ static void atk76_various(void) else gBankTarget = gActiveBank; break; - case 2: + case VARIOUS_CAN_RUN_FROM_BATTLE: gBattleCommunication[0] = IsRunningFromBattleImpossible(); break; case VARIOUS_GET_MOVE_TARGET: @@ -7196,7 +7196,7 @@ static void atk76_various(void) gBattleOutcome = BATTLE_OPPONENT_TELEPORTED; break; case VARIOUS_PLAY_TRAINER_DEFEATED_MUSIC: - EmitPlaySound(0, 0x19C, 1); + EmitPlaySound(0, BGM_KACHI1, 1); MarkBufferBankForExecution(gActiveBank); break; } @@ -7212,7 +7212,7 @@ static void atk77_set_protect_like(void) // protect and endure if (lastMove != MOVE_PROTECT && lastMove != MOVE_DETECT && lastMove != MOVE_ENDURE) gDisableStructs[gBankAttacker].protectUses = 0; - if (gCurrentMoveTurn == (gNoOfAllBanks - 1)) + if (gCurrentTurnActionNumber == (gNoOfAllBanks - 1)) notLastTurn = FALSE; if (sProtectSuccessRates[gDisableStructs[gBankAttacker].protectUses] >= Random() && notLastTurn) @@ -9715,7 +9715,7 @@ static void atkBA_jumpifnopursuitswitchdmg(void) } gCurrentMove = MOVE_PURSUIT; - gCurrMovePos = gUnknown_020241E9 = *(gBattleStruct->chosenMovesIds + gBankTarget); + gCurrMovePos = gUnknown_020241E9 = *(gBattleStruct->chosenMovePositions + gBankTarget); gBattlescriptCurrInstr += 5; gBattleScripting.animTurn = 1; gHitMarker &= ~(HITMARKER_ATTACKSTRING_PRINTED); @@ -10631,7 +10631,7 @@ static void atkDF_setmagiccoat(void) { gBankTarget = gBankAttacker; gSpecialStatuses[gBankAttacker].flag20 = 1; - if (gCurrentMoveTurn == gNoOfAllBanks - 1) // moves last turn + if (gCurrentTurnActionNumber == gNoOfAllBanks - 1) // moves last turn { gBattlescriptCurrInstr = BSScriptReadPtr(gBattlescriptCurrInstr + 1); } @@ -10645,7 +10645,7 @@ static void atkDF_setmagiccoat(void) static void atkE0_setstealstatchange(void) // snatch { gSpecialStatuses[gBankAttacker].flag20 = 1; - if (gCurrentMoveTurn == gNoOfAllBanks - 1) // moves last turn + if (gCurrentTurnActionNumber == gNoOfAllBanks - 1) // moves last turn { gBattlescriptCurrInstr = BSScriptReadPtr(gBattlescriptCurrInstr + 1); } @@ -11393,15 +11393,15 @@ static void atkF5_removeattackerstatus1(void) gBattlescriptCurrInstr++; } -static void atkF6_802BF48(void) +static void atkF6_action_finished(void) { - gFightStateTracker = 0xC; + gCurrentActionFuncId = ACTION_FINISHED; } -static void atkF7_802BF54(void) +static void atkF7_turn_finished(void) { - gFightStateTracker = 0xC; - gCurrentMoveTurn = gNoOfAllBanks; + gCurrentActionFuncId = ACTION_FINISHED; + gCurrentTurnActionNumber = gNoOfAllBanks; } static void atkF8_trainer_slide_back(void) diff --git a/sym_ewram.txt b/sym_ewram.txt index c50d8f0305..c00f5e1d65 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -310,10 +310,10 @@ gActionsByTurnOrder: @ 202407A gBanksByTurnOrder: @ 202407E .space 0x4 -gCurrentMoveTurn: @ 2024082 +gCurrentTurnActionNumber: @ 2024082 .space 0x1 -gFightStateTracker: @ 2024083 +gCurrentActionFuncId: @ 2024083 .space 0x1 gBattleMons: @ 2024084