diff --git a/asm/battle_2.s b/asm/battle_2.s deleted file mode 100644 index c0d8fd72a..000000000 --- a/asm/battle_2.s +++ /dev/null @@ -1,1422 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start sub_803EE48 -sub_803EE48: @ 803EE48 - push {r4-r6,lr} - ldr r4, =gBankAttacker - ldr r1, =gBanksByTurnOrder - ldr r5, =gCurrentTurnActionNumber - ldrb r0, [r5] - adds r0, r1 - ldrb r0, [r0] - strb r0, [r4] - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - ldr r1, =0x02000002 - ands r0, r1 - cmp r0, 0 - beq _0803EF0C - ldr r0, =gNoOfAllBanks - ldrb r1, [r0] - strb r1, [r5] - ldr r2, =gActiveBank - movs r0, 0 - strb r0, [r2] - lsls r1, 24 - cmp r1, 0 - beq _0803EEE0 - adds r4, r2, 0 - ldr r6, =gActionForBanks - ldr r5, =gBattleOutcome -_0803EE7C: - ldrb r0, [r4] - bl GetBankSide - lsls r0, 24 - cmp r0, 0 - bne _0803EEBC - ldrb r0, [r4] - adds r0, r6 - ldrb r0, [r0] - cmp r0, 0x3 - bne _0803EECE - ldrb r0, [r5] - movs r1, 0x2 - b _0803EECA - .pool -_0803EEBC: - ldrb r0, [r4] - adds r0, r6 - ldrb r0, [r0] - cmp r0, 0x3 - bne _0803EECE - ldrb r0, [r5] - movs r1, 0x1 -_0803EECA: - orrs r0, r1 - strb r0, [r5] -_0803EECE: - 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 _0803EE7C -_0803EEE0: - ldr r2, =gBattleOutcome - ldrb r0, [r2] - movs r1, 0x80 - orrs r0, r1 - strb r0, [r2] - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r0, =0x00000ca9 - adds r1, r0 - ldrb r0, [r1] - movs r2, 0x8 - orrs r0, r2 - b _0803EF96 - .pool -_0803EF0C: - ldrb r0, [r4] - bl GetBankSide - lsls r0, 24 - cmp r0, 0 - bne _0803EF4C - ldrb r0, [r4] - bl TryRunFromBattle - lsls r0, 24 - cmp r0, 0 - bne _0803EF98 - ldrb r0, [r4] - bl ClearFuryCutterDestinyBondGrudge - ldr r1, =gBattleCommunication - movs r0, 0x3 - strb r0, [r1, 0x5] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DAB02 - str r0, [r1] - ldr r1, =gCurrentActionFuncId - movs r0, 0xA - b _0803EF96 - .pool -_0803EF4C: - ldr r1, =gBattleMons - ldrb r2, [r4] - movs r0, 0x58 - muls r0, r2 - adds r1, 0x50 - adds r0, r1 - ldr r0, [r0] - ldr r1, =0x0400e000 - ands r0, r1 - cmp r0, 0 - beq _0803EF8C - ldr r1, =gBattleCommunication - movs r0, 0x4 - strb r0, [r1, 0x5] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DAB02 - str r0, [r1] - ldr r1, =gCurrentActionFuncId - movs r0, 0xA - b _0803EF96 - .pool -_0803EF8C: - ldr r0, =gNoOfAllBanks - ldrb r0, [r0] - strb r0, [r5] - ldr r1, =gBattleOutcome - movs r0, 0x6 -_0803EF96: - strb r0, [r1] -_0803EF98: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_803EE48 - - thumb_func_start sub_803EFA8 -sub_803EFA8: @ 803EFA8 - ldr r2, =gBankAttacker - ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentTurnActionNumber - ldrb r0, [r0] - adds r0, r1 - ldrb r0, [r0] - strb r0, [r2] - ldr r0, =gBattle_BG0_X - movs r1, 0 - strh r1, [r0] - ldr r0, =gBattle_BG0_Y - strh r1, [r0] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DBD58 - ldr r0, [r0] - str r0, [r1] - ldr r1, =gCurrentActionFuncId - movs r0, 0xA - strb r0, [r1] - bx lr - .pool - thumb_func_end sub_803EFA8 - - thumb_func_start bs5_8016AC0 -bs5_8016AC0: @ 803EFF0 - ldr r2, =gBankAttacker - ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentTurnActionNumber - ldrb r0, [r0] - adds r0, r1 - ldrb r0, [r0] - strb r0, [r2] - ldr r0, =gBattle_BG0_X - movs r1, 0 - strh r1, [r0] - ldr r0, =gBattle_BG0_Y - strh r1, [r0] - ldr r1, =gNumSafariBalls - ldrb r0, [r1] - subs r0, 0x1 - strb r0, [r1] - ldr r1, =gLastUsedItem - movs r0, 0x5 - strh r0, [r1] - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gBattlescriptsForBallThrow - ldr r0, [r0, 0x14] - str r0, [r1] - ldr r1, =gCurrentActionFuncId - movs r0, 0xA - strb r0, [r1] - bx lr - .pool - thumb_func_end bs5_8016AC0 - - thumb_func_start sub_803F050 -sub_803F050: @ 803F050 - push {r4-r6,lr} - ldr r3, =gBankAttacker - ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentTurnActionNumber - ldrb r0, [r0] - adds r0, r1 - ldrb r0, [r0] - strb r0, [r3] - ldr r0, =gBattle_BG0_X - movs r1, 0 - strh r1, [r0] - ldr r0, =gBattle_BG0_Y - strh r1, [r0] - ldr r6, =gBattleCommunication - ldr r2, =gBattleBufferB - ldrb r0, [r3] - lsls r0, 9 - adds r1, r2, 0x1 - adds r0, r1 - ldrb r0, [r0] - subs r0, 0x1 - strb r0, [r6, 0x5] - ldr r1, =gLastUsedItem - ldrb r0, [r3] - lsls r0, 9 - adds r2, 0x2 - adds r0, r2 - ldrb r0, [r0] - strh r0, [r1] - ldr r1, =gBattleResults - ldrb r0, [r1, 0x1F] - cmp r0, 0xFE - bhi _0803F096 - adds r0, 0x1 - strb r0, [r1, 0x1F] -_0803F096: - ldr r2, =gBattleStruct - ldr r0, [r2] - adds r1, r0, 0 - adds r1, 0x7A - ldrb r0, [r1] - cmp r0, 0x2 - bhi _0803F0A8 - adds r0, 0x1 - strb r0, [r1] -_0803F0A8: - ldr r0, [r2] - adds r3, r0, 0 - adds r3, 0x7B - ldrb r5, [r3] - adds r4, r5, 0 - cmp r4, 0x1 - bls _0803F100 - ldr r2, =gUnknown_0831BCE0 - adds r0, 0x7A - ldrb r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - ldrb r6, [r6, 0x5] - adds r0, r6 - adds r0, r2 - ldrb r0, [r0] - cmp r4, r0 - bcs _0803F0FC - movs r0, 0x1 - b _0803F0FE - .pool -_0803F0FC: - subs r0, r5, r0 -_0803F0FE: - strb r0, [r3] -_0803F100: - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DBD58 - ldr r0, [r0, 0x8] - str r0, [r1] - ldr r1, =gCurrentActionFuncId - movs r0, 0xA - strb r0, [r1] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_803F050 - - thumb_func_start sub_803F120 -sub_803F120: @ 803F120 - push {r4,lr} - ldr r2, =gBankAttacker - ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentTurnActionNumber - ldrb r0, [r0] - adds r0, r1 - ldrb r0, [r0] - strb r0, [r2] - ldr r0, =gBattle_BG0_X - movs r4, 0 - strh r4, [r0] - ldr r0, =gBattle_BG0_Y - strh r4, [r0] - ldr r3, =gBattleStruct - ldr r0, [r3] - adds r2, r0, 0 - adds r2, 0x7C - ldr r1, =gUnknown_0831BCEF - adds r0, 0x79 - ldrb r0, [r0] - adds r0, r1 - ldrb r0, [r0] - ldrb r1, [r2] - adds r0, r1 - strb r0, [r2] - ldr r0, [r3] - adds r1, r0, 0 - adds r1, 0x7C - ldrb r0, [r1] - cmp r0, 0x14 - bls _0803F162 - movs r0, 0x14 - strb r0, [r1] -_0803F162: - ldr r0, [r3] - adds r2, r0, 0 - adds r2, 0x7B - ldr r1, =gUnknown_0831BCF3 - adds r0, 0x79 - ldrb r0, [r0] - adds r0, r1 - ldrb r0, [r0] - ldrb r1, [r2] - adds r0, r1 - strb r0, [r2] - ldr r0, [r3] - adds r1, r0, 0 - adds r1, 0x7B - ldrb r0, [r1] - cmp r0, 0x14 - bls _0803F188 - movs r0, 0x14 - strb r0, [r1] -_0803F188: - ldr r0, [r3] - adds r1, r0, 0 - adds r1, 0x79 - ldrb r0, [r1] - cmp r0, 0x2 - bhi _0803F1C4 - adds r0, 0x1 - strb r0, [r1] - ldr r0, =gBattleCommunication - strb r4, [r0, 0x5] - b _0803F1CA - .pool -_0803F1C4: - ldr r1, =gBattleCommunication - movs r0, 0x1 - strb r0, [r1, 0x5] -_0803F1CA: - ldr r1, =gBattlescriptCurrInstr - ldr r0, =gUnknown_082DBD58 - ldr r0, [r0, 0x4] - str r0, [r1] - ldr r1, =gCurrentActionFuncId - movs r0, 0xA - strb r0, [r1] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_803F120 - - thumb_func_start bs8_exit_by_flight -bs8_exit_by_flight: @ 803F1F0 - push {r4,lr} - ldr r2, =gBankAttacker - ldr r1, =gBanksByTurnOrder - ldr r4, =gCurrentTurnActionNumber - ldrb r0, [r4] - adds r0, r1 - ldrb r0, [r0] - strb r0, [r2] - movs r0, 0x11 - bl PlaySE - ldr r0, =gNoOfAllBanks - ldrb r0, [r0] - strb r0, [r4] - ldr r1, =gBattleOutcome - movs r0, 0x4 - strb r0, [r1] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end bs8_exit_by_flight - - thumb_func_start bs9_8016C9C -bs9_8016C9C: @ 803F22C - ldr r3, =gBankAttacker - ldr r1, =gBanksByTurnOrder - ldr r0, =gCurrentTurnActionNumber - ldrb r0, [r0] - adds r0, r1 - ldrb r2, [r0] - strb r2, [r3] - ldr r0, =gBattle_BG0_X - movs r1, 0 - strh r1, [r0] - ldr r0, =gBattle_BG0_Y - strh r1, [r0] - 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, =gUnknown_082DBD58 - ldr r0, [r0, 0xC] - str r0, [r1] - ldr r1, =gCurrentActionFuncId - movs r0, 0xA - strb r0, [r1] - ldr r1, =gActionsByTurnOrder - movs r0, 0xC - strb r0, [r1, 0x1] - bx lr - .pool - thumb_func_end bs9_8016C9C - - thumb_func_start bsB_exit_by_move -bsB_exit_by_move: @ 803F2A4 - push {lr} - bl sub_8041728 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0 - bne _0803F2C0 - ldr r0, =gBattleStruct - ldr r0, [r0] - adds r0, 0x4D - strb r1, [r0] - ldr r1, =gCurrentActionFuncId - movs r0, 0xC - strb r0, [r1] -_0803F2C0: - pop {r0} - bx r0 - .pool - thumb_func_end bsB_exit_by_move - - thumb_func_start bsD_proceed -bsD_proceed: @ 803F2CC - ldr r1, =gCurrentTurnActionNumber - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - ldr r3, =gCurrentActionFuncId - ldr r2, =gActionsByTurnOrder - ldrb r0, [r1] - adds r0, r2 - ldrb r0, [r0] - strb r0, [r3] - ldr r2, =gHitMarker - ldr r0, [r2] - ldr r1, =0xf1e892af - ands r0, r1 - str r0, [r2] - bx lr - .pool - thumb_func_end bsD_proceed - - thumb_func_start bsC_8016D70 -bsC_8016D70: @ 803F300 - push {r4-r6,lr} - ldr r1, =gBanksByTurnOrder - ldr r2, =gCurrentTurnActionNumber - ldrb r0, [r2] - adds r0, r1 - ldrb r0, [r0] - ldr r6, =gBattleStruct - ldr r1, [r6] - adds r0, r1 - adds r0, 0x5C - movs r1, 0x6 - strb r1, [r0] - ldrb r0, [r2] - adds r0, 0x1 - strb r0, [r2] - ldr r3, =gCurrentActionFuncId - ldr r1, =gActionsByTurnOrder - ldrb r0, [r2] - adds r0, r1 - ldrb r0, [r0] - strb r0, [r3] - bl SpecialStatusesClear - ldr r2, =gHitMarker - ldr r0, [r2] - ldr r1, =0xf1e892af - ands r0, r1 - str r0, [r2] - ldr r0, =gCurrentMove - movs r1, 0 - strh r1, [r0] - ldr r0, =gBattleMoveDamage - movs r4, 0 - str r4, [r0] - ldr r0, =gBattleMoveFlags - strb r1, [r0] - ldr r5, =gBattleScripting - strb r1, [r5, 0x18] - strb r1, [r5, 0x19] - ldr r2, =gUnknown_02024250 - ldr r3, =gBankAttacker - ldrb r0, [r3] - lsls r0, 1 - adds r0, r2 - strh r4, [r0] - ldr r2, =gUnknown_02024258 - ldrb r0, [r3] - lsls r0, 1 - adds r0, r2 - strh r4, [r0] - ldr r0, [r6] - strb r1, [r0, 0x13] - ldr r0, =gDynamicBasePower - strh r4, [r0] - strb r1, [r5, 0x14] - ldr r0, =gBattleCommunication - strb r1, [r0, 0x3] - strb r1, [r0, 0x4] - strb r1, [r5, 0x16] - ldr r0, =gBattleResources - ldr r0, [r0] - ldr r0, [r0, 0x8] - adds r0, 0x20 - strb r1, [r0] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end bsC_8016D70 - - thumb_func_start GetBattleBank -GetBattleBank: @ 803F3CC - push {lr} - lsls r0, 24 - lsrs r1, r0, 24 - movs r0, 0 - cmp r1, 0xE - bhi _0803F47A - lsls r0, r1, 2 - ldr r1, =_0803F3E8 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0803F3E8: - .4byte _0803F424 - .4byte _0803F430 - .4byte _0803F43C - .4byte _0803F458 - .4byte _0803F464 - .4byte _0803F458 - .4byte _0803F464 - .4byte _0803F448 - .4byte _0803F464 - .4byte _0803F464 - .4byte _0803F44C - .4byte _0803F464 - .4byte _0803F468 - .4byte _0803F46C - .4byte _0803F470 -_0803F424: - ldr r0, =gBankTarget - ldrb r0, [r0] - b _0803F47A - .pool -_0803F430: - ldr r0, =gBankAttacker - ldrb r0, [r0] - b _0803F47A - .pool -_0803F43C: - ldr r0, =gEffectBank - ldrb r0, [r0] - b _0803F47A - .pool -_0803F448: - movs r0, 0 - b _0803F47A -_0803F44C: - ldr r0, =gBattleScripting - ldrb r0, [r0, 0x17] - b _0803F47A - .pool -_0803F458: - ldr r0, =gBank1 - ldrb r0, [r0] - b _0803F47A - .pool -_0803F464: - movs r0, 0 - b _0803F472 -_0803F468: - movs r0, 0x1 - b _0803F472 -_0803F46C: - movs r0, 0x2 - b _0803F472 -_0803F470: - movs r0, 0x3 -_0803F472: - bl GetBankByIdentity - lsls r0, 24 - lsrs r0, 24 -_0803F47A: - pop {r1} - bx r1 - thumb_func_end GetBattleBank - - thumb_func_start PressurePPLose -PressurePPLose: @ 803F480 - push {r4-r7,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r0, 24 - lsls r1, 24 - lsrs r5, r1, 24 - lsls r2, 16 - lsrs r2, 16 - ldr r1, =gBattleMons - movs r4, 0x58 - muls r0, r4 - adds r0, r1 - adds r0, 0x20 - ldrb r0, [r0] - mov r12, r1 - cmp r0, 0x2E - bne _0803F532 - movs r3, 0 - adds r0, r5, 0 - muls r0, r4 - adds r1, 0xC - adds r1, r0, r1 - b _0803F4BC - .pool -_0803F4B4: - adds r1, 0x2 - adds r3, 0x1 - cmp r3, 0x3 - bgt _0803F4C2 -_0803F4BC: - ldrh r0, [r1] - cmp r0, r2 - bne _0803F4B4 -_0803F4C2: - cmp r3, 0x4 - beq _0803F532 - movs r7, 0x58 - adds r2, r5, 0 - muls r2, r7 - adds r0, r3, r2 - mov r6, r12 - adds r6, 0x24 - adds r1, r0, r6 - ldrb r0, [r1] - cmp r0, 0 - beq _0803F4DE - subs r0, 0x1 - strb r0, [r1] -_0803F4DE: - mov r0, r12 - adds r0, 0x50 - adds r0, r2, r0 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 14 - ands r0, r1 - cmp r0, 0 - bne _0803F532 - ldr r1, =gDisableStructs - lsls r0, r5, 3 - subs r0, r5 - lsls r0, 2 - adds r0, r1 - ldrb r1, [r0, 0x18] - lsrs r1, 4 - ldr r2, =gBitTable - lsls r0, r3, 2 - adds r0, r2 - ldr r0, [r0] - ands r1, r0 - cmp r1, 0 - bne _0803F532 - ldr r4, =gActiveBank - strb r5, [r4] - adds r1, r3, 0 - adds r1, 0x9 - lsls r1, 24 - lsrs r1, 24 - ldrb r0, [r4] - muls r0, r7 - adds r0, r6 - adds r0, r3 - str r0, [sp] - movs r0, 0 - movs r2, 0 - movs r3, 0x1 - bl EmitSetMonData - ldrb r0, [r4] - bl MarkBufferBankForExecution -_0803F532: - add sp, 0x4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end PressurePPLose - - thumb_func_start PressurePPLoseOnUsingImprision -PressurePPLoseOnUsingImprision: @ 803F548 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - lsls r0, 24 - lsrs r5, r0, 24 - movs r0, 0x4 - mov r8, r0 - adds r0, r5, 0 - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - movs r4, 0 - ldr r0, =gNoOfAllBanks - ldrb r0, [r0] - cmp r4, r0 - bge _0803F5F0 - ldr r1, =gBattleMons - movs r0, 0x58 - adds r7, r5, 0 - muls r7, r0 - adds r1, 0xC - mov r10, r1 -_0803F57E: - lsls r0, r4, 24 - lsrs r0, 24 - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - adds r6, r4, 0x1 - cmp r9, r0 - beq _0803F5E6 - ldr r0, =gBattleMons - movs r3, 0x58 - adds r1, r4, 0 - muls r1, r3 - adds r1, r0 - adds r1, 0x20 - ldrb r1, [r1] - adds r4, r0, 0 - cmp r1, 0x2E - bne _0803F5E6 - movs r2, 0 - adds r0, r5, 0 - muls r0, r3 - adds r1, r4, 0 - adds r1, 0xC - adds r0, r1 - ldrh r0, [r0] - movs r1, 0x8F - lsls r1, 1 - cmp r0, r1 - beq _0803F5CE - adds r3, r1, 0 - mov r0, r10 - adds r1, r7, r0 -_0803F5C0: - adds r1, 0x2 - adds r2, 0x1 - cmp r2, 0x3 - bgt _0803F5CE - ldrh r0, [r1] - cmp r0, r3 - bne _0803F5C0 -_0803F5CE: - cmp r2, 0x4 - beq _0803F5E6 - mov r8, r2 - adds r1, r2, r7 - adds r0, r4, 0 - adds r0, 0x24 - adds r1, r0 - ldrb r0, [r1] - cmp r0, 0 - beq _0803F5E6 - subs r0, 0x1 - strb r0, [r1] -_0803F5E6: - adds r4, r6, 0 - ldr r0, =gNoOfAllBanks - ldrb r0, [r0] - cmp r4, r0 - blt _0803F57E -_0803F5F0: - mov r1, r8 - cmp r1, 0x4 - beq _0803F658 - ldr r6, =gBattleMons - movs r3, 0x58 - adds r0, r5, 0 - muls r0, r3 - adds r1, r6, 0 - adds r1, 0x50 - adds r0, r1 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 14 - ands r0, r1 - cmp r0, 0 - bne _0803F658 - ldr r1, =gDisableStructs - lsls r0, r5, 3 - subs r0, r5 - lsls r0, 2 - adds r0, r1 - ldrb r1, [r0, 0x18] - lsrs r1, 4 - ldr r2, =gBitTable - mov r4, r8 - lsls r0, r4, 2 - adds r0, r2 - ldr r0, [r0] - ands r1, r0 - cmp r1, 0 - bne _0803F658 - ldr r4, =gActiveBank - strb r5, [r4] - mov r1, r8 - adds r1, 0x9 - lsls r1, 24 - lsrs r1, 24 - ldrb r0, [r4] - muls r0, r3 - adds r2, r6, 0 - adds r2, 0x24 - adds r0, r2 - add r0, r8 - str r0, [sp] - movs r0, 0 - movs r2, 0 - movs r3, 0x1 - bl EmitSetMonData - ldrb r0, [r4] - bl MarkBufferBankForExecution -_0803F658: - 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 PressurePPLoseOnUsingImprision - - thumb_func_start PressurePPLoseOnUsingPerishSong -PressurePPLoseOnUsingPerishSong: @ 803F67C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - lsls r0, 24 - lsrs r3, r0, 24 - movs r6, 0x4 - movs r1, 0 - ldr r0, =gNoOfAllBanks - mov r8, r0 - ldrb r0, [r0] - cmp r1, r0 - bge _0803F6FE - ldr r7, =gBattleMons - movs r2, 0x58 - mov r12, r2 - mov r5, r12 - muls r5, r3 - adds r0, r7, 0 - adds r0, 0xC - adds r2, r5, r0 - mov r10, r2 - mov r9, r5 -_0803F6AE: - mov r0, r12 - muls r0, r1 - adds r0, r7 - adds r0, 0x20 - ldrb r0, [r0] - adds r4, r1, 0x1 - cmp r0, 0x2E - bne _0803F6F4 - cmp r1, r3 - beq _0803F6F4 - movs r2, 0 - mov r1, r10 - ldrh r0, [r1] - cmp r0, 0xC3 - beq _0803F6DE - ldr r1, =gBattleMons + 0xC - add r1, r9 -_0803F6D0: - adds r1, 0x2 - adds r2, 0x1 - cmp r2, 0x3 - bgt _0803F6DE - ldrh r0, [r1] - cmp r0, 0xC3 - bne _0803F6D0 -_0803F6DE: - cmp r2, 0x4 - beq _0803F6F4 - adds r6, r2, 0 - adds r0, r6, r5 - ldr r2, =gBattleMons + 0x24 - adds r1, r0, r2 - ldrb r0, [r1] - cmp r0, 0 - beq _0803F6F4 - subs r0, 0x1 - strb r0, [r1] -_0803F6F4: - adds r1, r4, 0 - mov r0, r8 - ldrb r0, [r0] - cmp r1, r0 - blt _0803F6AE -_0803F6FE: - cmp r6, 0x4 - beq _0803F762 - ldr r7, =gBattleMons - movs r5, 0x58 - adds r0, r3, 0 - muls r0, r5 - adds r1, r7, 0 - adds r1, 0x50 - adds r0, r1 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 14 - ands r0, r1 - cmp r0, 0 - bne _0803F762 - ldr r1, =gDisableStructs - lsls r0, r3, 3 - subs r0, r3 - lsls r0, 2 - adds r0, r1 - ldrb r1, [r0, 0x18] - lsrs r1, 4 - ldr r2, =gBitTable - lsls r0, r6, 2 - adds r0, r2 - ldr r0, [r0] - ands r1, r0 - cmp r1, 0 - bne _0803F762 - ldr r4, =gActiveBank - strb r3, [r4] - adds r1, r6, 0 - adds r1, 0x9 - lsls r1, 24 - lsrs r1, 24 - ldrb r0, [r4] - muls r0, r5 - adds r2, r7, 0 - adds r2, 0x24 - adds r0, r2 - adds r0, r6 - str r0, [sp] - movs r0, 0 - movs r2, 0 - movs r3, 0x1 - bl EmitSetMonData - ldrb r0, [r4] - bl MarkBufferBankForExecution -_0803F762: - 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 PressurePPLoseOnUsingPerishSong - - thumb_func_start sub_803F790 -sub_803F790: @ 803F790 - push {r4,r5,lr} - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0803F7D0 - movs r2, 0 - ldr r4, =gNoOfAllBanks - ldrb r0, [r4] - cmp r2, r0 - bge _0803F7EE - ldr r3, =gBattleExecBuffer - ldr r5, =gBitTable -_0803F7AC: - ldm r5!, {r1} - lsls r1, 28 - ldr r0, [r3] - orrs r0, r1 - str r0, [r3] - adds r2, 0x1 - ldrb r0, [r4] - cmp r2, r0 - blt _0803F7AC - b _0803F7EE - .pool -_0803F7D0: - movs r2, 0 - ldr r4, =gNoOfAllBanks - ldrb r0, [r4] - cmp r2, r0 - bge _0803F7EE - ldr r3, =gBattleExecBuffer - ldr r5, =gBitTable -_0803F7DE: - ldr r0, [r3] - ldm r5!, {r1} - orrs r0, r1 - str r0, [r3] - adds r2, 0x1 - ldrb r0, [r4] - cmp r2, r0 - blt _0803F7DE -_0803F7EE: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_803F790 - - thumb_func_start MarkBufferBankForExecution -MarkBufferBankForExecution: @ 803F800 - push {lr} - lsls r0, 24 - lsrs r3, r0, 24 - ldr r0, =gBattleTypeFlags - ldr r0, [r0] - movs r1, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0803F834 - ldr r2, =gBattleExecBuffer - ldr r1, =gBitTable - lsls r0, r3, 2 - adds r0, r1 - ldr r1, [r0] - lsls r1, 28 - ldr r0, [r2] - orrs r0, r1 - str r0, [r2] - b _0803F844 - .pool -_0803F834: - ldr r2, =gBattleExecBuffer - ldr r1, =gBitTable - lsls r0, r3, 2 - adds r0, r1 - ldr r1, [r2] - ldr r0, [r0] - orrs r1, r0 - str r1, [r2] -_0803F844: - pop {r0} - bx r0 - .pool - thumb_func_end MarkBufferBankForExecution - - thumb_func_start sub_803F850 -sub_803F850: @ 803F850 - push {r4-r7,lr} - lsls r0, 24 - lsrs r7, r0, 24 - movs r4, 0 - ldr r5, =gBattleExecBuffer - ldr r1, =gBitTable - lsls r0, r7, 2 - adds r6, r0, r1 - b _0803F87A - .pool -_0803F86C: - lsls r0, r4, 2 - ldr r1, [r6] - lsls r1, r0 - ldr r0, [r5] - orrs r0, r1 - str r0, [r5] - adds r4, 0x1 -_0803F87A: - bl sub_8009FCC - lsls r0, 24 - lsrs r0, 24 - cmp r4, r0 - blt _0803F86C - ldr r2, =gBattleExecBuffer - movs r1, 0x80 - lsls r1, 21 - lsls r1, r7 - ldr r0, [r2] - bics r0, r1 - str r0, [r2] - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_803F850 - - thumb_func_start CancelMultiTurnMoves -CancelMultiTurnMoves: @ 803F8A0 - lsls r0, 24 - lsrs r0, 24 - ldr r1, =gBattleMons - movs r2, 0x58 - adds r3, r0, 0 - muls r3, r2 - adds r1, 0x50 - adds r3, r1 - ldr r1, [r3] - ldr r2, =0xffffefff - ands r1, r2 - ldr r2, =0xfffff3ff - ands r1, r2 - movs r2, 0x71 - negs r2, r2 - ands r1, r2 - ldr r2, =0xfffffcff - ands r1, r2 - str r1, [r3] - ldr r1, =gStatuses3 - lsls r2, r0, 2 - adds r2, r1 - ldr r1, [r2] - ldr r3, =0xfffbff3f - ands r1, r3 - str r1, [r2] - ldr r2, =gDisableStructs - lsls r1, r0, 3 - subs r1, r0 - lsls r1, 2 - adds r1, r2 - ldrb r2, [r1, 0x11] - movs r0, 0x10 - negs r0, r0 - ands r0, r2 - strb r0, [r1, 0x11] - movs r0, 0 - strb r0, [r1, 0x10] - bx lr - .pool - thumb_func_end CancelMultiTurnMoves - - thumb_func_start HasMoveFailed -HasMoveFailed: @ 803F90C - push {lr} - lsls r0, 24 - ldr r1, =gProtectStructs - lsrs r0, 20 - adds r1, r0, r1 - ldrb r0, [r1] - lsrs r0, 7 - cmp r0, 0 - bne _0803F952 - ldrb r2, [r1, 0x1] - lsls r0, r2, 30 - cmp r0, 0 - blt _0803F952 - lsls r0, r2, 26 - cmp r0, 0 - blt _0803F952 - lsls r0, r2, 25 - cmp r0, 0 - blt _0803F952 - lsrs r0, r2, 7 - cmp r0, 0 - bne _0803F952 - ldrb r1, [r1, 0x2] - lsls r0, r1, 31 - cmp r0, 0 - bne _0803F952 - lsls r0, r1, 30 - cmp r0, 0 - blt _0803F952 - lsls r0, r1, 29 - cmp r0, 0 - blt _0803F952 - lsls r0, r2, 31 - cmp r0, 0 - beq _0803F95C -_0803F952: - movs r0, 0x1 - b _0803F95E - .pool -_0803F95C: - movs r0, 0 -_0803F95E: - pop {r1} - bx r1 - thumb_func_end HasMoveFailed - - thumb_func_start PrepareStringBattle -PrepareStringBattle: @ 803F964 - push {r4,lr} - adds r2, r0, 0 - lsls r2, 16 - lsrs r2, 16 - ldr r4, =gActiveBank - strb r1, [r4] - movs r0, 0 - adds r1, r2, 0 - bl dp01_build_cmdbuf_x10_TODO - ldrb r0, [r4] - bl MarkBufferBankForExecution - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end PrepareStringBattle - - thumb_func_start ResetSentPokesToOpponentValue -ResetSentPokesToOpponentValue: @ 803F988 - push {r4-r6,lr} - movs r3, 0 - ldr r0, =gSentPokesToOpponent - strb r3, [r0] - strb r3, [r0, 0x1] - movs r1, 0 - ldr r0, =gNoOfAllBanks - ldrb r2, [r0] - adds r6, r0, 0 - cmp r1, r2 - bge _0803F9B6 - ldr r5, =gBitTable - adds r4, r2, 0 - ldr r2, =gBattlePartyID -_0803F9A4: - ldrh r0, [r2] - lsls r0, 2 - adds r0, r5 - ldr r0, [r0] - orrs r3, r0 - adds r2, 0x4 - adds r1, 0x2 - cmp r1, r4 - blt _0803F9A4 -_0803F9B6: - movs r1, 0x1 - adds r2, r6, 0 - ldrb r0, [r2] - cmp r1, r0 - bge _0803F9D6 - ldr r5, =gSentPokesToOpponent - movs r4, 0x2 -_0803F9C4: - adds r0, r1, 0 - ands r0, r4 - asrs r0, 1 - adds r0, r5 - strb r3, [r0] - adds r1, 0x2 - ldrb r0, [r2] - cmp r1, r0 - blt _0803F9C4 -_0803F9D6: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end ResetSentPokesToOpponentValue - - thumb_func_start sub_803F9EC -sub_803F9EC: @ 803F9EC - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r0, 24 - lsrs r5, r0, 24 - movs r4, 0 - adds r0, r5, 0 - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _0803FA50 - movs r0, 0x2 - ands r0, r5 - lsls r0, 24 - lsrs r0, 25 - mov r12, r0 - ldr r1, =gSentPokesToOpponent - adds r0, r1 - strb r4, [r0] - adds r5, r4, 0 - ldr r0, =gNoOfAllBanks - ldrb r2, [r0] - mov r8, r1 - cmp r4, r2 - bge _0803FA4A - ldr r0, =gAbsentBankFlags - ldrb r7, [r0] - ldr r1, =gBitTable - adds r6, r2, 0 - ldr r3, =gBattlePartyID - adds r2, r1, 0 -_0803FA2E: - ldr r0, [r2] - ands r0, r7 - cmp r0, 0 - bne _0803FA40 - ldrh r0, [r3] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - orrs r4, r0 -_0803FA40: - adds r3, 0x4 - adds r2, 0x8 - adds r5, 0x2 - cmp r5, r6 - blt _0803FA2E -_0803FA4A: - mov r0, r12 - add r0, r8 - strb r4, [r0] -_0803FA50: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_803F9EC - - thumb_func_start sub_803FA70 -sub_803FA70: @ 803FA70 - push {r4-r7,lr} - lsls r0, 24 - lsrs r4, r0, 24 - adds r0, r4, 0 - bl GetBankSide - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _0803FA8C - adds r0, r4, 0 - bl sub_803F9EC - b _0803FAC2 -_0803FA8C: - movs r3, 0x1 - ldr r5, =gNoOfAllBanks - ldrb r0, [r5] - cmp r3, r0 - bge _0803FAC2 - ldr r0, =gSentPokesToOpponent - mov r12, r0 - movs r7, 0x2 - ldr r6, =gBitTable - ldr r1, =gBattlePartyID - lsls r0, r4, 1 - adds r4, r0, r1 -_0803FAA4: - adds r2, r3, 0 - ands r2, r7 - asrs r2, 1 - add r2, r12 - ldrh r0, [r4] - lsls r0, 2 - adds r0, r6 - ldr r0, [r0] - ldrb r1, [r2] - orrs r0, r1 - strb r0, [r2] - adds r3, 0x1 - ldrb r0, [r5] - cmp r3, r0 - blt _0803FAA4 -_0803FAC2: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_803FA70 - - .align 2, 0 @ Don't pad with nop. - \ No newline at end of file diff --git a/asm/rom3.s b/asm/rom3.s index 6a3e7e299..bde493568 100644 --- a/asm/rom3.s +++ b/asm/rom3.s @@ -2570,8 +2570,8 @@ _08033BB6: .pool thumb_func_end EmitMoveAnimation - thumb_func_start dp01_build_cmdbuf_x10_TODO -dp01_build_cmdbuf_x10_TODO: @ 8033BE4 + thumb_func_start EmitPrintString +EmitPrintString: @ 8033BE4 push {r4-r7,lr} mov r7, r10 mov r6, r9 @@ -2685,7 +2685,7 @@ _08033C88: pop {r0} bx r0 .pool - thumb_func_end dp01_build_cmdbuf_x10_TODO + thumb_func_end EmitPrintString thumb_func_start EmitPrintStringPlayerOnly EmitPrintStringPlayerOnly: @ 8033CFC diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index faa945bdd..b2dfec5d8 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -78,7 +78,7 @@ BattleScript_WildMonFled:: @ 82DAAF7 gUnknown_082DAAFE:: @ 82DAAFE .incbin "baserom.gba", 0x2daafe, 0x4 -gUnknown_082DAB02:: @ 82DAB02 +BattleScript_PrintFailedToRunString:: @ 82DAB02 .incbin "baserom.gba", 0x2dab02, 0x9 gUnknown_082DAB0B:: @ 82DAB0B diff --git a/data/battle_scripts_2.s b/data/battle_scripts_2.s index 985c09b23..4a4dc4665 100644 --- a/data/battle_scripts_2.s +++ b/data/battle_scripts_2.s @@ -33,7 +33,7 @@ gBattlescriptsForRunningByItem:: @ 82DBD54 .4byte BattleScript_RunByUsingItem .align 2 -gUnknown_082DBD58:: @ 82DBD58 +gBattlescriptsForSafariActions:: @ 82DBD58 .4byte gUnknown_082DBEBD .4byte gUnknown_082DBEC4 .4byte gUnknown_082DBECD diff --git a/include/battle.h b/include/battle.h index 639558e60..d41702396 100644 --- a/include/battle.h +++ b/include/battle.h @@ -1,6 +1,11 @@ #ifndef GUARD_BATTLE_H #define GUARD_BATTLE_H +// should they be included here or included individually by every file? +#include "battle_util.h" +#include "battle_script_commands.h" +#include "battle_2.h" + /* Banks are a name given to what could be called a 'battlerId' or 'monControllerId'. Each bank has a value consisting of two bits. @@ -119,8 +124,8 @@ #define STATUS3_MINIMIZED 0x100 #define STATUS3_ROOTED 0x400 #define STATUS3_CHARGED_UP 0x200 -#define STATUS3_YAWN 0x1800 //two bits -#define STATUS3_IMPRISONED_OTHERS 0x2000 +#define STATUS3_YAWN 0x1800 // two bits +#define STATUS3_IMPRISONED_OTHERS 0x2000 #define STATUS3_GRUDGE 0x4000 #define STATUS3_CANT_SCORE_A_CRIT 0x8000 #define STATUS3_MUDSPORT 0x10000 @@ -131,6 +136,7 @@ #define STATUS3_SEMI_INVULNERABLE ((STATUS3_UNDERGROUND | STATUS3_ON_AIR | STATUS3_UNDERWATER)) +#define HITMARKER_x10 0x00000010 #define HITMARKER_x20 0x00000020 #define HITMARKER_DESTINYBOND 0x00000040 #define HITMARKER_NO_ANIMATIONS 0x00000080 @@ -141,7 +147,7 @@ #define HITMARKER_PURSUIT_TRAP 0x00001000 #define HITMARKER_IGNORE_SAFEGUARD 0x00002000 #define HITMARKER_SYNCHRONISE_EFFECT 0x00004000 -#define HITMARKER_x8000 0x00008000 +#define HITMARKER_RUN 0x00008000 #define HITMARKER_IGNORE_ON_AIR 0x00010000 #define HITMARKER_IGNORE_UNDERGROUND 0x00020000 #define HITMARKER_IGNORE_UNDERWATER 0x00040000 @@ -152,6 +158,7 @@ #define HITMARKER_x800000 0x00800000 #define HITMARKER_GRUDGE 0x01000000 #define HITMARKER_OBEYS 0x02000000 +#define HITMARKER_x4000000 0x04000000 #define HITMARKER_x8000000 0x08000000 #define HITMARKER_FAINTED(bank) ((gBitTable[bank] << 0x1C)) #define HITMARKER_UNK(bank) ((0x10000000 << bank)) @@ -181,32 +188,6 @@ #define ACTION_NOTHING_FAINTED 13 // when choosing an action #define ACTION_INIT_VALUE 0xFF -#define ABILITYEFFECT_ON_SWITCHIN 0x0 -#define ABILITYEFFECT_ENDTURN 0x1 -#define ABILITYEFFECT_MOVES_BLOCK 0x2 -#define ABILITYEFFECT_ABSORBING 0x3 -#define ABILITYEFFECT_CONTACT 0x4 -#define ABILITYEFFECT_IMMUNITY 0x5 -#define ABILITYEFFECT_FORECAST 0x6 -#define ABILITYEFFECT_SYNCHRONIZE 0x7 -#define ABILITYEFFECT_ATK_SYNCHRONIZE 0x8 -#define ABILITYEFFECT_INTIMIDATE1 0x9 -#define ABILITYEFFECT_INTIMIDATE2 0xA -#define ABILITYEFFECT_TRACE 0xB -#define ABILITYEFFECT_CHECK_OTHER_SIDE 0xC -#define ABILITYEFFECT_CHECK_BANK_SIDE 0xD -#define ABILITYEFFECT_FIELD_SPORT 0xE -#define ABILITYEFFECT_CHECK_FIELD_EXCEPT_BANK 0xF -#define ABILITYEFFECT_COUNT_OTHER_SIDE 0x10 -#define ABILITYEFFECT_COUNT_BANK_SIDE 0x11 -#define ABILITYEFFECT_COUNT_ON_FIELD 0x12 -#define ABILITYEFFECT_CHECK_ON_FIELD 0x13 -#define ABILITYEFFECT_SWITCH_IN_WEATHER 0xFF - -#define ITEMEFFECT_ON_SWITCH_IN 0x0 - -#define WEATHER_HAS_EFFECT ((!AbilityBattleEffects(ABILITYEFFECT_CHECK_ON_FIELD, 0, ABILITY_CLOUD_NINE, 0, 0) && !AbilityBattleEffects(ABILITYEFFECT_CHECK_ON_FIELD, 0, ABILITY_AIR_LOCK, 0, 0))) - #define MOVESTATUS_MISSED (1 << 0) #define MOVESTATUS_SUPEREFFECTIVE (1 << 1) #define MOVESTATUS_NOTVERYEFFECTIVE (1 << 2) @@ -271,25 +252,6 @@ #define TYPE_MUL_NORMAL 10 #define TYPE_MUL_SUPER_EFFECTIVE 20 -#define BS_GET_TARGET 0 -#define BS_GET_ATTACKER 1 -#define BS_GET_EFFECT_BANK 2 -#define BS_ATTACKER_WITH_PARTNER 4 // for atk98_status_icon_update -#define BS_GET_ATTACKER_SIDE 8 // for atk1E_jumpifability -#define BS_GET_NOT_ATTACKER_SIDE 9 // for atk1E_jumpifability -#define BS_GET_SCRIPTING_BANK 10 -#define BS_GET_OPPONENT1 12 -#define BS_GET_PLAYER2 13 -#define BS_GET_OPPONENT2 14 - -// for battle script commands -#define CMP_EQUAL 0x0 -#define CMP_NOT_EQUAL 0x1 -#define CMP_GREATER_THAN 0x2 -#define CMP_LESS_THAN 0x3 -#define CMP_COMMON_BITS 0x4 -#define CMP_NO_COMMON_BITS 0x5 - struct TrainerMonNoItemDefaultMoves { u16 iv; @@ -375,8 +337,8 @@ struct DisableStruct /*0x0F*/ u8 perishSong1 : 4; /*0x0F*/ u8 perishSong2 : 4; /*0x10*/ u8 furyCutterCounter; - /*0x11*/ u8 rolloutTimer1 : 4; - /*0x11*/ u8 rolloutTimer2 : 4; + /*0x11*/ u8 rolloutCounter1 : 4; + /*0x11*/ u8 rolloutCounter2 : 4; /*0x12*/ u8 chargeTimer1 : 4; /*0x12*/ u8 chargeTimer2 : 4; /*0x13*/ u8 tauntTimer1:4; @@ -408,7 +370,7 @@ struct ProtectStruct u32 prlzImmobility:1; /* field_1 */ u32 confusionSelfDmg:1; - u32 notEffective:1; + u32 targetNotAffected:1; u32 chargingTurn:1; u32 fleeFlag:2; // for RunAway and Smoke Ball u32 usedImprisionedMove:1; @@ -574,6 +536,7 @@ struct BattleResults u8 playerMon1Name[11]; // 0x8 u8 battleTurnCounter; // 0x13 u8 playerMon2Name[11]; // 0x14 + u8 field_1F; // 0x1F u16 lastOpponentSpecies; // 0x20 u16 lastUsedMovePlayer; // 0x22 u16 lastUsedMoveOpponent; // 0x24 @@ -814,39 +777,10 @@ extern struct BattleStruct* gBattleStruct; #define B_ANIM_x1C 0x1C #define B_ANIM_x1D 0x1D -#define ATK48_STAT_NEGATIVE 0x1 -#define ATK48_STAT_BY_TWO 0x2 -#define ATK48_BIT_x4 0x4 -#define ATK48_LOWER_FAIL_CHECK 0x8 - -#define ATK4F_DONT_CHECK_STATUSES 0x80 - -#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 -#define VARIOUS_WAIT_CRY 18 -#define VARIOUS_RETURN_OPPONENT_MON1 19 -#define VARIOUS_RETURN_OPPONENT_MON2 20 -#define VARIOUS_SET_TELEPORT_OUTCOME 25 -#define VARIOUS_PLAY_TRAINER_DEFEATED_MUSIC 26 - -#define ATK80_DMG_CHANGE_SIGN 0 -#define ATK80_DMG_HALF_BY_TWO_NOT_MORE_THAN_HALF_MAX_HP 1 -#define ATK80_DMG_DOUBLED 2 - #define GET_STAT_BUFF_ID(n)((n & 0xF)) // first four bits 0x1, 0x2, 0x4, 0x8 #define GET_STAT_BUFF_VALUE(n)(((n >> 4) & 7)) // 0x10, 0x20, 0x40 #define STAT_BUFF_NEGATIVE 0x80 // 0x80, the sign bit -#define STAT_CHANGE_BS_PTR 0x1 -#define STAT_CHANGE_NOT_PROTECT_AFFECTED 0x20 - -#define STAT_CHANGE_WORKED 0 -#define STAT_CHANGE_DIDNT_WORK 1 - #define SET_STAT_BUFF_ID(n)((n & 0xF)) #define SET_STAT_BUFF_VALUE(n)(((s8)(((s8)(n) << 4)) & 0xF0)) @@ -892,78 +826,6 @@ void ApplyPlayerChosenFrameToBattleMenu(void); bool8 LoadChosenBattleElement(u8 caseId); void task00_0800F6FC(u8 taskId); -// battle_2 -void CB2_InitBattle(void); -void CB2_QuitRecordedBattle(void); -void CancelMultiTurnMoves(u8 bank); -void PressurePPLose(u8 bankAtk, u8 bankDef, u16 move); -void PrepareStringBattle(u16 stringId, u8 bank); -u8 GetBattleBank(u8 caseId); -void FaintClearSetData(void); -bool8 HasMoveFailed(u8 bank); -void SwitchInClearSetData(void); -void sub_803BDA0(u8 bank); -void sub_803FA70(u8 bank); -void BattleMainCB2(void); -void VBlankCB_Battle(void); -void ResetSentPokesToOpponentValue(void); -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) -#define MOVE_LIMITATION_PP (1 << 1) -#define MOVE_LIMITATION_DISABLED (1 << 2) -#define MOVE_LIMITATION_TORMENTED (1 << 3) -#define MOVE_LIMITATION_TAUNT (1 << 4) -#define MOVE_LIMITATION_IMPRISION (1 << 5) - -void BattleScriptPush(const u8* bsPtr); -void BattleScriptPushCursor(void); -void BattleScriptPop(void); -u8 TrySetCantSelectMoveBattleScript(void); -u8 CheckMoveLimitations(u8 bank, u8 unusableMoves, u8 check); -bool8 AreAllMovesUnusable(void); -u8 GetImprisonedMovesCount(u8 bank, u16 move); -u8 UpdateTurnCounters(void); -u8 TurnBasedEffects(void); -bool8 sub_8041364(void); -bool8 sub_8041728(void); -void TryClearRageStatuses(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 BattleScriptExecute(const u8* BS_ptr); -void BattleScriptPushCursorAndCallback(const u8* BS_ptr); -u8 ItemBattleEffects(u8 caseID, u8 bank, bool8 moveTurn); -void ClearFuryCutterDestinyBondGrudge(u8 bank); -void sub_80458B4(void); -u8 GetMoveTarget(u16 move, u8 useMoveTarget); -u8 IsPokeDisobedient(void); - -// battle_script_commands -void AI_CalcDmg(u8 bankAtk, u8 bankDef); -u8 TypeCalc(u16 move, u8 bankAtk, u8 bankDef); -u8 AI_TypeCalc(u16 move, u16 species, u8 ability); -u8 BankGetTurnOrder(u8 bank); -void SetMoveEffect(bool8 primary, u8 certain); -void BattleDestroyCursorAt(u8 cursorPosition); -void BattleCreateCursorAt(u8 cursorPosition); -void BufferMoveToLearnIntoBattleTextBuff2(void); -void sub_8056A3C(u8 xStart, u8 yStart, u8 xEnd, u8 yEnd, u8 flags); -bool8 UproarWakeUpCheck(u8 bank); - -extern void (* const gBattleScriptingCommandsTable[])(void); -extern const u8 gUnknown_0831C494[]; - // battle_5 void AllocateBattleResrouces(void); void FreeBattleResources(void); diff --git a/include/battle_2.h b/include/battle_2.h new file mode 100644 index 000000000..e4385db04 --- /dev/null +++ b/include/battle_2.h @@ -0,0 +1,19 @@ +#ifndef GUARD_BATTLE_2_H +#define GUARD_BATTLE_2_H + +void CB2_InitBattle(void); +void CB2_QuitRecordedBattle(void); +void FaintClearSetData(void); +void SwitchInClearSetData(void); +void sub_803BDA0(u8 bank); +void BattleMainCB2(void); +void VBlankCB_Battle(void); +bool8 TryRunFromBattle(u8 bank); +u8 IsRunningFromBattleImpossible(void); +u8 GetWhoStrikesFirst(u8 bank1, u8 bank2, bool8 ignoreChosenMoves); +void SwapTurnOrder(u8 id1, u8 id2); +void BattleTurnPassed(void); +void RunBattleScriptCommands_PopCallbacksStack(void); +void RunBattleScriptCommands(void); + +#endif // GUARD_BATTLE_2_H diff --git a/include/battle_controllers.h b/include/battle_controllers.h index 9a7f947fa..2281fdaff 100644 --- a/include/battle_controllers.h +++ b/include/battle_controllers.h @@ -1,6 +1,28 @@ #ifndef GUARD_BATTLE_CONTROLLERS_H #define GUARD_BATTLE_CONTROLLERS_H +#define REQUEST_ALL_BATTLE 0x0 +#define REQUEST_SPECIES_BATTLE 0x1 +#define REQUEST_HELDITEM_BATTLE 0x2 +#define REQUEST_MOVES_PP_BATTLE 0x3 +#define REQUEST_PPMOVE1_BATTLE 0x9 +#define REQUEST_PPMOVE2_BATTLE 0xA +#define REQUEST_PPMOVE3_BATTLE 0xB +#define REQUEST_PPMOVE4_BATTLE 0xC +#define REQUEST_STATUS_BATTLE 0x28 +#define REQUEST_HP_BATTLE 0x2A + +#define RESET_ACTION_MOVE_SELECTION 0 +#define RESET_ACTION_SELECTION 1 +#define RESET_MOVE_SELECTION 2 + +#define BALL_NO_SHAKES 0 +#define BALL_1_SHAKE 1 +#define BALL_2_SHAKES 2 +#define BALL_3_SHAKES_FAIL 3 +#define BALL_3_SHAKES_SUCCESS 4 +#define BALL_TRAINER_BLOCK 5 + struct HpAndStatus { u16 hp; @@ -24,17 +46,6 @@ struct ChooseMoveStruct u8 monType2; }; -#define REQUEST_ALL_BATTLE 0x0 -#define REQUEST_SPECIES_BATTLE 0x1 -#define REQUEST_HELDITEM_BATTLE 0x2 -#define REQUEST_MOVES_PP_BATTLE 0x3 -#define REQUEST_PPMOVE1_BATTLE 0x9 -#define REQUEST_PPMOVE2_BATTLE 0xA -#define REQUEST_PPMOVE3_BATTLE 0xB -#define REQUEST_PPMOVE4_BATTLE 0xC -#define REQUEST_STATUS_BATTLE 0x28 -#define REQUEST_HP_BATTLE 0x2A - // rom3.s, emitters void EmitSetMonData(u8 bufferId, u8 request, u8 c, u8 bytes, void *data); void EmitMoveAnimation(u8 bufferId, u16 move, u8 turnOfMove, u16 movePower, s32 dmg, u8 friendship, struct DisableStruct* disableStructPtr, u8 multihit); @@ -70,22 +81,8 @@ void EmitChooseAction(u8 bufferId, u8 arg1, u16 arg2); void EmitChooseMove(u8 bufferId, bool8 isDoubleBattle, bool8 NoPpNumber, struct ChooseMoveStruct* movePpData); void EmitOpenBag(u8 bufferId, u8* arg1); void Emit_x32(u8 bufferId); - -#define RESET_ACTION_MOVE_SELECTION 0 -#define RESET_ACTION_SELECTION 1 -#define RESET_MOVE_SELECTION 2 - +void EmitPrintString(u8 bufferId, u16 stringId); void EmitResetActionMoveSelection(u8 bufferId, u8 caseId); - -#define BALL_NO_SHAKES 0 -#define BALL_1_SHAKE 1 -#define BALL_2_SHAKES 2 -#define BALL_3_SHAKES_FAIL 3 -#define BALL_3_SHAKES_SUCCESS 4 -#define BALL_TRAINER_BLOCK 5 - void EmitBallThrow(u8 bufferId, u8 caseId); -void MarkBufferBankForExecution(u8 bank); - #endif // GUARD_BATTLE_CONTROLLERS_H diff --git a/include/battle_script_commands.h b/include/battle_script_commands.h new file mode 100644 index 000000000..ae0d20f28 --- /dev/null +++ b/include/battle_script_commands.h @@ -0,0 +1,58 @@ +#ifndef GUARD_BATTLE_SCRIPT_COMMANDS_H +#define GUARD_BATTLE_SCRIPT_COMMANDS_H + +#define CMP_EQUAL 0x0 +#define CMP_NOT_EQUAL 0x1 +#define CMP_GREATER_THAN 0x2 +#define CMP_LESS_THAN 0x3 +#define CMP_COMMON_BITS 0x4 +#define CMP_NO_COMMON_BITS 0x5 + +#define BS_ATTACKER_WITH_PARTNER 4 // for atk98_status_icon_update +#define BS_GET_ATTACKER_SIDE 8 // for atk1E_jumpifability +#define BS_GET_NOT_ATTACKER_SIDE 9 // for atk1E_jumpifability + +#define ATK48_STAT_NEGATIVE 0x1 +#define ATK48_STAT_BY_TWO 0x2 +#define ATK48_BIT_x4 0x4 +#define ATK48_LOWER_FAIL_CHECK 0x8 + +#define ATK4F_DONT_CHECK_STATUSES 0x80 + +#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 +#define VARIOUS_WAIT_CRY 18 +#define VARIOUS_RETURN_OPPONENT_MON1 19 +#define VARIOUS_RETURN_OPPONENT_MON2 20 +#define VARIOUS_SET_TELEPORT_OUTCOME 25 +#define VARIOUS_PLAY_TRAINER_DEFEATED_MUSIC 26 + +#define ATK80_DMG_CHANGE_SIGN 0 +#define ATK80_DMG_HALF_BY_TWO_NOT_MORE_THAN_HALF_MAX_HP 1 +#define ATK80_DMG_DOUBLED 2 + +#define STAT_CHANGE_BS_PTR 0x1 +#define STAT_CHANGE_NOT_PROTECT_AFFECTED 0x20 + +#define STAT_CHANGE_WORKED 0 +#define STAT_CHANGE_DIDNT_WORK 1 + +void AI_CalcDmg(u8 bankAtk, u8 bankDef); +u8 TypeCalc(u16 move, u8 bankAtk, u8 bankDef); +u8 AI_TypeCalc(u16 move, u16 species, u8 ability); +u8 BankGetTurnOrder(u8 bank); +void SetMoveEffect(bool8 primary, u8 certain); +void BattleDestroyCursorAt(u8 cursorPosition); +void BattleCreateCursorAt(u8 cursorPosition); +void BufferMoveToLearnIntoBattleTextBuff2(void); +void sub_8056A3C(u8 xStart, u8 yStart, u8 xEnd, u8 yEnd, u8 flags); +bool8 UproarWakeUpCheck(u8 bank); + +extern void (* const gBattleScriptingCommandsTable[])(void); +extern const u8 gUnknown_0831C494[]; + +#endif // GUARD_BATTLE_SCRIPT_COMMANDS_H diff --git a/include/battle_util.h b/include/battle_util.h new file mode 100644 index 000000000..c1ff7d8ab --- /dev/null +++ b/include/battle_util.h @@ -0,0 +1,83 @@ +#ifndef GUARD_BATTLE_UTIL_H +#define GUARD_BATTLE_UTIL_H + +#define MOVE_LIMITATION_ZEROMOVE (1 << 0) +#define MOVE_LIMITATION_PP (1 << 1) +#define MOVE_LIMITATION_DISABLED (1 << 2) +#define MOVE_LIMITATION_TORMENTED (1 << 3) +#define MOVE_LIMITATION_TAUNT (1 << 4) +#define MOVE_LIMITATION_IMPRISION (1 << 5) + +#define ABILITYEFFECT_ON_SWITCHIN 0x0 +#define ABILITYEFFECT_ENDTURN 0x1 +#define ABILITYEFFECT_MOVES_BLOCK 0x2 +#define ABILITYEFFECT_ABSORBING 0x3 +#define ABILITYEFFECT_CONTACT 0x4 +#define ABILITYEFFECT_IMMUNITY 0x5 +#define ABILITYEFFECT_FORECAST 0x6 +#define ABILITYEFFECT_SYNCHRONIZE 0x7 +#define ABILITYEFFECT_ATK_SYNCHRONIZE 0x8 +#define ABILITYEFFECT_INTIMIDATE1 0x9 +#define ABILITYEFFECT_INTIMIDATE2 0xA +#define ABILITYEFFECT_TRACE 0xB +#define ABILITYEFFECT_CHECK_OTHER_SIDE 0xC +#define ABILITYEFFECT_CHECK_BANK_SIDE 0xD +#define ABILITYEFFECT_FIELD_SPORT 0xE +#define ABILITYEFFECT_CHECK_FIELD_EXCEPT_BANK 0xF +#define ABILITYEFFECT_COUNT_OTHER_SIDE 0x10 +#define ABILITYEFFECT_COUNT_BANK_SIDE 0x11 +#define ABILITYEFFECT_COUNT_ON_FIELD 0x12 +#define ABILITYEFFECT_CHECK_ON_FIELD 0x13 +#define ABILITYEFFECT_SWITCH_IN_WEATHER 0xFF + +#define ITEMEFFECT_ON_SWITCH_IN 0x0 + +#define WEATHER_HAS_EFFECT ((!AbilityBattleEffects(ABILITYEFFECT_CHECK_ON_FIELD, 0, ABILITY_CLOUD_NINE, 0, 0) && !AbilityBattleEffects(ABILITYEFFECT_CHECK_ON_FIELD, 0, ABILITY_AIR_LOCK, 0, 0))) + +#define BS_GET_TARGET 0 +#define BS_GET_ATTACKER 1 +#define BS_GET_EFFECT_BANK 2 +#define BS_GET_SCRIPTING_BANK 10 +#define BS_GET_PLAYER1 11 +#define BS_GET_OPPONENT1 12 +#define BS_GET_PLAYER2 13 +#define BS_GET_OPPONENT2 14 + +u8 GetBattleBank(u8 caseId); +void PressurePPLose(u8 bankDef, u8 bankAtk, u16 move); +void PressurePPLoseOnUsingPerishSong(u8 bankAtk); +void PressurePPLoseOnUsingImprision(u8 bankAtk); +void MarkAllBufferBanksForExecution(void); // unused +void MarkBufferBankForExecution(u8 bank); +void sub_803F850(u8 arg0); +void CancelMultiTurnMoves(u8 bank); +bool8 WasUnableToUseMove(u8 bank); +void PrepareStringBattle(u16 stringId, u8 bank); +void ResetSentPokesToOpponentValue(void); +void sub_803F9EC(u8 bank); +void sub_803FA70(u8 bank); +void BattleScriptPush(const u8* bsPtr); +void BattleScriptPushCursor(void); +void BattleScriptPop(void); +u8 TrySetCantSelectMoveBattleScript(void); +u8 CheckMoveLimitations(u8 bank, u8 unusableMoves, u8 check); +bool8 AreAllMovesUnusable(void); +u8 GetImprisonedMovesCount(u8 bank, u16 move); +u8 UpdateTurnCounters(void); +u8 TurnBasedEffects(void); +bool8 sub_8041364(void); +bool8 sub_8041728(void); +void TryClearRageStatuses(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 BattleScriptExecute(const u8* BS_ptr); +void BattleScriptPushCursorAndCallback(const u8* BS_ptr); +u8 ItemBattleEffects(u8 caseID, u8 bank, bool8 moveTurn); +void ClearFuryCutterDestinyBondGrudge(u8 bank); +void HandleAction_RunBattleScript(void); +u8 GetMoveTarget(u16 move, u8 useMoveTarget); +u8 IsPokeDisobedient(void); + +#endif // GUARD_BATTLE_UTIL_H diff --git a/include/link.h b/include/link.h index 9d581a6c1..012c90480 100644 --- a/include/link.h +++ b/include/link.h @@ -183,5 +183,6 @@ bool8 sub_800A520(void); bool8 sub_8010500(void); void sub_800DFB4(u8, u8); void sub_800ADF8(void); +u8 sub_8009FCC(void); #endif // GUARD_LINK_H diff --git a/include/pokemon.h b/include/pokemon.h index c41099b09..263a37426 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -640,6 +640,8 @@ u8 CheckPartyPokerus(struct Pokemon *party, u8 selection); u8 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection); void UpdatePartyPokerusTime(u16 days); void PartySpreadPokerus(struct Pokemon *party); +s8 GetMonFlavourRelation(struct Pokemon *mon, u8 a2); +s8 GetFlavourRelationByPersonality(u32 personality, u8 a2); #include "sprite.h" diff --git a/ld_script.txt b/ld_script.txt index f5361e8e4..0e8454ef8 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -58,8 +58,7 @@ SECTIONS { src/decompress.o(.text); asm/battle_1.o(.text); src/battle_2.o(.text); - asm/battle_2.o(.text); - src/battle_3.o(.text); + src/battle_util.o(.text); src/battle_script_commands.o(.text); asm/battle_5.o(.text); asm/battle_controller_player.o(.text); diff --git a/src/battle_2.c b/src/battle_2.c index ab1aae747..37ab7ab1f 100644 --- a/src/battle_2.c +++ b/src/battle_2.c @@ -40,6 +40,7 @@ #include "trainer_classes.h" #include "evolution_scene.h" #include "roamer.h" +#include "safari_zone.h" struct UnknownStruct6 { @@ -157,6 +158,10 @@ extern const struct BgTemplate gUnknown_0831AA08[]; extern const struct WindowTemplate * const gUnknown_0831ABA0[]; extern const u8 gUnknown_0831ACE0[]; extern const u8 gStatStageRatios[][2]; +extern const u8 gUnknown_0831BCE0[]; +extern const u8 gUnknown_0831BCEF[]; +extern const u8 gUnknown_0831BCF3[]; +extern const u8 * const gBattleScriptsForMoveEffects[]; // strings extern const u8 gText_LinkStandby3[]; @@ -190,6 +195,7 @@ extern const u8 BattleScript_GotAwaySafely[]; extern const u8 BattleScript_WildMonFled[]; extern const u8 BattleScript_MoveUsedLoafingAround[]; extern const u8 BattleScript_ActionSwitch[]; +extern const u8 BattleScript_PrintFailedToRunString[]; // functions extern void HandleLinkBattleSetup(void); // rom_3 @@ -2942,7 +2948,7 @@ void FaintClearSetData(void) gProtectStructs[gActiveBank].flag0Unknown = 0; gProtectStructs[gActiveBank].prlzImmobility = 0; gProtectStructs[gActiveBank].confusionSelfDmg = 0; - gProtectStructs[gActiveBank].notEffective = 0; + gProtectStructs[gActiveBank].targetNotAffected = 0; gProtectStructs[gActiveBank].chargingTurn = 0; gProtectStructs[gActiveBank].fleeFlag = 0; gProtectStructs[gActiveBank].usedImprisionedMove = 0; @@ -3824,15 +3830,18 @@ void sub_803BDA0(u8 bank) } } -#define STATE_TURN_START_RECORD 0 -#define STATE_BEFORE_ACTION_CHOSEN 1 -#define STATE_WAIT_ACTION_CHOSEN 2 -#define STATE_WAIT_ACTION_CASE_CHOSEN 3 -#define STATE_WAIT_ACTION_CONFIRMED_STANDBY 4 -#define STATE_WAIT_ACTION_CONFIRMED 5 -#define STATE_SELECTION_SCRIPT 6 -#define STATE_WAIT_SET_BEFORE_ACTION 7 -#define STATE_SELECTION_SCRIPT_MAY_RUN 8 +enum +{ + STATE_TURN_START_RECORD, + STATE_BEFORE_ACTION_CHOSEN, + STATE_WAIT_ACTION_CHOSEN, + STATE_WAIT_ACTION_CASE_CHOSEN, + STATE_WAIT_ACTION_CONFIRMED_STANDBY, + STATE_WAIT_ACTION_CONFIRMED, + STATE_SELECTION_SCRIPT, + STATE_WAIT_SET_BEFORE_ACTION, + STATE_SELECTION_SCRIPT_MAY_RUN +}; void HandleTurnActionSelectionState(void) { @@ -4137,7 +4146,7 @@ void HandleTurnActionSelectionState(void) } break; case ACTION_RUN: - gHitMarker |= HITMARKER_x8000; + gHitMarker |= HITMARKER_RUN; gBattleCommunication[gActiveBank]++; break; case ACTION_WATCHES_CAREFULLY: @@ -4160,7 +4169,7 @@ void HandleTurnActionSelectionState(void) gBattleCommunication[gActiveBank]++; break; case ACTION_SAFARI_ZONE_RUN: - gHitMarker |= HITMARKER_x8000; + gHitMarker |= HITMARKER_RUN; gBattleCommunication[gActiveBank]++; break; case ACTION_9: @@ -4221,7 +4230,7 @@ void HandleTurnActionSelectionState(void) { if (gBattleBufferB[gActiveBank][1] == 13) { - gHitMarker |= HITMARKER_x8000; + gHitMarker |= HITMARKER_RUN; gActionForBanks[gActiveBank] = ACTION_RUN; gBattleCommunication[gActiveBank] = STATE_WAIT_ACTION_CONFIRMED_STANDBY; } @@ -4613,7 +4622,7 @@ void SpecialStatusesClear(void) static void CheckFocusPunch_ClearVarsBeforeTurnStarts(void) { - if (!(gHitMarker & HITMARKER_x8000)) + if (!(gHitMarker & HITMARKER_RUN)) { while (gBattleStruct->focusPunchBank < gNoOfAllBanks) { @@ -4976,8 +4985,6 @@ void RunBattleScriptCommands(void) gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); } -extern const u8 * const gBattleScriptsForMoveEffects[]; - void HandleAction_UseMove(void) { u8 side; @@ -5216,6 +5223,7 @@ void HandleAction_Switch(void) extern const u8 * const gBattlescriptsForBallThrow[]; extern const u8 * const gBattlescriptsForRunningByItem[]; extern const u8 * const gUnknown_082DBD3C[]; +extern const u8 * const gBattlescriptsForSafariActions[]; void HandleAction_UseItem(void) { @@ -5375,3 +5383,198 @@ bool8 TryRunFromBattle(u8 bank) return effect; } + +void HandleAction_Run(void) +{ + gBankAttacker = gBanksByTurnOrder[gCurrentTurnActionNumber]; + + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) + { + gCurrentTurnActionNumber = gNoOfAllBanks; + + for (gActiveBank = 0; gActiveBank < gNoOfAllBanks; gActiveBank++) + { + if (GetBankSide(gActiveBank) == SIDE_PLAYER) + { + if (gActionForBanks[gActiveBank] == ACTION_RUN) + gBattleOutcome |= BATTLE_LOST; + } + else + { + if (gActionForBanks[gActiveBank] == ACTION_RUN) + gBattleOutcome |= BATTLE_WON; + } + } + + gBattleOutcome |= BATTLE_OUTCOME_BIT_x80; + gSaveBlock2Ptr->field_CA9_b = 1; + } + else + { + if (GetBankSide(gBankAttacker) == SIDE_PLAYER) + { + if (!TryRunFromBattle(gBankAttacker)) // failed to run away + { + ClearFuryCutterDestinyBondGrudge(gBankAttacker); + gBattleCommunication[MULTISTRING_CHOOSER] = 3; + gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; + gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT; + } + } + else + { + if (gBattleMons[gBankAttacker].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) + { + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; + gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT; + } + else + { + gCurrentTurnActionNumber = gNoOfAllBanks; + gBattleOutcome = BATTLE_POKE_FLED; + } + } + } +} + +void HandleAction_WatchesCarefully(void) +{ + gBankAttacker = gBanksByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[0]; + gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT; +} + +void HandleAction_SafariZoneBallThrow(void) +{ + gBankAttacker = gBanksByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gNumSafariBalls--; + gLastUsedItem = ITEM_SAFARI_BALL; + gBattlescriptCurrInstr = gBattlescriptsForBallThrow[ITEM_SAFARI_BALL]; + gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT; +} + +void HandleAction_ThrowPokeblock(void) +{ + gBankAttacker = gBanksByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = gBattleBufferB[gBankAttacker][1] - 1; + gLastUsedItem = gBattleBufferB[gBankAttacker][2]; + + if (gBattleResults.field_1F < 0xFF) + gBattleResults.field_1F++; + if (gBattleStruct->field_7A < 3) + gBattleStruct->field_7A++; + if (gBattleStruct->field_7B > 1) + { + if (gBattleStruct->field_7B < gUnknown_0831BCE0[3 * gBattleStruct->field_7A + gBattleCommunication[MULTISTRING_CHOOSER]]) + gBattleStruct->field_7B = 1; + else + gBattleStruct->field_7B -= gUnknown_0831BCE0[3 * gBattleStruct->field_7A + gBattleCommunication[MULTISTRING_CHOOSER]]; + } + + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[2]; + gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT; +} + +void HandleAction_GoNear(void) +{ + gBankAttacker = gBanksByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + + gBattleStruct->field_7C += gUnknown_0831BCEF[gBattleStruct->field_79]; + if (gBattleStruct->field_7C > 20) + gBattleStruct->field_7C = 20; + + gBattleStruct->field_7B +=gUnknown_0831BCF3[gBattleStruct->field_79]; + if (gBattleStruct->field_7B > 20) + gBattleStruct->field_7B = 20; + + if (gBattleStruct->field_79 < 3) + { + gBattleStruct->field_79++; + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + } + else + { + gBattleCommunication[MULTISTRING_CHOOSER] = 1; + } + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[1]; + gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT; +} + +void HandleAction_SafriZoneRun(void) +{ + gBankAttacker = gBanksByTurnOrder[gCurrentTurnActionNumber]; + PlaySE(SE_NIGERU); + gCurrentTurnActionNumber = gNoOfAllBanks; + gBattleOutcome = BATTLE_RAN; +} + +void HandleAction_Action9(void) +{ + gBankAttacker = gBanksByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBankAttacker, gBattlePartyID[gBankAttacker]) + + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[3]; + gCurrentActionFuncId = ACTION_RUN_BATTLESCRIPT; + gActionsByTurnOrder[1] = ACTION_FINISHED; +} + +void HandleAction_Action11(void) +{ + if (!sub_8041728()) + { + gBattleStruct->field_4D = 0; + gCurrentActionFuncId = ACTION_FINISHED; + } +} + +void HandleAction_NothingIsFainted(void) +{ + gCurrentTurnActionNumber++; + gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; + gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED + | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR + | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 + | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT + | HITMARKER_x8000000 | HITMARKER_x4000000); +} + +void HandleAction_ActionFinished(void) +{ + *(gBattleStruct->field_5C + gBanksByTurnOrder[gCurrentTurnActionNumber]) = 6; + gCurrentTurnActionNumber++; + gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; + SpecialStatusesClear(); + gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED + | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR + | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 + | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT + | HITMARKER_x8000000 | HITMARKER_x4000000); + + gCurrentMove = 0; + gBattleMoveDamage = 0; + gBattleMoveFlags = 0; + gBattleScripting.animTurn = 0; + gBattleScripting.animTargetsHit = 0; + gUnknown_02024250[gBankAttacker] = 0; + gUnknown_02024258[gBankAttacker] = 0; + gBattleStruct->dynamicMoveType = 0; + gDynamicBasePower = 0; + gBattleScripting.atk49_state = 0; + gBattleCommunication[3] = 0; + gBattleCommunication[4] = 0; + gBattleScripting.field_16 = 0; + gBattleResources->battleScriptsStack->size = 0; +} + diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index e68137c47..e53292442 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1600,7 +1600,7 @@ static void atk06_typecalc(void) RecordAbilityBattle(gBankTarget, gLastUsedAbility); } if (gBattleMoveFlags & MOVESTATUS_NOTAFFECTED) - gProtectStructs[gBankAttacker].notEffective = 1; + gProtectStructs[gBankAttacker].targetNotAffected = 1; gBattlescriptCurrInstr++; } @@ -1639,14 +1639,14 @@ static void CheckWonderGuardAndLevitate(void) if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type1 && gTypeEffectiveness[i + 2] == 0) { gBattleMoveFlags |= MOVESTATUS_NOTAFFECTED; - gProtectStructs[gBankAttacker].notEffective = 1; + gProtectStructs[gBankAttacker].targetNotAffected = 1; } if (gTypeEffectiveness[i + 1] == gBattleMons[gBankTarget].type2 && gBattleMons[gBankTarget].type1 != gBattleMons[gBankTarget].type2 && gTypeEffectiveness[i + 2] == TYPE_MUL_NO_EFFECT) { gBattleMoveFlags |= MOVESTATUS_NOTAFFECTED; - gProtectStructs[gBankAttacker].notEffective = 1; + gProtectStructs[gBankAttacker].targetNotAffected = 1; } // check super effective @@ -5066,7 +5066,7 @@ static void atk49_moveend(void) case 9: // make attacker sprite visible if (gBattleMoveFlags & MOVESTATUS_NOEFFECT || !(gStatuses3[gBankAttacker] & (STATUS3_SEMI_INVULNERABLE)) - || HasMoveFailed(gBankAttacker)) + || WasUnableToUseMove(gBankAttacker)) { gActiveBank = gBankAttacker; EmitSpriteInvisibility(0, FALSE); @@ -5297,7 +5297,7 @@ static void atk4A_typecalc2(void) RecordAbilityBattle(gBankTarget, gLastUsedAbility); } if (gBattleMoveFlags & MOVESTATUS_NOTAFFECTED) - gProtectStructs[gBankAttacker].notEffective = 1; + gProtectStructs[gBankAttacker].targetNotAffected = 1; gBattlescriptCurrInstr++; } @@ -9518,19 +9518,19 @@ static void atkB3_rolloutdamagecalculation(void) if (!(gBattleMons[gBankAttacker].status2 & STATUS2_MULTIPLETURNS)) // first hit { - gDisableStructs[gBankAttacker].rolloutTimer1 = 5; - gDisableStructs[gBankAttacker].rolloutTimer2 = 5; + gDisableStructs[gBankAttacker].rolloutCounter1 = 5; + gDisableStructs[gBankAttacker].rolloutCounter2 = 5; gBattleMons[gBankAttacker].status2 |= STATUS2_MULTIPLETURNS; gLockedMoves[gBankAttacker] = gCurrentMove; } - if (--gDisableStructs[gBankAttacker].rolloutTimer1 == 0) // last hit + if (--gDisableStructs[gBankAttacker].rolloutCounter1 == 0) // last hit { gBattleMons[gBankAttacker].status2 &= ~(STATUS2_MULTIPLETURNS); } gDynamicBasePower = gBattleMoves[gCurrentMove].power; - for (i = 1; i < (5 - gDisableStructs[gBankAttacker].rolloutTimer1); i++) + for (i = 1; i < (5 - gDisableStructs[gBankAttacker].rolloutCounter1); i++) gDynamicBasePower *= 2; if (gBattleMons[gBankAttacker].status2 & STATUS2_DEFENSE_CURL) diff --git a/src/battle_3.c b/src/battle_util.c similarity index 96% rename from src/battle_3.c rename to src/battle_util.c index 58e0a05c7..c5a85dd2b 100644 --- a/src/battle_3.c +++ b/src/battle_util.c @@ -17,6 +17,7 @@ #include "battle_controllers.h" #include "event_data.h" #include "calculate_base_damage.h" +#include "link.h" extern const u8* gBattlescriptCurrInstr; extern const u8* gBattlescriptPtrsForSelection[BATTLE_BANKS_COUNT]; @@ -33,7 +34,7 @@ extern u8 gBankTarget; extern u8 gAbsentBankFlags; extern u16 gBattleWeather; extern u8 gBanksByTurnOrder[BATTLE_BANKS_COUNT]; -extern u16 gSideAffecting[]; +extern u16 gSideAffecting[2]; extern u8 gBattleCommunication[]; extern void (*gBattleMainFunc)(void); extern s32 gBattleMoveDamage; @@ -45,7 +46,7 @@ extern u32 gHitMarker; extern u8 gEffectBank; extern u16 gBattlePartyID[BATTLE_BANKS_COUNT]; extern u8 gBank1; -extern u16 gChosenMovesByBanks[]; +extern u16 gChosenMovesByBanks[BATTLE_BANKS_COUNT]; extern u8 gBattleMoveFlags; extern s32 gTakenDmg[BATTLE_BANKS_COUNT]; extern u8 gTakenDmgBanks[BATTLE_BANKS_COUNT]; @@ -55,8 +56,10 @@ extern u32 gBattleExecBuffer; extern u16 gRandomMove; extern u8 gCurrMovePos; extern u8 gUnknown_020241E9; +extern u8 gSentPokesToOpponent[2]; extern const struct BattleMove gBattleMoves[]; +extern const u16 gSoundMovesTable[]; // scripts extern const u8 gUnknown_082DAE2A[]; @@ -169,6 +172,7 @@ extern const u8 gUnknown_082DB6A5[]; //disobedient, uses a random move extern const u8 gUnknown_082DB6D9[]; //disobedient, went to sleep extern const u8 gUnknown_082DB6F0[]; //disobedient, hits itself +// strings extern const u8 gStatusConditionString_PoisonJpn[]; extern const u8 gStatusConditionString_SleepJpn[]; extern const u8 gStatusConditionString_ParalysisJpn[]; @@ -176,12 +180,272 @@ extern const u8 gStatusConditionString_BurnJpn[]; extern const u8 gStatusConditionString_IceJpn[]; extern const u8 gStatusConditionString_ConfusionJpn[]; extern const u8 gStatusConditionString_LoveJpn[]; -extern const u16 gSoundMovesTable[]; -extern void sub_803F9EC(); -extern bool8 sub_80423F4(u8 bank, u8, u8); extern u8 weather_get_current(void); -extern s8 GetFlavourRelationByPersonality(u32 personality, u8 flavor); + +u8 GetBattleBank(u8 caseId) +{ + u8 ret = 0; + switch (caseId) + { + case BS_GET_TARGET: + ret = gBankTarget; + break; + case BS_GET_ATTACKER: + ret = gBankAttacker; + break; + case BS_GET_EFFECT_BANK: + ret = gEffectBank; + break; + case 7: + ret = 0; + break; + case BS_GET_SCRIPTING_BANK: + ret = gBattleScripting.bank; + break; + case 3: + ret = gBank1; + break; + case 5: + ret = gBank1; + break; + case 4: + case 6: + case 8: + case 9: + case BS_GET_PLAYER1: + ret = GetBankByIdentity(IDENTITY_PLAYER_MON1); + break; + case BS_GET_OPPONENT1: + ret = GetBankByIdentity(IDENTITY_OPPONENT_MON1); + break; + case BS_GET_PLAYER2: + ret = GetBankByIdentity(IDENTITY_PLAYER_MON2); + break; + case BS_GET_OPPONENT2: + ret = GetBankByIdentity(IDENTITY_OPPONENT_MON2); + break; + } + return ret; +} + +void PressurePPLose(u8 bankDef, u8 bankAtk, u16 move) +{ + s32 i; + + if (gBattleMons[bankDef].ability != ABILITY_PRESSURE) + return; + + for (i = 0; i < 4; i++) + { + if (gBattleMons[bankAtk].moves[i] == move) + break; + } + + if (i == 4) // mons don't share any moves + return; + + if (gBattleMons[bankAtk].pp[i] != 0) + gBattleMons[bankAtk].pp[i]--; + + if (!(gBattleMons[bankAtk].status2 & STATUS2_TRANSFORMED) + && !(gDisableStructs[bankAtk].unk18_b & gBitTable[i])) + { + gActiveBank = bankAtk; + EmitSetMonData(0, REQUEST_PPMOVE1_BATTLE + i, 0, 1, &gBattleMons[gActiveBank].pp[i]); + MarkBufferBankForExecution(gActiveBank); + } +} + +void PressurePPLoseOnUsingImprision(u8 bankAtk) +{ + s32 i, j; + s32 imprisionPos = 4; + u8 atkSide = GetBankSide(bankAtk); + + for (i = 0; i < gNoOfAllBanks; i++) + { + if (atkSide != GetBankSide(i) && gBattleMons[i].ability == ABILITY_PRESSURE) + { + for (j = 0; j < 4; j++) + { + if (gBattleMons[bankAtk].moves[j] == MOVE_IMPRISON) + break; + } + if (j != 4) + { + imprisionPos = j; + if (gBattleMons[bankAtk].pp[j] != 0) + gBattleMons[bankAtk].pp[j]--; + } + } + } + + if (imprisionPos != 4 + && !(gBattleMons[bankAtk].status2 & STATUS2_TRANSFORMED) + && !(gDisableStructs[bankAtk].unk18_b & gBitTable[imprisionPos])) + { + gActiveBank = bankAtk; + EmitSetMonData(0, REQUEST_PPMOVE1_BATTLE + imprisionPos, 0, 1, &gBattleMons[gActiveBank].pp[imprisionPos]); + MarkBufferBankForExecution(gActiveBank); + } +} + +void PressurePPLoseOnUsingPerishSong(u8 bankAtk) +{ + s32 i, j; + s32 perishSongPos = 4; + + for (i = 0; i < gNoOfAllBanks; i++) + { + if (gBattleMons[i].ability == ABILITY_PRESSURE && i != bankAtk) + { + for (j = 0; j < 4; j++) + { + if (gBattleMons[bankAtk].moves[j] == MOVE_PERISH_SONG) + break; + } + if (j != 4) + { + perishSongPos = j; + if (gBattleMons[bankAtk].pp[j] != 0) + gBattleMons[bankAtk].pp[j]--; + } + } + } + + if (perishSongPos != 4 + && !(gBattleMons[bankAtk].status2 & STATUS2_TRANSFORMED) + && !(gDisableStructs[bankAtk].unk18_b & gBitTable[perishSongPos])) + { + gActiveBank = bankAtk; + EmitSetMonData(0, REQUEST_PPMOVE1_BATTLE + perishSongPos, 0, 1, &gBattleMons[gActiveBank].pp[perishSongPos]); + MarkBufferBankForExecution(gActiveBank); + } +} + +void MarkAllBufferBanksForExecution(void) // unused +{ + s32 i; + + if (gBattleTypeFlags & BATTLE_TYPE_LINK) + { + for (i = 0; i < gNoOfAllBanks; i++) + gBattleExecBuffer |= gBitTable[i] << 0x1C; + } + else + { + for (i = 0; i < gNoOfAllBanks; i++) + gBattleExecBuffer |= gBitTable[i]; + } +} + +void MarkBufferBankForExecution(u8 bank) +{ + if (gBattleTypeFlags & BATTLE_TYPE_LINK) + { + gBattleExecBuffer |= gBitTable[bank] << 0x1C; + } + else + { + gBattleExecBuffer |= gBitTable[bank]; + } +} + +void sub_803F850(u8 arg0) +{ + s32 i; + + for (i = 0; i < sub_8009FCC(); i++) + gBattleExecBuffer |= gBitTable[arg0] << (i << 2); + + gBattleExecBuffer &= ~(0x10000000 << arg0); +} + +void CancelMultiTurnMoves(u8 bank) +{ + gBattleMons[bank].status2 &= ~(STATUS2_MULTIPLETURNS); + gBattleMons[bank].status2 &= ~(STATUS2_LOCK_CONFUSE); + gBattleMons[bank].status2 &= ~(STATUS2_UPROAR); + gBattleMons[bank].status2 &= ~(STATUS2_BIDE); + + gStatuses3[bank] &= ~(STATUS3_SEMI_INVULNERABLE); + + gDisableStructs[bank].rolloutCounter1 = 0; + gDisableStructs[bank].furyCutterCounter = 0; +} + +bool8 WasUnableToUseMove(u8 bank) +{ + if (gProtectStructs[bank].prlzImmobility + || gProtectStructs[bank].targetNotAffected + || gProtectStructs[bank].usedImprisionedMove + || gProtectStructs[bank].loveImmobility + || gProtectStructs[bank].usedDisabledMove + || gProtectStructs[bank].usedTauntedMove + || gProtectStructs[bank].flag2Unknown + || gProtectStructs[bank].flinchImmobility + || gProtectStructs[bank].confusionSelfDmg) + return TRUE; + else + return FALSE; +} + +void PrepareStringBattle(u16 stringId, u8 bank) +{ + gActiveBank = bank; + EmitPrintString(0, stringId); + MarkBufferBankForExecution(gActiveBank); +} + +void ResetSentPokesToOpponentValue(void) +{ + s32 i; + u32 bits = 0; + + gSentPokesToOpponent[0] = 0; + gSentPokesToOpponent[1] = 0; + + for (i = 0; i < gNoOfAllBanks; i += 2) + bits |= gBitTable[gBattlePartyID[i]]; + + for (i = 1; i < gNoOfAllBanks; i += 2) + gSentPokesToOpponent[(i & BIT_MON) >> 1] = bits; +} + +void sub_803F9EC(u8 bank) +{ + s32 i = 0; + u32 bits = 0; + + if (GetBankSide(bank) == SIDE_OPPONENT) + { + u8 id = ((bank & BIT_MON) >> 1); + gSentPokesToOpponent[id] = 0; + + for (i = 0; i < gNoOfAllBanks; i += 2) + { + if (!(gAbsentBankFlags & gBitTable[i])) + bits |= gBitTable[gBattlePartyID[i]]; + } + + gSentPokesToOpponent[id] = bits; + } +} + +void sub_803FA70(u8 bank) +{ + if (GetBankSide(bank) == SIDE_OPPONENT) + { + sub_803F9EC(bank); + } + else + { + s32 i; + for (i = 1; i < gNoOfAllBanks; i++) + gSentPokesToOpponent[(i & BIT_MON) >> 1] |= gBitTable[gBattlePartyID[bank]]; + } +} void BattleScriptPush(const u8* bsPtr) { @@ -828,7 +1092,7 @@ u8 TurnBasedEffects(void) { gBankAttacker = gActiveBank; gBattleMons[gActiveBank].status2 -= 0x10; // uproar timer goes down - if (HasMoveFailed(gActiveBank)) + if (WasUnableToUseMove(gActiveBank)) { CancelMultiTurnMoves(gActiveBank); gBattleCommunication[MULTISTRING_CHOOSER] = 1; @@ -854,7 +1118,7 @@ u8 TurnBasedEffects(void) if (gBattleMons[gActiveBank].status2 & STATUS2_LOCK_CONFUSE) { gBattleMons[gActiveBank].status2 -= 0x400; - if (HasMoveFailed(gActiveBank)) + if (WasUnableToUseMove(gActiveBank)) CancelMultiTurnMoves(gActiveBank); else if (!(gBattleMons[gActiveBank].status2 & STATUS2_LOCK_CONFUSE) && (gBattleMons[gActiveBank].status2 & STATUS2_MULTIPLETURNS)) @@ -1125,7 +1389,7 @@ bool8 sub_8041728(void) case 4: do { - gBank1 = gBankTarget = gBattleStruct->field_4E; //or should banks be switched? + gBank1 = gBankTarget = gBattleStruct->field_4E; if (gBattleMons[gBattleStruct->field_4E].hp == 0 && !(gAbsentBankFlags & gBitTable[gBattleStruct->field_4E])) { @@ -6190,7 +6454,7 @@ void ClearFuryCutterDestinyBondGrudge(u8 bank) gStatuses3[bank] &= ~(STATUS3_GRUDGE); } -void sub_80458B4(void) +void HandleAction_RunBattleScript(void) // identical to RunBattleScriptCommands { if (gBattleExecBuffer == 0) gBattleScriptingCommandsTable[*gBattlescriptCurrInstr]();