From 898d0b20ad524e2837079a50f33f6fae0e72b685 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 24 Sep 2017 00:29:52 +0200 Subject: [PATCH] up to x50 --- asm/battle_2.s | 20 +- asm/battle_4.s | 1130 +--------------------------------- asm/pokemon_item_effect.s | 2 +- asm/rom3.s | 30 +- include/battle.h | 21 +- include/battle_controllers.h | 4 + include/pokemon.h | 3 + src/battle_3.c | 2 - src/battle_4.c | 368 +++++++++++ src/pokemon_3.c | 4 +- 10 files changed, 422 insertions(+), 1162 deletions(-) diff --git a/asm/battle_2.s b/asm/battle_2.s index 61ee83101..cc387f1a8 100644 --- a/asm/battle_2.s +++ b/asm/battle_2.s @@ -6678,8 +6678,8 @@ _0803A1E4: .pool thumb_func_end sub_8039F40 - thumb_func_start sub_803A284 -sub_803A284: @ 803A284 + thumb_func_start SwitchInClearStructs +SwitchInClearStructs: @ 803A284 push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -7254,7 +7254,7 @@ _0803A6B4: pop {r0} bx r0 .pool - thumb_func_end sub_803A284 + thumb_func_end SwitchInClearStructs thumb_func_start UndoEffectsAfterFainting UndoEffectsAfterFainting: @ 803A75C @@ -7806,7 +7806,7 @@ _0803ABD4: movs r0, 0 movs r1, 0 movs r2, 0 - bl dp01_build_cmdbuf_x00_a_b_0 + bl EmitGetAttributes ldrb r0, [r4] bl MarkBufferBankForExecution ldrb r0, [r5] @@ -8947,7 +8947,7 @@ _0803B5B2: ldrb r1, [r0] movs r0, 0 movs r2, 0 - bl dp01_build_cmdbuf_x05_a_b_c + bl EmitSwitchInAnim ldrb r0, [r4] bl MarkBufferBankForExecution _0803B5D4: @@ -10488,7 +10488,7 @@ _0803C374: str r0, [sp] movs r0, 0 movs r2, 0x6 - bl dp01_build_cmdbuf_x16_a_b_c_ptr_d_e_f + bl EmitChoosePokemon b _0803C42E .pool _0803C3B0: @@ -10531,7 +10531,7 @@ _0803C3EE: movs r1, 0 _0803C400: movs r3, 0 - bl dp01_build_cmdbuf_x16_a_b_c_ptr_d_e_f + bl EmitChoosePokemon b _0803C42E .pool _0803C410: @@ -10548,7 +10548,7 @@ _0803C410: movs r1, 0 movs r2, 0x6 movs r3, 0 - bl dp01_build_cmdbuf_x16_a_b_c_ptr_d_e_f + bl EmitChoosePokemon _0803C42E: ldr r0, =gActiveBank ldrb r0, [r0] @@ -11287,14 +11287,14 @@ _0803CB3C: movs r0, 0 movs r1, 0 adds r2, r4, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg b _0803CB66 .pool _0803CB5C: movs r0, 0 movs r1, 0x1 adds r2, r4, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg _0803CB66: ldr r4, =gActiveBank _0803CB68: diff --git a/asm/battle_4.s b/asm/battle_4.s index c2654ad64..8c3a0ea7e 100644 --- a/asm/battle_4.s +++ b/asm/battle_4.s @@ -5,1108 +5,6 @@ .text - thumb_func_start atk4A_typecalc2 -atk4A_typecalc2: @ 804C5F4 - push {r4-r7,lr} - mov r7, r8 - push {r7} - movs r4, 0 - movs r5, 0 - 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, 0x2] - mov r8, r0 - ldr r2, =gBattleMons - ldr r3, =gBankTarget - ldrb r1, [r3] - movs r0, 0x58 - muls r0, r1 - adds r0, r2 - adds r0, 0x20 - ldrb r0, [r0] - mov r12, r2 - adds r7, r3, 0 - cmp r0, 0x1A - bne _0804C688 - mov r1, r8 - cmp r1, 0x4 - bne _0804C688 - ldr r3, =gLastUsedAbility - strb r0, [r3] - ldr r2, =gBattleMoveFlags - ldrb r0, [r2] - movs r1, 0x9 - orrs r0, r1 - strb r0, [r2] - ldr r1, =gUnknown_02024250 - ldrb r0, [r7] - lsls r0, 1 - adds r0, r1 - strh r4, [r0] - ldr r0, =gBattleCommunication - mov r2, r8 - strb r2, [r0, 0x6] - ldrb r0, [r7] - ldrb r1, [r3] - bl RecordAbilityBattle - b _0804C76A - .pool -_0804C678: - ldr r0, =gBattleMoveFlags - ldrb r1, [r0] - movs r2, 0x8 - orrs r1, r2 - strb r1, [r0] - b _0804C76A - .pool -_0804C688: - ldr r1, =gTypeEffectiveness - adds r0, r5, r1 - ldrb r0, [r0] - adds r6, r1, 0 - b _0804C74A - .pool -_0804C698: - adds r0, r5, r6 - ldrb r0, [r0] - cmp r0, r8 - bne _0804C744 - adds r2, r5, 0x1 - adds r3, r2, r6 - ldrb r1, [r7] - movs r0, 0x58 - muls r0, r1 - add r0, r12 - adds r0, 0x21 - ldrb r1, [r3] - adds r3, r2, 0 - ldrb r0, [r0] - cmp r1, r0 - bne _0804C6D6 - adds r0, r5, 0x2 - adds r0, r6 - ldrb r1, [r0] - cmp r1, 0 - beq _0804C678 - cmp r1, 0x5 - bne _0804C6CA - movs r0, 0x4 - orrs r4, r0 -_0804C6CA: - cmp r1, 0x14 - bne _0804C6D6 - movs r0, 0x2 - orrs r4, r0 - lsls r0, r4, 24 - lsrs r4, r0, 24 -_0804C6D6: - adds r2, r3, r6 - ldrb r1, [r7] - movs r0, 0x58 - muls r0, r1 - add r0, r12 - adds r1, r0, 0 - adds r1, 0x22 - ldrb r2, [r2] - ldrb r1, [r1] - cmp r2, r1 - bne _0804C744 - adds r0, 0x21 - ldrb r1, [r0] - cmp r1, r2 - beq _0804C6FE - adds r0, r5, 0x2 - adds r0, r6 - ldrb r0, [r0] - cmp r0, 0 - beq _0804C678 -_0804C6FE: - cmp r1, r2 - beq _0804C714 - adds r0, r5, 0x2 - adds r0, r6 - ldrb r0, [r0] - cmp r0, 0x5 - bne _0804C714 - movs r0, 0x4 - orrs r4, r0 - lsls r0, r4, 24 - lsrs r4, r0, 24 -_0804C714: - adds r2, r3, r6 - ldrb r1, [r7] - movs r0, 0x58 - muls r0, r1 - add r0, r12 - adds r1, r0, 0 - adds r1, 0x22 - ldrb r2, [r2] - ldrb r1, [r1] - cmp r2, r1 - bne _0804C744 - adds r0, 0x21 - ldrb r0, [r0] - cmp r0, r2 - beq _0804C744 - adds r0, r5, 0x2 - adds r0, r6 - ldrb r0, [r0] - cmp r0, 0x14 - bne _0804C744 - movs r0, 0x2 - orrs r4, r0 - lsls r0, r4, 24 - lsrs r4, r0, 24 -_0804C744: - adds r5, 0x3 - adds r0, r5, r6 - ldrb r0, [r0] -_0804C74A: - cmp r0, 0xFF - beq _0804C76A - cmp r0, 0xFE - bne _0804C698 - ldrb r1, [r7] - movs r0, 0x58 - muls r0, r1 - mov r1, r12 - adds r1, 0x50 - adds r0, r1 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 22 - ands r0, r1 - cmp r0, 0 - beq _0804C744 -_0804C76A: - ldr r2, =gBattleMons - ldr r0, =gBankTarget - mov r8, r0 - ldrb r1, [r0] - movs r0, 0x58 - muls r0, r1 - adds r0, r2 - adds r0, 0x20 - ldrb r6, [r0] - cmp r6, 0x19 - bne _0804C7E6 - movs r5, 0x29 - ands r5, r4 - cmp r5, 0 - bne _0804C7E6 - ldr r0, =gBankAttacker - ldrb r0, [r0] - ldr r7, =gCurrentMove - ldrh r1, [r7] - bl AttacksThisTurn - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0x2 - bne _0804C7E6 - adds r0, r4, 0 - ands r0, r1 - cmp r0, 0 - beq _0804C7AC - movs r0, 0x6 - ands r4, r0 - cmp r4, 0x6 - bne _0804C7E6 -_0804C7AC: - ldr r2, =gBattleMoves - ldrh r1, [r7] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r0, [r0, 0x1] - cmp r0, 0 - beq _0804C7E6 - ldr r3, =gLastUsedAbility - strb r6, [r3] - ldr r2, =gBattleMoveFlags - ldrb r0, [r2] - movs r1, 0x1 - orrs r0, r1 - strb r0, [r2] - ldr r1, =gUnknown_02024250 - mov r2, r8 - ldrb r0, [r2] - lsls r0, 1 - adds r0, r1 - strh r5, [r0] - ldr r1, =gBattleCommunication - movs r0, 0x3 - strb r0, [r1, 0x6] - ldrb r0, [r2] - ldrb r1, [r3] - bl RecordAbilityBattle -_0804C7E6: - ldr r0, =gBattleMoveFlags - ldrb r1, [r0] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _0804C804 - ldr r2, =gProtectStructs - ldr r0, =gBankAttacker - ldrb r1, [r0] - lsls r1, 4 - adds r1, r2 - ldrb r0, [r1, 0x1] - movs r2, 0x2 - orrs r0, r2 - strb r0, [r1, 0x1] -_0804C804: - ldr r1, =gBattlescriptCurrInstr - ldr r0, [r1] - adds r0, 0x1 - str r0, [r1] - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end atk4A_typecalc2 - - thumb_func_start atk4B_return_atk_to_ball -atk4B_return_atk_to_ball: @ 804C844 - push {r4,lr} - ldr r4, =gActiveBank - ldr r0, =gBankAttacker - ldrb r0, [r0] - strb r0, [r4] - ldr r2, =gHitMarker - ldr r1, =gBitTable - ldrb r0, [r4] - lsls r0, 2 - adds r0, r1 - ldr r1, [r0] - lsls r1, 28 - ldr r0, [r2] - ands r0, r1 - cmp r0, 0 - bne _0804C872 - movs r0, 0 - movs r1, 0 - bl dp01_build_cmdbuf_x06_a - ldrb r0, [r4] - bl MarkBufferBankForExecution -_0804C872: - ldr r1, =gBattlescriptCurrInstr - ldr r0, [r1] - adds r0, 0x1 - str r0, [r1] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end atk4B_return_atk_to_ball - - thumb_func_start atk4C_copy_poke_data -atk4C_copy_poke_data: @ 804C894 - push {r4,r5,lr} - ldr r0, =gBattleExecBuffer - ldr r0, [r0] - cmp r0, 0 - bne _0804C8E4 - ldr r5, =gBattlescriptCurrInstr - ldr r0, [r5] - ldrb r0, [r0, 0x1] - bl GetBattleBank - ldr r4, =gActiveBank - strb r0, [r4] - ldr r3, =gBattlePartyID - ldrb r0, [r4] - lsls r2, r0, 1 - adds r2, r3 - ldr r1, =gBattleStruct - ldr r1, [r1] - adds r0, r1 - adds r0, 0x5C - ldrb r0, [r0] - strh r0, [r2] - ldr r1, =gBitTable - ldrb r0, [r4] - lsls r0, 1 - adds r0, r3 - ldrh r0, [r0] - lsls r0, 2 - adds r0, r1 - ldrb r2, [r0] - movs r0, 0 - movs r1, 0 - bl dp01_build_cmdbuf_x00_a_b_0 - ldrb r0, [r4] - bl MarkBufferBankForExecution - ldr r0, [r5] - adds r0, 0x2 - str r0, [r5] -_0804C8E4: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end atk4C_copy_poke_data - - thumb_func_start atk4D_switch_data_update -atk4D_switch_data_update: @ 804C904 - push {r4-r7,lr} - sub sp, 0x58 - ldr r0, =gBattleExecBuffer - ldr r0, [r0] - cmp r0, 0 - beq _0804C912 - b _0804CAA4 -_0804C912: - ldr r0, =gBattlescriptCurrInstr - ldr r0, [r0] - ldrb r0, [r0, 0x1] - bl GetBattleBank - ldr r4, =gActiveBank - strb r0, [r4] - ldr r6, =gBattleMons - ldrb r0, [r4] - movs r5, 0x58 - adds r1, r0, 0 - muls r1, r5 - adds r1, r6 - mov r0, sp - movs r2, 0x58 - bl memcpy - ldrb r0, [r4] - muls r0, r5 - adds r3, r0, r6 - movs r2, 0 - ldr r5, =gBattleBufferB -_0804C93E: - adds r0, r3, r2 - ldrb r1, [r4] - lsls r1, 9 - adds r1, 0x4 - adds r1, r2, r1 - adds r1, r5 - ldrb r1, [r1] - strb r1, [r0] - adds r2, 0x1 - cmp r2, 0x57 - bls _0804C93E - ldr r4, =gBattleMons - ldr r6, =gActiveBank - ldrb r0, [r6] - movs r7, 0x58 - adds r2, r0, 0 - muls r2, r7 - adds r2, r4 - ldr r3, =gBaseStats - ldrh r1, [r2] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r0, r3 - ldrb r0, [r0, 0x6] - adds r2, 0x21 - strb r0, [r2] - ldrb r0, [r6] - adds r1, r0, 0 - muls r1, r7 - adds r1, r4 - ldrh r2, [r1] - lsls r0, r2, 3 - subs r0, r2 - lsls r0, 2 - adds r0, r3 - ldrb r0, [r0, 0x7] - adds r1, 0x22 - strb r0, [r1] - ldrb r0, [r6] - adds r1, r0, 0 - muls r1, r7 - adds r1, r4 - ldrh r0, [r1] - ldrb r1, [r1, 0x17] - lsrs r1, 7 - bl GetAbilityBySpecies - ldrb r1, [r6] - muls r1, r7 - adds r1, r4 - adds r1, 0x20 - strb r0, [r1] - ldrb r0, [r6] - bl GetBankSide - lsls r0, 24 - lsrs r2, r0, 24 - ldr r0, =gWishFutureKnock - adds r0, 0x29 - adds r0, r2, r0 - ldrb r1, [r0] - ldr r3, =gBitTable - ldr r2, =gBattlePartyID - ldrb r5, [r6] - lsls r0, r5, 1 - adds r0, r2 - ldrh r0, [r0] - lsls r0, 2 - adds r0, r3 - ldr r0, [r0] - ands r1, r0 - mov r12, r4 - cmp r1, 0 - beq _0804C9DE - adds r0, r5, 0 - muls r0, r7 - add r0, r12 - movs r1, 0 - strh r1, [r0, 0x2E] -_0804C9DE: - 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] - cmp r0, 0x7F - bne _0804CA26 - movs r2, 0 - adds r4, r6, 0 - movs r6, 0x58 - mov r5, r12 - adds r5, 0x18 - add r3, sp, 0x18 -_0804C9FE: - ldrb r0, [r4] - adds r1, r0, 0 - muls r1, r6 - adds r1, r2, r1 - adds r1, r5 - adds r0, r3, r2 - ldrb r0, [r0] - strb r0, [r1] - adds r2, 0x1 - cmp r2, 0x7 - ble _0804C9FE - ldr r0, =gActiveBank - ldrb r1, [r0] - movs r0, 0x58 - muls r0, r1 - mov r1, r12 - adds r1, 0x50 - adds r0, r1 - ldr r1, [sp, 0x50] - str r1, [r0] -_0804CA26: - bl sub_803A284 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 10 - ands r0, r1 - cmp r0, 0 - beq _0804CA78 - ldr r4, =gBattleMons - ldr r0, =gActiveBank - ldrb r3, [r0] - movs r0, 0x58 - adds r2, r3, 0 - muls r2, r0 - adds r1, r2, r4 - ldrh r0, [r1, 0x2C] - lsrs r0, 1 - ldrh r1, [r1, 0x28] - cmp r0, r1 - bcc _0804CA78 - cmp r1, 0 - beq _0804CA78 - adds r0, r4, 0 - adds r0, 0x4C - adds r0, r2, r0 - ldr r0, [r0] - movs r1, 0x7 - ands r0, r1 - cmp r0, 0 - bne _0804CA78 - ldr r0, =gBattleStruct - ldr r2, [r0] - adds r2, 0x92 - ldr r1, =gBitTable - lsls r0, r3, 2 - adds r0, r1 - ldr r0, [r0] - ldrb r1, [r2] - orrs r0, r1 - strb r0, [r2] -_0804CA78: - ldr r0, =gBattleScripting - ldr r3, =gActiveBank - ldrb r2, [r3] - strb r2, [r0, 0x17] - ldr r1, =gBattleTextBuff1 - movs r0, 0xFD - strb r0, [r1] - movs r0, 0x7 - strb r0, [r1, 0x1] - strb r2, [r1, 0x2] - ldr r2, =gBattlePartyID - ldrb r0, [r3] - lsls r0, 1 - adds r0, r2 - ldrh r0, [r0] - strb r0, [r1, 0x3] - movs r0, 0xFF - strb r0, [r1, 0x4] - ldr r1, =gBattlescriptCurrInstr - ldr r0, [r1] - adds r0, 0x2 - str r0, [r1] -_0804CAA4: - add sp, 0x58 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end atk4D_switch_data_update - - thumb_func_start atk4E_switchin_anim -atk4E_switchin_anim: @ 804CAE8 - push {r4-r6,lr} - ldr r0, =gBattleExecBuffer - ldr r0, [r0] - cmp r0, 0 - bne _0804CB86 - ldr r0, =gBattlescriptCurrInstr - ldr r0, [r0] - ldrb r0, [r0, 0x1] - bl GetBattleBank - ldr r6, =gActiveBank - strb r0, [r6] - ldrb r0, [r6] - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _0804CB3E - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - ldr r1, =0x063f0902 - ands r0, r1 - cmp r0, 0 - bne _0804CB3E - ldr r4, =gBattleMons - ldrb r0, [r6] - movs r5, 0x58 - muls r0, r5 - adds r0, r4 - ldrh r0, [r0] - bl SpeciesToNationalPokedexNum - lsls r0, 16 - lsrs r0, 16 - ldrb r1, [r6] - muls r1, r5 - adds r4, 0x48 - adds r1, r4 - ldr r2, [r1] - movs r1, 0x2 - bl HandleSetPokedexFlag -_0804CB3E: - ldr r2, =gAbsentBankFlags - ldr r1, =gBitTable - ldr r5, =gActiveBank - ldrb r0, [r5] - lsls r0, 2 - adds r0, r1 - ldr r1, [r0] - ldrb r0, [r2] - bics r0, r1 - strb r0, [r2] - ldr r1, =gBattlePartyID - ldrb r0, [r5] - lsls r0, 1 - adds r0, r1 - ldrb r1, [r0] - ldr r4, =gBattlescriptCurrInstr - ldr r0, [r4] - ldrb r2, [r0, 0x2] - movs r0, 0 - bl dp01_build_cmdbuf_x05_a_b_c - ldrb r0, [r5] - bl MarkBufferBankForExecution - ldr r0, [r4] - adds r0, 0x3 - str r0, [r4] - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 11 - ands r0, r1 - cmp r0, 0 - beq _0804CB86 - bl sub_81A56B4 -_0804CB86: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end atk4E_switchin_anim - - thumb_func_start atk4F_jump_if_cannot_switch -atk4F_jump_if_cannot_switch: @ 804CBB0 - push {r4-r7,lr} - mov r7, r8 - push {r7} - ldr r4, =gBattlescriptCurrInstr - ldr r0, [r4] - ldrb r1, [r0, 0x1] - movs r0, 0x7F - ands r0, r1 - bl GetBattleBank - ldr r3, =gActiveBank - strb r0, [r3] - ldr r2, [r4] - ldrb r1, [r2, 0x1] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _0804CC28 - ldr r1, =gBattleMons - ldrb r3, [r3] - movs r0, 0x58 - muls r0, r3 - adds r1, 0x50 - adds r0, r1 - ldr r0, [r0] - ldr r1, =0x0400e000 - ands r0, r1 - cmp r0, 0 - bne _0804CBFC - ldr r1, =gStatuses3 - lsls r0, r3, 2 - adds r0, r1 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 3 - ands r0, r1 - cmp r0, 0 - beq _0804CC28 -_0804CBFC: - ldrb r1, [r2, 0x2] - ldrb r0, [r2, 0x3] - lsls r0, 8 - orrs r1, r0 - ldrb r0, [r2, 0x4] - lsls r0, 16 - orrs r1, r0 - ldrb r0, [r2, 0x5] - lsls r0, 24 - orrs r1, r0 - str r1, [r4] - b _0804CF00 - .pool -_0804CC28: - ldr r0, =gBattleTypeFlags - ldr r1, [r0] - movs r0, 0x80 - lsls r0, 15 - ands r0, r1 - cmp r0, 0 - beq _0804CCC0 - ldr r5, =gActiveBank - ldrb r0, [r5] - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gPlayerParty - mov r8, r1 - cmp r0, 0x1 - bne _0804CC4E - ldr r0, =gEnemyParty - mov r8, r0 -_0804CC4E: - movs r4, 0 - ldrb r1, [r5] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0804CC5C - movs r4, 0x3 -_0804CC5C: - adds r6, r4, 0x3 - cmp r4, r6 - bge _0804CCA4 - ldr r7, =gBattlePartyID -_0804CC64: - movs r0, 0x64 - muls r0, r4 - mov r1, r8 - adds r5, r1, r0 - adds r0, r5, 0 - movs r1, 0xB - bl GetMonData - cmp r0, 0 - beq _0804CC9E - adds r0, r5, 0 - movs r1, 0x2D - bl GetMonData - cmp r0, 0 - bne _0804CC9E - adds r0, r5, 0 - movs r1, 0x39 - bl GetMonData - cmp r0, 0 - beq _0804CC9E - ldr r0, =gActiveBank - ldrb r0, [r0] - lsls r0, 1 - adds r0, r7 - ldrh r0, [r0] - cmp r0, r4 - bne _0804CCA4 -_0804CC9E: - adds r4, 0x1 - cmp r4, r6 - blt _0804CC64 -_0804CCA4: - cmp r4, r6 - bne _0804CCAA - b _0804CED0 -_0804CCAA: - b _0804CEF8 - .pool -_0804CCC0: - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - beq _0804CD8C - movs r0, 0x80 - lsls r0, 16 - ands r1, r0 - cmp r1, 0 - beq _0804CD00 - ldr r5, =gActiveBank - ldrb r0, [r5] - bl GetBankSide - lsls r0, 24 - cmp r0, 0 - bne _0804CCEC - ldr r0, =gPlayerParty - b _0804CD16 - .pool -_0804CCEC: - ldr r1, =gEnemyParty - mov r8, r1 - ldrb r0, [r5] - movs r4, 0x3 - cmp r0, 0x1 - bne _0804CD32 - movs r4, 0 - b _0804CD32 - .pool -_0804CD00: - ldr r5, =gActiveBank - ldrb r0, [r5] - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gPlayerParty - mov r8, r1 - cmp r0, 0x1 - bne _0804CD18 - ldr r0, =gEnemyParty -_0804CD16: - mov r8, r0 -_0804CD18: - movs r4, 0 - ldrb r0, [r5] - bl sub_806D864 - lsls r0, 24 - lsrs r0, 24 - bl sub_806D82C - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x1 - bne _0804CD32 - movs r4, 0x3 -_0804CD32: - adds r6, r4, 0x3 - cmp r4, r6 - bge _0804CCA4 - ldr r7, =gBattlePartyID -_0804CD3A: - movs r0, 0x64 - muls r0, r4 - mov r1, r8 - adds r5, r1, r0 - adds r0, r5, 0 - movs r1, 0xB - bl GetMonData - cmp r0, 0 - beq _0804CD74 - adds r0, r5, 0 - movs r1, 0x2D - bl GetMonData - cmp r0, 0 - bne _0804CD74 - adds r0, r5, 0 - movs r1, 0x39 - bl GetMonData - cmp r0, 0 - beq _0804CD74 - ldr r0, =gActiveBank - ldrb r0, [r0] - lsls r0, 1 - adds r0, r7 - ldrh r0, [r0] - cmp r0, r4 - bne _0804CCA4 -_0804CD74: - adds r4, 0x1 - cmp r4, r6 - blt _0804CD3A - b _0804CCA4 - .pool -_0804CD8C: - movs r0, 0x80 - lsls r0, 8 - ands r1, r0 - cmp r1, 0 - beq _0804CE10 - ldr r5, =gActiveBank - ldrb r0, [r5] - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _0804CE10 - ldr r0, =gEnemyParty - mov r8, r0 - movs r4, 0 - ldrb r0, [r5] - cmp r0, 0x3 - bne _0804CDB4 - movs r4, 0x3 -_0804CDB4: - adds r6, r4, 0x3 - cmp r4, r6 - blt _0804CDBC - b _0804CCA4 -_0804CDBC: - ldr r7, =gBattlePartyID -_0804CDBE: - movs r0, 0x64 - muls r0, r4 - mov r1, r8 - adds r5, r1, r0 - adds r0, r5, 0 - movs r1, 0xB - bl GetMonData - cmp r0, 0 - beq _0804CDFA - adds r0, r5, 0 - movs r1, 0x2D - bl GetMonData - cmp r0, 0 - bne _0804CDFA - adds r0, r5, 0 - movs r1, 0x39 - bl GetMonData - cmp r0, 0 - beq _0804CDFA - ldr r0, =gActiveBank - ldrb r0, [r0] - lsls r0, 1 - adds r0, r7 - ldrh r0, [r0] - cmp r0, r4 - beq _0804CDFA - b _0804CCA4 -_0804CDFA: - adds r4, 0x1 - cmp r4, r6 - blt _0804CDBE - b _0804CCA4 - .pool -_0804CE10: - ldr r0, =gActiveBank - ldrb r0, [r0] - bl GetBankSide - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x1 - bne _0804CE54 - movs r0, 0x1 - bl GetBankByPlayerAI - lsls r0, 24 - lsrs r7, r0, 24 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - ands r0, r4 - cmp r0, 0 - beq _0804CE48 - movs r0, 0x3 - bl GetBankByPlayerAI - lsls r0, 24 - lsrs r6, r0, 24 - b _0804CE4A - .pool -_0804CE48: - adds r6, r7, 0 -_0804CE4A: - ldr r0, =gEnemyParty - mov r8, r0 - b _0804CE82 - .pool -_0804CE54: - movs r0, 0 - bl GetBankByPlayerAI - lsls r0, 24 - lsrs r7, r0, 24 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - beq _0804CE7C - movs r0, 0x2 - bl GetBankByPlayerAI - lsls r0, 24 - lsrs r6, r0, 24 - b _0804CE7E - .pool -_0804CE7C: - adds r6, r7, 0 -_0804CE7E: - ldr r1, =gPlayerParty - mov r8, r1 -_0804CE82: - movs r4, 0 -_0804CE84: - movs r0, 0x64 - muls r0, r4 - mov r1, r8 - adds r5, r1, r0 - adds r0, r5, 0 - movs r1, 0x39 - bl GetMonData - cmp r0, 0 - beq _0804CEC6 - adds r0, r5, 0 - movs r1, 0xB - bl GetMonData - cmp r0, 0 - beq _0804CEC6 - adds r0, r5, 0 - movs r1, 0x2D - bl GetMonData - cmp r0, 0 - bne _0804CEC6 - ldr r1, =gBattlePartyID - lsls r0, r7, 1 - adds r0, r1 - ldrh r0, [r0] - cmp r4, r0 - beq _0804CEC6 - lsls r0, r6, 1 - adds r0, r1 - ldrh r0, [r0] - cmp r4, r0 - bne _0804CECC -_0804CEC6: - adds r4, 0x1 - cmp r4, 0x5 - ble _0804CE84 -_0804CECC: - cmp r4, 0x6 - bne _0804CEF8 -_0804CED0: - ldr r3, =gBattlescriptCurrInstr - ldr r2, [r3] - ldrb r1, [r2, 0x2] - ldrb r0, [r2, 0x3] - lsls r0, 8 - orrs r1, r0 - ldrb r0, [r2, 0x4] - lsls r0, 16 - orrs r1, r0 - ldrb r0, [r2, 0x5] - lsls r0, 24 - orrs r1, r0 - str r1, [r3] - b _0804CF00 - .pool -_0804CEF8: - ldr r1, =gBattlescriptCurrInstr - ldr r0, [r1] - adds r0, 0x6 - str r0, [r1] -_0804CF00: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end atk4F_jump_if_cannot_switch - - thumb_func_start sub_804CF10 -sub_804CF10: @ 804CF10 - push {r4,r5,lr} - sub sp, 0x4 - adds r2, r0, 0 - lsls r2, 24 - lsrs r2, 24 - ldr r5, =gActiveBank - ldrb r0, [r5] - ldr r4, =gBattleStruct - ldr r1, [r4] - adds r1, r0, r1 - adds r1, 0x58 - ldr r3, =gBattlePartyID - lsls r0, 1 - adds r0, r3 - ldrh r0, [r0] - strb r0, [r1] - ldrb r0, [r5] - ldr r1, [r4] - adds r0, r1 - adds r0, 0x5C - movs r1, 0x6 - strb r1, [r0] - ldr r1, [r4] - adds r1, 0x93 - ldr r3, =gBitTable - ldrb r0, [r5] - lsls r0, 2 - adds r0, r3 - ldr r3, [r0] - ldrb r0, [r1] - bics r0, r3 - strb r0, [r1] - ldrb r0, [r5] - lsls r1, r0, 1 - adds r1, r0 - adds r1, 0x60 - ldr r0, [r4] - adds r0, r1 - str r0, [sp] - movs r0, 0 - movs r1, 0x1 - movs r3, 0 - bl dp01_build_cmdbuf_x16_a_b_c_ptr_d_e_f - ldrb r0, [r5] - bl MarkBufferBankForExecution - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_804CF10 - thumb_func_start atk50_openpartyscreen atk50_openpartyscreen: @ 804CF88 push {r4-r7,lr} @@ -1192,7 +90,7 @@ _0804CFE2: movs r0, 0 movs r1, 0x2 movs r2, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg ldrb r0, [r4] bl MarkBufferBankForExecution b _0804D098 @@ -1225,7 +123,7 @@ _0804D088: movs r0, 0 movs r1, 0x2 movs r2, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg ldrb r0, [r4] bl MarkBufferBankForExecution _0804D098: @@ -1318,7 +216,7 @@ _0804D15C: movs r0, 0 movs r1, 0x2 movs r2, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg ldrb r0, [r4] bl MarkBufferBankForExecution movs r0, 0x1 @@ -1402,7 +300,7 @@ _0804D214: movs r0, 0 movs r1, 0x2 movs r2, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg ldrb r0, [r4] bl MarkBufferBankForExecution _0804D22E: @@ -1475,7 +373,7 @@ _0804D2CC: movs r0, 0 movs r1, 0x2 movs r2, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg ldrb r0, [r4] bl MarkBufferBankForExecution movs r0, 0x2 @@ -1561,7 +459,7 @@ _0804D388: movs r0, 0 movs r1, 0x2 movs r2, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg ldrb r0, [r4] bl MarkBufferBankForExecution _0804D3A2: @@ -1597,7 +495,7 @@ _0804D3E8: movs r0, 0 movs r1, 0x2 movs r2, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg ldr r0, =gActiveBank ldrb r0, [r0] bl MarkBufferBankForExecution @@ -1634,7 +532,7 @@ _0804D43C: movs r0, 0 movs r1, 0x2 movs r2, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg ldr r0, =gActiveBank ldrb r0, [r0] bl MarkBufferBankForExecution @@ -1964,7 +862,7 @@ _0804D6E0: movs r0, 0 adds r1, r5, 0 movs r3, 0 - bl dp01_build_cmdbuf_x16_a_b_c_ptr_d_e_f + bl EmitChoosePokemon ldrb r0, [r4] bl MarkBufferBankForExecution ldr r0, [r6] @@ -2003,7 +901,7 @@ _0804D77C: movs r0, 0 movs r1, 0x2 movs r2, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg ldrb r0, [r4] bl MarkBufferBankForExecution _0804D792: @@ -2045,7 +943,7 @@ _0804D7F4: movs r0, 0 movs r1, 0x2 movs r2, 0 - bl sub_8034464 + bl EmitLinkStandbyMsg ldrb r0, [r4] bl MarkBufferBankForExecution _0804D804: @@ -2825,7 +1723,7 @@ atk58_return_to_ball: @ 804DEB8 strb r0, [r4] movs r0, 0 movs r1, 0x1 - bl dp01_build_cmdbuf_x06_a + bl EmitReturnPokeToBall ldrb r0, [r4] bl MarkBufferBankForExecution ldr r0, [r5] @@ -3829,7 +2727,7 @@ _0804E794: movs r0, 0 movs r1, 0 movs r2, 0 - bl dp01_build_cmdbuf_x00_a_b_0 + bl EmitGetAttributes ldrb r0, [r6] bl MarkBufferBankForExecution ldrb r0, [r5] @@ -6202,7 +5100,7 @@ _0804FCA2: beq _0804FD70 movs r0, 0 movs r1, 0 - bl dp01_build_cmdbuf_x06_a + bl EmitReturnPokeToBall ldrb r0, [r4] bl MarkBufferBankForExecution b _0804FD70 diff --git a/asm/pokemon_item_effect.s b/asm/pokemon_item_effect.s index c798d7753..69895d5d0 100644 --- a/asm/pokemon_item_effect.s +++ b/asm/pokemon_item_effect.s @@ -1155,7 +1155,7 @@ _0806C6AE: movs r0, 0 movs r1, 0 movs r2, 0 - bl dp01_build_cmdbuf_x00_a_b_0 + bl EmitGetAttributes ldrb r0, [r4] bl MarkBufferBankForExecution strb r5, [r4] diff --git a/asm/rom3.s b/asm/rom3.s index f4a273d95..4ab819fa2 100644 --- a/asm/rom3.s +++ b/asm/rom3.s @@ -2134,8 +2134,8 @@ _0803389C: .pool thumb_func_end sub_803375C - thumb_func_start dp01_build_cmdbuf_x00_a_b_0 -dp01_build_cmdbuf_x00_a_b_0: @ 80338B4 + thumb_func_start EmitGetAttributes +EmitGetAttributes: @ 80338B4 push {r4,lr} adds r4, r1, 0 lsls r0, 24 @@ -2152,7 +2152,7 @@ dp01_build_cmdbuf_x00_a_b_0: @ 80338B4 pop {r0} bx r0 .pool - thumb_func_end dp01_build_cmdbuf_x00_a_b_0 + thumb_func_end EmitGetAttributes thumb_func_start dp01_build_cmdbuf_x01_a_b_0 dp01_build_cmdbuf_x01_a_b_0: @ 80338D8 @@ -2264,8 +2264,8 @@ dp01_build_cmdbuf_x04_4_4_4: @ 8033980 .pool thumb_func_end dp01_build_cmdbuf_x04_4_4_4 - thumb_func_start dp01_build_cmdbuf_x05_a_b_c -dp01_build_cmdbuf_x05_a_b_c: @ 80339A0 + thumb_func_start EmitSwitchInAnim +EmitSwitchInAnim: @ 80339A0 push {r4,lr} adds r4, r1, 0 lsls r0, 24 @@ -2282,10 +2282,10 @@ dp01_build_cmdbuf_x05_a_b_c: @ 80339A0 pop {r0} bx r0 .pool - thumb_func_end dp01_build_cmdbuf_x05_a_b_c + thumb_func_end EmitSwitchInAnim - thumb_func_start dp01_build_cmdbuf_x06_a -dp01_build_cmdbuf_x06_a: @ 80339C4 + thumb_func_start EmitReturnPokeToBall +EmitReturnPokeToBall: @ 80339C4 push {lr} adds r3, r1, 0 lsls r0, 24 @@ -2299,7 +2299,7 @@ dp01_build_cmdbuf_x06_a: @ 80339C4 pop {r0} bx r0 .pool - thumb_func_end dp01_build_cmdbuf_x06_a + thumb_func_end EmitReturnPokeToBall thumb_func_start dp01_build_cmdbuf_x07_7_7_7 dp01_build_cmdbuf_x07_7_7_7: @ 80339E4 @@ -2888,8 +2888,8 @@ _08033E7E: .pool thumb_func_end sub_8033E6C - thumb_func_start dp01_build_cmdbuf_x16_a_b_c_ptr_d_e_f -dp01_build_cmdbuf_x16_a_b_c_ptr_d_e_f: @ 8033EA0 + thumb_func_start EmitChoosePokemon +EmitChoosePokemon: @ 8033EA0 push {r4-r6,lr} ldr r6, [sp, 0x10] lsls r0, 24 @@ -2918,7 +2918,7 @@ _08033EBA: pop {r0} bx r0 .pool - thumb_func_end dp01_build_cmdbuf_x16_a_b_c_ptr_d_e_f + thumb_func_end EmitChoosePokemon thumb_func_start dp01_build_cmdbuf_x17_17_17_17 dp01_build_cmdbuf_x17_17_17_17: @ 8033EDC @@ -3684,8 +3684,8 @@ EmitBattleAnimation: @ 8034438 .pool thumb_func_end EmitBattleAnimation - thumb_func_start sub_8034464 -sub_8034464: @ 8034464 + thumb_func_start EmitLinkStandbyMsg +EmitLinkStandbyMsg: @ 8034464 push {r4,r5,lr} lsls r0, 24 lsrs r5, r0, 24 @@ -3716,7 +3716,7 @@ _08034490: pop {r0} bx r0 .pool - thumb_func_end sub_8034464 + thumb_func_end EmitLinkStandbyMsg thumb_func_start dp01_build_cmdbuf_x38_a dp01_build_cmdbuf_x38_a: @ 80344A8 diff --git a/include/battle.h b/include/battle.h index a6573934f..e71a23e28 100644 --- a/include/battle.h +++ b/include/battle.h @@ -561,23 +561,9 @@ struct BattleStruct u8 field_52; u8 sentInPokes; u8 field_54[4]; - u8 field_58; - u8 field_59; - u8 field_5A; - u8 field_5B; + u8 field_58[4]; u8 field_5C[4]; - u8 field_60; - u8 field_61; - u8 field_62; - u8 field_63; - u8 field_64; - u8 field_65; - u8 field_66; - u8 field_67; - u8 field_68; - u8 field_69; - u8 field_6A; - u8 field_6B; + u8 field_60[4][3]; u8 field_6C; u8 field_6D; u8 field_6E; @@ -792,6 +778,8 @@ extern struct BattleStruct* gBattleStruct; #define ATK48_BIT_x4 0x4 #define ATK48_LOWER_FAIL_CHECK 0x8 +#define ATK4F_DONT_CHECK_STATUSES 0x80 + #define GET_STAT_BUFF_ID(n)((n & 0xF)) // first four bits 0x1, 0x2, 0x4, 0x8 #define GET_STAT_BUFF_VALUE(n)((n & 0xF0) >> 4) // 0x10, 0x20, 0x40 #define STAT_BUFF_NEGATIVE 0x80 // 0x80, the sign bit @@ -840,6 +828,7 @@ void PrepareStringBattle(u16 stringId, u8 bank); u8 GetBattleBank(u8 caseId); void UndoEffectsAfterFainting(void); bool8 HasMoveFailed(u8 bank); +void SwitchInClearStructs(void); // battle_3 void BattleScriptPush(const u8* bsPtr); diff --git a/include/battle_controllers.h b/include/battle_controllers.h index 2ae6f002f..443ca5be1 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -11,6 +11,10 @@ void EmitFaintAnimation(u8 bufferId); void EmitExpUpdate(u8 bufferId, u8 partyId, u16 expPoints); void EmitBattleAnimation(u8 bufferId, u8 animationId, u16 argument); void EmitSpriteInvisibility(u8 bufferId, bool8 isInvisible); +void EmitReturnPokeToBall(u8 bufferId, u8 arg1); +void EmitGetAttributes(u8 bufferId, u8 arg1, u8 arg2); +void EmitSwitchInAnim(u8 bufferId, u8 partyId, bool8 dontClearSubstituteBit); +void EmitChoosePokemon(u8 bufferId, u8 caseId, u8 arg2, u8 abilityId, const u8* arg4); void MarkBufferBankForExecution(u8 bank); diff --git a/include/pokemon.h b/include/pokemon.h index 1049776e8..f629799e5 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -623,6 +623,9 @@ bool8 IsShinyOtIdPersonality(u32 otId, u32 personality); void MonGainEVs(struct Pokemon *mon, u16 defeatedSpecies); bool8 IsTradedMon(struct Pokemon *mon); +void HandleSetPokedexFlag(u16 nationalNum, u8 caseId, u32 personality); +s32 sub_806D864(u16 a1); +bool16 sub_806D82C(u8 id); #include "sprite.h" diff --git a/src/battle_3.c b/src/battle_3.c index 4453545d3..1b443118d 100644 --- a/src/battle_3.c +++ b/src/battle_3.c @@ -188,8 +188,6 @@ extern void SetMoveEffect(bool8 primary, u8 certainArg); extern bool8 UproarWakeUpCheck(u8 bank); extern void sub_803F9EC(); extern bool8 sub_80423F4(u8 bank, u8, u8); -extern u8 sub_806D864(u8); -extern u8 sub_806D82C(u8); extern u8 weather_get_current(void); extern void sub_803E08C(void); extern void bc_move_exec_returning(void); diff --git a/src/battle_4.c b/src/battle_4.c index f896cd806..db6d7fe53 100644 --- a/src/battle_4.c +++ b/src/battle_4.c @@ -17,6 +17,7 @@ #include "songs.h" #include "text.h" #include "sound.h" +#include "pokedex.h" // variables @@ -94,6 +95,7 @@ extern const u8* const gBattleScriptsForMoveEffects[]; // functions extern void sub_81A5718(u8 bank); // battle frontier 2 +extern void sub_81A56B4(void); // battle frontier 2 // BattleScripts extern const u8 BattleScript_MoveEnd[]; @@ -4912,3 +4914,369 @@ void atk49_moveend(void) gBattlescriptCurrInstr += 3; } +void atk4A_typecalc2(void) +{ + u8 flags = 0; + s32 i = 0; + u8 moveType = gBattleMoves[gCurrentMove].type; + + if (gBattleMons[gBankTarget].ability == ABILITY_LEVITATE && moveType == TYPE_GROUND) + { + gLastUsedAbility = gBattleMons[gBankTarget].ability; + gBattleMoveFlags |= (MOVESTATUS_MISSED | MOVESTATUS_NOTAFFECTED); + gUnknown_02024250[gBankTarget] = 0; + gBattleCommunication[6] = moveType; + RecordAbilityBattle(gBankTarget, gLastUsedAbility); + } + else + { + while (gTypeEffectiveness[i]!= TYPE_ENDTABLE) + { + if (gTypeEffectiveness[i] == TYPE_FORESIGHT) + { + if (gBattleMons[gBankTarget].status2 & STATUS2_FORESIGHT) + { + break; + } + else + { + i += 3; + continue; + } + } + + if (gTypeEffectiveness[i] == moveType) + { + // check type1 + if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type1) + { + if (gTypeEffectiveness[i + 2] == 0) + { + gBattleMoveFlags |= MOVESTATUS_NOTAFFECTED; + break; + } + if (gTypeEffectiveness[i + 2] == 5) + { + flags |= MOVESTATUS_NOTVERYEFFECTIVE; + } + if (gTypeEffectiveness[i + 2] == 20) + { + flags |= MOVESTATUS_SUPEREFFECTIVE; + } + } + // check type2 + if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type2) + { + if (gBattleMons[gBankTarget].type1 != gBattleMons[gBankTarget].type2 + && gTypeEffectiveness[i + 2] == 0) + { + gBattleMoveFlags |= MOVESTATUS_NOTAFFECTED; + break; + } + if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type2 + && gBattleMons[gBankTarget].type1 != gBattleMons[gBankTarget].type2 + && gTypeEffectiveness[i + 2] == 5) + { + flags |= MOVESTATUS_NOTVERYEFFECTIVE; + } + if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type2 + && gBattleMons[gBankTarget].type1 != gBattleMons[gBankTarget].type2 + && gTypeEffectiveness[i + 2] == 20) + { + flags |= MOVESTATUS_SUPEREFFECTIVE; + } + } + } + i += 3; + } + } + + if (gBattleMons[gBankTarget].ability == ABILITY_WONDER_GUARD + && !(flags & MOVESTATUS_NOEFFECT) + && AttacksThisTurn(gBankAttacker, gCurrentMove) == 2 + && (!(flags & MOVESTATUS_SUPEREFFECTIVE) || ((flags & (MOVESTATUS_SUPEREFFECTIVE | MOVESTATUS_NOTVERYEFFECTIVE)) == (MOVESTATUS_SUPEREFFECTIVE | MOVESTATUS_NOTVERYEFFECTIVE))) + && gBattleMoves[gCurrentMove].power) + { + gLastUsedAbility = ABILITY_WONDER_GUARD; + gBattleMoveFlags |= MOVESTATUS_MISSED; + gUnknown_02024250[gBankTarget] = 0; + gBattleCommunication[6] = 3; + RecordAbilityBattle(gBankTarget, gLastUsedAbility); + } + if (gBattleMoveFlags & MOVESTATUS_NOTAFFECTED) + gProtectStructs[gBankAttacker].notEffective = 1; + + gBattlescriptCurrInstr++; +} + +void atk4B_return_atk_to_ball(void) +{ + gActiveBank = gBankAttacker; + if (!(gHitMarker & HITMARKER_FAINTED(gActiveBank))) + { + EmitReturnPokeToBall(0, 0); + MarkBufferBankForExecution(gActiveBank); + } + gBattlescriptCurrInstr++; +} + +void atk4C_copy_poke_data(void) +{ + if (gBattleExecBuffer) + return; + + gActiveBank = GetBattleBank(BSScriptRead8(gBattlescriptCurrInstr + 1)); + + gBattlePartyID[gActiveBank] = *(gBattleStruct->field_5C + gActiveBank); + + EmitGetAttributes(0, 0, gBitTable[gBattlePartyID[gActiveBank]]); + MarkBufferBankForExecution(gActiveBank); + + gBattlescriptCurrInstr += 2; +} + +void atk4D_switch_data_update(void) +{ + struct BattlePokemon oldData; + s32 i; + u8 *monData; + + if (gBattleExecBuffer) + return; + + gActiveBank = GetBattleBank(BSScriptRead8(gBattlescriptCurrInstr + 1)); + oldData = gBattleMons[gActiveBank]; + monData = (u8*)(&gBattleMons[gActiveBank]); + + for (i = 0; i < sizeof(struct BattlePokemon); i++) + { + monData[i] = gBattleBufferB[gActiveBank][4 + i]; + } + + gBattleMons[gActiveBank].type1 = gBaseStats[gBattleMons[gActiveBank].species].type1; + gBattleMons[gActiveBank].type2 = gBaseStats[gBattleMons[gActiveBank].species].type2; + gBattleMons[gActiveBank].ability = GetAbilityBySpecies(gBattleMons[gActiveBank].species, gBattleMons[gActiveBank].altAbility); + + // check knocked off item + i = GetBankSide(gActiveBank); + if (gWishFutureKnock.knockedOffPokes[i] & gBitTable[gBattlePartyID[gActiveBank]]) + { + gBattleMons[gActiveBank].item = 0; + } + + if (gBattleMoves[gCurrentMove].effect == EFFECT_BATON_PASS) + { + for (i = 0; i < 8; i++) + { + gBattleMons[gActiveBank].statStages[i] = oldData.statStages[i]; + } + gBattleMons[gActiveBank].status2 = oldData.status2; + } + + SwitchInClearStructs(); + + if (gBattleTypeFlags & BATTLE_TYPE_PALACE && gBattleMons[gActiveBank].maxHP / 2 >= gBattleMons[gActiveBank].hp + && gBattleMons[gActiveBank].hp != 0 && !(gBattleMons[gActiveBank].status1 & STATUS_SLEEP)) + { + gBattleStruct->field_92 |= gBitTable[gActiveBank]; + } + + gBattleScripting.bank = gActiveBank; + gBattleTextBuff1[0] = PLACEHOLDER_BEGIN; + gBattleTextBuff1[1] = 7; + gBattleTextBuff1[2] = gActiveBank; + gBattleTextBuff1[3] = gBattlePartyID[gActiveBank]; + gBattleTextBuff1[4] = EOS; + + gBattlescriptCurrInstr += 2; +} + +void atk4E_switchin_anim(void) +{ + if (gBattleExecBuffer) + return; + + gActiveBank = GetBattleBank(BSScriptRead8(gBattlescriptCurrInstr + 1)); + + if (GetBankSide(gActiveBank) == SIDE_OPPONENT + && !(gBattleTypeFlags & (BATTLE_TYPE_LINK + | BATTLE_TYPE_EREADER_TRAINER + | BATTLE_TYPE_x2000000 + | BATTLE_TYPE_x4000000 + | BATTLE_TYPE_FRONTIER))) + HandleSetPokedexFlag(SpeciesToNationalPokedexNum(gBattleMons[gActiveBank].species), FLAG_SET_SEEN, gBattleMons[gActiveBank].personality); + + gAbsentBankFlags &= ~(gBitTable[gActiveBank]); + + EmitSwitchInAnim(0, gBattlePartyID[gActiveBank], gBattlescriptCurrInstr[2]); + MarkBufferBankForExecution(gActiveBank); + + gBattlescriptCurrInstr += 3; + + if (gBattleTypeFlags & BATTLE_TYPE_ARENA) + sub_81A56B4(); +} + +void atk4F_jump_if_cannot_switch(void) +{ + s32 val = 0; + s32 compareVar = 0; + struct Pokemon *party = NULL; + s32 r7 = 0; + + gActiveBank = GetBattleBank(gBattlescriptCurrInstr[1] & ~(ATK4F_DONT_CHECK_STATUSES)); + + if (!(gBattlescriptCurrInstr[1] & ATK4F_DONT_CHECK_STATUSES) + && ((gBattleMons[gActiveBank].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) + || (gStatuses3[gActiveBank] & STATUS3_ROOTED))) + { + gBattlescriptCurrInstr = BSScriptReadPtr(gBattlescriptCurrInstr + 2); + } + else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) + { + #ifndef NONMATCHING + asm("":::"r5"); + #endif // NONMATCHING + if (GetBankSide(gActiveBank) == SIDE_OPPONENT) + party = gEnemyParty; + else + party = gPlayerParty; + + val = 0; + if (2 & gActiveBank) + val = 3; + + for (compareVar = val + 3; val < compareVar; val++) + { + if (GetMonData(&party[val], MON_DATA_SPECIES) != SPECIES_NONE + && !GetMonData(&party[val], MON_DATA_IS_EGG) + && GetMonData(&party[val], MON_DATA_HP) != 0 + && gBattlePartyID[gActiveBank] != val) + break; + } + + if (val == compareVar) + gBattlescriptCurrInstr = BSScriptReadPtr(gBattlescriptCurrInstr + 2); + else + gBattlescriptCurrInstr += 6; + } + else if (gBattleTypeFlags & BATTLE_TYPE_MULTI) + { + if (gBattleTypeFlags & BATTLE_TYPE_x800000) + { + if (GetBankSide(gActiveBank) == SIDE_PLAYER) + { + party = gPlayerParty; + + val = 0; + if (sub_806D82C(sub_806D864(gActiveBank)) == TRUE) + val = 3; + } + else + { + party = gEnemyParty; + + if (gActiveBank == 1) + val = 0; + else + val = 3; + } + } + else + { + if (GetBankSide(gActiveBank) == SIDE_OPPONENT) + party = gEnemyParty; + else + party = gPlayerParty; + + + val = 0; + if (sub_806D82C(sub_806D864(gActiveBank)) == TRUE) + val = 3; + } + + for (compareVar = val + 3; val < compareVar; val++) + { + if (GetMonData(&party[val], MON_DATA_SPECIES) != SPECIES_NONE + && !GetMonData(&party[val], MON_DATA_IS_EGG) + && GetMonData(&party[val], MON_DATA_HP) != 0 + && gBattlePartyID[gActiveBank] != val) + break; + } + + if (val == compareVar) + gBattlescriptCurrInstr = BSScriptReadPtr(gBattlescriptCurrInstr + 2); + else + gBattlescriptCurrInstr += 6; + } + else if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && GetBankSide(gActiveBank) == SIDE_OPPONENT) + { + party = gEnemyParty; + + val = 0; + if (gActiveBank == 3) + val = 3; + + for (compareVar = val + 3; val < compareVar; val++) + { + if (GetMonData(&party[val], MON_DATA_SPECIES) != SPECIES_NONE + && !GetMonData(&party[val], MON_DATA_IS_EGG) + && GetMonData(&party[val], MON_DATA_HP) != 0 + && gBattlePartyID[gActiveBank] != val) + break; + } + + if (val == compareVar) + gBattlescriptCurrInstr = BSScriptReadPtr(gBattlescriptCurrInstr + 2); + else + gBattlescriptCurrInstr += 6; + } + else + { + if (GetBankSide(gActiveBank) == SIDE_OPPONENT) + { + r7 = GetBankByPlayerAI(1); + + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + compareVar = GetBankByPlayerAI(3); + else + compareVar = r7; + + party = gEnemyParty; + } + else + { + r7 = GetBankByPlayerAI(0); + + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + compareVar = GetBankByPlayerAI(2); + else + compareVar = r7; + + party = gPlayerParty; + } + for (val = 0; val < 6; val++) + { + if (GetMonData(&party[val], MON_DATA_HP) != 0 + && GetMonData(&party[val], MON_DATA_SPECIES) != SPECIES_NONE + && !GetMonData(&party[val], MON_DATA_IS_EGG) + && val != gBattlePartyID[r7] && val != gBattlePartyID[compareVar]) + break; + } + + if (val == 6) + gBattlescriptCurrInstr = BSScriptReadPtr(gBattlescriptCurrInstr + 2); + else + gBattlescriptCurrInstr += 6; + } +} + +void sub_804CF10(u8 arg0) +{ + *(gBattleStruct->field_58 + gActiveBank) = gBattlePartyID[gActiveBank]; + *(gBattleStruct->field_5C + gActiveBank) = 6; + gBattleStruct->field_93 &= ~(gBitTable[gActiveBank]); + + EmitChoosePokemon(0, 1, arg0, 0, gBattleStruct->field_60[gActiveBank]); + MarkBufferBankForExecution(gActiveBank); +} diff --git a/src/pokemon_3.c b/src/pokemon_3.c index 603732a34..2bc06c580 100644 --- a/src/pokemon_3.c +++ b/src/pokemon_3.c @@ -601,9 +601,9 @@ bool8 sub_806D7EC(void) return retVal; } -bool8 sub_806D82C(u8 id) +bool16 sub_806D82C(u8 id) { - bool8 retVal = FALSE; + bool16 retVal = FALSE; switch (gLinkPlayers[id].lp_field_18) { case 0: