From b3c788f2ca9e3d0ab6e43617ed7fedfe605bc249 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 19 Sep 2017 21:01:12 +0200 Subject: [PATCH] begin work on battle4, organize battle headers --- asm/battle_2.s | 20 +- asm/battle_4.s | 1177 +------------------------------ data/battle_scripts_1.s | 10 +- include/battle.h | 58 +- include/calculate_base_damage.h | 6 + src/battle_3.c | 27 +- src/battle_4.c | 423 ++++++++++- 7 files changed, 523 insertions(+), 1198 deletions(-) create mode 100644 include/calculate_base_damage.h diff --git a/asm/battle_2.s b/asm/battle_2.s index 502f2bab8..3e1d67f4c 100644 --- a/asm/battle_2.s +++ b/asm/battle_2.s @@ -8409,7 +8409,7 @@ bc_battle_begin_message: @ 803B120 strb r0, [r1] ldrb r1, [r1] movs r0, 0 - bl b_std_message + bl PrepareStringBattle ldr r1, =gBattleMainFunc ldr r0, =sub_803B180 str r0, [r1] @@ -8431,7 +8431,7 @@ bc_8013568: @ 803B158 str r0, [r1] movs r0, 0 movs r1, 0 - bl b_std_message + bl PrepareStringBattle _0803B170: pop {r0} bx r0 @@ -8473,7 +8473,7 @@ _0803B1BA: lsls r1, 24 lsrs r1, 24 movs r0, 0x1 - bl b_std_message + bl PrepareStringBattle ldr r1, =gBattleMainFunc ldr r0, =sub_803B25C str r0, [r1] @@ -8743,7 +8743,7 @@ _0803B3F6: lsls r1, 24 lsrs r1, 24 movs r0, 0x1 - bl b_std_message + bl PrepareStringBattle _0803B412: ldr r1, =gBattleMainFunc ldr r0, =sub_803B4C8 @@ -15698,8 +15698,8 @@ _0803F47A: bx r1 thumb_func_end get_battle_side_of_something - thumb_func_start sub_803F480 -sub_803F480: @ 803F480 + thumb_func_start PressurePPLose +PressurePPLose: @ 803F480 push {r4-r7,lr} sub sp, 0x4 lsls r0, 24 @@ -15795,7 +15795,7 @@ _0803F532: pop {r0} bx r0 .pool - thumb_func_end sub_803F480 + thumb_func_end PressurePPLose thumb_func_start sub_803F548 sub_803F548: @ 803F548 @@ -16300,8 +16300,8 @@ _0803F95E: bx r1 thumb_func_end sub_803F90C - thumb_func_start b_std_message -b_std_message: @ 803F964 + thumb_func_start PrepareStringBattle +PrepareStringBattle: @ 803F964 push {r4,lr} adds r2, r0, 0 lsls r2, 16 @@ -16317,7 +16317,7 @@ b_std_message: @ 803F964 pop {r0} bx r0 .pool - thumb_func_end b_std_message + thumb_func_end PrepareStringBattle thumb_func_start sub_803F988 sub_803F988: @ 803F988 diff --git a/asm/battle_4.s b/asm/battle_4.s index 075321c71..8300024e6 100644 --- a/asm/battle_4.s +++ b/asm/battle_4.s @@ -5,1149 +5,6 @@ .text - - thumb_func_start atk00_attackcanceler -atk00_attackcanceler: @ 8045FFC - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x4 - ldr r0, =gBattleOutcome - ldrb r0, [r0] - cmp r0, 0 - beq _08046020 - ldr r1, =gFightStateTracker - movs r0, 0xC - strb r0, [r1] - b _08046398 - .pool -_08046020: - ldr r2, =gBattleMons - ldr r0, =gBankAttacker - ldrb r1, [r0] - movs r0, 0x58 - muls r0, r1 - adds r0, r2 - ldrh r0, [r0, 0x28] - cmp r0, 0 - bne _08046064 - ldr r2, =gHitMarker - ldr r1, [r2] - movs r0, 0x80 - lsls r0, 2 - ands r0, r1 - cmp r0, 0 - bne _08046064 - movs r0, 0x80 - lsls r0, 12 - orrs r1, r0 - str r1, [r2] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082D8A4E - b _08046396 - .pool -_08046064: - bl AtkCanceller_UnableToUseMove - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0 - beq _08046072 - b _08046398 -_08046072: - ldr r0, =gBankTarget - ldrb r1, [r0] - str r2, [sp] - movs r0, 0x2 - movs r2, 0 - movs r3, 0 - bl AbilityBattleEffects - lsls r0, 24 - cmp r0, 0 - beq _0804608A - b _08046398 -_0804608A: - ldr r4, =gBattleMons - ldr r0, =gCurrMovePos - ldrb r1, [r0] - ldr r3, =gBankAttacker - ldrb r2, [r3] - movs r0, 0x58 - muls r2, r0 - adds r1, r2 - adds r0, r4, 0 - adds r0, 0x24 - adds r1, r0 - ldrb r0, [r1] - ldr r5, =gHitMarker - cmp r0, 0 - bne _08046108 - ldr r0, =gCurrentMove - ldrh r0, [r0] - cmp r0, 0xA5 - beq _08046108 - ldr r0, [r5] - ldr r1, =0x00800200 - ands r0, r1 - cmp r0, 0 - bne _08046108 - adds r0, r4, 0 - adds r0, 0x50 - adds r0, r2, r0 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 5 - ands r0, r1 - cmp r0, 0 - bne _08046108 - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DB07A - str r0, [r1] - ldr r2, =gBattleMoveFlags - ldrb r0, [r2] - movs r1, 0x1 - orrs r0, r1 - strb r0, [r2] - b _08046398 - .pool -_08046108: - ldr r0, [r5] - ldr r1, =0xff7fffff - ands r0, r1 - str r0, [r5] - movs r6, 0x80 - lsls r6, 18 - ands r0, r6 - cmp r0, 0 - bne _08046160 - ldrb r1, [r3] - movs r0, 0x58 - muls r0, r1 - adds r1, r4, 0 - adds r1, 0x50 - adds r0, r1 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 5 - ands r0, r1 - cmp r0, 0 - bne _08046160 - bl IsPokeDisobedient - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0 - beq _08046160 - cmp r2, 0x2 - bne _08046150 - ldr r0, [r5] - orrs r0, r6 - str r0, [r5] - b _08046398 - .pool -_08046150: - ldr r0, =gBattleMoveFlags - ldrb r1, [r0] - movs r2, 0x1 - orrs r1, r2 - strb r1, [r0] - b _08046398 - .pool -_08046160: - ldr r2, =gHitMarker - ldr r0, [r2] - movs r1, 0x80 - lsls r1, 18 - orrs r0, r1 - str r0, [r2] - ldr r2, =gProtectStructs - ldr r1, =gBankTarget - ldrb r3, [r1] - lsls r0, r3, 4 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 27 - mov r8, r1 - mov r9, r2 - cmp r0, 0 - bge _080461E8 - ldr r2, =gBattleMoves - ldr r0, =gCurrentMove - ldrh r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r1, [r0, 0x8] - movs r0, 0x4 - ands r0, r1 - cmp r0, 0 - beq _080461E8 - ldr r0, =gBankAttacker - ldrb r0, [r0] - ldr r2, =0x00000115 - adds r1, r3, 0 - bl sub_803F480 - mov r0, r8 - ldrb r1, [r0] - lsls r1, 4 - add r1, r9 - ldrb r2, [r1] - movs r0, 0x11 - negs r0, r0 - ands r0, r2 - strb r0, [r1] - bl b_movescr_stack_push_cursor - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DB194 - b _08046396 - .pool -_080461E8: - movs r2, 0 - ldr r0, =gNoOfAllBanks - ldrb r0, [r0] - cmp r2, r0 - bge _0804622A - ldr r6, =gProtectStructs - ldr r1, =gBattleMoves - mov r12, r1 - adds r5, r0, 0 - ldr r7, =gTurnOrder -_080461FC: - adds r4, r2, r7 - ldrb r3, [r4] - lsls r0, r3, 4 - adds r0, r6 - ldrb r0, [r0] - lsls r0, 26 - cmp r0, 0 - bge _08046224 - ldr r0, =gCurrentMove - ldrh r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - add r0, r12 - ldrb r1, [r0, 0x8] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _08046224 - b _08046350 -_08046224: - adds r2, 0x1 - cmp r2, r5 - blt _080461FC -_0804622A: - ldr r0, =gSpecialStatuses - mov r1, r8 - ldrb r2, [r1] - lsls r1, r2, 2 - adds r1, r2 - lsls r1, 2 - adds r1, r0 - ldrb r3, [r1] - lsls r0, r3, 30 - cmp r0, 0 - bge _08046288 - movs r0, 0x3 - negs r0, r0 - ands r0, r3 - strb r0, [r1] - ldr r4, =gLastUsedAbility - movs r0, 0x1F - strb r0, [r4] - bl b_movescr_stack_push_cursor - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DB53E - str r0, [r1] - mov r1, r8 - ldrb r0, [r1] - ldrb r1, [r4] - bl RecordAbilityBattle - b _08046398 - .pool -_08046288: - lsls r0, r2, 4 - add r0, r9 - ldrb r0, [r0] - lsls r0, 31 - cmp r0, 0 - bne _08046296 - b _08046390 -_08046296: - ldr r1, =gBattleMoves - ldr r2, =gCurrentMove - ldrh r3, [r2] - lsls r0, r3, 1 - adds r0, r3 - lsls r0, 2 - adds r0, r1 - ldrb r1, [r0, 0x8] - movs r0, 0x2 - ands r0, r1 - adds r4, r2, 0 - cmp r0, 0 - beq _08046390 - cmp r3, 0xAE - bne _080462D4 - ldr r2, =gBattleMons - ldr r0, =gBankAttacker - ldrb r1, [r0] - movs r0, 0x58 - muls r0, r1 - adds r1, r0, r2 - adds r0, r1, 0 - adds r0, 0x21 - ldrb r0, [r0] - cmp r0, 0x7 - beq _080462D4 - adds r0, r1, 0 - adds r0, 0x22 - ldrb r0, [r0] - cmp r0, 0x7 - bne _08046390 -_080462D4: - ldrh r0, [r4] - bl sub_8052F48 - lsls r0, 24 - cmp r0, 0 - beq _080462FA - ldr r1, =gBattleMons - ldr r0, =gBankAttacker - ldrb r2, [r0] - movs r0, 0x58 - muls r0, r2 - adds r1, 0x50 - adds r0, r1 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 5 - ands r0, r1 - cmp r0, 0 - beq _08046390 -_080462FA: - ldr r0, =gBankAttacker - ldrb r0, [r0] - bl CancelMultiTurnMoves - ldr r2, =gBattleMoveFlags - ldrb r0, [r2] - movs r1, 0x1 - orrs r0, r1 - strb r0, [r2] - ldr r1, =gUnknown_02024250 - ldr r3, =gBankTarget - ldrb r0, [r3] - lsls r0, 1 - adds r0, r1 - movs r2, 0 - strh r2, [r0] - ldr r1, =gUnknown_02024258 - ldrb r0, [r3] - lsls r0, 1 - adds r0, r1 - strh r2, [r0] - ldr r1, =gBattleCommunication - movs r0, 0x1 - strb r0, [r1, 0x6] - b _08046390 - .pool -_08046350: - ldr r0, =gBankAttacker - ldrb r0, [r0] - ldr r2, =0x00000121 - adds r1, r3, 0 - bl sub_803F480 - ldrb r1, [r4] - lsls r1, 4 - adds r1, r6 - ldrb r2, [r1] - movs r0, 0x21 - negs r0, r0 - ands r0, r2 - strb r0, [r1] - ldr r1, =gBattleScripting - ldrb r0, [r4] - strb r0, [r1, 0x17] - bl b_movescr_stack_push_cursor - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DB1AC - b _08046396 - .pool -_08046390: - ldr r1, =gBattlescriptCurrInstr - ldr r0, [r1] - adds r0, 0x1 -_08046396: - str r0, [r1] -_08046398: - add sp, 0x4 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end atk00_attackcanceler - - thumb_func_start mcmd_jump_if_move_not_executed -mcmd_jump_if_move_not_executed: @ 80463AC - push {r4-r6,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r0, 24 - lsls r1, 16 - lsrs r6, r1, 16 - ldr r1, =gBattlescriptCurrInstr - ldr r5, [r1] - adds r4, r5, r0 - ldr r0, =gBattleMoveFlags - ldrb r1, [r0] - movs r0, 0x29 - ands r0, r1 - cmp r0, 0 - beq _0804640C - ldr r1, =gUnknown_02024250 - ldr r3, =gBankTarget - ldrb r0, [r3] - lsls r0, 1 - adds r0, r1 - movs r2, 0 - strh r2, [r0] - ldr r1, =gUnknown_02024258 - ldrb r0, [r3] - lsls r0, 1 - adds r0, r1 - strh r2, [r0] - ldrb r4, [r5, 0x1] - ldrb r0, [r5, 0x2] - lsls r0, 8 - orrs r4, r0 - ldrb r0, [r5, 0x3] - lsls r0, 16 - orrs r4, r0 - ldrb r0, [r5, 0x4] - lsls r0, 24 - orrs r4, r0 - b _08046426 - .pool -_0804640C: - bl b_feature_update_destiny_bond - ldr r0, =gBankTarget - ldrb r1, [r0] - str r6, [sp] - movs r0, 0x3 - movs r2, 0 - movs r3, 0 - bl AbilityBattleEffects - lsls r0, 24 - cmp r0, 0 - bne _0804642A -_08046426: - ldr r0, =gBattlescriptCurrInstr - str r4, [r0] -_0804642A: - add sp, 0x4 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end mcmd_jump_if_move_not_executed - - thumb_func_start atk40_jump_if_move_affected_by_protect -atk40_jump_if_move_affected_by_protect: @ 804643C - push {lr} - ldr r1, =gProtectStructs - ldr r0, =gBankTarget - ldrb r0, [r0] - lsls r0, 4 - adds r0, r1 - ldrb r0, [r0] - lsls r0, 31 - cmp r0, 0 - beq _0804649C - ldr r2, =gBattleMoves - ldr r0, =gCurrentMove - ldrh r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r1, [r0, 0x8] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0804649C - ldr r2, =gBattleMoveFlags - ldrb r0, [r2] - movs r1, 0x1 - orrs r0, r1 - strb r0, [r2] - movs r0, 0x5 - movs r1, 0 - bl mcmd_jump_if_move_not_executed - ldr r1, =gBattleCommunication - movs r0, 0x1 - strb r0, [r1, 0x6] - b _080464A4 - .pool -_0804649C: - ldr r1, =gBattlescriptCurrInstr - ldr r0, [r1] - adds r0, 0x5 - str r0, [r1] -_080464A4: - pop {r0} - bx r0 - .pool - thumb_func_end atk40_jump_if_move_affected_by_protect - - thumb_func_start sub_80464AC -sub_80464AC: @ 80464AC - push {r4,lr} - lsls r0, 16 - lsrs r3, r0, 16 - movs r4, 0 - ldr r1, =gProtectStructs - ldr r0, =gBankTarget - ldrb r0, [r0] - lsls r0, 4 - adds r0, r1 - ldrb r0, [r0] - lsls r0, 31 - cmp r0, 0 - beq _080464F8 - ldr r2, =gBattleMoves - ldr r0, =gCurrentMove - ldrh r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r1, [r0, 0x8] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _080464F8 - ldr r2, =gBattleMoveFlags - ldrb r0, [r2] - movs r1, 0x1 - orrs r0, r1 - strb r0, [r2] - movs r0, 0x7 - adds r1, r3, 0 - bl mcmd_jump_if_move_not_executed - ldr r1, =gBattleCommunication - movs r0, 0x1 - strb r0, [r1, 0x6] - movs r4, 0x1 -_080464F8: - adds r0, r4, 0 - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end sub_80464AC - - thumb_func_start sub_8046518 -sub_8046518: @ 8046518 - push {r4-r6,lr} - sub sp, 0x4 - lsls r0, 16 - lsrs r5, r0, 16 - ldr r2, =gStatuses3 - ldr r3, =gBankTarget - ldrb r4, [r3] - lsls r0, r4, 2 - adds r0, r2 - ldr r1, [r0] - movs r0, 0x18 - ands r1, r0 - adds r6, r2, 0 - cmp r1, 0 - beq _0804654A - ldr r1, =gDisableStructs - lsls r0, r4, 3 - subs r0, r4 - lsls r0, 2 - adds r0, r1 - ldr r1, =gBankAttacker - ldrb r0, [r0, 0x15] - ldrb r1, [r1] - cmp r0, r1 - beq _08046634 -_0804654A: - ldr r0, =gHitMarker - ldr r1, [r0] - movs r2, 0x80 - lsls r2, 9 - ands r1, r2 - adds r2, r0, 0 - cmp r1, 0 - bne _08046590 - ldrb r0, [r3] - lsls r0, 2 - adds r0, r6 - ldr r0, [r0] - movs r1, 0x40 - ands r0, r1 - cmp r0, 0 - beq _08046590 -_0804656A: - ldr r0, =gBattleMoveFlags - ldrb r1, [r0] - movs r2, 0x1 - orrs r1, r2 - strb r1, [r0] - b _08046634 - .pool -_08046590: - ldr r0, [r2] - ldr r1, =0xfffeffff - ands r0, r1 - str r0, [r2] - movs r1, 0x80 - lsls r1, 10 - ands r0, r1 - cmp r0, 0 - bne _080465B2 - ldrb r0, [r3] - lsls r0, 2 - adds r0, r6 - ldr r0, [r0] - movs r1, 0x80 - ands r0, r1 - cmp r0, 0 - bne _0804656A -_080465B2: - ldr r0, [r2] - ldr r1, =0xfffdffff - ands r0, r1 - str r0, [r2] - movs r1, 0x80 - lsls r1, 11 - ands r0, r1 - cmp r0, 0 - bne _080465D2 - ldrb r0, [r3] - lsls r0, 2 - adds r0, r6 - ldr r0, [r0] - ands r0, r1 - cmp r0, 0 - bne _0804656A -_080465D2: - ldr r0, [r2] - ldr r1, =0xfffbffff - ands r0, r1 - str r0, [r2] - movs r0, 0 - str r0, [sp] - movs r0, 0x13 - movs r1, 0 - movs r2, 0xD - movs r3, 0 - bl AbilityBattleEffects - lsls r0, 24 - lsrs r0, 24 - lsls r4, r5, 1 - cmp r0, 0 - bne _08046622 - str r0, [sp] - movs r0, 0x13 - movs r1, 0 - movs r2, 0x4D - movs r3, 0 - bl AbilityBattleEffects - lsls r0, 24 - cmp r0, 0 - bne _08046622 - ldr r0, =gBattleWeather - ldrh r1, [r0] - movs r0, 0x7 - ands r0, r1 - cmp r0, 0 - beq _08046622 - ldr r0, =gBattleMoves - adds r1, r4, r5 - lsls r1, 2 - adds r1, r0 - ldrb r0, [r1] - cmp r0, 0x98 - beq _08046634 -_08046622: - ldr r1, =gBattleMoves - adds r0, r4, r5 - lsls r0, 2 - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0x11 - beq _08046634 - cmp r0, 0x4E - bne _08046654 -_08046634: - movs r0, 0x7 - adds r1, r5, 0 - bl mcmd_jump_if_move_not_executed - movs r0, 0x1 - b _08046656 - .pool -_08046654: - movs r0, 0 -_08046656: - add sp, 0x4 - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_8046518 - - thumb_func_start atk01_accuracycheck -atk01_accuracycheck: @ 8046660 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - ldr r0, =gBattlescriptCurrInstr - ldr r5, [r0] - ldrb r6, [r5, 0x5] - ldrb r1, [r5, 0x6] - lsls r1, 8 - orrs r6, r1 - adds r1, r6, 0x2 - lsls r1, 16 - lsrs r1, 16 - adds r7, r0, 0 - cmp r1, 0x1 - bhi _0804671C - ldr r2, =gStatuses3 - ldr r3, =gBankTarget - ldrb r4, [r3] - lsls r0, r4, 2 - adds r0, r2 - ldr r1, [r0] - movs r0, 0x18 - ands r1, r0 - cmp r1, 0 - beq _080466D0 - ldr r0, =0x0000ffff - cmp r6, r0 - bne _080466D0 - ldr r1, =gDisableStructs - lsls r0, r4, 3 - subs r0, r4 - lsls r0, 2 - adds r0, r1 - ldr r1, =gBankAttacker - ldrb r0, [r0, 0x15] - ldrb r1, [r1] - cmp r0, r1 - bne _080466D0 - adds r0, r5, 0x7 - str r0, [r7] - b _080469D2 - .pool -_080466D0: - ldrb r0, [r3] - lsls r0, 2 - adds r0, r2 - ldr r0, [r0] - ldr r1, =0x000400c0 - ands r0, r1 - cmp r0, 0 - beq _08046700 - ldr r2, [r7] - ldrb r1, [r2, 0x1] - ldrb r0, [r2, 0x2] - lsls r0, 8 - orrs r1, r0 - ldrb r0, [r2, 0x3] - lsls r0, 16 - orrs r1, r0 - ldrb r0, [r2, 0x4] - lsls r0, 24 - orrs r1, r0 - str r1, [r7] - b _080469D2 - .pool -_08046700: - movs r0, 0 - bl sub_80464AC - lsls r0, 24 - cmp r0, 0 - beq _0804670E - b _080469D2 -_0804670E: - ldr r1, =gBattlescriptCurrInstr - ldr r0, [r1] - adds r0, 0x7 - str r0, [r1] - b _080469D2 - .pool -_0804671C: - cmp r6, 0 - bne _08046724 - ldr r0, =gCurrentMove - ldrh r6, [r0] -_08046724: - ldr r0, =gBattleStruct - ldr r0, [r0] - ldrb r0, [r0, 0x13] - cmp r0, 0 - beq _08046744 - movs r1, 0x3F - mov r10, r1 - mov r2, r10 - ands r2, r0 - mov r10, r2 - b _08046752 - .pool -_08046744: - ldr r1, =gBattleMoves - lsls r0, r6, 1 - adds r0, r6 - lsls r0, 2 - adds r0, r1 - ldrb r0, [r0, 0x2] - mov r10, r0 -_08046752: - adds r0, r6, 0 - bl sub_80464AC - lsls r0, 24 - cmp r0, 0 - beq _08046760 - b _080469D2 -_08046760: - adds r0, r6, 0 - bl sub_8046518 - lsls r0, 24 - cmp r0, 0 - beq _0804676E - b _080469D2 -_0804676E: - ldr r3, =gBattleMons - ldr r0, =gBankTarget - ldrb r0, [r0] - movs r2, 0x58 - adds r4, r0, 0 - muls r4, r2 - adds r0, r3, 0 - adds r0, 0x50 - adds r0, r4, r0 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 22 - ands r0, r1 - cmp r0, 0 - beq _080467A8 - ldr r0, =gBankAttacker - ldrb r0, [r0] - muls r0, r2 - adds r0, r3 - ldrb r5, [r0, 0x1E] - b _080467BE - .pool -_080467A8: - ldr r0, =gBankAttacker - ldrb r0, [r0] - muls r0, r2 - adds r0, r3 - ldrb r0, [r0, 0x1E] - adds r0, 0x6 - adds r1, r4, r3 - ldrb r1, [r1, 0x1F] - subs r0, r1 - lsls r0, 24 - lsrs r5, r0, 24 -_080467BE: - lsls r0, r5, 24 - cmp r0, 0 - bge _080467C6 - movs r5, 0 -_080467C6: - lsls r0, r5, 24 - asrs r0, 24 - cmp r0, 0xC - ble _080467D0 - movs r5, 0xC -_080467D0: - ldr r1, =gBattleMoves - lsls r4, r6, 1 - adds r0, r4, r6 - lsls r0, 2 - adds r7, r0, r1 - ldrb r3, [r7, 0x3] - mov r8, r3 - movs r0, 0 - str r0, [sp] - movs r0, 0x13 - movs r1, 0 - movs r2, 0xD - movs r3, 0 - bl AbilityBattleEffects - lsls r0, 24 - lsrs r0, 24 - str r4, [sp, 0x4] - cmp r0, 0 - bne _08046822 - str r0, [sp] - movs r0, 0x13 - movs r1, 0 - movs r2, 0x4D - movs r3, 0 - bl AbilityBattleEffects - lsls r0, 24 - cmp r0, 0 - bne _08046822 - ldr r0, =gBattleWeather - ldrh r1, [r0] - movs r0, 0x60 - ands r0, r1 - cmp r0, 0 - beq _08046822 - ldrb r0, [r7] - cmp r0, 0x98 - bne _08046822 - movs r0, 0x32 - mov r8, r0 -_08046822: - ldr r1, =gAccuracyStageRatios - lsls r0, r5, 24 - asrs r0, 22 - adds r0, r1 - ldrb r1, [r0] - mov r4, r8 - muls r4, r1 - ldrb r1, [r0, 0x1] - adds r0, r4, 0 - bl __divsi3 - lsls r0, 16 - lsrs r4, r0, 16 - ldr r7, =gBattleMons - ldr r0, =gBankAttacker - ldrb r0, [r0] - movs r5, 0x58 - muls r0, r5 - adds r0, r7 - adds r0, 0x20 - ldrb r0, [r0] - cmp r0, 0xE - bne _08046860 - lsls r0, r4, 6 - adds r0, r4 - lsls r0, 1 - movs r1, 0x64 - bl __divsi3 - lsls r0, 16 - lsrs r4, r0, 16 -_08046860: - movs r0, 0 - str r0, [sp] - movs r0, 0x13 - movs r1, 0 - movs r2, 0xD - movs r3, 0 - bl AbilityBattleEffects - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0 - bne _080468B8 - str r0, [sp] - movs r0, 0x13 - movs r1, 0 - movs r2, 0x4D - movs r3, 0 - bl AbilityBattleEffects - lsls r0, 24 - cmp r0, 0 - bne _080468B8 - ldr r0, =gBankTarget - ldrb r0, [r0] - muls r0, r5 - adds r0, r7 - adds r0, 0x20 - ldrb r0, [r0] - cmp r0, 0x8 - bne _080468B8 - ldr r0, =gBattleWeather - ldrh r1, [r0] - movs r0, 0x18 - ands r0, r1 - cmp r0, 0 - beq _080468B8 - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 4 - movs r1, 0x64 - bl __divsi3 - lsls r0, 16 - lsrs r4, r0, 16 -_080468B8: - ldr r2, =gBattleMons - ldr r0, =gBankAttacker - ldrb r1, [r0] - movs r0, 0x58 - muls r0, r1 - adds r0, r2 - adds r0, 0x20 - ldrb r0, [r0] - mov r9, r2 - cmp r0, 0x37 - bne _080468E4 - mov r1, r10 - cmp r1, 0x8 - bhi _080468E4 - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 4 - movs r1, 0x64 - bl __divsi3 - lsls r0, 16 - lsrs r4, r0, 16 -_080468E4: - ldr r2, =gBankTarget - mov r8, r2 - ldrb r2, [r2] - movs r7, 0x58 - adds r0, r2, 0 - muls r0, r7 - mov r3, r9 - adds r1, r0, r3 - ldrh r0, [r1, 0x2E] - cmp r0, 0xAF - bne _08046928 - ldr r1, =gEnigmaBerries - lsls r0, r2, 3 - subs r0, r2 - lsls r0, 2 - adds r0, r1 - ldrb r5, [r0, 0x7] - ldrb r2, [r0, 0x1A] - b _08046944 - .pool -_08046928: - ldrh r0, [r1, 0x2E] - bl ItemId_GetHoldEffect - lsls r0, 24 - lsrs r5, r0, 24 - mov r1, r8 - ldrb r0, [r1] - muls r0, r7 - add r0, r9 - ldrh r0, [r0, 0x2E] - bl ItemId_GetHoldEffectParam - lsls r0, 24 - lsrs r2, r0, 24 -_08046944: - ldr r0, =gStringBank - ldr r1, =gBankTarget - ldrb r1, [r1] - strb r1, [r0] - cmp r5, 0x16 - bne _08046960 - movs r0, 0x64 - subs r0, r2 - muls r0, r4 - movs r1, 0x64 - bl __divsi3 - lsls r0, 16 - lsrs r4, r0, 16 -_08046960: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x64 - bl __umodsi3 - lsls r0, 16 - lsrs r0, 16 - adds r0, 0x1 - cmp r0, r4 - ble _080469CA - ldr r2, =gBattleMoveFlags - ldrb r0, [r2] - movs r1, 0x1 - orrs r0, r1 - strb r0, [r2] - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - beq _080469C0 - ldr r1, =gBattleMoves - ldr r2, [sp, 0x4] - adds r0, r2, r6 - lsls r0, 2 - adds r0, r1 - ldrb r0, [r0, 0x6] - cmp r0, 0x8 - beq _080469A2 - cmp r0, 0x20 - bne _080469C0 -_080469A2: - ldr r1, =gBattleCommunication - movs r0, 0x2 - b _080469C4 - .pool -_080469C0: - ldr r1, =gBattleCommunication - movs r0, 0 -_080469C4: - strb r0, [r1, 0x6] - bl b_wonderguard_and_levitate -_080469CA: - movs r0, 0x7 - adds r1, r6, 0 - bl mcmd_jump_if_move_not_executed -_080469D2: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end atk01_accuracycheck - - thumb_func_start atk02_attackstring -atk02_attackstring: @ 80469E8 - push {r4,r5,lr} - ldr r0, =gBattleExecBuffer - ldr r5, [r0] - cmp r5, 0 - bne _08046A20 - ldr r4, =gHitMarker - ldr r0, [r4] - movs r1, 0xC0 - lsls r1, 3 - ands r0, r1 - cmp r0, 0 - bne _08046A14 - ldr r0, =gBankAttacker - ldrb r1, [r0] - movs r0, 0x4 - bl b_std_message - ldr r0, [r4] - movs r1, 0x80 - lsls r1, 3 - orrs r0, r1 - str r0, [r4] -_08046A14: - ldr r0, =gBattlescriptCurrInstr - ldr r1, [r0] - adds r1, 0x1 - str r1, [r0] - ldr r0, =gBattleCommunication - strb r5, [r0, 0x7] -_08046A20: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end atk02_attackstring thumb_func_start atk03_ppreduce atk03_ppreduce: @ 8046A3C @@ -3519,7 +2376,7 @@ atk0B_healthbarupdate: @ 8047DE8 bne _08047E68 movs r0, 0x80 adds r1, r2, 0 - bl b_std_message + bl PrepareStringBattle b _08047EA2 .pool _08047E68: @@ -4022,7 +2879,7 @@ atk0D_critmessage: @ 80482BC ldr r0, =gBankAttacker ldrb r1, [r0] movs r0, 0xD9 - bl b_std_message + bl PrepareStringBattle ldr r1, =gBattleCommunication movs r0, 0x1 strb r0, [r1, 0x7] @@ -4325,7 +3182,7 @@ _0804856E: adds r0, r3, 0 ldr r1, =gBankAttacker ldrb r1, [r1] - bl b_std_message + bl PrepareStringBattle _08048578: ldr r1, =gBattlescriptCurrInstr ldr r0, [r1] @@ -4354,7 +3211,7 @@ atk10_printstring: @ 8048590 orrs r0, r1 ldr r1, =gBankAttacker ldrb r1, [r1] - bl b_std_message + bl PrepareStringBattle ldr r0, [r4] adds r0, 0x3 str r0, [r4] @@ -4467,7 +3324,7 @@ atk13_printfromtable: @ 8048670 ldrh r0, [r1] ldr r1, =gBankAttacker ldrb r1, [r1] - bl b_std_message + bl PrepareStringBattle ldr r0, [r4] adds r0, 0x5 str r0, [r4] @@ -8175,7 +7032,7 @@ _0804A78E: mov r2, r8 ldrb r1, [r2] movs r0, 0xD - bl b_std_message + bl PrepareStringBattle ldr r0, [r6] ldrb r1, [r0, 0x10] movs r0, 0x64 @@ -14979,7 +13836,7 @@ _0804E224: ldr r0, =0x0000013f ldr r1, =gActiveBank ldrb r1, [r1] - bl b_std_message + bl PrepareStringBattle ldr r1, =gBattleScripting movs r0, 0x6 strb r0, [r1, 0x1F] @@ -19656,7 +18513,7 @@ _08050B48: cmp r0, 0x1 beq _08050B78 movs r0, 0 - bl sub_80464AC + bl JumpIfMoveAffectedByProtect lsls r0, 24 cmp r0, 0 beq _08050B78 @@ -23356,7 +22213,7 @@ atkA6_settypetorandomresistance: @ 8052B34 cmp r1, r0 beq _08052B7E ldrh r0, [r2] - bl sub_8052F48 + bl IsTwoTurnsMove lsls r0, 24 cmp r0, 0 beq _08052C1C @@ -23825,8 +22682,8 @@ _08052F32: .pool thumb_func_end atkA8_copymovepermanently - thumb_func_start sub_8052F48 -sub_8052F48: @ 8052F48 + thumb_func_start IsTwoTurnsMove +IsTwoTurnsMove: @ 8052F48 push {lr} lsls r0, 16 lsrs r0, 16 @@ -23857,7 +22714,7 @@ _08052F7C: _08052F7E: pop {r1} bx r1 - thumb_func_end sub_8052F48 + thumb_func_end IsTwoTurnsMove thumb_func_start sub_8052F84 sub_8052F84: @ 8052F84 @@ -23986,7 +22843,7 @@ _08053036: cmp r1, 0xFD beq _08053076 adds r0, r1, 0 - bl sub_8052F48 + bl IsTwoTurnsMove lsls r0, 24 cmp r0, 0 beq _08053084 @@ -24100,8 +22957,8 @@ atkAA_set_destinybond: @ 8053150 .pool thumb_func_end atkAA_set_destinybond - thumb_func_start b_feature_update_destiny_bond -b_feature_update_destiny_bond: @ 8053180 + thumb_func_start DestinyBondFlagUpdate +DestinyBondFlagUpdate: @ 8053180 push {r4,r5,lr} ldr r0, =gBankAttacker ldrb r0, [r0] @@ -24142,12 +22999,12 @@ _080531CA: pop {r0} bx r0 .pool - thumb_func_end b_feature_update_destiny_bond + thumb_func_end DestinyBondFlagUpdate thumb_func_start atkAB_DestinyBondFlagUpdate atkAB_DestinyBondFlagUpdate: @ 80531E0 push {lr} - bl b_feature_update_destiny_bond + bl DestinyBondFlagUpdate ldr r1, =gBattlescriptCurrInstr ldr r0, [r1] adds r0, 0x1 diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index ca599631c..b3dafed16 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -9,7 +9,7 @@ gUnknown_082D86A8:: @ 82D86A8 gUnknown_082D8A30:: @ 82D8A30 .incbin "baserom.gba", 0x2d8a30, 0x1e -gUnknown_082D8A4E:: @ 82D8A4E +BattleScript_MoveEnd:: @ 82D8A4E .incbin "baserom.gba", 0x2d8a4e, 0x12 gUnknown_082D8A60:: @ 82D8A60 @@ -198,7 +198,7 @@ BattleScript_NoMovesLeft:: @ 82DB072 gUnknown_082DB076:: @ 82DB076 .incbin "baserom.gba", 0x2db076, 0x4 -gUnknown_082DB07A:: @ 82DB07A +BattleScript_NoPPForMove:: @ 82DB07A .incbin "baserom.gba", 0x2db07a, 0xf gUnknown_082DB089:: @ 82DB089 @@ -240,10 +240,10 @@ gUnknown_082DB185:: @ 82DB185 gUnknown_082DB18D:: @ 82DB18D .incbin "baserom.gba", 0x2db18d, 0x7 -gUnknown_082DB194:: @ 82DB194 +BattleScript_MagicCoatBounce:: @ 82DB194 .incbin "baserom.gba", 0x2db194, 0x18 -gUnknown_082DB1AC:: @ 82DB1AC +BattleScript_SnatchedMove:: @ 82DB1AC .incbin "baserom.gba", 0x2db1ac, 0x1b gUnknown_082DB1C7:: @ 82DB1C7 @@ -360,7 +360,7 @@ gUnknown_082DB4C1:: @ 82DB4C1 BattleScript_DroughtActivates:: @ 82DB52A .incbin "baserom.gba", 0x2db52a, 0x14 -gUnknown_082DB53E:: @ 82DB53E +BattleScript_TookAttack:: @ 82DB53E .incbin "baserom.gba", 0x2db53e, 0x14 gUnknown_082DB552:: @ 82DB552 diff --git a/include/battle.h b/include/battle.h index 4093f55d1..b04b8db8f 100644 --- a/include/battle.h +++ b/include/battle.h @@ -204,10 +204,14 @@ #define MULTISTRING_CHOOSER 0x5 #define MSG_DISPLAY 0x7 -// functions - -extern u8 AbilityBattleEffects(u8 caseID, u8 bank, u8 ability, u8 special, u16 moveArg); -extern u8 GetBankSide(u8 bank); +#define MOVE_TARGET_SELECTED 0x0 +#define MOVE_TARGET_DEPENDS 0x1 +#define MOVE_TARGET_USER 0x2 +#define MOVE_TARGET_RANDOM 0x4 +#define MOVE_TARGET_x10 0x10 +#define MOVE_TARGET_BOTH 0x8 +#define MOVE_TARGET_FOES_AND_ALLY 0x20 +#define MOVE_TARGET_OPPONENTS_FIELD 0x40 struct Trainer { @@ -636,6 +640,14 @@ extern struct BattleStruct* gBattleStruct; var2[offsetof(struct structName, offsetField)] = value; \ } +#define GET_MOVE_TYPE(move, type) \ +{ \ + if (gBattleStruct->dynamicMoveType) \ + type = gBattleStruct->dynamicMoveType & 0x3F; \ + else \ + type = gBattleMoves[move].type; \ +} + struct BattleScripting { u8 field_0; @@ -666,6 +678,44 @@ struct BattleScripting extern struct BattleScripting gBattleScripting; +// functions + +// battle_2 +void CancelMultiTurnMoves(u8 bank); +void PressurePPLose(u8 bankAtk, u8 bankDef, u16 move); +void PrepareStringBattle(u16 stringId, u8 bank); + +// battle_3 +void b_movescr_stack_push(const u8* bsPtr); +void b_movescr_stack_push_cursor(void); +u8 sub_803FB4C(void); // msg, can't select a move +u8 CheckMoveLimitations(u8 bank, u8 unusableMoves, u8 check); +bool8 AreAllMovesUnusable(void); +u8 IsImprisoned(u8 bank, u16 move); +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); +u8 AtkCanceller_UnableToUseMove(void); +bool8 sub_80423F4(u8 bank, u8 r1, u8 r2); +u8 CastformDataTypeChange(u8 bank); +u8 AbilityBattleEffects(u8 caseID, u8 bank, u8 ability, u8 special, u16 moveArg); +void b_call_bc_move_exec(const u8* BS_ptr); +void b_push_move_exec(const u8* BS_ptr); +u8 ItemBattleEffects(u8 caseID, u8 bank, bool8 moveTurn); +void sub_8045868(u8 bank); +void sub_80458B4(void); +u8 GetMoveTarget(u16 move, u8 useMoveTarget); +u8 IsPokeDisobedient(void); + +// rom_80A5C6C +u8 GetBankSide(u8 bank); +u8 GetBankIdentity(u8 bank); +u8 GetBankByPlayerAI(u8 bank); + +// Move this somewhere else + #include "sprite.h" struct BattleSpritesGfx diff --git a/include/calculate_base_damage.h b/include/calculate_base_damage.h new file mode 100644 index 000000000..e9146c188 --- /dev/null +++ b/include/calculate_base_damage.h @@ -0,0 +1,6 @@ +#ifndef GUARD_CALCULATE_BASE_DAMAGE_H +#define GUARD_CALCULATE_BASE_DAMAGE_H + +s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *defender, u32 move, u16 sideStatus, u16 powerOverride, u8 typeOverride, u8 bankAtk, u8 bankDef); + +#endif // GUARD_CALCULATE_BASE_DAMAGE_H diff --git a/src/battle_3.c b/src/battle_3.c index a2ddd1c2d..283305d6c 100644 --- a/src/battle_3.c +++ b/src/battle_3.c @@ -15,6 +15,7 @@ #include "battle_message.h" #include "battle_ai.h" #include "event_data.h" +#include "calculate_base_damage.h" extern const u8* gBattlescriptCurrInstr; extern const u8* gUnknown_02024220[BATTLE_BANKS_COUNT]; @@ -187,11 +188,8 @@ extern void SetMoveEffect(bool8 primary, u8 certainArg); extern bool8 UproarWakeUpCheck(u8 bank); extern void MarkBufferBankForExecution(u8 bank); extern u8 sub_803F90C(u8 bank); -extern u8 GetBankIdentity(u8); extern void sub_803F9EC(); extern bool8 sub_80423F4(u8 bank, u8, u8); -extern s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *defender, u32 move, u16 sideFlags, u16 powerOverride, u8 typeOverride, u8 bankAtk, u8 bankDef); -extern u8 GetBankByPlayerAI(u8); extern u8 sub_806D864(u8); extern u8 sub_806D82C(u8); extern u8 weather_get_current(void); @@ -199,11 +197,6 @@ extern void sub_803E08C(void); extern void bc_move_exec_returning(void); extern s8 GetFlavourRelationByPersonality(u32 personality, u8 flavor); -u8 IsImprisoned(u8 bank, u16 move); -u8 ItemBattleEffects(u8 caseID, u8 bank, bool8 moveTurn); -u8 GetMoveTarget(u16 move, u8 useMoveTarget); -void b_push_move_exec(const u8* BS_ptr); - void b_movescr_stack_push(const u8* bsPtr) { BATTLESCRIPTS_STACK->ptr[BATTLESCRIPTS_STACK->size++] = bsPtr; @@ -6237,7 +6230,7 @@ u8 GetMoveTarget(u16 move, u8 useMoveTarget) switch (moveTarget) { - case 0: + case MOVE_TARGET_SELECTED: side = GetBankSide(gBankAttacker) ^ 1; if (gSideTimers[side].followmeTimer && gBattleMons[gSideTimers[side].followmeTarget].hp) targetBank = gSideTimers[side].followmeTarget; @@ -6258,19 +6251,19 @@ u8 GetMoveTarget(u16 move, u8 useMoveTarget) } } break; - case 1: - case 8: - case 32: - case 64: + case MOVE_TARGET_DEPENDS: + case MOVE_TARGET_BOTH: + case MOVE_TARGET_FOES_AND_ALLY: + case MOVE_TARGET_OPPONENTS_FIELD: targetBank = GetBankByPlayerAI((GetBankIdentity(gBankAttacker) & 1) ^ 1); if (gAbsentBankFlags & gBitTable[targetBank]) targetBank ^= 2; break; - case 4: + case MOVE_TARGET_RANDOM: side = GetBankSide(gBankAttacker) ^ 1; if (gSideTimers[side].followmeTimer && gBattleMons[gSideTimers[side].followmeTarget].hp) targetBank = gSideTimers[side].followmeTarget; - else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && moveTarget & 4) + else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && moveTarget & MOVE_TARGET_RANDOM) { if (GetBankSide(gBankAttacker) == SIDE_PLAYER) { @@ -6292,8 +6285,8 @@ u8 GetMoveTarget(u16 move, u8 useMoveTarget) else targetBank = GetBankByPlayerAI((GetBankIdentity(gBankAttacker) & 1) ^ 1); break; - case 2: - case 16: + case MOVE_TARGET_USER: + case MOVE_TARGET_x10: targetBank = gBankAttacker; break; } diff --git a/src/battle_4.c b/src/battle_4.c index 92561251f..e693162cc 100644 --- a/src/battle_4.c +++ b/src/battle_4.c @@ -1,11 +1,141 @@ #include "global.h" #include "battle.h" #include "battle_move_effects.h" +#include "battle_message.h" +#include "battle_ai.h" #include "moves.h" #include "abilities.h" #include "item.h" #include "items.h" #include "hold_effects.h" +#include "util.h" +#include "pokemon.h" +#include "calculate_base_damage.h" +#include "rng.h" + +// variables + +extern u8 gCritMultiplier; +extern s32 gBattleMoveDamage; +extern u32 gStatuses3[BATTLE_BANKS_COUNT]; +extern u32 gBattleTypeFlags; +extern struct BattleEnigmaBerry gEnigmaBerries[BATTLE_BANKS_COUNT]; +extern struct BattlePokemon gBattleMons[BATTLE_BANKS_COUNT]; +extern u8 gActiveBank; +extern u32 gBattleExecBuffer; +extern u8 gNoOfAllBanks; +extern u16 gBattlePartyID[BATTLE_BANKS_COUNT]; +extern u8 gTurnOrder[BATTLE_BANKS_COUNT]; +extern u8 gUnknown_02024A76[BATTLE_BANKS_COUNT]; +extern u16 gCurrentMove; +extern u8 gLastUsedAbility; +extern u16 gBattleWeather; +extern u8 gStringBank; +extern u8 gEffectBank; +extern u8 gAbsentBankFlags; +extern u8 gMultiHitCounter; +extern u16 gChosenMovesByBanks[BATTLE_BANKS_COUNT]; +extern u16 gSideAffecting[2]; +extern u16 gPauseCounterBattle; +extern u16 gPaydayMoney; +extern u16 gRandomTurnNumber; +extern u8 gBattleOutcome; +extern u8 gBattleTerrain; +extern u16 gTrainerBattleOpponent; +extern u8 gBankAttacker; +extern u8 gBankTarget; +extern const u8* gBattlescriptCurrInstr; +extern u8 gCurrMovePos; +extern u8 gFightStateTracker; +extern u32 gHitMarker; +extern u8 gBattleMoveFlags; +extern u8 gBattleCommunication[]; +extern u16 gUnknown_02024250[4]; +extern u16 gUnknown_02024258[4]; +extern u8 gStringBank; +extern u16 gDynamicBasePower; +extern u16 gLastUsedItem; +extern u16 gBattleMovePower; +extern s32 gHP_dealt; +extern s32 gTakenDmg[BATTLE_BANKS_COUNT]; +extern u8 gTakenDmgBanks[BATTLE_BANKS_COUNT]; +extern u8 gSentPokesToOpponent[2]; +extern u8 gBank1; +extern u16 gExpShareExp; +extern u8 gLeveledUpInBattle; +extern void (*gBattleMainFunc)(void); +extern u8 gPlayerPartyCount; +extern u16 gMoveToLearn; +extern u16 gRandomMove; +extern u8 gBankInMenu; +extern u8 gActionForBanks[4]; +extern u8 gCurrentMoveTurn; +extern u8 gBattleBufferB[4][0x200]; + +extern const struct BattleMove gBattleMoves[]; +extern const u16 gMissStrings[]; +extern const u8 gTrainerMoney[]; +extern const u8 gTypeEffectiveness[]; +extern const struct BaseStats gBaseStats[]; + +// functions + + +// BattleScripts +extern const u8 BattleScript_MoveEnd[]; +extern const u8 BattleScript_NoPPForMove[]; +extern const u8 BattleScript_MagicCoatBounce[]; +extern const u8 BattleScript_TookAttack[]; +extern const u8 BattleScript_SnatchedMove[]; +extern const u8 BattleScript_Pausex20[]; +extern const u8 BattleScript_SubstituteFade[]; +extern const u8 BattleScript_HangedOnMsg[]; +extern const u8 BattleScript_OneHitKOMsg[]; +extern const u8 BattleScript_EnduredMsg[]; +extern const u8 BattleScript_PSNPrevention[]; +extern const u8 BattleScript_BRNPrevention[]; +extern const u8 BattleScript_PRLZPrevention[]; +extern const u8 BattleScript_FlinchPrevention[]; +extern const u8 BattleScript_StatUp[]; +extern const u8 BattleScript_StatDown[]; +extern const u8 BattleScript_NoItemSteal[]; +extern const u8 BattleScript_ItemSteal[]; +extern const u8 BattleScript_RapidSpinAway[]; +extern const u8 BattleScript_TargetPRLZHeal[]; +extern const u8 BattleScript_KnockedOff[]; +extern const u8 BattleScript_LevelUp[]; +extern const u8 BattleScript_WrapFree[]; +extern const u8 BattleScript_LeechSeedFree[]; +extern const u8 BattleScript_SpikesFree[]; +extern const u8 BattleScript_ButItFailed[]; +extern const u8 BattleScript_ObliviousPreventsAttraction[]; +extern const u8 BattleScript_MistProtected[]; +extern const u8 BattleScript_AbilityNoStatLoss[]; +extern const u8 BattleScript_AbilityNoSpecificStatLoss[]; +extern const u8 BattleScript_TrainerBallBlock[]; +extern const u8 BattleScript_WallyBallThrow[]; +extern const u8 BattleScript_SuccessBallThrow[]; +extern const u8 BattleScript_ShakeBallThrow[]; + +// read via orr +#define BSScriptRead32(ptr) ((ptr)[0] | (ptr)[1] << 8 | (ptr)[2] << 16 | (ptr)[3] << 24) +#define BSScriptRead8(ptr) (((u8)((ptr)[0]))) +#define BSScriptReadPtr(ptr) ((void *)BSScriptRead32(ptr)) + +// read via add +#define BS2ScriptRead32(ptr) ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24)) +#define BS2ScriptRead16(ptr) ((ptr)[0] + ((ptr)[1] << 8)) +#define BS2ScriptReadPtr(ptr) ((void *)BS2ScriptRead32(ptr)) + +#define TARGET_PROTECT_AFFECTED ((gProtectStructs[gBankTarget].protected && gBattleMoves[gCurrentMove].flags & FLAG_PROTECT_AFFECTED)) + +#define TARGET_TURN_DAMAGED (((gSpecialStatuses[gBankTarget].moveturnLostHP_physical || gSpecialStatuses[gBankTarget].moveturnLostHP_physical.moveturnLostHP_special))) + +// this file's functions +bool8 IsTwoTurnsMove(u16 move); +void DestinyBondFlagUpdate(void); +u8 AttacksThisTurn(u8 bank, u16 move); // Note: returns 1 if it's a charging turn, otherwise 2. +void b_wonderguard_and_levitate(void); void atk00_attackcanceler(void); void atk01_accuracycheck(void); @@ -510,13 +640,13 @@ void (* const gBattleScriptingCommandsTable[])(void) = sub_8056EF8 }; -struct statFractions +struct StatFractions { u8 dividend; u8 divisor; }; -const struct statFractions gAccuracyStageRatios[] = +const struct StatFractions gAccuracyStageRatios[] = { { 33, 100}, // -6 { 36, 100}, // -5 @@ -599,3 +729,292 @@ const u32 gStatusFlagsForMoveEffects[] = 0x00000000, 0x00000000 }; + +void atk00_attackcanceler(void) +{ + s32 i; + + if (gBattleOutcome) + { + gFightStateTracker = 0xC; + return; + } + if (gBattleMons[gBankAttacker].hp == 0 && !(gHitMarker & HITMARKER_NO_ATTACKSTRING)) + { + gHitMarker |= HITMARKER_UNABLE_TO_USE_MOVE; + gBattlescriptCurrInstr = BattleScript_MoveEnd; + return; + } + if (AtkCanceller_UnableToUseMove()) + return; + if (AbilityBattleEffects(ABILITYEFFECT_MOVES_BLOCK, gBankTarget, 0, 0, 0)) + return; + if (!gBattleMons[gBankAttacker].pp[gCurrMovePos] && gCurrentMove != MOVE_STRUGGLE && !(gHitMarker & 0x800200) + && !(gBattleMons[gBankAttacker].status2 & STATUS2_MULTIPLETURNS)) + { + gBattlescriptCurrInstr = BattleScript_NoPPForMove; + gBattleMoveFlags |= MOVESTATUS_MISSED; + return; + } + + gHitMarker &= ~(HITMARKER_x800000); + + if (!(gHitMarker & HITMARKER_OBEYS) && !(gBattleMons[gBankAttacker].status2 & STATUS2_MULTIPLETURNS)) + { + i = IsPokeDisobedient(); // why use the 'i' variable...? + switch (i) + { + case 0: + break; + case 2: + gHitMarker |= HITMARKER_OBEYS; + return; + default: + gBattleMoveFlags |= MOVESTATUS_MISSED; + return; + } + } + + gHitMarker |= HITMARKER_OBEYS; + + if (gProtectStructs[gBankTarget].bounceMove && gBattleMoves[gCurrentMove].flags & FLAG_MAGICCOAT_AFFECTED) + { + PressurePPLose(gBankAttacker, gBankTarget, MOVE_MAGIC_COAT); + gProtectStructs[gBankTarget].bounceMove = 0; + b_movescr_stack_push_cursor(); + gBattlescriptCurrInstr = BattleScript_MagicCoatBounce; + return; + } + + for (i = 0; i < gNoOfAllBanks; i++) + { + if ((gProtectStructs[gTurnOrder[i]].stealMove) && gBattleMoves[gCurrentMove].flags & FLAG_SNATCH_AFFECTED) + { + PressurePPLose(gBankAttacker, gTurnOrder[i], MOVE_SNATCH); + gProtectStructs[gTurnOrder[i]].stealMove = 0; + gBattleScripting.bank = gTurnOrder[i]; + b_movescr_stack_push_cursor(); + gBattlescriptCurrInstr = BattleScript_SnatchedMove; + return; + } + } + + if (gSpecialStatuses[gBankTarget].lightningRodRedirected) + { + gSpecialStatuses[gBankTarget].lightningRodRedirected = 0; + gLastUsedAbility = ABILITY_LIGHTNING_ROD; + b_movescr_stack_push_cursor(); + gBattlescriptCurrInstr = BattleScript_TookAttack; + RecordAbilityBattle(gBankTarget, gLastUsedAbility); + } + else if (TARGET_PROTECT_AFFECTED + && (gCurrentMove != MOVE_CURSE || (gBattleMons[gBankAttacker].type1 == TYPE_GHOST || gBattleMons[gBankAttacker].type2 == TYPE_GHOST)) + && ((!IsTwoTurnsMove(gCurrentMove) || (gBattleMons[gBankAttacker].status2 & STATUS2_MULTIPLETURNS)))) + { + CancelMultiTurnMoves(gBankAttacker); + gBattleMoveFlags |= MOVESTATUS_MISSED; + gUnknown_02024250[gBankTarget] = 0; + gUnknown_02024258[gBankTarget] = 0; + gBattleCommunication[6] = 1; + gBattlescriptCurrInstr++; + } + else + { + gBattlescriptCurrInstr++; + } +} + +void JumpIfMoveFailed(u8 adder, u16 move) +{ + const void* BS_ptr = gBattlescriptCurrInstr + adder; + if (gBattleMoveFlags & MOVESTATUS_NOEFFECT) + { + gUnknown_02024250[gBankTarget] = 0; + gUnknown_02024258[gBankTarget] = 0; + BS_ptr = BSScriptReadPtr(gBattlescriptCurrInstr + 1); + } + else + { + DestinyBondFlagUpdate(); + if (AbilityBattleEffects(ABILITYEFFECT_ABSORBING, gBankTarget, 0, 0, move)) + return; + } + gBattlescriptCurrInstr = BS_ptr; +} + +void atk40_jump_if_move_affected_by_protect(void) +{ + if (TARGET_PROTECT_AFFECTED) + { + gBattleMoveFlags |= MOVESTATUS_MISSED; + JumpIfMoveFailed(5, 0); + gBattleCommunication[6] = 1; + } + else + { + gBattlescriptCurrInstr += 5; + } +} + +bool8 JumpIfMoveAffectedByProtect(u16 move) +{ + bool8 affected = FALSE; + if (TARGET_PROTECT_AFFECTED) + { + gBattleMoveFlags |= MOVESTATUS_MISSED; + JumpIfMoveFailed(7, move); + gBattleCommunication[6] = 1; + affected = TRUE; + } + return affected; +} + +bool8 AccuracyCalcHelper(u16 move) +{ + if (gStatuses3[gBankTarget] & STATUS3_ALWAYS_HITS && gDisableStructs[gBankTarget].bankWithSureHit == gBankAttacker) + { + JumpIfMoveFailed(7, move); + return TRUE; + } + + if (!(gHitMarker & HITMARKER_IGNORE_ON_AIR) && gStatuses3[gBankTarget] & STATUS3_ON_AIR) + { + gBattleMoveFlags |= MOVESTATUS_MISSED; + JumpIfMoveFailed(7, move); + return TRUE; + } + + gHitMarker &= ~HITMARKER_IGNORE_ON_AIR; + + if (!(gHitMarker & HITMARKER_IGNORE_UNDERGROUND) && gStatuses3[gBankTarget] & STATUS3_UNDERGROUND) + { + gBattleMoveFlags |= MOVESTATUS_MISSED; + JumpIfMoveFailed(7, move); + return TRUE; + } + + gHitMarker &= ~HITMARKER_IGNORE_UNDERGROUND; + + if (!(gHitMarker & HITMARKER_IGNORE_UNDERWATER) && gStatuses3[gBankTarget] & STATUS3_UNDERWATER) + { + gBattleMoveFlags |= MOVESTATUS_MISSED; + JumpIfMoveFailed(7, move); + return TRUE; + } + + gHitMarker &= ~HITMARKER_IGNORE_UNDERWATER; + + if ((WEATHER_HAS_EFFECT && (gBattleWeather & WEATHER_RAIN_ANY) && gBattleMoves[move].effect == EFFECT_THUNDER) + || (gBattleMoves[move].effect == EFFECT_ALWAYS_HIT || gBattleMoves[move].effect == EFFECT_VITAL_THROW)) + { + JumpIfMoveFailed(7, move); + return TRUE; + } + + return FALSE; +} + +void atk01_accuracycheck(void) +{ + u16 move = BS2ScriptRead16(gBattlescriptCurrInstr + 5); + + if (move == 0xFFFE || move == 0xFFFF) + { + if (gStatuses3[gBankTarget] & STATUS3_ALWAYS_HITS && move == 0xFFFF && gDisableStructs[gBankTarget].bankWithSureHit == gBankAttacker) + gBattlescriptCurrInstr += 7; + else if (gStatuses3[gBankTarget] & (STATUS3_ON_AIR | STATUS3_UNDERGROUND | STATUS3_UNDERWATER)) + gBattlescriptCurrInstr = BSScriptReadPtr(gBattlescriptCurrInstr + 1); + else if (!JumpIfMoveAffectedByProtect(0)) + gBattlescriptCurrInstr += 7; + } + else + { + u8 type, moveAcc, holdEffect, quality; + s8 buff; + u16 calc; + + if (move == 0) + move = gCurrentMove; + + GET_MOVE_TYPE(move, type); + + if (JumpIfMoveAffectedByProtect(move)) + return; + if (AccuracyCalcHelper(move)) + return; + + if (gBattleMons[gBankTarget].status2 & STATUS2_FORESIGHT) + { + u8 acc = gBattleMons[gBankAttacker].statStages[STAT_STAGE_ACC]; + buff = acc; + } + else + { + u8 acc = gBattleMons[gBankAttacker].statStages[STAT_STAGE_ACC]; + buff = acc + 6 - gBattleMons[gBankTarget].statStages[STAT_STAGE_EVASION]; + } + + if (buff < 0) + buff = 0; + if (buff > 0xC) + buff = 0xC; + + moveAcc = gBattleMoves[move].accuracy; + // check Thunder on sunny weather + if (WEATHER_HAS_EFFECT && gBattleWeather & WEATHER_SUN_ANY && gBattleMoves[move].effect == EFFECT_THUNDER) + moveAcc = 50; + + calc = gAccuracyStageRatios[buff].dividend * moveAcc; + calc /= gAccuracyStageRatios[buff].divisor; + + if (gBattleMons[gBankAttacker].ability == ABILITY_COMPOUND_EYES) + calc = (calc * 130) / 100; // 1.3 compound eyes boost + if (WEATHER_HAS_EFFECT && gBattleMons[gBankTarget].ability == ABILITY_SAND_VEIL && gBattleWeather & WEATHER_SANDSTORM_ANY) + calc = (calc * 80) / 100; // 1.2 sand veil loss + if (gBattleMons[gBankAttacker].ability == ABILITY_HUSTLE && type < 9) + calc = (calc * 80) / 100; // 1.2 hustle loss + + if (gBattleMons[gBankTarget].item == ITEM_ENIGMA_BERRY) + { + holdEffect = gEnigmaBerries[gBankTarget].holdEffect; + quality = gEnigmaBerries[gBankTarget].holdEffectParam; + } + else + { + holdEffect = ItemId_GetHoldEffect(gBattleMons[gBankTarget].item); + quality = ItemId_GetHoldEffectParam(gBattleMons[gBankTarget].item); + } + + gStringBank = gBankTarget; + + if (holdEffect == HOLD_EFFECT_EVASION_UP) + calc = (calc * (100 - quality)) / 100; + + // final calculation + if ((Random() % 100 + 1) > calc) + { + gBattleMoveFlags |= MOVESTATUS_MISSED; + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && + (gBattleMoves[move].target == MOVE_TARGET_BOTH || gBattleMoves[move].target == MOVE_TARGET_FOES_AND_ALLY)) + gBattleCommunication[6] = 2; + else + gBattleCommunication[6] = 0; + + b_wonderguard_and_levitate(); + } + JumpIfMoveFailed(7, move); + } +} + +void atk02_attackstring(void) +{ + if (gBattleExecBuffer) + return; + if (!(gHitMarker & (HITMARKER_NO_ATTACKSTRING | HITMARKER_ATTACKSTRING_PRINTED))) + { + PrepareStringBattle(4, gBankAttacker); + gHitMarker |= HITMARKER_ATTACKSTRING_PRINTED; + } + gBattlescriptCurrInstr++; + gBattleCommunication[MSG_DISPLAY] = 0; +}