From 1a1bad312972217a7ef390df469b8cf763626a66 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 9 Feb 2018 18:46:00 +0100 Subject: [PATCH] decompile pokemon_item_effect --- asm/pokemon_1.s | 9 - asm/pokemon_item_effect.s | 1967 ---------------------------- include/constants/items.h | 3 + include/pokemon_item_effects.h | 2 +- ld_script.txt | 4 - src/battle_script_commands.c | 2 +- src/calculate_base_damage.c | 283 ----- src/pokemon_1.c | 2179 ++++++++++++++++++++++++++++++++ src/pokemon_2.c | 1365 -------------------- src/pokemon_3.c | 27 +- 10 files changed, 2196 insertions(+), 3645 deletions(-) delete mode 100644 asm/pokemon_1.s delete mode 100644 asm/pokemon_item_effect.s delete mode 100644 src/calculate_base_damage.c delete mode 100644 src/pokemon_2.c diff --git a/asm/pokemon_1.s b/asm/pokemon_1.s deleted file mode 100644 index da4dca0ed..000000000 --- a/asm/pokemon_1.s +++ /dev/null @@ -1,9 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/pokemon_item_effect.s b/asm/pokemon_item_effect.s deleted file mode 100644 index be7d3be49..000000000 --- a/asm/pokemon_item_effect.s +++ /dev/null @@ -1,1967 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start ExecuteTableBasedItemEffect_ -@ bool8 ExecuteTableBasedItemEffect_(struct pokemon *mon, u16 itemId, u8 a3, u8 monMoveIndex) -ExecuteTableBasedItemEffect_: @ 806BD04 - push {r4,lr} - sub sp, 0x4 - lsls r1, 16 - lsrs r1, 16 - lsls r2, 24 - lsrs r2, 24 - lsls r3, 24 - lsrs r3, 24 - movs r4, 0 - str r4, [sp] - bl ExecuteTableBasedItemEffect - lsls r0, 24 - lsrs r0, 24 - add sp, 0x4 - pop {r4} - pop {r1} - bx r1 - thumb_func_end ExecuteTableBasedItemEffect_ - - thumb_func_start ExecuteTableBasedItemEffect -@ bool8 ExecuteTableBasedItemEffect(struct pokemon *mon, u16 itemId, u8 a3, u8 monMoveIndex, u8 a5) -ExecuteTableBasedItemEffect: @ 806BD28 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x44 - mov r8, r0 - ldr r0, [sp, 0x64] - lsls r1, 16 - lsrs r1, 16 - str r1, [sp, 0xC] - lsls r2, 24 - lsrs r2, 24 - str r2, [sp, 0x10] - lsls r3, 24 - lsrs r3, 24 - str r3, [sp, 0x14] - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x18] - movs r0, 0x1 - str r0, [sp, 0x20] - movs r1, 0x6 - str r1, [sp, 0x28] - movs r2, 0 - str r2, [sp, 0x30] - movs r3, 0x4 - str r3, [sp, 0x38] - movs r5, 0 - str r5, [sp, 0x3C] - mov r0, r8 - movs r1, 0xC - bl GetMonData - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0xAF - bne _0806BDBC - ldr r0, =gMain - ldr r1, =0x00000439 - adds r0, r1 - ldrb r1, [r0] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0806BDA8 - ldr r2, =gEnigmaBerries - ldr r0, =gBankInMenu - ldrb r1, [r0] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r0, [r0, 0x7] - b _0806BDC4 - .pool -_0806BDA8: - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r2, =0x00003226 - adds r0, r2 - ldrb r0, [r0] - b _0806BDC4 - .pool -_0806BDBC: - bl ItemId_GetHoldEffect - lsls r0, 24 - lsrs r0, 24 -_0806BDC4: - str r0, [sp, 0x34] - ldr r1, =gStringBattler - ldr r0, =gBankInMenu - ldrb r2, [r0] - strb r2, [r1] - ldr r0, =gMain - ldr r3, =0x00000439 - adds r0, r3 - ldrb r1, [r0] - movs r0, 0x2 - ands r0, r1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0 - beq _0806BE64 - ldr r0, =gActiveBattler - strb r2, [r0] - ldrb r0, [r0] - bl GetBattlerSide - lsls r0, 24 - lsrs r0, 24 - negs r1, r0 - orrs r1, r0 - lsrs r1, 31 - str r1, [sp, 0x1C] - ldr r0, =gBattlersCount - ldr r4, [sp, 0xC] - subs r4, 0xD - ldrb r0, [r0] - cmp r1, r0 - bge _0806BE70 - ldr r2, =gBattlerPartyIndexes - lsls r0, r1, 1 - adds r0, r2 - ldrh r3, [r0] - ldr r5, [sp, 0x10] - lsls r0, r5, 16 - lsrs r1, r0, 16 - adds r5, r0, 0 - cmp r3, r1 - bne _0806BE3C - ldr r0, [sp, 0x1C] - str r0, [sp, 0x38] - b _0806BE70 - .pool -_0806BE3C: - ldr r1, [sp, 0x1C] - adds r1, 0x2 - str r1, [sp, 0x1C] - ldr r0, =gBattlersCount - ldrb r0, [r0] - cmp r1, r0 - bge _0806BE70 - lsls r0, r1, 1 - adds r0, r2 - ldrh r1, [r0] - lsrs r0, r5, 16 - cmp r1, r0 - bne _0806BE3C - ldr r2, [sp, 0x1C] - lsls r0, r2, 24 - lsrs r0, 24 - str r0, [sp, 0x38] - b _0806BE70 - .pool -_0806BE64: - ldr r0, =gActiveBattler - strb r1, [r0] - movs r3, 0x4 - str r3, [sp, 0x38] - ldr r4, [sp, 0xC] - subs r4, 0xD -_0806BE70: - lsls r0, r4, 16 - lsrs r0, 16 - cmp r0, 0xA5 - bhi _0806BEF0 - ldr r1, =gItemEffectTable - lsls r0, r4, 2 - adds r0, r1 - ldr r0, [r0] - cmp r0, 0 - bne _0806BE94 - ldr r5, [sp, 0xC] - cmp r5, 0xAF - beq _0806BE9A - b _0806BEF0 - .pool -_0806BE94: - ldr r1, [sp, 0xC] - cmp r1, 0xAF - bne _0806BEF6 -_0806BE9A: - ldr r0, =gMain - ldr r2, =0x00000439 - adds r0, r2 - ldrb r1, [r0] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0806BECC - ldr r0, =gActiveBattler - ldrb r1, [r0] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - ldr r1, =gEnigmaBerries + 8 - adds r0, r1 - b _0806BEF6 - .pool -_0806BECC: - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r3, =0x00003214 - adds r3, r0, r3 - str r3, [sp, 0x24] - b _0806BEF8 - .pool -_0806BEE0: - mov r0, r8 - movs r2, 0 - ldr r3, [sp, 0x10] - bl BeginEvolutionScene - movs r0, 0 - bl _0806CD5C -_0806BEF0: - movs r0, 0x1 - bl _0806CD5C -_0806BEF6: - str r0, [sp, 0x24] -_0806BEF8: - movs r5, 0 - str r5, [sp, 0x1C] -_0806BEFC: - ldr r0, [sp, 0x1C] - cmp r0, 0x5 - bls _0806BF06 - bl _0806CD4C -_0806BF06: - lsls r0, 2 - ldr r1, =_0806BF14 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0806BF14: - .4byte _0806BF2C - .4byte _0806BFFC - .4byte _0806C08C - .4byte _0806C120 - .4byte _0806C300 - .4byte _0806C9BE -_0806BF2C: - ldr r1, [sp, 0x24] - ldr r3, [sp, 0x1C] - adds r2, r1, r3 - ldrb r1, [r2] - movs r0, 0x80 - ands r0, r1 - adds r6, r2, 0 - cmp r0, 0 - beq _0806BF76 - ldr r0, =gMain - ldr r5, =0x00000439 - adds r0, r5 - ldrb r1, [r0] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0806BF76 - ldr r0, [sp, 0x38] - cmp r0, 0x4 - beq _0806BF76 - ldr r1, =gBattleMons - movs r0, 0x58 - ldr r2, [sp, 0x38] - muls r0, r2 - adds r1, 0x50 - adds r2, r0, r1 - ldr r1, [r2] - movs r0, 0xF0 - lsls r0, 12 - ands r0, r1 - cmp r0, 0 - beq _0806BF76 - ldr r0, =0xfff0ffff - ands r1, r0 - str r1, [r2] - movs r3, 0 - str r3, [sp, 0x20] -_0806BF76: - ldrb r1, [r6] - movs r0, 0x30 - ands r0, r1 - cmp r0, 0 - beq _0806BFA4 - ldr r1, =gBattleMons - ldr r0, =gActiveBattler - ldrb r2, [r0] - movs r0, 0x58 - muls r0, r2 - adds r1, 0x50 - adds r2, r0, r1 - ldr r1, [r2] - movs r3, 0x80 - lsls r3, 13 - adds r0, r1, 0 - ands r0, r3 - cmp r0, 0 - bne _0806BFA4 - orrs r1, r3 - str r1, [r2] - movs r5, 0 - str r5, [sp, 0x20] -_0806BFA4: - ldrb r0, [r6] - movs r3, 0xF - ands r3, r0 - cmp r3, 0 - bne _0806BFB2 - bl _0806CD4C -_0806BFB2: - ldr r6, =gBattleMons - ldr r5, =gActiveBattler - ldrb r0, [r5] - movs r4, 0x58 - muls r0, r4 - adds r1, r0, r6 - ldrb r2, [r1, 0x19] - movs r0, 0x19 - ldrsb r0, [r1, r0] - cmp r0, 0xB - ble _0806BFCC - bl _0806CD4C -_0806BFCC: - adds r0, r2, r3 - strb r0, [r1, 0x19] - ldrb r0, [r5] - muls r0, r4 - adds r1, r0, r6 - movs r0, 0x19 - ldrsb r0, [r1, r0] - cmp r0, 0xC - bgt _0806BFE0 - b _0806C110 -_0806BFE0: - movs r0, 0xC - strb r0, [r1, 0x19] - b _0806C110 - .pool -_0806BFFC: - ldr r1, [sp, 0x24] - ldr r3, [sp, 0x1C] - adds r2, r1, r3 - ldrb r1, [r2] - movs r0, 0xF0 - ands r0, r1 - lsls r3, r0, 24 - adds r6, r2, 0 - cmp r3, 0 - beq _0806C042 - ldr r7, =gBattleMons - ldr r5, =gActiveBattler - ldrb r0, [r5] - movs r4, 0x58 - muls r0, r4 - adds r1, r0, r7 - ldrb r2, [r1, 0x1A] - movs r0, 0x1A - ldrsb r0, [r1, r0] - cmp r0, 0xB - bgt _0806C042 - lsrs r0, r3, 28 - adds r0, r2, r0 - strb r0, [r1, 0x1A] - ldrb r0, [r5] - muls r0, r4 - adds r1, r0, r7 - movs r0, 0x1A - ldrsb r0, [r1, r0] - cmp r0, 0xC - ble _0806C03E - movs r0, 0xC - strb r0, [r1, 0x1A] -_0806C03E: - movs r5, 0 - str r5, [sp, 0x20] -_0806C042: - ldrb r0, [r6] - movs r3, 0xF - ands r3, r0 - cmp r3, 0 - bne _0806C050 - bl _0806CD4C -_0806C050: - ldr r6, =gBattleMons - ldr r5, =gActiveBattler - ldrb r0, [r5] - movs r4, 0x58 - muls r0, r4 - adds r1, r0, r6 - ldrb r2, [r1, 0x1B] - movs r0, 0x1B - ldrsb r0, [r1, r0] - cmp r0, 0xB - ble _0806C06A - bl _0806CD4C -_0806C06A: - adds r0, r2, r3 - strb r0, [r1, 0x1B] - ldrb r0, [r5] - muls r0, r4 - adds r1, r0, r6 - movs r0, 0x1B - ldrsb r0, [r1, r0] - cmp r0, 0xC - ble _0806C110 - movs r0, 0xC - strb r0, [r1, 0x1B] - b _0806C110 - .pool -_0806C08C: - ldr r1, [sp, 0x24] - ldr r3, [sp, 0x1C] - adds r2, r1, r3 - ldrb r1, [r2] - movs r0, 0xF0 - ands r0, r1 - lsls r3, r0, 24 - adds r6, r2, 0 - cmp r3, 0 - beq _0806C0D2 - ldr r7, =gBattleMons - ldr r5, =gActiveBattler - ldrb r0, [r5] - movs r4, 0x58 - muls r0, r4 - adds r1, r0, r7 - ldrb r2, [r1, 0x1E] - movs r0, 0x1E - ldrsb r0, [r1, r0] - cmp r0, 0xB - bgt _0806C0D2 - lsrs r0, r3, 28 - adds r0, r2, r0 - strb r0, [r1, 0x1E] - ldrb r0, [r5] - muls r0, r4 - adds r1, r0, r7 - movs r0, 0x1E - ldrsb r0, [r1, r0] - cmp r0, 0xC - ble _0806C0CE - movs r0, 0xC - strb r0, [r1, 0x1E] -_0806C0CE: - movs r5, 0 - str r5, [sp, 0x20] -_0806C0D2: - ldrb r0, [r6] - movs r3, 0xF - ands r3, r0 - cmp r3, 0 - bne _0806C0E0 - bl _0806CD4C -_0806C0E0: - ldr r6, =gBattleMons - ldr r5, =gActiveBattler - ldrb r0, [r5] - movs r4, 0x58 - muls r0, r4 - adds r1, r0, r6 - ldrb r2, [r1, 0x1C] - movs r0, 0x1C - ldrsb r0, [r1, r0] - cmp r0, 0xB - ble _0806C0FA - bl _0806CD4C -_0806C0FA: - adds r0, r2, r3 - strb r0, [r1, 0x1C] - ldrb r0, [r5] - muls r0, r4 - adds r1, r0, r6 - movs r0, 0x1C - ldrsb r0, [r1, r0] - cmp r0, 0xC - ble _0806C110 - movs r0, 0xC - strb r0, [r1, 0x1C] -_0806C110: - movs r0, 0 - str r0, [sp, 0x20] - bl _0806CD4C - .pool -_0806C120: - ldr r1, [sp, 0x24] - ldr r3, [sp, 0x1C] - adds r2, r1, r3 - ldrb r1, [r2] - movs r0, 0x80 - ands r0, r1 - adds r6, r2, 0 - cmp r0, 0 - beq _0806C168 - ldr r5, =gSideTimers - ldr r4, =gActiveBattler - ldrb r0, [r4] - bl GetBattlerSide - lsls r0, 24 - lsrs r0, 24 - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 2 - adds r1, r5 - ldrb r0, [r1, 0x4] - cmp r0, 0 - bne _0806C168 - ldrb r0, [r4] - bl GetBattlerSide - lsls r0, 24 - lsrs r0, 24 - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 2 - adds r1, r5 - movs r0, 0x5 - strb r0, [r1, 0x4] - movs r5, 0 - str r5, [sp, 0x20] -_0806C168: - ldrb r1, [r6] - movs r0, 0x40 - ands r0, r1 - cmp r0, 0 - beq _0806C1CA - mov r0, r8 - movs r1, 0x38 - movs r2, 0 - bl GetMonData - cmp r0, 0x64 - beq _0806C1CA - ldr r5, =gExperienceTables - mov r0, r8 - movs r1, 0x38 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - mov r0, r8 - movs r1, 0xB - movs r2, 0 - bl GetMonData - adds r4, 0x1 - lsls r4, 2 - ldr r2, =gBaseStats - lsls r1, r0, 3 - subs r1, r0 - lsls r1, 2 - adds r1, r2 - ldrb r1, [r1, 0x13] - movs r0, 0xCA - lsls r0, 1 - muls r0, r1 - adds r4, r0 - adds r4, r5 - ldr r0, [r4] - str r0, [sp] - mov r0, r8 - movs r1, 0x19 - mov r2, sp - bl SetMonData - mov r0, r8 - bl CalculateMonStats - movs r0, 0 - str r0, [sp, 0x20] -_0806C1CA: - ldrb r1, [r6] - movs r0, 0x20 - ands r0, r1 - cmp r0, 0 - beq _0806C206 - mov r0, r8 - ldr r1, [sp, 0x10] - movs r2, 0x7 - ldr r3, [sp, 0x38] - bl HealStatusConditions - lsls r0, 24 - cmp r0, 0 - bne _0806C206 - ldr r1, [sp, 0x38] - cmp r1, 0x4 - beq _0806C202 - ldr r1, =gBattleMons - movs r0, 0x58 - ldr r3, [sp, 0x38] - adds r2, r3, 0 - muls r2, r0 - adds r1, 0x50 - adds r2, r1 - ldr r0, [r2] - ldr r1, =0xf7ffffff - ands r0, r1 - str r0, [r2] -_0806C202: - movs r5, 0 - str r5, [sp, 0x20] -_0806C206: - ldrb r1, [r6] - movs r0, 0x10 - ands r0, r1 - cmp r0, 0 - beq _0806C226 - ldr r2, =0x00000f88 - mov r0, r8 - ldr r1, [sp, 0x10] - ldr r3, [sp, 0x38] - bl HealStatusConditions - lsls r0, 24 - cmp r0, 0 - bne _0806C226 - movs r0, 0 - str r0, [sp, 0x20] -_0806C226: - ldrb r1, [r6] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _0806C246 - mov r0, r8 - ldr r1, [sp, 0x10] - movs r2, 0x10 - ldr r3, [sp, 0x38] - bl HealStatusConditions - lsls r0, 24 - cmp r0, 0 - bne _0806C246 - movs r1, 0 - str r1, [sp, 0x20] -_0806C246: - ldrb r1, [r6] - movs r0, 0x4 - ands r0, r1 - cmp r0, 0 - beq _0806C266 - mov r0, r8 - ldr r1, [sp, 0x10] - movs r2, 0x20 - ldr r3, [sp, 0x38] - bl HealStatusConditions - lsls r0, 24 - cmp r0, 0 - bne _0806C266 - movs r2, 0 - str r2, [sp, 0x20] -_0806C266: - ldrb r1, [r6] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0806C286 - mov r0, r8 - ldr r1, [sp, 0x10] - movs r2, 0x40 - ldr r3, [sp, 0x38] - bl HealStatusConditions - lsls r0, 24 - cmp r0, 0 - bne _0806C286 - movs r3, 0 - str r3, [sp, 0x20] -_0806C286: - ldrb r1, [r6] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _0806C294 - bl _0806CD4C -_0806C294: - ldr r0, =gMain - ldr r5, =0x00000439 - adds r0, r5 - ldrb r1, [r0] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _0806C2A8 - bl _0806CD4C -_0806C2A8: - ldr r0, [sp, 0x38] - cmp r0, 0x4 - bne _0806C2B2 - bl _0806CD4C -_0806C2B2: - ldr r1, =gBattleMons - movs r0, 0x58 - ldr r2, [sp, 0x38] - muls r0, r2 - adds r1, 0x50 - adds r2, r0, r1 - ldr r1, [r2] - movs r0, 0x7 - ands r0, r1 - cmp r0, 0 - bne _0806C2CC - bl _0806CD4C -_0806C2CC: - movs r0, 0x8 - negs r0, r0 - ands r1, r0 - str r1, [r2] - movs r3, 0 - str r3, [sp, 0x20] - bl _0806CD4C - .pool -_0806C300: - ldr r5, [sp, 0x24] - ldr r1, [sp, 0x1C] - adds r0, r5, r1 - ldrb r0, [r0] - mov r10, r0 - movs r0, 0x20 - mov r2, r10 - ands r0, r2 - cmp r0, 0 - beq _0806C3D8 - movs r0, 0xDF - ands r2, r0 - mov r10, r2 - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - ldr r1, =gUnknown_08329D22 - ldr r3, [sp, 0x14] - adds r1, r3, r1 - ldrb r1, [r1] - ands r0, r1 - lsls r1, r3, 1 - lsrs r0, r1 - str r0, [sp] - adds r5, r3, 0 - adds r5, 0xD - mov r0, r8 - adds r1, r5, 0 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - ldr r2, [sp, 0x14] - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x2C] - ldr r0, [sp] - cmp r0, 0x2 - bhi _0806C3D8 - ldr r0, [sp, 0x2C] - cmp r0, 0x4 - bls _0806C3D8 - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - ldr r1, =gUnknown_08329D2A - ldr r2, [sp, 0x14] - adds r1, r2, r1 - ldrb r1, [r1] - adds r0, r1 - str r0, [sp] - mov r0, r8 - movs r1, 0x15 - mov r2, sp - bl SetMonData - mov r0, r8 - adds r1, r5, 0 - movs r2, 0 - bl GetMonData - lsls r0, 16 - lsrs r0, 16 - ldr r1, [sp] - lsls r1, 24 - lsrs r1, 24 - ldr r2, [sp, 0x14] - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r0, 24 - ldr r3, [sp, 0x2C] - subs r0, r3 - str r0, [sp] - ldr r4, [sp, 0x14] - adds r4, 0x11 - mov r0, r8 - adds r1, r4, 0 - movs r2, 0 - bl GetMonData - ldr r1, [sp] - adds r0, r1 - str r0, [sp] - mov r0, r8 - adds r1, r4, 0 - mov r2, sp - bl SetMonData - movs r5, 0 - str r5, [sp, 0x20] -_0806C3D8: - movs r0, 0 - str r0, [sp, 0x2C] - mov r1, r10 - cmp r1, 0 - bne _0806C3E6 - bl _0806CD4C -_0806C3E6: - movs r0, 0x1 - mov r2, r10 - ands r0, r2 - cmp r0, 0 - bne _0806C3F2 - b _0806C9AA -_0806C3F2: - ldr r3, [sp, 0x2C] - cmp r3, 0x7 - bls _0806C3FA - b _0806C9AA -_0806C3FA: - lsls r0, r3, 2 - ldr r1, =_0806C410 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0806C410: - .4byte _0806C430 - .4byte _0806C430 - .4byte _0806C4DC - .4byte _0806C700 - .4byte _0806C9AA - .4byte _0806C9AA - .4byte _0806C9AA - .4byte _0806C994 -_0806C430: - mov r0, r8 - bl GetMonEVCount - lsls r0, 16 - lsrs r6, r0, 16 - ldr r5, [sp, 0x24] - ldr r1, [sp, 0x28] - adds r0, r5, r1 - ldrb r5, [r0] - ldr r0, =gUnknown_08329EC2 - ldr r2, [sp, 0x2C] - adds r0, r2, r0 - ldrb r1, [r0] - mov r0, r8 - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - str r1, [sp, 0x4] - lsls r0, r5, 24 - asrs r2, r0, 24 - cmp r2, 0 - ble _0806C498 - ldr r0, =0x000001fd - cmp r6, r0 - bls _0806C466 - b _0806BEF0 -_0806C466: - adds r3, r1, 0 - cmp r3, 0x63 - ble _0806C46E - b _0806C9AA -_0806C46E: - adds r1, r3, r2 - cmp r1, 0x64 - ble _0806C484 - adds r0, r2, 0 - adds r0, 0x64 - subs r5, r0, r1 - b _0806C486 - .pool -_0806C484: - adds r5, r2, 0 -_0806C486: - adds r1, r6, r5 - movs r0, 0xFF - lsls r0, 1 - cmp r1, r0 - bls _0806C494 - adds r0, r5, r0 - subs r5, r0, r1 -_0806C494: - adds r0, r3, r5 - b _0806C4B2 -_0806C498: - cmp r1, 0 - bne _0806C4A8 - movs r3, 0x1 - str r3, [sp, 0x3C] - ldr r0, [sp, 0x28] - adds r0, 0x1 - lsls r0, 24 - b _0806C83E -_0806C4A8: - adds r0, r1, r2 - str r0, [sp, 0x4] - cmp r0, 0 - bge _0806C4B4 - movs r0, 0 -_0806C4B2: - str r0, [sp, 0x4] -_0806C4B4: - ldr r0, =gUnknown_08329EC2 - ldr r5, [sp, 0x2C] - adds r0, r5, r0 - ldrb r1, [r0] - add r2, sp, 0x4 - mov r0, r8 - bl SetMonData - mov r0, r8 - bl CalculateMonStats - ldr r0, [sp, 0x28] - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x28] - b _0806C978 - .pool -_0806C4DC: - movs r0, 0x10 - mov r1, r10 - ands r0, r1 - cmp r0, 0 - beq _0806C59C - mov r0, r8 - movs r1, 0x39 - movs r2, 0 - bl GetMonData - cmp r0, 0 - beq _0806C4FC - ldr r0, [sp, 0x28] - adds r0, 0x1 - lsls r0, 24 - b _0806C83E -_0806C4FC: - ldr r0, =gMain - ldr r2, =0x00000439 - adds r0, r2 - ldrb r1, [r0] - movs r4, 0x2 - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0806C5B2 - ldr r3, [sp, 0x38] - cmp r3, 0x4 - beq _0806C55C - ldr r2, =gAbsentBattlerFlags - ldr r1, =gBitTable - lsls r0, r3, 2 - adds r0, r1 - ldr r1, [r0] - ldrb r0, [r2] - bics r0, r1 - strb r0, [r2] - ldr r1, =gBattlerPartyIndexes - lsls r0, r3, 1 - adds r0, r1 - ldrb r0, [r0] - bl pokemon_order_func - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - ldr r0, [sp, 0x38] - bl CopyPlayerPartyMonToBattleData - ldr r0, =gActiveBattler - ldrb r0, [r0] - b _0806C574 - .pool -_0806C55C: - ldr r3, =gAbsentBattlerFlags - ldr r1, =gBitTable - ldr r2, =gActiveBattler - ldrb r0, [r2] - eors r0, r4 - lsls r0, 2 - adds r0, r1 - ldr r1, [r0] - ldrb r0, [r3] - bics r0, r1 - strb r0, [r3] - ldrb r0, [r2] -_0806C574: - bl GetBattlerSide - lsls r0, 24 - cmp r0, 0 - bne _0806C5B2 - ldr r1, =gBattleResults - ldrb r0, [r1, 0x4] - cmp r0, 0xFE - bhi _0806C5B2 - adds r0, 0x1 - strb r0, [r1, 0x4] - b _0806C5B2 - .pool -_0806C59C: - mov r0, r8 - movs r1, 0x39 - movs r2, 0 - bl GetMonData - cmp r0, 0 - bne _0806C5B2 - ldr r0, [sp, 0x28] - adds r0, 0x1 - lsls r0, 24 - b _0806C83E -_0806C5B2: - ldr r1, [sp, 0x28] - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x28] - ldr r5, [sp, 0x24] - adds r1, r5, r1 - ldrb r1, [r1] - str r1, [sp] - adds r0, r1, 0 - cmp r0, 0xFE - beq _0806C5F4 - cmp r0, 0xFE - bhi _0806C5D4 - cmp r0, 0xFD - beq _0806C60A - b _0806C612 -_0806C5D4: - cmp r1, 0xFF - bne _0806C612 - mov r0, r8 - movs r1, 0x3A - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - mov r0, r8 - movs r1, 0x39 - movs r2, 0 - bl GetMonData - subs r4, r0 - str r4, [sp] - b _0806C612 -_0806C5F4: - mov r0, r8 - movs r1, 0x3A - movs r2, 0 - bl GetMonData - lsrs r0, 1 - str r0, [sp] - cmp r0, 0 - bne _0806C612 - movs r0, 0x1 - b _0806C610 -_0806C60A: - ldr r0, =gBattleScripting - adds r0, 0x23 - ldrb r0, [r0] -_0806C610: - str r0, [sp] -_0806C612: - mov r0, r8 - movs r1, 0x3A - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - mov r0, r8 - movs r1, 0x39 - movs r2, 0 - bl GetMonData - cmp r4, r0 - beq _0806C6F0 - ldr r0, [sp, 0x18] - cmp r0, 0 - bne _0806C6E4 - mov r0, r8 - movs r1, 0x39 - movs r2, 0 - bl GetMonData - ldr r1, [sp] - adds r0, r1 - str r0, [sp] - mov r0, r8 - movs r1, 0x3A - movs r2, 0 - bl GetMonData - ldr r1, [sp] - cmp r1, r0 - bls _0806C65E - mov r0, r8 - movs r1, 0x3A - movs r2, 0 - bl GetMonData - str r0, [sp] -_0806C65E: - mov r0, r8 - movs r1, 0x39 - mov r2, sp - bl SetMonData - ldr r0, =gMain - ldr r1, =0x00000439 - adds r0, r1 - ldrb r1, [r0] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0806C6EC - ldr r2, [sp, 0x38] - cmp r2, 0x4 - beq _0806C6EC - ldr r1, =gBattleMons - movs r0, 0x58 - muls r0, r2 - adds r0, r1 - ldr r1, [sp] - strh r1, [r0, 0x28] - movs r0, 0x10 - mov r3, r10 - ands r0, r3 - cmp r0, 0 - bne _0806C6EC - ldr r4, =gActiveBattler - ldrb r0, [r4] - bl GetBattlerSide - lsls r0, 24 - cmp r0, 0 - bne _0806C6EC - ldr r1, =gBattleResults - ldrb r0, [r1, 0x3] - cmp r0, 0xFE - bhi _0806C6AE - adds r0, 0x1 - strb r0, [r1, 0x3] -_0806C6AE: - ldrb r5, [r4] - add r0, sp, 0x38 - ldrb r0, [r0] - strb r0, [r4] - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl BtlController_EmitGetMonData - ldrb r0, [r4] - bl MarkBattlerForControllerExec - strb r5, [r4] - b _0806C6EC - .pool -_0806C6E4: - ldr r1, =gBattleMoveDamage - ldr r0, [sp] - negs r0, r0 - str r0, [r1] -_0806C6EC: - movs r1, 0 - str r1, [sp, 0x20] -_0806C6F0: - movs r0, 0xEF - mov r2, r10 - ands r2, r0 - mov r10, r2 - b _0806C9AA - .pool -_0806C700: - movs r7, 0x2 - mov r0, r10 - ands r0, r7 - cmp r0, 0 - beq _0806C70C - b _0806C858 -_0806C70C: - movs r5, 0 - ldr r3, [sp, 0x28] - adds r3, 0x1 - str r3, [sp, 0x40] -_0806C714: - movs r0, 0x11 - adds r0, r5 - mov r9, r0 - mov r0, r8 - mov r1, r9 - movs r2, 0 - bl GetMonData - str r0, [sp] - adds r7, r5, 0 - adds r7, 0xD - mov r0, r8 - adds r1, r7, 0 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - lsls r0, r5, 24 - lsrs r6, r0, 24 - adds r0, r4, 0 - adds r2, r6, 0 - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r0, 24 - ldr r1, [sp] - cmp r1, r0 - beq _0806C832 - ldr r2, [sp, 0x24] - ldr r3, [sp, 0x28] - adds r0, r2, r3 - ldrb r0, [r0] - adds r0, r1, r0 - str r0, [sp] - mov r0, r8 - adds r1, r7, 0 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - adds r2, r6, 0 - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r0, 24 - ldr r1, [sp] - cmp r1, r0 - bls _0806C7CC - mov r0, r8 - adds r1, r7, 0 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - adds r2, r6, 0 - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] -_0806C7CC: - mov r0, r8 - mov r1, r9 - mov r2, sp - bl SetMonData - ldr r0, =gMain - ldr r1, =0x00000439 - adds r0, r1 - ldrb r1, [r0] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _0806C82E - ldr r2, [sp, 0x38] - cmp r2, 0x4 - beq _0806C82E - ldr r4, =gBattleMons - movs r0, 0x58 - adds r3, r2, 0 - muls r3, r0 - adds r0, r4, 0 - adds r0, 0x50 - adds r0, r3, r0 - ldr r1, [r0] - movs r0, 0x80 - lsls r0, 14 - ands r1, r0 - cmp r1, 0 - bne _0806C82E - ldr r1, =gDisableStructs - lsls r0, r2, 3 - subs r0, r2 - lsls r0, 2 - adds r0, r1 - ldrb r1, [r0, 0x18] - lsrs r1, 4 - ldr r2, =gBitTable - lsls r0, r5, 2 - adds r0, r2 - ldr r0, [r0] - ands r1, r0 - cmp r1, 0 - bne _0806C82E - adds r0, r5, r3 - adds r1, r4, 0 - adds r1, 0x24 - adds r0, r1 - ldr r1, [sp] - strb r1, [r0] -_0806C82E: - movs r3, 0 - str r3, [sp, 0x20] -_0806C832: - adds r5, 0x1 - cmp r5, 0x3 - bgt _0806C83A - b _0806C714 -_0806C83A: - ldr r5, [sp, 0x40] - lsls r0, r5, 24 -_0806C83E: - lsrs r0, 24 - str r0, [sp, 0x28] - b _0806C9AA - .pool -_0806C858: - ldr r6, [sp, 0x14] - adds r6, 0x11 - mov r0, r8 - adds r1, r6, 0 - movs r2, 0 - bl GetMonData - str r0, [sp] - ldr r5, [sp, 0x14] - adds r5, 0xD - mov r0, r8 - adds r1, r5, 0 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - ldr r2, [sp, 0x14] - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r0, 24 - ldr r2, [sp] - cmp r2, r0 - bne _0806C8A0 - b _0806C9AA -_0806C8A0: - ldr r1, [sp, 0x28] - adds r0, r1, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x28] - ldr r0, [sp, 0x24] - adds r1, r0, r1 - ldrb r0, [r1] - adds r0, r2, r0 - str r0, [sp] - mov r0, r8 - adds r1, r5, 0 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - ldr r2, [sp, 0x14] - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r0, 24 - ldr r1, [sp] - cmp r1, r0 - bls _0806C914 - mov r0, r8 - adds r1, r5, 0 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - ldr r2, [sp, 0x14] - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] -_0806C914: - mov r0, r8 - adds r1, r6, 0 - mov r2, sp - bl SetMonData - ldr r0, =gMain - ldr r1, =0x00000439 - adds r0, r1 - ldrb r1, [r0] - adds r0, r7, 0 - ands r0, r1 - cmp r0, 0 - beq _0806C978 - ldr r2, [sp, 0x38] - cmp r2, 0x4 - beq _0806C978 - ldr r4, =gBattleMons - movs r0, 0x58 - adds r3, r2, 0 - muls r3, r0 - adds r0, r4, 0 - adds r0, 0x50 - adds r0, r3, r0 - ldr r0, [r0] - movs r1, 0x80 - lsls r1, 14 - ands r0, r1 - cmp r0, 0 - bne _0806C978 - ldr r1, =gDisableStructs - lsls r0, r2, 3 - subs r0, r2 - lsls r0, 2 - adds r0, r1 - ldrb r1, [r0, 0x18] - lsrs r1, 4 - ldr r2, =gBitTable - ldr r5, [sp, 0x14] - lsls r0, r5, 2 - adds r0, r2 - ldr r0, [r0] - ands r1, r0 - cmp r1, 0 - bne _0806C978 - adds r0, r5, r3 - adds r1, r4, 0 - adds r1, 0x24 - adds r0, r1 - ldr r1, [sp] - strb r1, [r0] -_0806C978: - movs r0, 0 - str r0, [sp, 0x20] - b _0806C9AA - .pool -_0806C994: - mov r0, r8 - movs r1, 0x2 - ldr r2, [sp, 0xC] - bl GetEvolutionTargetSpecies - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - beq _0806C9AA - bl _0806BEE0 -_0806C9AA: - ldr r1, [sp, 0x2C] - adds r1, 0x1 - str r1, [sp, 0x2C] - mov r2, r10 - lsrs r2, 1 - mov r10, r2 - cmp r2, 0 - beq _0806C9BC - b _0806C3E6 -_0806C9BC: - b _0806CD4C -_0806C9BE: - ldr r3, [sp, 0x24] - ldr r5, [sp, 0x1C] - adds r0, r3, r5 - ldrb r0, [r0] - mov r10, r0 - movs r0, 0 - str r0, [sp, 0x2C] - mov r1, r10 - cmp r1, 0 - bne _0806C9D4 - b _0806CD4C -_0806C9D4: - movs r0, 0x1 - mov r2, r10 - ands r0, r2 - cmp r0, 0 - bne _0806C9E0 - b _0806CD3A -_0806C9E0: - ldr r3, [sp, 0x2C] - cmp r3, 0x7 - bls _0806C9E8 - b _0806CD3A -_0806C9E8: - lsls r0, r3, 2 - ldr r1, =_0806C9F8 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0806C9F8: - .4byte _0806CA18 - .4byte _0806CA18 - .4byte _0806CA18 - .4byte _0806CA18 - .4byte _0806CAB8 - .4byte _0806CB94 - .4byte _0806CC00 - .4byte _0806CC68 -_0806CA18: - mov r0, r8 - bl GetMonEVCount - lsls r0, 16 - lsrs r6, r0, 16 - ldr r5, [sp, 0x24] - ldr r1, [sp, 0x28] - adds r0, r5, r1 - ldrb r5, [r0] - ldr r0, =gUnknown_08329EC2 - ldr r4, [sp, 0x2C] - adds r4, 0x2 - adds r0, r4, r0 - ldrb r1, [r0] - mov r0, r8 - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - str r1, [sp, 0x4] - lsls r0, r5, 24 - asrs r2, r0, 24 - cmp r2, 0 - ble _0806CA84 - ldr r0, =0x000001fd - cmp r6, r0 - bls _0806CA52 - bl _0806BEF0 -_0806CA52: - adds r3, r1, 0 - cmp r3, 0x63 - ble _0806CA5A - b _0806CD3A -_0806CA5A: - adds r1, r3, r2 - cmp r1, 0x64 - ble _0806CA70 - adds r0, r2, 0 - adds r0, 0x64 - subs r5, r0, r1 - b _0806CA72 - .pool -_0806CA70: - adds r5, r2, 0 -_0806CA72: - adds r1, r6, r5 - movs r0, 0xFF - lsls r0, 1 - cmp r1, r0 - bls _0806CA80 - adds r0, r5, r0 - subs r5, r0, r1 -_0806CA80: - adds r0, r3, r5 - b _0806CA98 -_0806CA84: - cmp r1, 0 - bne _0806CA8E - movs r2, 0x1 - str r2, [sp, 0x3C] - b _0806CD30 -_0806CA8E: - adds r0, r1, r2 - str r0, [sp, 0x4] - cmp r0, 0 - bge _0806CA9A - movs r0, 0 -_0806CA98: - str r0, [sp, 0x4] -_0806CA9A: - ldr r0, =gUnknown_08329EC2 - adds r0, r4, r0 - ldrb r1, [r0] - add r2, sp, 0x4 - mov r0, r8 - bl SetMonData - mov r0, r8 - bl CalculateMonStats - movs r3, 0 - str r3, [sp, 0x20] - b _0806CD30 - .pool -_0806CAB8: - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - ldr r1, =gUnknown_08329D22 - ldr r5, [sp, 0x14] - adds r1, r5, r1 - ldrb r1, [r1] - ands r0, r1 - lsls r1, r5, 1 - lsrs r0, r1 - str r0, [sp] - adds r6, r5, 0 - adds r6, 0xD - mov r0, r8 - adds r1, r6, 0 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - ldr r2, [sp, 0x14] - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r5, r0, 24 - ldr r0, [sp] - cmp r0, 0x2 - bls _0806CB0A - b _0806CD3A -_0806CB0A: - cmp r5, 0x4 - bhi _0806CB10 - b _0806CD3A -_0806CB10: - mov r0, r8 - movs r1, 0x15 - movs r2, 0 - bl GetMonData - str r0, [sp] - ldr r1, =gUnknown_08329D26 - ldr r2, [sp, 0x14] - adds r1, r2, r1 - ldrb r2, [r1] - ands r2, r0 - str r2, [sp] - ldr r0, =gUnknown_08329D2A - ldr r3, [sp, 0x14] - adds r0, r3, r0 - ldrb r1, [r0] - lsls r0, r1, 1 - adds r0, r1 - adds r2, r0 - str r2, [sp] - mov r0, r8 - movs r1, 0x15 - mov r2, sp - bl SetMonData - mov r0, r8 - adds r1, r6, 0 - movs r2, 0 - bl GetMonData - lsls r0, 16 - lsrs r0, 16 - ldr r1, [sp] - lsls r1, 24 - lsrs r1, 24 - ldr r2, [sp, 0x14] - bl CalculatePPWithBonus - lsls r0, 24 - lsrs r0, 24 - subs r0, r5 - str r0, [sp] - ldr r4, [sp, 0x14] - adds r4, 0x11 - mov r0, r8 - adds r1, r4, 0 - movs r2, 0 - bl GetMonData - ldr r1, [sp] - adds r0, r1 - str r0, [sp] - mov r0, r8 - adds r1, r4, 0 - mov r2, sp - bl SetMonData - movs r5, 0 - str r5, [sp, 0x20] - b _0806CD3A - .pool -_0806CB94: - mov r0, r8 - movs r1, 0x20 - movs r2, 0 - bl GetMonData - cmp r0, 0x63 - bls _0806CBA4 - b _0806CD30 -_0806CBA4: - ldr r0, [sp, 0x20] - cmp r0, 0 - beq _0806CBB2 - ldr r1, [sp, 0x3C] - cmp r1, 0 - bne _0806CBB2 - b _0806CD30 -_0806CBB2: - bl sub_806F104 - lsls r0, 24 - cmp r0, 0 - beq _0806CBBE - b _0806CD30 -_0806CBBE: - ldr r2, [sp, 0x30] - cmp r2, 0 - beq _0806CBC6 - b _0806CD30 -_0806CBC6: - ldr r3, [sp, 0x24] - ldr r5, [sp, 0x28] - adds r0, r3, r5 - ldrb r0, [r0] - str r0, [sp, 0x30] - mov r0, r8 - movs r1, 0x20 - movs r2, 0 - bl GetMonData - adds r5, r0, 0 - str r5, [sp, 0x8] - ldr r0, [sp, 0x30] - lsls r4, r0, 24 - asrs r1, r4, 24 - cmp r1, 0 - ble _0806CCCC - ldr r2, [sp, 0x34] - cmp r2, 0x1B - bne _0806CCCC - movs r0, 0x96 - muls r0, r1 - movs r1, 0x64 - bl __divsi3 - adds r0, r5, r0 - str r0, [sp, 0x8] - adds r2, r4, 0 - b _0806CCD8 -_0806CC00: - mov r0, r8 - movs r1, 0x20 - movs r2, 0 - bl GetMonData - cmp r0, 0x63 - bhi _0806CC10 - b _0806CD30 -_0806CC10: - mov r0, r8 - movs r1, 0x20 - movs r2, 0 - bl GetMonData - cmp r0, 0xC7 - bls _0806CC20 - b _0806CD30 -_0806CC20: - ldr r0, [sp, 0x20] - cmp r0, 0 - beq _0806CC2E - ldr r1, [sp, 0x3C] - cmp r1, 0 - bne _0806CC2E - b _0806CD30 -_0806CC2E: - bl sub_806F104 - lsls r0, 24 - cmp r0, 0 - bne _0806CD30 - ldr r2, [sp, 0x30] - cmp r2, 0 - bne _0806CD30 - ldr r3, [sp, 0x24] - ldr r5, [sp, 0x28] - adds r0, r3, r5 - ldrb r0, [r0] - str r0, [sp, 0x30] - mov r0, r8 - movs r1, 0x20 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - str r4, [sp, 0x8] - ldr r0, [sp, 0x30] - lsls r5, r0, 24 - asrs r1, r5, 24 - cmp r1, 0 - ble _0806CCCC - ldr r2, [sp, 0x34] - cmp r2, 0x1B - beq _0806CCBA - b _0806CCCC -_0806CC68: - mov r0, r8 - movs r1, 0x20 - movs r2, 0 - bl GetMonData - cmp r0, 0xC7 - bls _0806CD30 - ldr r0, [sp, 0x20] - cmp r0, 0 - beq _0806CC82 - ldr r1, [sp, 0x3C] - cmp r1, 0 - beq _0806CD30 -_0806CC82: - bl sub_806F104 - lsls r0, 24 - cmp r0, 0 - bne _0806CD30 - ldr r2, [sp, 0x30] - cmp r2, 0 - bne _0806CD30 - ldr r3, [sp, 0x24] - ldr r5, [sp, 0x28] - adds r0, r3, r5 - ldrb r0, [r0] - str r0, [sp, 0x30] - mov r0, r8 - movs r1, 0x20 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - str r4, [sp, 0x8] - ldr r0, [sp, 0x30] - lsls r5, r0, 24 - asrs r1, r5, 24 - cmp r1, 0 - ble _0806CCCC - ldr r2, [sp, 0x34] - cmp r2, 0x1B - bne _0806CCCC -_0806CCBA: - movs r0, 0x96 - muls r0, r1 - movs r1, 0x64 - bl __divsi3 - adds r0, r4, r0 - str r0, [sp, 0x8] - adds r2, r5, 0 - b _0806CCD8 -_0806CCCC: - ldr r3, [sp, 0x30] - lsls r2, r3, 24 - asrs r1, r2, 24 - ldr r0, [sp, 0x8] - adds r0, r1 - str r0, [sp, 0x8] -_0806CCD8: - cmp r2, 0 - ble _0806CD0E - mov r0, r8 - movs r1, 0x26 - movs r2, 0 - bl GetMonData - cmp r0, 0xB - bne _0806CCF0 - ldr r0, [sp, 0x8] - adds r0, 0x1 - str r0, [sp, 0x8] -_0806CCF0: - mov r0, r8 - movs r1, 0x23 - movs r2, 0 - bl GetMonData - adds r4, r0, 0 - bl sav1_map_get_name - lsls r0, 24 - lsrs r0, 24 - cmp r4, r0 - bne _0806CD0E - ldr r0, [sp, 0x8] - adds r0, 0x1 - str r0, [sp, 0x8] -_0806CD0E: - ldr r0, [sp, 0x8] - cmp r0, 0 - bge _0806CD18 - movs r0, 0 - str r0, [sp, 0x8] -_0806CD18: - ldr r0, [sp, 0x8] - cmp r0, 0xFF - ble _0806CD22 - movs r0, 0xFF - str r0, [sp, 0x8] -_0806CD22: - add r2, sp, 0x8 - mov r0, r8 - movs r1, 0x20 - bl SetMonData - movs r5, 0 - str r5, [sp, 0x20] -_0806CD30: - ldr r0, [sp, 0x28] - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x28] -_0806CD3A: - ldr r0, [sp, 0x2C] - adds r0, 0x1 - str r0, [sp, 0x2C] - mov r1, r10 - lsrs r1, 1 - mov r10, r1 - cmp r1, 0 - beq _0806CD4C - b _0806C9D4 -_0806CD4C: - ldr r2, [sp, 0x1C] - adds r2, 0x1 - str r2, [sp, 0x1C] - cmp r2, 0x5 - bgt _0806CD5A - bl _0806BEFC -_0806CD5A: - ldr r0, [sp, 0x20] -_0806CD5C: - add sp, 0x44 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end ExecuteTableBasedItemEffect - - .align 2, 0 @ Don't pad with nop. - \ No newline at end of file diff --git a/include/constants/items.h b/include/constants/items.h index ca6fdbf64..8717ecbd5 100644 --- a/include/constants/items.h +++ b/include/constants/items.h @@ -464,4 +464,7 @@ #define NUM_TECHNICAL_MACHINES 50 #define NUM_HIDDEN_MACHINES 8 +// Check if the item is one that can be used on a Pokemon. +#define IS_POKEMON_ITEM(item) ((item) >= ITEM_POTION && (item) <= ITEM_0B2) + #endif // GUARD_CONSTANTS_ITEMS_H diff --git a/include/pokemon_item_effects.h b/include/pokemon_item_effects.h index 505cc0f25..1564f7f99 100644 --- a/include/pokemon_item_effects.h +++ b/include/pokemon_item_effects.h @@ -57,6 +57,6 @@ struct PokemonItemEffect }; */ -bool8 ExecuteTableBasedItemEffect(struct Pokemon *mon, u16 itemId, u8 partyId, u8 monMoveIndex, u8 a5); +bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 itemId, u8 partyId, u8 monMoveIndex, u8 a5); #endif // GUARD_POKEMON_ITEM_EFFECTS diff --git a/ld_script.txt b/ld_script.txt index cf1f96f25..14ddd43bf 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -69,10 +69,6 @@ SECTIONS { src/battle_ai_switch_items.o(.text); src/battle_controller_link_opponent.o(.text); src/pokemon_1.o(.text); - asm/pokemon_1.o(.text); - src/calculate_base_damage.o(.text); - src/pokemon_2.o(.text); - asm/pokemon_item_effect.o(.text); src/pokemon_3.o(.text); asm/pokemon_3.o(.text); src/trig.o(.text); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index fab1c18bb..2acdd02f6 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6940,7 +6940,7 @@ static void atk74_hpthresholds2(void) static void atk75_useitemonopponent(void) { gBankInMenu = gBattlerAttacker; - ExecuteTableBasedItemEffect(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker]], gLastUsedItem, gBattlerPartyIndexes[gBattlerAttacker], 0, 1); + PokemonUseItemEffects(&gEnemyParty[gBattlerPartyIndexes[gBattlerAttacker]], gLastUsedItem, gBattlerPartyIndexes[gBattlerAttacker], 0, 1); gBattlescriptCurrInstr += 1; } diff --git a/src/calculate_base_damage.c b/src/calculate_base_damage.c deleted file mode 100644 index b6b83086b..000000000 --- a/src/calculate_base_damage.c +++ /dev/null @@ -1,283 +0,0 @@ -#include "global.h" -#include "constants/abilities.h" -#include "battle.h" -#include "constants/hold_effects.h" -#include "event_data.h" -#include "item.h" -#include "constants/items.h" -#include "pokemon.h" -#include "constants/species.h" -#include "constants/moves.h" -#include "constants/battle_move_effects.h" - -extern u32 gBattleTypeFlags; -extern struct BattlePokemon gBattleMons[4]; -extern u16 gCurrentMove; -extern u8 gCritMultiplier; -extern u16 gBattleWeather; -extern struct BattleEnigmaBerry gEnigmaBerries[]; -extern u16 gBattleMovePower; -extern u16 gTrainerBattleOpponent_A; - -bool8 ShouldGetStatBadgeBoost(u16 flagId, u8 bank); - -extern const struct BattleMove gBattleMoves[]; -extern const u8 gHoldEffectToType[][2]; -extern const u8 gStatStageRatios[][2]; - -#define APPLY_STAT_MOD(var, mon, stat, statIndex) \ -{ \ - (var) = (stat) * (gStatStageRatios)[(mon)->statStages[(statIndex)]][0]; \ - (var) /= (gStatStageRatios)[(mon)->statStages[(statIndex)]][1]; \ -} - -s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *defender, u32 move, u16 sideStatus, u16 powerOverride, u8 typeOverride, u8 bankAtk, u8 bankDef) -{ - u32 i; - s32 damage = 0; - s32 damageHelper; - u8 type; - u16 attack, defense; - u16 spAttack, spDefense; - u8 defenderHoldEffect; - u8 defenderHoldEffectParam; - u8 attackerHoldEffect; - u8 attackerHoldEffectParam; - - if (!powerOverride) - gBattleMovePower = gBattleMoves[move].power; - else - gBattleMovePower = powerOverride; - - if (!typeOverride) - type = gBattleMoves[move].type; - else - type = typeOverride & 0x3F; - - attack = attacker->attack; - defense = defender->defense; - spAttack = attacker->spAttack; - spDefense = defender->spDefense; - - if (attacker->item == ITEM_ENIGMA_BERRY) - { - attackerHoldEffect = gEnigmaBerries[bankAtk].holdEffect; - attackerHoldEffectParam = gEnigmaBerries[bankAtk].holdEffectParam; - } - else - { - attackerHoldEffect = ItemId_GetHoldEffect(attacker->item); - attackerHoldEffectParam = ItemId_GetHoldEffectParam(attacker->item); - } - - if (defender->item == ITEM_ENIGMA_BERRY) - { - defenderHoldEffect = gEnigmaBerries[bankDef].holdEffect; - defenderHoldEffectParam = gEnigmaBerries[bankDef].holdEffectParam; - } - else - { - defenderHoldEffect = ItemId_GetHoldEffect(defender->item); - defenderHoldEffectParam = ItemId_GetHoldEffectParam(defender->item); - } - - if (attacker->ability == ABILITY_HUGE_POWER || attacker->ability == ABILITY_PURE_POWER) - attack *= 2; - - if (ShouldGetStatBadgeBoost(FLAG_BADGE01_GET, bankAtk)) - attack = (110 * attack) / 100; - if (ShouldGetStatBadgeBoost(FLAG_BADGE05_GET, bankDef)) - defense = (110 * defense) / 100; - if (ShouldGetStatBadgeBoost(FLAG_BADGE07_GET, bankAtk)) - spAttack = (110 * spAttack) / 100; - if (ShouldGetStatBadgeBoost(FLAG_BADGE07_GET, bankDef)) - spDefense = (110 * spDefense) / 100; - - for (i = 0; i < 17; i++) - { - if (attackerHoldEffect == gHoldEffectToType[i][0] - && type == gHoldEffectToType[i][1]) - { - if (type <= 8) - attack = (attack * (attackerHoldEffectParam + 100)) / 100; - else - spAttack = (spAttack * (attackerHoldEffectParam + 100)) / 100; - break; - } - } - - if (attackerHoldEffect == HOLD_EFFECT_CHOICE_BAND) - attack = (150 * attack) / 100; - if (attackerHoldEffect == HOLD_EFFECT_SOUL_DEW && !(gBattleTypeFlags & (BATTLE_TYPE_FRONTIER)) && (attacker->species == SPECIES_LATIAS || attacker->species == SPECIES_LATIOS)) - spAttack = (150 * spAttack) / 100; - if (defenderHoldEffect == HOLD_EFFECT_SOUL_DEW && !(gBattleTypeFlags & (BATTLE_TYPE_FRONTIER)) && (defender->species == SPECIES_LATIAS || defender->species == SPECIES_LATIOS)) - spDefense = (150 * spDefense) / 100; - if (attackerHoldEffect == HOLD_EFFECT_DEEP_SEA_TOOTH && attacker->species == SPECIES_CLAMPERL) - spAttack *= 2; - if (defenderHoldEffect == HOLD_EFFECT_DEEP_SEA_SCALE && defender->species == SPECIES_CLAMPERL) - spDefense *= 2; - if (attackerHoldEffect == HOLD_EFFECT_LIGHT_BALL && attacker->species == SPECIES_PIKACHU) - spAttack *= 2; - if (defenderHoldEffect == HOLD_EFFECT_METAL_POWDER && defender->species == SPECIES_DITTO) - defense *= 2; - if (attackerHoldEffect == HOLD_EFFECT_THICK_CLUB && (attacker->species == SPECIES_CUBONE || attacker->species == SPECIES_MAROWAK)) - attack *= 2; - if (defender->ability == ABILITY_THICK_FAT && (type == TYPE_FIRE || type == TYPE_ICE)) - spAttack /= 2; - if (attacker->ability == ABILITY_HUSTLE) - attack = (150 * attack) / 100; - if (attacker->ability == ABILITY_PLUS && AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_MINUS, 0, 0)) - spAttack = (150 * spAttack) / 100; - if (attacker->ability == ABILITY_MINUS && AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_PLUS, 0, 0)) - spAttack = (150 * spAttack) / 100; - if (attacker->ability == ABILITY_GUTS && attacker->status1) - attack = (150 * attack) / 100; - if (defender->ability == ABILITY_MARVEL_SCALE && defender->status1) - defense = (150 * defense) / 100; - if (type == TYPE_ELECTRIC && AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, 0, 0xFD, 0)) - gBattleMovePower /= 2; - if (type == TYPE_FIRE && AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, 0, 0xFE, 0)) - gBattleMovePower /= 2; - if (type == TYPE_GRASS && attacker->ability == ABILITY_OVERGROW && attacker->hp <= (attacker->maxHP / 3)) - gBattleMovePower = (150 * gBattleMovePower) / 100; - if (type == TYPE_FIRE && attacker->ability == ABILITY_BLAZE && attacker->hp <= (attacker->maxHP / 3)) - gBattleMovePower = (150 * gBattleMovePower) / 100; - if (type == TYPE_WATER && attacker->ability == ABILITY_TORRENT && attacker->hp <= (attacker->maxHP / 3)) - gBattleMovePower = (150 * gBattleMovePower) / 100; - if (type == TYPE_BUG && attacker->ability == ABILITY_SWARM && attacker->hp <= (attacker->maxHP / 3)) - gBattleMovePower = (150 * gBattleMovePower) / 100; - if (gBattleMoves[gCurrentMove].effect == EFFECT_EXPLOSION) - defense /= 2; - - if (type < TYPE_MYSTERY) // is physical - { - if (gCritMultiplier == 2) - { - if (attacker->statStages[STAT_STAGE_ATK] > 6) - APPLY_STAT_MOD(damage, attacker, attack, STAT_STAGE_ATK) - else - damage = attack; - } - else - APPLY_STAT_MOD(damage, attacker, attack, STAT_STAGE_ATK) - - damage = damage * gBattleMovePower; - damage *= (2 * attacker->level / 5 + 2); - - if (gCritMultiplier == 2) - { - if (defender->statStages[STAT_STAGE_DEF] < 6) - APPLY_STAT_MOD(damageHelper, defender, defense, STAT_STAGE_DEF) - else - damageHelper = defense; - } - else - APPLY_STAT_MOD(damageHelper, defender, defense, STAT_STAGE_DEF) - - damage = damage / damageHelper; - damage /= 50; - - if ((attacker->status1 & STATUS1_BURN) && attacker->ability != ABILITY_GUTS) - damage /= 2; - - if ((sideStatus & SIDE_STATUS_REFLECT) && gCritMultiplier == 1) - { - if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && CountAliveMonsInBattle(2) == 2) - damage = 2 * (damage / 3); - else - damage /= 2; - } - - if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && gBattleMoves[move].target == 8 && CountAliveMonsInBattle(2) == 2) - damage /= 2; - - // moves always do at least 1 damage. - if (damage == 0) - damage = 1; - } - - if (type == TYPE_MYSTERY) - damage = 0; // is ??? type. does 0 damage. - - if (type > TYPE_MYSTERY) // is special? - { - if (gCritMultiplier == 2) - { - if (attacker->statStages[STAT_STAGE_SPATK] > 6) - APPLY_STAT_MOD(damage, attacker, spAttack, STAT_STAGE_SPATK) - else - damage = spAttack; - } - else - APPLY_STAT_MOD(damage, attacker, spAttack, STAT_STAGE_SPATK) - - damage = damage * gBattleMovePower; - damage *= (2 * attacker->level / 5 + 2); - - if (gCritMultiplier == 2) - { - if (defender->statStages[STAT_STAGE_SPDEF] < 6) - APPLY_STAT_MOD(damageHelper, defender, spDefense, STAT_STAGE_SPDEF) - else - damageHelper = spDefense; - } - else - APPLY_STAT_MOD(damageHelper, defender, spDefense, STAT_STAGE_SPDEF) - - damage = (damage / damageHelper); - damage /= 50; - - if ((sideStatus & SIDE_STATUS_LIGHTSCREEN) && gCritMultiplier == 1) - { - if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && CountAliveMonsInBattle(2) == 2) - damage = 2 * (damage / 3); - else - damage /= 2; - } - - if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && gBattleMoves[move].target == 8 && CountAliveMonsInBattle(2) == 2) - damage /= 2; - - // are effects of weather negated with cloud nine or air lock - if (!AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_CLOUD_NINE, 0, 0) - && !AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_AIR_LOCK, 0, 0)) - { - if (gBattleWeather & WEATHER_RAIN_TEMPORARY) - { - switch (type) - { - case TYPE_FIRE: - damage /= 2; - break; - case TYPE_WATER: - damage = (15 * damage) / 10; - break; - } - } - - // any weather except sun weakens solar beam - if ((gBattleWeather & (WEATHER_RAIN_ANY | WEATHER_SANDSTORM_ANY | WEATHER_HAIL)) && gCurrentMove == MOVE_SOLAR_BEAM) - damage /= 2; - - // sunny - if (gBattleWeather & WEATHER_SUN_ANY) - { - switch (type) - { - case TYPE_FIRE: - damage = (15 * damage) / 10; - break; - case TYPE_WATER: - damage /= 2; - break; - } - } - } - - // flash fire triggered - if ((gBattleResources->flags->flags[bankAtk] & UNKNOWN_FLAG_FLASH_FIRE) && type == TYPE_FIRE) - damage = (15 * damage) / 10; - } - - return damage + 2; -} diff --git a/src/pokemon_1.c b/src/pokemon_1.c index ad951296f..90071b8a4 100644 --- a/src/pokemon_1.c +++ b/src/pokemon_1.c @@ -8,10 +8,15 @@ #include "constants/items.h" #include "constants/trainers.h" #include "constants/moves.h" +#include "constants/hold_effects.h" +#include "constants/battle_move_effects.h" #include "string_util.h" #include "text.h" #include "link.h" #include "event_data.h" +#include "item.h" +#include "battle_controllers.h" +#include "evolution_scene.h" //Extracts the upper 16 bits of a 32-bit number #define HIHALF(n) (((n) & 0xFFFF0000) >> 16) @@ -19,19 +24,86 @@ //Extracts the lower 16 bits of a 32-bit number #define LOHALF(n) ((n) & 0xFFFF) +struct Unknown_020249B4 +{ + u8 unk0[0xC]; + struct SpriteTemplate* templates; +}; + +extern u8 gAbsentBattlerFlags; +extern u8 gActiveBattler; +extern u8 gBattlersCount; +extern u8 gBattlerAttacker; +extern u16 gBattlerPartyIndexes[]; +extern u8 gBattlerTarget; +extern u8 gBankInMenu; +extern u8 gLastUsedAbility; +extern u16 gTrainerBattleOpponent_A; extern u32 gBattleTypeFlags; +extern struct SpriteTemplate gUnknown_0202499C; +extern struct Unknown_020249B4* gUnknown_020249B4[2]; +extern struct BattlePokemon gBattleMons[4]; +extern u32 gBattleTypeFlags; +extern struct BattlePokemon gBattleMons[4]; +extern u16 gCurrentMove; +extern u8 gCritMultiplier; +extern u16 gBattleWeather; +extern struct BattleEnigmaBerry gEnigmaBerries[]; +extern u16 gBattleMovePower; +extern u16 gTrainerBattleOpponent_A; +extern u32 gBattleTypeFlags; +extern s32 gBattleMoveDamage; extern u8 gUnknown_0203C7B4; extern u16 gMoveToLearn; +extern u8 gStringBattler; +extern const u32 gBitTable[]; +extern const struct SpriteTemplate gUnknown_08329D98[]; +extern const struct SpriteTemplate gUnknown_08329DF8[]; +extern const union AnimCmd* gUnknown_082FF70C[]; +extern const union AnimCmd* const * const gMonAnimationsSpriteAnimsPtrTable[]; +extern const union AnimCmd* const * const gUnknown_08305D0C[]; +extern const union AnimCmd* const * const gUnknown_0830536C[]; +extern const u8 gText_BadEgg[]; +extern const u8 gText_EggNickname[]; +extern const u8 gFacilityClassToPicIndex[]; +extern const u8 gFacilityClassToTrainerClass[]; +extern const u8 gSecretBaseTrainerClasses[][5]; +extern const struct BattleMove gBattleMoves[]; +extern const u8 gSpeciesNames[][POKEMON_NAME_LENGTH + 1]; +extern const u8 gUnknown_08329D22[]; +extern const u8 gUnknown_08329D26[]; +extern const u8 gHoldEffectToType[][2]; +extern const u8 gStatStageRatios[][2]; extern const struct UnknownPokemonStruct3 gUnknown_08610970[]; extern const u16 gUnknown_08329D48[]; extern const u16 gUnknown_08329D54[]; extern const struct BattleMove gBattleMoves[]; +extern const u8 gUnknown_08329D22[]; +extern const u8 gUnknown_08329D26[]; +extern const u8 gUnknown_08329D2A[]; +extern const u8 gUnknown_08329EC2[]; +extern bool8 ShouldGetStatBadgeBoost(u16 flagId, u8 bank); +extern u8 pokemon_order_func(u8); +extern u8 GetBattlerSide(u8 bank); +extern u8 GetBattlerAtPosition(u8 bank); +extern u8 GetBattlerPosition(u8 bank); +extern u16 get_unknown_box_id(void); +extern u8 StorageGetCurrentBox(void); +extern void set_unknown_box_id(u8); +extern struct BoxPokemon* GetBoxedMonPtr(u8 boxNumber, u8 boxPosition); +extern s32 GetDeoxysStat(struct Pokemon *mon, s32 statId); +extern void sub_803FA70(u8 bank); +extern void ClearTemporarySpeciesSpriteData(u8 bank, bool8); +extern u32 GetBoxMonDataFromAnyBox(u8 boxNo, u8 boxPos, s32 field); extern u8 sav1_map_get_name(void); extern const u8 *sub_81A1650(u8, u8 language); extern u8 BattleFrontierGetOpponentLvl(u8); extern u16 sub_806EFF0(u16); +extern bool8 HealStatusConditions(struct Pokemon *mon, u32 unused, u32 healMask, u8 battleId); +extern bool8 sub_806F104(void); +extern bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 moveIndex, u8 e); // this file's functions union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, u8 substructType); @@ -1034,3 +1106,2110 @@ void DeleteFirstMoveAndGiveMoveToBoxMon(struct BoxPokemon *boxMon, u16 move) SetBoxMonData(boxMon, MON_DATA_PP_BONUSES, &ppBonuses); } + +#define APPLY_STAT_MOD(var, mon, stat, statIndex) \ +{ \ + (var) = (stat) * (gStatStageRatios)[(mon)->statStages[(statIndex)]][0]; \ + (var) /= (gStatStageRatios)[(mon)->statStages[(statIndex)]][1]; \ +} + +s32 CalculateBaseDamage(struct BattlePokemon *attacker, struct BattlePokemon *defender, u32 move, u16 sideStatus, u16 powerOverride, u8 typeOverride, u8 bankAtk, u8 bankDef) +{ + u32 i; + s32 damage = 0; + s32 damageHelper; + u8 type; + u16 attack, defense; + u16 spAttack, spDefense; + u8 defenderHoldEffect; + u8 defenderHoldEffectParam; + u8 attackerHoldEffect; + u8 attackerHoldEffectParam; + + if (!powerOverride) + gBattleMovePower = gBattleMoves[move].power; + else + gBattleMovePower = powerOverride; + + if (!typeOverride) + type = gBattleMoves[move].type; + else + type = typeOverride & 0x3F; + + attack = attacker->attack; + defense = defender->defense; + spAttack = attacker->spAttack; + spDefense = defender->spDefense; + + if (attacker->item == ITEM_ENIGMA_BERRY) + { + attackerHoldEffect = gEnigmaBerries[bankAtk].holdEffect; + attackerHoldEffectParam = gEnigmaBerries[bankAtk].holdEffectParam; + } + else + { + attackerHoldEffect = ItemId_GetHoldEffect(attacker->item); + attackerHoldEffectParam = ItemId_GetHoldEffectParam(attacker->item); + } + + if (defender->item == ITEM_ENIGMA_BERRY) + { + defenderHoldEffect = gEnigmaBerries[bankDef].holdEffect; + defenderHoldEffectParam = gEnigmaBerries[bankDef].holdEffectParam; + } + else + { + defenderHoldEffect = ItemId_GetHoldEffect(defender->item); + defenderHoldEffectParam = ItemId_GetHoldEffectParam(defender->item); + } + + if (attacker->ability == ABILITY_HUGE_POWER || attacker->ability == ABILITY_PURE_POWER) + attack *= 2; + + if (ShouldGetStatBadgeBoost(FLAG_BADGE01_GET, bankAtk)) + attack = (110 * attack) / 100; + if (ShouldGetStatBadgeBoost(FLAG_BADGE05_GET, bankDef)) + defense = (110 * defense) / 100; + if (ShouldGetStatBadgeBoost(FLAG_BADGE07_GET, bankAtk)) + spAttack = (110 * spAttack) / 100; + if (ShouldGetStatBadgeBoost(FLAG_BADGE07_GET, bankDef)) + spDefense = (110 * spDefense) / 100; + + for (i = 0; i < 17; i++) + { + if (attackerHoldEffect == gHoldEffectToType[i][0] + && type == gHoldEffectToType[i][1]) + { + if (type <= 8) + attack = (attack * (attackerHoldEffectParam + 100)) / 100; + else + spAttack = (spAttack * (attackerHoldEffectParam + 100)) / 100; + break; + } + } + + if (attackerHoldEffect == HOLD_EFFECT_CHOICE_BAND) + attack = (150 * attack) / 100; + if (attackerHoldEffect == HOLD_EFFECT_SOUL_DEW && !(gBattleTypeFlags & (BATTLE_TYPE_FRONTIER)) && (attacker->species == SPECIES_LATIAS || attacker->species == SPECIES_LATIOS)) + spAttack = (150 * spAttack) / 100; + if (defenderHoldEffect == HOLD_EFFECT_SOUL_DEW && !(gBattleTypeFlags & (BATTLE_TYPE_FRONTIER)) && (defender->species == SPECIES_LATIAS || defender->species == SPECIES_LATIOS)) + spDefense = (150 * spDefense) / 100; + if (attackerHoldEffect == HOLD_EFFECT_DEEP_SEA_TOOTH && attacker->species == SPECIES_CLAMPERL) + spAttack *= 2; + if (defenderHoldEffect == HOLD_EFFECT_DEEP_SEA_SCALE && defender->species == SPECIES_CLAMPERL) + spDefense *= 2; + if (attackerHoldEffect == HOLD_EFFECT_LIGHT_BALL && attacker->species == SPECIES_PIKACHU) + spAttack *= 2; + if (defenderHoldEffect == HOLD_EFFECT_METAL_POWDER && defender->species == SPECIES_DITTO) + defense *= 2; + if (attackerHoldEffect == HOLD_EFFECT_THICK_CLUB && (attacker->species == SPECIES_CUBONE || attacker->species == SPECIES_MAROWAK)) + attack *= 2; + if (defender->ability == ABILITY_THICK_FAT && (type == TYPE_FIRE || type == TYPE_ICE)) + spAttack /= 2; + if (attacker->ability == ABILITY_HUSTLE) + attack = (150 * attack) / 100; + if (attacker->ability == ABILITY_PLUS && AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_MINUS, 0, 0)) + spAttack = (150 * spAttack) / 100; + if (attacker->ability == ABILITY_MINUS && AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_PLUS, 0, 0)) + spAttack = (150 * spAttack) / 100; + if (attacker->ability == ABILITY_GUTS && attacker->status1) + attack = (150 * attack) / 100; + if (defender->ability == ABILITY_MARVEL_SCALE && defender->status1) + defense = (150 * defense) / 100; + if (type == TYPE_ELECTRIC && AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, 0, 0xFD, 0)) + gBattleMovePower /= 2; + if (type == TYPE_FIRE && AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, 0, 0xFE, 0)) + gBattleMovePower /= 2; + if (type == TYPE_GRASS && attacker->ability == ABILITY_OVERGROW && attacker->hp <= (attacker->maxHP / 3)) + gBattleMovePower = (150 * gBattleMovePower) / 100; + if (type == TYPE_FIRE && attacker->ability == ABILITY_BLAZE && attacker->hp <= (attacker->maxHP / 3)) + gBattleMovePower = (150 * gBattleMovePower) / 100; + if (type == TYPE_WATER && attacker->ability == ABILITY_TORRENT && attacker->hp <= (attacker->maxHP / 3)) + gBattleMovePower = (150 * gBattleMovePower) / 100; + if (type == TYPE_BUG && attacker->ability == ABILITY_SWARM && attacker->hp <= (attacker->maxHP / 3)) + gBattleMovePower = (150 * gBattleMovePower) / 100; + if (gBattleMoves[gCurrentMove].effect == EFFECT_EXPLOSION) + defense /= 2; + + if (type < TYPE_MYSTERY) // is physical + { + if (gCritMultiplier == 2) + { + if (attacker->statStages[STAT_STAGE_ATK] > 6) + APPLY_STAT_MOD(damage, attacker, attack, STAT_STAGE_ATK) + else + damage = attack; + } + else + APPLY_STAT_MOD(damage, attacker, attack, STAT_STAGE_ATK) + + damage = damage * gBattleMovePower; + damage *= (2 * attacker->level / 5 + 2); + + if (gCritMultiplier == 2) + { + if (defender->statStages[STAT_STAGE_DEF] < 6) + APPLY_STAT_MOD(damageHelper, defender, defense, STAT_STAGE_DEF) + else + damageHelper = defense; + } + else + APPLY_STAT_MOD(damageHelper, defender, defense, STAT_STAGE_DEF) + + damage = damage / damageHelper; + damage /= 50; + + if ((attacker->status1 & STATUS1_BURN) && attacker->ability != ABILITY_GUTS) + damage /= 2; + + if ((sideStatus & SIDE_STATUS_REFLECT) && gCritMultiplier == 1) + { + if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && CountAliveMonsInBattle(2) == 2) + damage = 2 * (damage / 3); + else + damage /= 2; + } + + if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && gBattleMoves[move].target == 8 && CountAliveMonsInBattle(2) == 2) + damage /= 2; + + // moves always do at least 1 damage. + if (damage == 0) + damage = 1; + } + + if (type == TYPE_MYSTERY) + damage = 0; // is ??? type. does 0 damage. + + if (type > TYPE_MYSTERY) // is special? + { + if (gCritMultiplier == 2) + { + if (attacker->statStages[STAT_STAGE_SPATK] > 6) + APPLY_STAT_MOD(damage, attacker, spAttack, STAT_STAGE_SPATK) + else + damage = spAttack; + } + else + APPLY_STAT_MOD(damage, attacker, spAttack, STAT_STAGE_SPATK) + + damage = damage * gBattleMovePower; + damage *= (2 * attacker->level / 5 + 2); + + if (gCritMultiplier == 2) + { + if (defender->statStages[STAT_STAGE_SPDEF] < 6) + APPLY_STAT_MOD(damageHelper, defender, spDefense, STAT_STAGE_SPDEF) + else + damageHelper = spDefense; + } + else + APPLY_STAT_MOD(damageHelper, defender, spDefense, STAT_STAGE_SPDEF) + + damage = (damage / damageHelper); + damage /= 50; + + if ((sideStatus & SIDE_STATUS_LIGHTSCREEN) && gCritMultiplier == 1) + { + if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && CountAliveMonsInBattle(2) == 2) + damage = 2 * (damage / 3); + else + damage /= 2; + } + + if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && gBattleMoves[move].target == 8 && CountAliveMonsInBattle(2) == 2) + damage /= 2; + + // are effects of weather negated with cloud nine or air lock + if (!AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_CLOUD_NINE, 0, 0) + && !AbilityBattleEffects(ABILITYEFFECT_FIELD_SPORT, 0, ABILITY_AIR_LOCK, 0, 0)) + { + if (gBattleWeather & WEATHER_RAIN_TEMPORARY) + { + switch (type) + { + case TYPE_FIRE: + damage /= 2; + break; + case TYPE_WATER: + damage = (15 * damage) / 10; + break; + } + } + + // any weather except sun weakens solar beam + if ((gBattleWeather & (WEATHER_RAIN_ANY | WEATHER_SANDSTORM_ANY | WEATHER_HAIL)) && gCurrentMove == MOVE_SOLAR_BEAM) + damage /= 2; + + // sunny + if (gBattleWeather & WEATHER_SUN_ANY) + { + switch (type) + { + case TYPE_FIRE: + damage = (15 * damage) / 10; + break; + case TYPE_WATER: + damage /= 2; + break; + } + } + } + + // flash fire triggered + if ((gBattleResources->flags->flags[bankAtk] & UNKNOWN_FLAG_FLASH_FIRE) && type == TYPE_FIRE) + damage = (15 * damage) / 10; + } + + return damage + 2; +} + +u8 CountAliveMonsInBattle(u8 caseId) +{ + s32 i; + u8 retVal = 0; + + switch (caseId) + { + case BATTLE_ALIVE_EXCEPT_ACTIVE: + for (i = 0; i < 4; i++) + { + if (i != gActiveBattler && !(gAbsentBattlerFlags & gBitTable[i])) + retVal++; + } + break; + case BATTLE_ALIVE_ATK_SIDE: + for (i = 0; i < 4; i++) + { + if (GetBattlerSide(i) == GetBattlerSide(gBattlerAttacker) && !(gAbsentBattlerFlags & gBitTable[i])) + retVal++; + } + break; + case BATTLE_ALIVE_DEF_SIDE: + for (i = 0; i < 4; i++) + { + if (GetBattlerSide(i) == GetBattlerSide(gBattlerTarget) && !(gAbsentBattlerFlags & gBitTable[i])) + retVal++; + } + break; + } + + return retVal; +} + +bool8 ShouldGetStatBadgeBoost(u16 badgeFlag, u8 bank) +{ + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_x2000000 | BATTLE_TYPE_FRONTIER)) + return FALSE; + if (GetBattlerSide(bank) != B_SIDE_PLAYER) + return FALSE; + if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gTrainerBattleOpponent_A == SECRET_BASE_OPPONENT) + return FALSE; + if (FlagGet(badgeFlag)) + return TRUE; + return FALSE; +} + +u8 GetDefaultMoveTarget(u8 bank) +{ + u8 status = GetBattlerPosition(bank) & 1; + + status ^= 1; + if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) + return GetBattlerAtPosition(status); + if (CountAliveMonsInBattle(BATTLE_ALIVE_EXCEPT_ACTIVE) > 1) + { + u8 val; + + if ((Random() & 1) == 0) + val = status ^ 2; + else + val = status; + return GetBattlerAtPosition(val); + } + else + { + if ((gAbsentBattlerFlags & gBitTable[status])) + return GetBattlerAtPosition(status ^ 2); + else + return GetBattlerAtPosition(status); + } +} + +u8 GetMonGender(struct Pokemon *mon) +{ + return GetBoxMonGender(&mon->box); +} + +u8 GetBoxMonGender(struct BoxPokemon *boxMon) +{ + u16 species = GetBoxMonData(boxMon, MON_DATA_SPECIES, NULL); + u32 personality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY, NULL); + + switch (gBaseStats[species].genderRatio) + { + case MON_MALE: + case MON_FEMALE: + case MON_GENDERLESS: + return gBaseStats[species].genderRatio; + } + + if (gBaseStats[species].genderRatio > (personality & 0xFF)) + return MON_FEMALE; + else + return MON_MALE; +} + +u8 GetGenderFromSpeciesAndPersonality(u16 species, u32 personality) +{ + switch (gBaseStats[species].genderRatio) + { + case MON_MALE: + case MON_FEMALE: + case MON_GENDERLESS: + return gBaseStats[species].genderRatio; + } + + if (gBaseStats[species].genderRatio > (personality & 0xFF)) + return MON_FEMALE; + else + return MON_MALE; +} + +void sub_806A068(u16 species, u8 bankIdentity) +{ + if (gMonSpritesGfxPtr != NULL) + gUnknown_0202499C = gMonSpritesGfxPtr->templates[bankIdentity]; + else if (gUnknown_020249B4[0]) + gUnknown_0202499C = gUnknown_020249B4[0]->templates[bankIdentity]; + else if (gUnknown_020249B4[1]) + gUnknown_0202499C = gUnknown_020249B4[1]->templates[bankIdentity]; + else + gUnknown_0202499C = gUnknown_08329D98[bankIdentity]; + + gUnknown_0202499C.paletteTag = species; + if (bankIdentity == 0 || bankIdentity == 2) + gUnknown_0202499C.anims = gUnknown_082FF70C; + else if (species > 500) + gUnknown_0202499C.anims = gMonAnimationsSpriteAnimsPtrTable[species - 500]; + else + gUnknown_0202499C.anims = gMonAnimationsSpriteAnimsPtrTable[species]; +} + +void sub_806A12C(u16 trainerSpriteId, u8 bankIdentity) +{ + gUnknown_0202499C.paletteTag = trainerSpriteId; + if (bankIdentity == 0 || bankIdentity == 2) + { + gUnknown_0202499C = gUnknown_08329DF8[trainerSpriteId]; + gUnknown_0202499C.anims = gUnknown_08305D0C[trainerSpriteId]; + } + else + { + if (gMonSpritesGfxPtr != NULL) + gUnknown_0202499C = gMonSpritesGfxPtr->templates[bankIdentity]; + else + gUnknown_0202499C = gUnknown_08329D98[bankIdentity]; + gUnknown_0202499C.anims = gUnknown_0830536C[trainerSpriteId]; + } +} + +void sub_806A1C0(u16 arg0, u8 bankIdentity) +{ + if (gMonSpritesGfxPtr != NULL) + gUnknown_0202499C = gMonSpritesGfxPtr->templates[bankIdentity]; + else + gUnknown_0202499C = gUnknown_08329D98[bankIdentity]; + + gUnknown_0202499C.paletteTag = arg0; + gUnknown_0202499C.anims = gUnknown_0830536C[arg0]; +} + +void EncryptBoxMon(struct BoxPokemon *boxMon) +{ + u32 i; + for (i = 0; i < 12; i++) + { + boxMon->secure.raw[i] ^= boxMon->personality; + boxMon->secure.raw[i] ^= boxMon->otId; + } +} + +void DecryptBoxMon(struct BoxPokemon *boxMon) +{ + u32 i; + for (i = 0; i < 12; i++) + { + boxMon->secure.raw[i] ^= boxMon->otId; + boxMon->secure.raw[i] ^= boxMon->personality; + } +} + +#define SUBSTRUCT_CASE(n, v1, v2, v3, v4) \ +case n: \ + { \ + union PokemonSubstruct *substructs0 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs1 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs2 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs3 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs4 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs5 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs6 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs7 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs8 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs9 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs10 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs11 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs12 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs13 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs14 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs15 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs16 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs17 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs18 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs19 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs20 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs21 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs22 = boxMon->secure.substructs; \ + union PokemonSubstruct *substructs23 = boxMon->secure.substructs; \ + \ + switch (substructType) \ + { \ + case 0: \ + substruct = &substructs ## n [v1]; \ + break; \ + case 1: \ + substruct = &substructs ## n [v2]; \ + break; \ + case 2: \ + substruct = &substructs ## n [v3]; \ + break; \ + case 3: \ + substruct = &substructs ## n [v4]; \ + break; \ + } \ + break; \ + } \ + + +union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, u8 substructType) +{ + union PokemonSubstruct *substruct = NULL; + + switch (personality % 24) + { + SUBSTRUCT_CASE( 0,0,1,2,3) + SUBSTRUCT_CASE( 1,0,1,3,2) + SUBSTRUCT_CASE( 2,0,2,1,3) + SUBSTRUCT_CASE( 3,0,3,1,2) + SUBSTRUCT_CASE( 4,0,2,3,1) + SUBSTRUCT_CASE( 5,0,3,2,1) + SUBSTRUCT_CASE( 6,1,0,2,3) + SUBSTRUCT_CASE( 7,1,0,3,2) + SUBSTRUCT_CASE( 8,2,0,1,3) + SUBSTRUCT_CASE( 9,3,0,1,2) + SUBSTRUCT_CASE(10,2,0,3,1) + SUBSTRUCT_CASE(11,3,0,2,1) + SUBSTRUCT_CASE(12,1,2,0,3) + SUBSTRUCT_CASE(13,1,3,0,2) + SUBSTRUCT_CASE(14,2,1,0,3) + SUBSTRUCT_CASE(15,3,1,0,2) + SUBSTRUCT_CASE(16,2,3,0,1) + SUBSTRUCT_CASE(17,3,2,0,1) + SUBSTRUCT_CASE(18,1,2,3,0) + SUBSTRUCT_CASE(19,1,3,2,0) + SUBSTRUCT_CASE(20,2,1,3,0) + SUBSTRUCT_CASE(21,3,1,2,0) + SUBSTRUCT_CASE(22,2,3,1,0) + SUBSTRUCT_CASE(23,3,2,1,0) + } + + return substruct; +} + +u32 GetMonData(struct Pokemon *mon, s32 field, u8* data) +{ + u32 ret; + + switch (field) + { + case MON_DATA_STATUS: + ret = mon->status; + break; + case MON_DATA_LEVEL: + ret = mon->level; + break; + case MON_DATA_HP: + ret = mon->hp; + break; + case MON_DATA_MAX_HP: + ret = mon->maxHP; + break; + case MON_DATA_ATK: + ret = (u16)GetDeoxysStat(mon, STAT_ATK); + if (!ret) + ret = mon->attack; + break; + case MON_DATA_DEF: + ret = (u16)GetDeoxysStat(mon, STAT_DEF); + if (!ret) + ret = mon->defense; + break; + case MON_DATA_SPEED: + ret = (u16)GetDeoxysStat(mon, STAT_SPD); + if (!ret) + ret = mon->speed; + break; + case MON_DATA_SPATK: + ret = (u16)GetDeoxysStat(mon, STAT_SPATK); + if (!ret) + ret = mon->spAttack; + break; + case MON_DATA_SPDEF: + ret = (u16)GetDeoxysStat(mon, STAT_SPDEF); + if (!ret) + ret = mon->spDefense; + break; + case MON_DATA_ATK2: + ret = mon->attack; + break; + case MON_DATA_DEF2: + ret = mon->defense; + break; + case MON_DATA_SPEED2: + ret = mon->speed; + break; + case MON_DATA_SPATK2: + ret = mon->spAttack; + break; + case MON_DATA_SPDEF2: + ret = mon->spDefense; + break; + case MON_DATA_MAIL: + ret = mon->mail; + break; + default: + ret = GetBoxMonData(&mon->box, field, data); + break; + } + return ret; +} + +u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data) +{ + s32 i; + u32 retVal = 0; + struct PokemonSubstruct0 *substruct0 = NULL; + struct PokemonSubstruct1 *substruct1 = NULL; + struct PokemonSubstruct2 *substruct2 = NULL; + struct PokemonSubstruct3 *substruct3 = NULL; + + if (field > MON_DATA_10) + { + substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0); + substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1); + substruct2 = &(GetSubstruct(boxMon, boxMon->personality, 2)->type2); + substruct3 = &(GetSubstruct(boxMon, boxMon->personality, 3)->type3); + + DecryptBoxMon(boxMon); + + if (CalculateBoxMonChecksum(boxMon) != boxMon->checksum) + { + boxMon->isBadEgg = 1; + boxMon->isEgg = 1; + substruct3->isEgg = 1; + } + } + + switch (field) + { + case MON_DATA_PERSONALITY: + retVal = boxMon->personality; + break; + case MON_DATA_OT_ID: + retVal = boxMon->otId; + break; + case MON_DATA_NICKNAME: + { + if (boxMon->isBadEgg) + { + for (retVal = 0; + retVal < POKEMON_NAME_LENGTH && gText_BadEgg[retVal] != EOS; + data[retVal] = gText_BadEgg[retVal], retVal++) {} + + data[retVal] = EOS; + } + else if (boxMon->isEgg) + { + StringCopy(data, gText_EggNickname); + retVal = StringLength(data); + } + else if (boxMon->language == LANGUAGE_JAPANESE) + { + data[0] = EXT_CTRL_CODE_BEGIN; + data[1] = EXT_CTRL_CODE_JPN; + + for (retVal = 2, i = 0; + i < 5 && boxMon->nickname[i] != EOS; + data[retVal] = boxMon->nickname[i], retVal++, i++) {} + + data[retVal++] = EXT_CTRL_CODE_BEGIN; + data[retVal++] = EXT_CTRL_CODE_ENG; + data[retVal] = EOS; + } + else + { + for (retVal = 0; + retVal < POKEMON_NAME_LENGTH; + data[retVal] = boxMon->nickname[retVal], retVal++){} + + data[retVal] = EOS; + } + break; + } + case MON_DATA_LANGUAGE: + retVal = boxMon->language; + break; + case MON_DATA_SANITY_BIT1: + retVal = boxMon->isBadEgg; + break; + case MON_DATA_SANITY_BIT2: + retVal = boxMon->hasSpecies; + break; + case MON_DATA_SANITY_BIT3: + retVal = boxMon->isEgg; + break; + case MON_DATA_OT_NAME: + { + retVal = 0; + + while (retVal < OT_NAME_LENGTH) + { + data[retVal] = boxMon->otName[retVal]; + retVal++; + } + + data[retVal] = EOS; + break; + } + case MON_DATA_MARKINGS: + retVal = boxMon->markings; + break; + case MON_DATA_CHECKSUM: + retVal = boxMon->checksum; + break; + case MON_DATA_10: + retVal = boxMon->unknown; + break; + case MON_DATA_SPECIES: + retVal = boxMon->isBadEgg ? SPECIES_EGG : substruct0->species; + break; + case MON_DATA_HELD_ITEM: + retVal = substruct0->heldItem; + break; + case MON_DATA_EXP: + retVal = substruct0->experience; + break; + case MON_DATA_PP_BONUSES: + retVal = substruct0->ppBonuses; + break; + case MON_DATA_FRIENDSHIP: + retVal = substruct0->friendship; + break; + case MON_DATA_MOVE1: + case MON_DATA_MOVE2: + case MON_DATA_MOVE3: + case MON_DATA_MOVE4: + retVal = substruct1->moves[field - MON_DATA_MOVE1]; + break; + case MON_DATA_PP1: + case MON_DATA_PP2: + case MON_DATA_PP3: + case MON_DATA_PP4: + retVal = substruct1->pp[field - MON_DATA_PP1]; + break; + case MON_DATA_HP_EV: + retVal = substruct2->hpEV; + break; + case MON_DATA_ATK_EV: + retVal = substruct2->attackEV; + break; + case MON_DATA_DEF_EV: + retVal = substruct2->defenseEV; + break; + case MON_DATA_SPEED_EV: + retVal = substruct2->speedEV; + break; + case MON_DATA_SPATK_EV: + retVal = substruct2->spAttackEV; + break; + case MON_DATA_SPDEF_EV: + retVal = substruct2->spDefenseEV; + break; + case MON_DATA_COOL: + retVal = substruct2->cool; + break; + case MON_DATA_BEAUTY: + retVal = substruct2->beauty; + break; + case MON_DATA_CUTE: + retVal = substruct2->cute; + break; + case MON_DATA_SMART: + retVal = substruct2->smart; + break; + case MON_DATA_TOUGH: + retVal = substruct2->tough; + break; + case MON_DATA_SHEEN: + retVal = substruct2->sheen; + break; + case MON_DATA_POKERUS: + retVal = substruct3->pokerus; + break; + case MON_DATA_MET_LOCATION: + retVal = substruct3->metLocation; + break; + case MON_DATA_MET_LEVEL: + retVal = substruct3->metLevel; + break; + case MON_DATA_MET_GAME: + retVal = substruct3->metGame; + break; + case MON_DATA_POKEBALL: + retVal = substruct3->pokeball; + break; + case MON_DATA_OT_GENDER: + retVal = substruct3->otGender; + break; + case MON_DATA_HP_IV: + retVal = substruct3->hpIV; + break; + case MON_DATA_ATK_IV: + retVal = substruct3->attackIV; + break; + case MON_DATA_DEF_IV: + retVal = substruct3->defenseIV; + break; + case MON_DATA_SPEED_IV: + retVal = substruct3->speedIV; + break; + case MON_DATA_SPATK_IV: + retVal = substruct3->spAttackIV; + break; + case MON_DATA_SPDEF_IV: + retVal = substruct3->spDefenseIV; + break; + case MON_DATA_IS_EGG: + retVal = substruct3->isEgg; + break; + case MON_DATA_ALT_ABILITY: + retVal = substruct3->altAbility; + break; + case MON_DATA_COOL_RIBBON: + retVal = substruct3->coolRibbon; + break; + case MON_DATA_BEAUTY_RIBBON: + retVal = substruct3->beautyRibbon; + break; + case MON_DATA_CUTE_RIBBON: + retVal = substruct3->cuteRibbon; + break; + case MON_DATA_SMART_RIBBON: + retVal = substruct3->smartRibbon; + break; + case MON_DATA_TOUGH_RIBBON: + retVal = substruct3->toughRibbon; + break; + case MON_DATA_CHAMPION_RIBBON: + retVal = substruct3->championRibbon; + break; + case MON_DATA_WINNING_RIBBON: + retVal = substruct3->winningRibbon; + break; + case MON_DATA_VICTORY_RIBBON: + retVal = substruct3->victoryRibbon; + break; + case MON_DATA_ARTIST_RIBBON: + retVal = substruct3->artistRibbon; + break; + case MON_DATA_EFFORT_RIBBON: + retVal = substruct3->effortRibbon; + break; + case MON_DATA_GIFT_RIBBON_1: + retVal = substruct3->giftRibbon1; + break; + case MON_DATA_GIFT_RIBBON_2: + retVal = substruct3->giftRibbon2; + break; + case MON_DATA_GIFT_RIBBON_3: + retVal = substruct3->giftRibbon3; + break; + case MON_DATA_GIFT_RIBBON_4: + retVal = substruct3->giftRibbon4; + break; + case MON_DATA_GIFT_RIBBON_5: + retVal = substruct3->giftRibbon5; + break; + case MON_DATA_GIFT_RIBBON_6: + retVal = substruct3->giftRibbon6; + break; + case MON_DATA_GIFT_RIBBON_7: + retVal = substruct3->giftRibbon7; + break; + case MON_DATA_FATEFUL_ENCOUNTER: + retVal = substruct3->fatefulEncounter; + break; + case MON_DATA_OBEDIENCE: + retVal = substruct3->obedient; + break; + case MON_DATA_SPECIES2: + retVal = substruct0->species; + if (substruct0->species && (substruct3->isEgg || boxMon->isBadEgg)) + retVal = SPECIES_EGG; + break; + case MON_DATA_IVS: + retVal = substruct3->hpIV | (substruct3->attackIV << 5) | (substruct3->defenseIV << 10) | (substruct3->speedIV << 15) | (substruct3->spAttackIV << 20) | (substruct3->spDefenseIV << 25); + break; + case MON_DATA_KNOWN_MOVES: + if (substruct0->species && !substruct3->isEgg) + { + u16 *moves = (u16 *)data; + s32 i = 0; + + while (moves[i] != 355) + { + u16 move = moves[i]; + if (substruct1->moves[0] == move + || substruct1->moves[1] == move + || substruct1->moves[2] == move + || substruct1->moves[3] == move) + retVal |= gBitTable[i]; + i++; + } + } + break; + case MON_DATA_RIBBON_COUNT: + retVal = 0; + if (substruct0->species && !substruct3->isEgg) + { + retVal += substruct3->coolRibbon; + retVal += substruct3->beautyRibbon; + retVal += substruct3->cuteRibbon; + retVal += substruct3->smartRibbon; + retVal += substruct3->toughRibbon; + retVal += substruct3->championRibbon; + retVal += substruct3->winningRibbon; + retVal += substruct3->victoryRibbon; + retVal += substruct3->artistRibbon; + retVal += substruct3->effortRibbon; + retVal += substruct3->giftRibbon1; + retVal += substruct3->giftRibbon2; + retVal += substruct3->giftRibbon3; + retVal += substruct3->giftRibbon4; + retVal += substruct3->giftRibbon5; + retVal += substruct3->giftRibbon6; + retVal += substruct3->giftRibbon7; + } + break; + case MON_DATA_RIBBONS: + retVal = 0; + if (substruct0->species && !substruct3->isEgg) + { + retVal = substruct3->championRibbon + | (substruct3->coolRibbon << 1) + | (substruct3->beautyRibbon << 4) + | (substruct3->cuteRibbon << 7) + | (substruct3->smartRibbon << 10) + | (substruct3->toughRibbon << 13) + | (substruct3->winningRibbon << 16) + | (substruct3->victoryRibbon << 17) + | (substruct3->artistRibbon << 18) + | (substruct3->effortRibbon << 19) + | (substruct3->giftRibbon1 << 20) + | (substruct3->giftRibbon2 << 21) + | (substruct3->giftRibbon3 << 22) + | (substruct3->giftRibbon4 << 23) + | (substruct3->giftRibbon5 << 24) + | (substruct3->giftRibbon6 << 25) + | (substruct3->giftRibbon7 << 26); + } + break; + default: + break; + } + + if (field > MON_DATA_10) + EncryptBoxMon(boxMon); + + return retVal; +} + +#define SET8(lhs) (lhs) = *data +#define SET16(lhs) (lhs) = data[0] + (data[1] << 8) +#define SET32(lhs) (lhs) = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24) + +void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg) +{ + const u8* data = dataArg; + switch (field) + { + case MON_DATA_STATUS: + SET32(mon->status); + break; + case MON_DATA_LEVEL: + SET8(mon->level); + break; + case MON_DATA_HP: + SET16(mon->hp); + break; + case MON_DATA_MAX_HP: + SET16(mon->maxHP); + break; + case MON_DATA_ATK: + SET16(mon->attack); + break; + case MON_DATA_DEF: + SET16(mon->defense); + break; + case MON_DATA_SPEED: + SET16(mon->speed); + break; + case MON_DATA_SPATK: + SET16(mon->spAttack); + break; + case MON_DATA_SPDEF: + SET16(mon->spDefense); + break; + case MON_DATA_MAIL: + SET8(mon->mail); + break; + case MON_DATA_SPECIES2: + break; + default: + SetBoxMonData(&mon->box, field, data); + break; + } +} + +void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg) +{ + const u8* data = dataArg; + + struct PokemonSubstruct0 *substruct0 = NULL; + struct PokemonSubstruct1 *substruct1 = NULL; + struct PokemonSubstruct2 *substruct2 = NULL; + struct PokemonSubstruct3 *substruct3 = NULL; + + if (field > MON_DATA_10) + { + substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0); + substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1); + substruct2 = &(GetSubstruct(boxMon, boxMon->personality, 2)->type2); + substruct3 = &(GetSubstruct(boxMon, boxMon->personality, 3)->type3); + + DecryptBoxMon(boxMon); + + if (CalculateBoxMonChecksum(boxMon) != boxMon->checksum) + { + boxMon->isBadEgg = 1; + boxMon->isEgg = 1; + substruct3->isEgg = 1; + EncryptBoxMon(boxMon); + return; + } + } + + switch (field) + { + case MON_DATA_PERSONALITY: + SET32(boxMon->personality); + break; + case MON_DATA_OT_ID: + SET32(boxMon->otId); + break; + case MON_DATA_NICKNAME: + { + s32 i; + for (i = 0; i < POKEMON_NAME_LENGTH; i++) + boxMon->nickname[i] = data[i]; + break; + } + case MON_DATA_LANGUAGE: + SET8(boxMon->language); + break; + case MON_DATA_SANITY_BIT1: + SET8(boxMon->isBadEgg); + break; + case MON_DATA_SANITY_BIT2: + SET8(boxMon->hasSpecies); + break; + case MON_DATA_SANITY_BIT3: + SET8(boxMon->isEgg); + break; + case MON_DATA_OT_NAME: + { + s32 i; + for (i = 0; i < OT_NAME_LENGTH; i++) + boxMon->otName[i] = data[i]; + break; + } + case MON_DATA_MARKINGS: + SET8(boxMon->markings); + break; + case MON_DATA_CHECKSUM: + SET16(boxMon->checksum); + break; + case MON_DATA_10: + SET16(boxMon->unknown); + break; + case MON_DATA_SPECIES: + { + SET16(substruct0->species); + if (substruct0->species) + boxMon->hasSpecies = 1; + else + boxMon->hasSpecies = 0; + break; + } + case MON_DATA_HELD_ITEM: + SET16(substruct0->heldItem); + break; + case MON_DATA_EXP: + SET32(substruct0->experience); + break; + case MON_DATA_PP_BONUSES: + SET8(substruct0->ppBonuses); + break; + case MON_DATA_FRIENDSHIP: + SET8(substruct0->friendship); + break; + case MON_DATA_MOVE1: + case MON_DATA_MOVE2: + case MON_DATA_MOVE3: + case MON_DATA_MOVE4: + SET16(substruct1->moves[field - MON_DATA_MOVE1]); + break; + case MON_DATA_PP1: + case MON_DATA_PP2: + case MON_DATA_PP3: + case MON_DATA_PP4: + SET8(substruct1->pp[field - MON_DATA_PP1]); + break; + case MON_DATA_HP_EV: + SET8(substruct2->hpEV); + break; + case MON_DATA_ATK_EV: + SET8(substruct2->attackEV); + break; + case MON_DATA_DEF_EV: + SET8(substruct2->defenseEV); + break; + case MON_DATA_SPEED_EV: + SET8(substruct2->speedEV); + break; + case MON_DATA_SPATK_EV: + SET8(substruct2->spAttackEV); + break; + case MON_DATA_SPDEF_EV: + SET8(substruct2->spDefenseEV); + break; + case MON_DATA_COOL: + SET8(substruct2->cool); + break; + case MON_DATA_BEAUTY: + SET8(substruct2->beauty); + break; + case MON_DATA_CUTE: + SET8(substruct2->cute); + break; + case MON_DATA_SMART: + SET8(substruct2->smart); + break; + case MON_DATA_TOUGH: + SET8(substruct2->tough); + break; + case MON_DATA_SHEEN: + SET8(substruct2->sheen); + break; + case MON_DATA_POKERUS: + SET8(substruct3->pokerus); + break; + case MON_DATA_MET_LOCATION: + SET8(substruct3->metLocation); + break; + case MON_DATA_MET_LEVEL: + { + u8 metLevel = *data; + substruct3->metLevel = metLevel; + break; + } + case MON_DATA_MET_GAME: + SET8(substruct3->metGame); + break; + case MON_DATA_POKEBALL: + { + u8 pokeball = *data; + substruct3->pokeball = pokeball; + break; + } + case MON_DATA_OT_GENDER: + SET8(substruct3->otGender); + break; + case MON_DATA_HP_IV: + SET8(substruct3->hpIV); + break; + case MON_DATA_ATK_IV: + SET8(substruct3->attackIV); + break; + case MON_DATA_DEF_IV: + SET8(substruct3->defenseIV); + break; + case MON_DATA_SPEED_IV: + SET8(substruct3->speedIV); + break; + case MON_DATA_SPATK_IV: + SET8(substruct3->spAttackIV); + break; + case MON_DATA_SPDEF_IV: + SET8(substruct3->spDefenseIV); + break; + case MON_DATA_IS_EGG: + SET8(substruct3->isEgg); + if (substruct3->isEgg) + boxMon->isEgg = 1; + else + boxMon->isEgg = 0; + break; + case MON_DATA_ALT_ABILITY: + SET8(substruct3->altAbility); + break; + case MON_DATA_COOL_RIBBON: + SET8(substruct3->coolRibbon); + break; + case MON_DATA_BEAUTY_RIBBON: + SET8(substruct3->beautyRibbon); + break; + case MON_DATA_CUTE_RIBBON: + SET8(substruct3->cuteRibbon); + break; + case MON_DATA_SMART_RIBBON: + SET8(substruct3->smartRibbon); + break; + case MON_DATA_TOUGH_RIBBON: + SET8(substruct3->toughRibbon); + break; + case MON_DATA_CHAMPION_RIBBON: + SET8(substruct3->championRibbon); + break; + case MON_DATA_WINNING_RIBBON: + SET8(substruct3->winningRibbon); + break; + case MON_DATA_VICTORY_RIBBON: + SET8(substruct3->victoryRibbon); + break; + case MON_DATA_ARTIST_RIBBON: + SET8(substruct3->artistRibbon); + break; + case MON_DATA_EFFORT_RIBBON: + SET8(substruct3->effortRibbon); + break; + case MON_DATA_GIFT_RIBBON_1: + SET8(substruct3->giftRibbon1); + break; + case MON_DATA_GIFT_RIBBON_2: + SET8(substruct3->giftRibbon2); + break; + case MON_DATA_GIFT_RIBBON_3: + SET8(substruct3->giftRibbon3); + break; + case MON_DATA_GIFT_RIBBON_4: + SET8(substruct3->giftRibbon4); + break; + case MON_DATA_GIFT_RIBBON_5: + SET8(substruct3->giftRibbon5); + break; + case MON_DATA_GIFT_RIBBON_6: + SET8(substruct3->giftRibbon6); + break; + case MON_DATA_GIFT_RIBBON_7: + SET8(substruct3->giftRibbon7); + break; + case MON_DATA_FATEFUL_ENCOUNTER: + SET8(substruct3->fatefulEncounter); + break; + case MON_DATA_OBEDIENCE: + SET8(substruct3->obedient); + break; + case MON_DATA_IVS: + { + u32 ivs = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); + substruct3->hpIV = ivs & 0x1F; + substruct3->attackIV = (ivs >> 5) & 0x1F; + substruct3->defenseIV = (ivs >> 10) & 0x1F; + substruct3->speedIV = (ivs >> 15) & 0x1F; + substruct3->spAttackIV = (ivs >> 20) & 0x1F; + substruct3->spDefenseIV = (ivs >> 25) & 0x1F; + break; + } + default: + break; + } + + if (field > MON_DATA_10) + { + boxMon->checksum = CalculateBoxMonChecksum(boxMon); + EncryptBoxMon(boxMon); + } +} + +void CopyMon(void *dest, void *src, size_t size) +{ + memcpy(dest, src, size); +} + +u8 GiveMonToPlayer(struct Pokemon *mon) +{ + s32 i; + + SetMonData(mon, MON_DATA_OT_NAME, gSaveBlock2Ptr->playerName); + SetMonData(mon, MON_DATA_OT_GENDER, &gSaveBlock2Ptr->playerGender); + SetMonData(mon, MON_DATA_OT_ID, gSaveBlock2Ptr->playerTrainerId); + + i = 0; + + while (i < 6 && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL) != SPECIES_NONE) + i++; + + if (i >= 6) + return SendMonToPC(mon); + + CopyMon(&gPlayerParty[i], mon, sizeof(*mon)); + gPlayerPartyCount = i + 1; + return MON_GIVEN_TO_PARTY; +} + +u8 SendMonToPC(struct Pokemon* mon) +{ + s32 boxNo, boxPos; + + set_unknown_box_id(VarGet(VAR_STORAGE_UNKNOWN)); + + boxNo = StorageGetCurrentBox(); + + do + { + for (boxPos = 0; boxPos < 30; boxPos++) + { + struct BoxPokemon* checkingMon = GetBoxedMonPtr(boxNo, boxPos); + if (GetBoxMonData(checkingMon, MON_DATA_SPECIES, NULL) == SPECIES_NONE) + { + MonRestorePP(mon); + CopyMon(checkingMon, &mon->box, sizeof(mon->box)); + gSpecialVar_MonBoxId = boxNo; + gSpecialVar_MonBoxPos = boxPos; + if (get_unknown_box_id() != boxNo) + FlagClear(FLAG_SYS_STORAGE_UNKNOWN_FLAG); + VarSet(VAR_STORAGE_UNKNOWN, boxNo); + return MON_GIVEN_TO_PC; + } + } + + boxNo++; + if (boxNo == 14) + boxNo = 0; + } while (boxNo != StorageGetCurrentBox()); + + return MON_CANT_GIVE; +} + +u8 CalculatePlayerPartyCount(void) +{ + gPlayerPartyCount = 0; + + while (gPlayerPartyCount < 6 + && GetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE) + { + gPlayerPartyCount++; + } + + return gPlayerPartyCount; +} + +u8 CalculateEnemyPartyCount(void) +{ + gEnemyPartyCount = 0; + + while (gEnemyPartyCount < 6 + && GetMonData(&gEnemyParty[gEnemyPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE) + { + gEnemyPartyCount++; + } + + return gEnemyPartyCount; +} + +u8 GetMonsStateToDoubles(void) +{ + s32 aliveCount = 0; + s32 i; + CalculatePlayerPartyCount(); + + if (gPlayerPartyCount == 1) + return gPlayerPartyCount; // PLAYER_HAS_ONE_MON + + for (i = 0; i < gPlayerPartyCount; i++) + { + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_EGG + && GetMonData(&gPlayerParty[i], MON_DATA_HP, NULL) != 0 + && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_NONE) + aliveCount++; + } + + return (aliveCount > 1) ? PLAYER_HAS_TWO_USABLE_MONS : PLAYER_HAS_ONE_USABLE_MON; +} + +u8 GetMonsStateToDoubles_2(void) +{ + s32 aliveCount = 0; + s32 i; + + for (i = 0; i < PARTY_SIZE; i++) + { + u32 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL); + if (species != SPECIES_EGG && species != SPECIES_NONE + && GetMonData(&gPlayerParty[i], MON_DATA_HP, NULL) != 0) + aliveCount++; + } + + if (aliveCount == 1) + return PLAYER_HAS_ONE_MON; // may have more than one, but only one is alive + + return (aliveCount > 1) ? PLAYER_HAS_TWO_USABLE_MONS : PLAYER_HAS_ONE_USABLE_MON; +} + +u8 GetAbilityBySpecies(u16 species, bool8 altAbility) +{ + if (altAbility) + gLastUsedAbility = gBaseStats[species].ability2; + else + gLastUsedAbility = gBaseStats[species].ability1; + + return gLastUsedAbility; +} + +u8 GetMonAbility(struct Pokemon *mon) +{ + u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); + u8 altAbility = GetMonData(mon, MON_DATA_ALT_ABILITY, NULL); + return GetAbilityBySpecies(species, altAbility); +} + +void CreateSecretBaseEnemyParty(struct SecretBaseRecord *secretBaseRecord) +{ + s32 i, j; + + ZeroEnemyPartyMons(); + *gBattleResources->secretBase = *secretBaseRecord; + + for (i = 0; i < PARTY_SIZE; i++) + { + if (gBattleResources->secretBase->party.species[i]) + { + CreateMon(&gEnemyParty[i], + gBattleResources->secretBase->party.species[i], + gBattleResources->secretBase->party.levels[i], + 15, + 1, + gBattleResources->secretBase->party.personality[i], + 2, + 0); + + SetMonData(&gEnemyParty[i], MON_DATA_HELD_ITEM, &gBattleResources->secretBase->party.heldItems[i]); + + for (j = 0; j < 6; j++) + SetMonData(&gEnemyParty[i], MON_DATA_HP_EV + j, &gBattleResources->secretBase->party.EVs[i]); + + for (j = 0; j < 4; j++) + { + SetMonData(&gEnemyParty[i], MON_DATA_MOVE1 + j, &gBattleResources->secretBase->party.moves[i * 4 + j]); + SetMonData(&gEnemyParty[i], MON_DATA_PP1 + j, &gBattleMoves[gBattleResources->secretBase->party.moves[i * 4 + j]].pp); + } + } + } +} + +u8 GetSecretBaseTrainerPicIndex(void) +{ + u8 trainerClass = gSecretBaseTrainerClasses[gBattleResources->secretBase->gender][gBattleResources->secretBase->trainerId[0] % 5]; + return gFacilityClassToPicIndex[trainerClass]; +} + +u8 GetSecretBaseTrainerNameIndex(void) +{ + u8 trainerClass = gSecretBaseTrainerClasses[gBattleResources->secretBase->gender][gBattleResources->secretBase->trainerId[0] % 5]; + return gFacilityClassToTrainerClass[trainerClass]; +} + +bool8 IsPlayerPartyAndPokemonStorageFull(void) +{ + s32 i; + + for (i = 0; i < 6; i++) + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL) == SPECIES_NONE) + return FALSE; + + return IsPokemonStorageFull(); +} + +bool8 IsPokemonStorageFull(void) +{ + s32 i, j; + + for (i = 0; i < 14; i++) + for (j = 0; j < 30; j++) + if (GetBoxMonDataFromAnyBox(i, j, MON_DATA_SPECIES) == SPECIES_NONE) + return FALSE; + + return TRUE; +} + +void GetSpeciesName(u8 *name, u16 species) +{ + s32 i; + + for (i = 0; i <= POKEMON_NAME_LENGTH; i++) + { + if (species > NUM_SPECIES) + name[i] = gSpeciesNames[0][i]; + else + name[i] = gSpeciesNames[species][i]; + + if (name[i] == EOS) + break; + } + + name[i] = EOS; +} + +u8 CalculatePPWithBonus(u16 move, u8 ppBonuses, u8 moveIndex) +{ + u8 basePP = gBattleMoves[move].pp; + return basePP + ((basePP * 20 * ((gUnknown_08329D22[moveIndex] & ppBonuses) >> (2 * moveIndex))) / 100); +} + +void RemoveMonPPBonus(struct Pokemon *mon, u8 moveIndex) +{ + u8 ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES, NULL); + ppBonuses &= gUnknown_08329D26[moveIndex]; + SetMonData(mon, MON_DATA_PP_BONUSES, &ppBonuses); +} + +void RemoveBattleMonPPBonus(struct BattlePokemon *mon, u8 moveIndex) +{ + mon->ppBonuses &= gUnknown_08329D26[moveIndex]; +} + +void CopyPlayerPartyMonToBattleData(u8 bank, u8 partyIndex) +{ + u16* hpSwitchout; + s32 i; + u8 nickname[POKEMON_NAME_LENGTH * 2]; + + gBattleMons[bank].species = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES, NULL); + gBattleMons[bank].item = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HELD_ITEM, NULL); + + for (i = 0; i < 4; i++) + { + gBattleMons[bank].moves[i] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_MOVE1 + i, NULL); + gBattleMons[bank].pp[i] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_PP1 + i, NULL); + } + + gBattleMons[bank].ppBonuses = GetMonData(&gPlayerParty[partyIndex], MON_DATA_PP_BONUSES, NULL); + gBattleMons[bank].friendship = GetMonData(&gPlayerParty[partyIndex], MON_DATA_FRIENDSHIP, NULL); + gBattleMons[bank].experience = GetMonData(&gPlayerParty[partyIndex], MON_DATA_EXP, NULL); + gBattleMons[bank].hpIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HP_IV, NULL); + gBattleMons[bank].attackIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_ATK_IV, NULL); + gBattleMons[bank].defenseIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_DEF_IV, NULL); + gBattleMons[bank].speedIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPEED_IV, NULL); + gBattleMons[bank].spAttackIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPATK_IV, NULL); + gBattleMons[bank].spDefenseIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPDEF_IV, NULL); + gBattleMons[bank].personality = GetMonData(&gPlayerParty[partyIndex], MON_DATA_PERSONALITY, NULL); + gBattleMons[bank].status1 = GetMonData(&gPlayerParty[partyIndex], MON_DATA_STATUS, NULL); + gBattleMons[bank].level = GetMonData(&gPlayerParty[partyIndex], MON_DATA_LEVEL, NULL); + gBattleMons[bank].hp = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HP, NULL); + gBattleMons[bank].maxHP = GetMonData(&gPlayerParty[partyIndex], MON_DATA_MAX_HP, NULL); + gBattleMons[bank].attack = GetMonData(&gPlayerParty[partyIndex], MON_DATA_ATK, NULL); + gBattleMons[bank].defense = GetMonData(&gPlayerParty[partyIndex], MON_DATA_DEF, NULL); + gBattleMons[bank].speed = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPEED, NULL); + gBattleMons[bank].spAttack = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPATK, NULL); + gBattleMons[bank].spDefense = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPDEF, NULL); + gBattleMons[bank].isEgg = GetMonData(&gPlayerParty[partyIndex], MON_DATA_IS_EGG, NULL); + gBattleMons[bank].altAbility = GetMonData(&gPlayerParty[partyIndex], MON_DATA_ALT_ABILITY, NULL); + gBattleMons[bank].otId = GetMonData(&gPlayerParty[partyIndex], MON_DATA_OT_ID, NULL); + gBattleMons[bank].type1 = gBaseStats[gBattleMons[bank].species].type1; + gBattleMons[bank].type2 = gBaseStats[gBattleMons[bank].species].type2; + gBattleMons[bank].ability = GetAbilityBySpecies(gBattleMons[bank].species, gBattleMons[bank].altAbility); + GetMonData(&gPlayerParty[partyIndex], MON_DATA_NICKNAME, nickname); + StringCopy10(gBattleMons[bank].nickname, nickname); + GetMonData(&gPlayerParty[partyIndex], MON_DATA_OT_NAME, gBattleMons[bank].otName); + + hpSwitchout = &gBattleStruct->hpOnSwitchout[GetBattlerSide(bank)]; + *hpSwitchout = gBattleMons[bank].hp; + + for (i = 0; i < 8; i++) + gBattleMons[bank].statStages[i] = 6; + + gBattleMons[bank].status2 = 0; + sub_803FA70(bank); + ClearTemporarySpeciesSpriteData(bank, FALSE); +} + +bool8 ExecuteTableBasedItemEffect_(struct Pokemon *mon, u16 item, u8 partyIndex, u8 moveIndex) +{ + return PokemonUseItemEffects(mon, item, partyIndex, moveIndex, 0); +} + +bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 moveIndex, u8 e) +{ + u32 dataUnsigned; + s32 dataSigned; + s32 friendship; + s32 cmdIndex; + bool8 retVal = TRUE; + const u8 *itemEffect; + u8 var_3C = 6; + u32 var_38; + s8 var_34 = 0; + u8 holdEffect; + u8 battlerId = 4; + u32 var_28 = 0; + u16 heldItem; + u8 r10; + u32 r4; + u32 r5; + s8 r2; + u16 evCount; + + heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, NULL); + if (heldItem == ITEM_ENIGMA_BERRY) + { + if (gMain.inBattle) + holdEffect = gEnigmaBerries[gBankInMenu].holdEffect; + else + holdEffect = gSaveBlock1Ptr->enigmaBerry.holdEffect; + } + else + { + holdEffect = ItemId_GetHoldEffect(heldItem); + } + + gStringBattler = gBankInMenu; + if (gMain.inBattle) + { + gActiveBattler = gBankInMenu; + cmdIndex = (GetBattlerSide(gActiveBattler) != B_SIDE_PLAYER); + while (cmdIndex < gBattlersCount) + { + if (gBattlerPartyIndexes[cmdIndex] == partyIndex) + { + battlerId = cmdIndex; + break; + } + cmdIndex += 2; + } + } + else + { + gActiveBattler = 0; + battlerId = MAX_BATTLERS_COUNT; + } + + if (!IS_POKEMON_ITEM(item)) + return TRUE; + if (gItemEffectTable[item - 13] == NULL && item != ITEM_ENIGMA_BERRY) + return TRUE; + + if (item == ITEM_ENIGMA_BERRY) + { + if (gMain.inBattle) + itemEffect = gEnigmaBerries[gActiveBattler].itemEffect; + else + itemEffect = gSaveBlock1Ptr->enigmaBerry.itemEffect; + } + else + { + itemEffect = gItemEffectTable[item - 13]; + } + + for (cmdIndex = 0; cmdIndex < 6; cmdIndex++) + { + switch (cmdIndex) + { + // status healing effects + case 0: + if ((itemEffect[cmdIndex] & 0x80) + && gMain.inBattle && battlerId != 4 && (gBattleMons[battlerId].status2 & STATUS2_INFATUATION)) + { + gBattleMons[battlerId].status2 &= ~STATUS2_INFATUATION; + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & 0x30) + && !(gBattleMons[gActiveBattler].status2 & STATUS2_FOCUS_ENERGY)) + { + gBattleMons[gActiveBattler].status2 |= STATUS2_FOCUS_ENERGY; + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & 0xF) + && gBattleMons[gActiveBattler].statStages[STAT_STAGE_ATK] < 12) + { + gBattleMons[gActiveBattler].statStages[STAT_STAGE_ATK] += itemEffect[cmdIndex] & 0xF; + if (gBattleMons[gActiveBattler].statStages[STAT_STAGE_ATK] > 12) + gBattleMons[gActiveBattler].statStages[STAT_STAGE_ATK] = 12; + retVal = FALSE; + } + break; + // in-battle stat boosting effects? + case 1: + if ((itemEffect[cmdIndex] & 0xF0) + && gBattleMons[gActiveBattler].statStages[STAT_STAGE_DEF] < 12) + { + gBattleMons[gActiveBattler].statStages[STAT_STAGE_DEF] += (itemEffect[cmdIndex] & 0xF0) >> 4; + if (gBattleMons[gActiveBattler].statStages[STAT_STAGE_DEF] > 12) + gBattleMons[gActiveBattler].statStages[STAT_STAGE_DEF] = 12; + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & 0xF) + && gBattleMons[gActiveBattler].statStages[STAT_STAGE_SPEED] < 12) + { + gBattleMons[gActiveBattler].statStages[STAT_STAGE_SPEED] += itemEffect[cmdIndex] & 0xF; + if (gBattleMons[gActiveBattler].statStages[STAT_STAGE_SPEED] > 12) + gBattleMons[gActiveBattler].statStages[STAT_STAGE_SPEED] = 12; + retVal = FALSE; + } + break; + // more stat boosting effects? + case 2: + if ((itemEffect[cmdIndex] & 0xF0) + && gBattleMons[gActiveBattler].statStages[STAT_STAGE_ACC] < 12) + { + gBattleMons[gActiveBattler].statStages[STAT_STAGE_ACC] += (itemEffect[cmdIndex] & 0xF0) >> 4; + if (gBattleMons[gActiveBattler].statStages[STAT_STAGE_ACC] > 12) + gBattleMons[gActiveBattler].statStages[STAT_STAGE_ACC] = 12; + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & 0xF) + && gBattleMons[gActiveBattler].statStages[STAT_STAGE_SPATK] < 12) + { + gBattleMons[gActiveBattler].statStages[STAT_STAGE_SPATK] += itemEffect[cmdIndex] & 0xF; + if (gBattleMons[gActiveBattler].statStages[STAT_STAGE_SPATK] > 12) + gBattleMons[gActiveBattler].statStages[STAT_STAGE_SPATK] = 12; + retVal = FALSE; + } + break; + case 3: + if ((itemEffect[cmdIndex] & 0x80) + && gSideTimers[GetBattlerSide(gActiveBattler)].mistTimer == 0) + { + gSideTimers[GetBattlerSide(gActiveBattler)].mistTimer = 5; + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & 0x40) // raise level + && GetMonData(mon, MON_DATA_LEVEL, NULL) != MAX_MON_LEVEL) + { + dataUnsigned = gExperienceTables[gBaseStats[GetMonData(mon, MON_DATA_SPECIES, NULL)].growthRate][GetMonData(mon, MON_DATA_LEVEL, NULL) + 1]; + SetMonData(mon, MON_DATA_EXP, &dataUnsigned); + CalculateMonStats(mon); + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & 0x20) + && HealStatusConditions(mon, partyIndex, 7, battlerId) == 0) + { + if (battlerId != 4) + gBattleMons[battlerId].status2 &= ~STATUS2_NIGHTMARE; + retVal = FALSE; + } + if ((itemEffect[cmdIndex] & 0x10) && HealStatusConditions(mon, partyIndex, STATUS1_PSN_ANY | STATUS1_TOXIC_COUNTER, battlerId) == 0) + retVal = FALSE; + if ((itemEffect[cmdIndex] & 8) && HealStatusConditions(mon, partyIndex, STATUS1_BURN, battlerId) == 0) + retVal = FALSE; + if ((itemEffect[cmdIndex] & 4) && HealStatusConditions(mon, partyIndex, STATUS1_FREEZE, battlerId) == 0) + retVal = FALSE; + if ((itemEffect[cmdIndex] & 2) && HealStatusConditions(mon, partyIndex, STATUS1_PARALYSIS, battlerId) == 0) + retVal = FALSE; + if ((itemEffect[cmdIndex] & 1) // heal confusion + && gMain.inBattle && battlerId != 4 && (gBattleMons[battlerId].status2 & STATUS2_CONFUSION)) + { + gBattleMons[battlerId].status2 &= ~STATUS2_CONFUSION; + retVal = FALSE; + } + break; + // EV, HP, and PP raising effects + case 4: + r10 = itemEffect[cmdIndex]; + if (r10 & 0x20) + { + r10 &= ~0x20; + dataUnsigned = (GetMonData(mon, MON_DATA_PP_BONUSES, NULL) & gUnknown_08329D22[moveIndex]) >> (moveIndex * 2); + var_38 = CalculatePPWithBonus(GetMonData(mon, MON_DATA_MOVE1 + moveIndex, NULL), GetMonData(mon, MON_DATA_PP_BONUSES, NULL), moveIndex); + if (dataUnsigned <= 2 && var_38 > 4) + { + dataUnsigned = GetMonData(mon, MON_DATA_PP_BONUSES, NULL) + gUnknown_08329D2A[moveIndex]; + SetMonData(mon, MON_DATA_PP_BONUSES, &dataUnsigned); + + dataUnsigned = CalculatePPWithBonus(GetMonData(mon, MON_DATA_MOVE1 + moveIndex, NULL), dataUnsigned, moveIndex) - var_38; + dataUnsigned = GetMonData(mon, MON_DATA_PP1 + moveIndex, NULL) + dataUnsigned; + SetMonData(mon, MON_DATA_PP1 + moveIndex, &dataUnsigned); + retVal = FALSE; + } + } + var_38 = 0; + while (r10 != 0) + { + if (r10 & 1) + { + switch (var_38) + { + case 0: + case 1: + evCount = GetMonEVCount(mon); + r5 = itemEffect[var_3C]; + dataSigned = GetMonData(mon, gUnknown_08329EC2[var_38], NULL); + r2 = r5; + if (r2 > 0) + { + if (evCount >= MAX_TOTAL_EVS) + return TRUE; + if (dataSigned >= 100) + break; + + if (dataSigned + r2 > 100) + r5 = 100 - (dataSigned + r2) + r2; + else + r5 = r2; + + if (evCount + r5 > MAX_TOTAL_EVS) + r5 += MAX_TOTAL_EVS - (evCount + r5); + dataSigned += r5; + } + else + { + if (dataSigned == 0) + { + var_28 = 1; + var_3C++; + break; + } + dataSigned += r2; + if (dataSigned < 0) + dataSigned = 0; + } + SetMonData(mon, gUnknown_08329EC2[var_38], &dataSigned); + CalculateMonStats(mon); + var_3C++; + retVal = FALSE; + break; + case 2: + // revive? + if (r10 & 0x10) + { + if (GetMonData(mon, MON_DATA_HP, NULL) != 0) + { + var_3C++; + break; + } + if (gMain.inBattle) + { + if (battlerId != 4) + { + gAbsentBattlerFlags &= ~gBitTable[battlerId]; + CopyPlayerPartyMonToBattleData(battlerId, pokemon_order_func(gBattlerPartyIndexes[battlerId])); + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER && gBattleResults.unk4 < 255) + gBattleResults.unk4++; + } + else + { + gAbsentBattlerFlags &= ~gBitTable[gActiveBattler ^ 2]; + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER && gBattleResults.unk4 < 255) + gBattleResults.unk4++; + } + } + } + else + { + if (GetMonData(mon, MON_DATA_HP, NULL) == 0) + { + var_3C++; + break; + } + } + dataUnsigned = itemEffect[var_3C++]; + switch (dataUnsigned) + { + case 0xFF: + dataUnsigned = GetMonData(mon, MON_DATA_MAX_HP, NULL) - GetMonData(mon, MON_DATA_HP, NULL); + break; + case 0xFE: + dataUnsigned = GetMonData(mon, MON_DATA_MAX_HP, NULL) / 2; + if (dataUnsigned == 0) + dataUnsigned = 1; + break; + case 0xFD: + dataUnsigned = gBattleScripting.field_23; + break; + } + if (GetMonData(mon, MON_DATA_MAX_HP, NULL) != GetMonData(mon, MON_DATA_HP, NULL)) + { + if (e == 0) + { + dataUnsigned = GetMonData(mon, MON_DATA_HP, NULL) + dataUnsigned; + if (dataUnsigned > GetMonData(mon, MON_DATA_MAX_HP, NULL)) + dataUnsigned = GetMonData(mon, MON_DATA_MAX_HP, NULL); + SetMonData(mon, MON_DATA_HP, &dataUnsigned); + if (gMain.inBattle && battlerId != 4) + { + gBattleMons[battlerId].hp = dataUnsigned; + if (!(r10 & 0x10) && GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + { + if (gBattleResults.unk3 < 255) + gBattleResults.unk3++; + // I have to re-use this variable to match. + r5 = gActiveBattler; + gActiveBattler = battlerId; + BtlController_EmitGetMonData(0, 0, 0); + MarkBattlerForControllerExec(gActiveBattler); + gActiveBattler = r5; + } + } + } + else + { + gBattleMoveDamage = -dataUnsigned; + } + retVal = FALSE; + } + r10 &= 0xEF; + break; + case 3: + if (!(r10 & 2)) + { + for (r5 = 0; (signed)(r5) < (signed)(4); r5++) + { + u16 moveId; + + dataUnsigned = GetMonData(mon, MON_DATA_PP1 + r5, NULL); + moveId = GetMonData(mon, MON_DATA_MOVE1 + r5, NULL); + if (dataUnsigned != CalculatePPWithBonus(moveId, GetMonData(mon, MON_DATA_PP_BONUSES, NULL), r5)) + { + dataUnsigned += itemEffect[var_3C]; + moveId = GetMonData(mon, MON_DATA_MOVE1 + r5, NULL); + if (dataUnsigned > CalculatePPWithBonus(moveId, GetMonData(mon, MON_DATA_PP_BONUSES, NULL), r5)) + { + moveId = GetMonData(mon, MON_DATA_MOVE1 + r5, NULL); + dataUnsigned = CalculatePPWithBonus(moveId, GetMonData(mon, MON_DATA_PP_BONUSES, NULL), r5); + } + SetMonData(mon, MON_DATA_PP1 + r5, &dataUnsigned); + if (gMain.inBattle + && battlerId != 4 && !(gBattleMons[battlerId].status2 & STATUS2_TRANSFORMED) + && !(gDisableStructs[battlerId].unk18_b & gBitTable[r5])) + gBattleMons[battlerId].pp[r5] = dataUnsigned; + retVal = FALSE; + } + } + var_3C++; + } + else + { + u16 moveId; + + dataUnsigned = GetMonData(mon, MON_DATA_PP1 + moveIndex, NULL); + moveId = GetMonData(mon, MON_DATA_MOVE1 + moveIndex, NULL); + if (dataUnsigned != CalculatePPWithBonus(moveId, GetMonData(mon, MON_DATA_PP_BONUSES, NULL), moveIndex)) + { + dataUnsigned += itemEffect[var_3C++]; + moveId = GetMonData(mon, MON_DATA_MOVE1 + moveIndex, NULL); + if (dataUnsigned > CalculatePPWithBonus(moveId, GetMonData(mon, MON_DATA_PP_BONUSES, NULL), moveIndex)) + { + moveId = GetMonData(mon, MON_DATA_MOVE1 + moveIndex, NULL); + dataUnsigned = CalculatePPWithBonus(moveId, GetMonData(mon, MON_DATA_PP_BONUSES, NULL), moveIndex); + } + SetMonData(mon, MON_DATA_PP1 + moveIndex, &dataUnsigned); + if (gMain.inBattle + && battlerId != 4 && !(gBattleMons[battlerId].status2 & STATUS2_TRANSFORMED) + && !(gDisableStructs[battlerId].unk18_b & gBitTable[moveIndex])) + gBattleMons[battlerId].pp[moveIndex] = dataUnsigned; + retVal = FALSE; + } + } + break; + case 7: + { + u16 targetSpecies = GetEvolutionTargetSpecies(mon, 2, item); + + if (targetSpecies != SPECIES_NONE) + { + BeginEvolutionScene(mon, targetSpecies, 0, partyIndex); + return FALSE; + } + } + break; + } + } + var_38++; + r10 >>= 1; + } + break; + case 5: + r10 = itemEffect[cmdIndex]; + var_38 = 0; + while (r10 != 0) + { + if (r10 & 1) + { + switch (var_38) + { + case 0: + case 1: + case 2: + case 3: + evCount = GetMonEVCount(mon); + r5 = itemEffect[var_3C]; + dataSigned = GetMonData(mon, gUnknown_08329EC2[var_38 + 2], NULL); + r2 = r5; + if (r2 > 0) + { + if (evCount >= MAX_TOTAL_EVS) + return TRUE; + if (dataSigned >= 100) + break; + + if (dataSigned + r2 > 100) + r5 = 100 - (dataSigned + r2) + r2; + else + r5 = r2; + + if (evCount + r5 > MAX_TOTAL_EVS) + r5 += MAX_TOTAL_EVS - (evCount + r5); + dataSigned += r5; + } + else + { + if (dataSigned == 0) + { + var_28 = 1; + var_3C++; + break; + } + dataSigned += r2; + if (dataSigned < 0) + dataSigned = 0; + } + SetMonData(mon, gUnknown_08329EC2[var_38 + 2], &dataSigned); + CalculateMonStats(mon); + retVal = FALSE; + var_3C++; + break; + case 4: + dataUnsigned = (GetMonData(mon, MON_DATA_PP_BONUSES, NULL) & gUnknown_08329D22[moveIndex]) >> (moveIndex * 2); + r5 = CalculatePPWithBonus(GetMonData(mon, MON_DATA_MOVE1 + moveIndex, NULL), GetMonData(mon, MON_DATA_PP_BONUSES, NULL), moveIndex); + if (dataUnsigned < 3 && r5 > 4) + { + dataUnsigned = GetMonData(mon, MON_DATA_PP_BONUSES, NULL); + dataUnsigned &= gUnknown_08329D26[moveIndex]; + dataUnsigned += gUnknown_08329D2A[moveIndex] * 3; + + SetMonData(mon, MON_DATA_PP_BONUSES, &dataUnsigned); + dataUnsigned = CalculatePPWithBonus(GetMonData(mon, MON_DATA_MOVE1 + moveIndex, NULL), dataUnsigned, moveIndex) - r5; + dataUnsigned = GetMonData(mon, MON_DATA_PP1 + moveIndex, NULL) + dataUnsigned; + SetMonData(mon, MON_DATA_PP1 + moveIndex, &dataUnsigned); + retVal = FALSE; + } + break; + case 5: + if (GetMonData(mon, MON_DATA_FRIENDSHIP, NULL) < 100 && (retVal == 0 || var_28 != 0) && !sub_806F104() && var_34 == 0) + { + var_34 = itemEffect[var_3C]; + friendship = GetMonData(mon, MON_DATA_FRIENDSHIP, NULL); + if (var_34 > 0 && holdEffect == HOLD_EFFECT_HAPPINESS_UP) + friendship += 150 * var_34 / 100; + else + friendship += var_34; + if (var_34 > 0) + { + if (GetMonData(mon, MON_DATA_POKEBALL, NULL) == 11) + friendship++; + if (GetMonData(mon, MON_DATA_MET_LOCATION, NULL) == sav1_map_get_name()) + friendship++; + } + if (friendship < 0) + friendship = 0; + if (friendship > 255) + friendship = 255; + SetMonData(mon, MON_DATA_FRIENDSHIP, &friendship); + retVal = FALSE; + } + var_3C++; + break; + case 6: + if (GetMonData(mon, MON_DATA_FRIENDSHIP, NULL) >= 100 && GetMonData(mon, MON_DATA_FRIENDSHIP, NULL) < 200 + && (retVal == 0 || var_28 != 0) && !sub_806F104() && var_34 == 0) + { + var_34 = itemEffect[var_3C]; + friendship = GetMonData(mon, MON_DATA_FRIENDSHIP, NULL); + if ((s8)(var_34) > 0 && holdEffect == HOLD_EFFECT_HAPPINESS_UP) + friendship += 150 * var_34 / 100; + else + friendship += var_34; + if (var_34 > 0) + { + if (GetMonData(mon, MON_DATA_POKEBALL, NULL) == 11) + friendship++; + if (GetMonData(mon, MON_DATA_MET_LOCATION, NULL) == sav1_map_get_name()) + friendship++; + } + if (friendship < 0) + friendship = 0; + if (friendship > 255) + friendship = 255; + SetMonData(mon, MON_DATA_FRIENDSHIP, &friendship); + retVal = FALSE; + } + var_3C++; + break; + case 7: + if (GetMonData(mon, MON_DATA_FRIENDSHIP, NULL) >= 200 && (retVal == 0 || var_28 != 0) && !sub_806F104() && var_34 == 0) + { + var_34 = itemEffect[var_3C]; + friendship = GetMonData(mon, MON_DATA_FRIENDSHIP, NULL); + if ((s8)(var_34) > 0 && holdEffect == HOLD_EFFECT_HAPPINESS_UP) + friendship += 150 * var_34 / 100; + else + friendship += var_34; + if (var_34 > 0) + { + if (GetMonData(mon, MON_DATA_POKEBALL, NULL) == 11) + friendship++; + if (GetMonData(mon, MON_DATA_MET_LOCATION, NULL) == sav1_map_get_name()) + friendship++; + } + if (friendship < 0) + friendship = 0; + if (friendship > 255) + friendship = 255; + SetMonData(mon, MON_DATA_FRIENDSHIP, &friendship); + retVal = FALSE; + } + var_3C++; + break; + } + } + var_38++; + r10 >>= 1; + } + break; + } + } + return retVal; +} + + diff --git a/src/pokemon_2.c b/src/pokemon_2.c deleted file mode 100644 index 28cecbb0b..000000000 --- a/src/pokemon_2.c +++ /dev/null @@ -1,1365 +0,0 @@ -#include "global.h" -#include "pokemon.h" -#include "battle.h" -#include "event_data.h" -#include "random.h" -#include "sprite.h" -#include "constants/species.h" -#include "text.h" -#include "string_util.h" - -struct Unknown_020249B4 -{ - u8 unk0[0xC]; - struct SpriteTemplate* templates; -}; - -extern u8 gAbsentBattlerFlags; -extern u8 gActiveBattler; -extern u8 gBattlerAttacker; -extern u8 gBattlerTarget; -extern u8 gLastUsedAbility; -extern u16 gTrainerBattleOpponent_A; -extern u32 gBattleTypeFlags; -extern struct SpriteTemplate gUnknown_0202499C; -extern struct Unknown_020249B4* gUnknown_020249B4[2]; - -extern const u32 gBitTable[]; -extern const struct SpriteTemplate gUnknown_08329D98[]; -extern const struct SpriteTemplate gUnknown_08329DF8[]; -extern const union AnimCmd* gUnknown_082FF70C[]; -extern const union AnimCmd* const * const gMonAnimationsSpriteAnimsPtrTable[]; -extern const union AnimCmd* const * const gUnknown_08305D0C[]; -extern const union AnimCmd* const * const gUnknown_0830536C[]; -extern const u8 gText_BadEgg[]; -extern const u8 gText_EggNickname[]; - -extern u8 GetBattlerSide(u8 bank); -extern u8 GetBattlerAtPosition(u8 bank); -extern u8 GetBattlerPosition(u8 bank); - -u8 CountAliveMonsInBattle(u8 caseId) -{ - s32 i; - u8 retVal = 0; - - switch (caseId) - { - case BATTLE_ALIVE_EXCEPT_ACTIVE: - for (i = 0; i < 4; i++) - { - if (i != gActiveBattler && !(gAbsentBattlerFlags & gBitTable[i])) - retVal++; - } - break; - case BATTLE_ALIVE_ATK_SIDE: - for (i = 0; i < 4; i++) - { - if (GetBattlerSide(i) == GetBattlerSide(gBattlerAttacker) && !(gAbsentBattlerFlags & gBitTable[i])) - retVal++; - } - break; - case BATTLE_ALIVE_DEF_SIDE: - for (i = 0; i < 4; i++) - { - if (GetBattlerSide(i) == GetBattlerSide(gBattlerTarget) && !(gAbsentBattlerFlags & gBitTable[i])) - retVal++; - } - break; - } - - return retVal; -} - -bool8 ShouldGetStatBadgeBoost(u16 badgeFlag, u8 bank) -{ - if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_x2000000 | BATTLE_TYPE_FRONTIER)) - return FALSE; - if (GetBattlerSide(bank) != B_SIDE_PLAYER) - return FALSE; - if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gTrainerBattleOpponent_A == SECRET_BASE_OPPONENT) - return FALSE; - if (FlagGet(badgeFlag)) - return TRUE; - return FALSE; -} - -u8 GetDefaultMoveTarget(u8 bank) -{ - u8 status = GetBattlerPosition(bank) & 1; - - status ^= 1; - if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) - return GetBattlerAtPosition(status); - if (CountAliveMonsInBattle(BATTLE_ALIVE_EXCEPT_ACTIVE) > 1) - { - u8 val; - - if ((Random() & 1) == 0) - val = status ^ 2; - else - val = status; - return GetBattlerAtPosition(val); - } - else - { - if ((gAbsentBattlerFlags & gBitTable[status])) - return GetBattlerAtPosition(status ^ 2); - else - return GetBattlerAtPosition(status); - } -} - -u8 GetMonGender(struct Pokemon *mon) -{ - return GetBoxMonGender(&mon->box); -} - -u8 GetBoxMonGender(struct BoxPokemon *boxMon) -{ - u16 species = GetBoxMonData(boxMon, MON_DATA_SPECIES, NULL); - u32 personality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY, NULL); - - switch (gBaseStats[species].genderRatio) - { - case MON_MALE: - case MON_FEMALE: - case MON_GENDERLESS: - return gBaseStats[species].genderRatio; - } - - if (gBaseStats[species].genderRatio > (personality & 0xFF)) - return MON_FEMALE; - else - return MON_MALE; -} - -u8 GetGenderFromSpeciesAndPersonality(u16 species, u32 personality) -{ - switch (gBaseStats[species].genderRatio) - { - case MON_MALE: - case MON_FEMALE: - case MON_GENDERLESS: - return gBaseStats[species].genderRatio; - } - - if (gBaseStats[species].genderRatio > (personality & 0xFF)) - return MON_FEMALE; - else - return MON_MALE; -} - -void sub_806A068(u16 species, u8 bankIdentity) -{ - if (gMonSpritesGfxPtr != NULL) - gUnknown_0202499C = gMonSpritesGfxPtr->templates[bankIdentity]; - else if (gUnknown_020249B4[0]) - gUnknown_0202499C = gUnknown_020249B4[0]->templates[bankIdentity]; - else if (gUnknown_020249B4[1]) - gUnknown_0202499C = gUnknown_020249B4[1]->templates[bankIdentity]; - else - gUnknown_0202499C = gUnknown_08329D98[bankIdentity]; - - gUnknown_0202499C.paletteTag = species; - if (bankIdentity == 0 || bankIdentity == 2) - gUnknown_0202499C.anims = gUnknown_082FF70C; - else if (species > 500) - gUnknown_0202499C.anims = gMonAnimationsSpriteAnimsPtrTable[species - 500]; - else - gUnknown_0202499C.anims = gMonAnimationsSpriteAnimsPtrTable[species]; -} - -void sub_806A12C(u16 trainerSpriteId, u8 bankIdentity) -{ - gUnknown_0202499C.paletteTag = trainerSpriteId; - if (bankIdentity == 0 || bankIdentity == 2) - { - gUnknown_0202499C = gUnknown_08329DF8[trainerSpriteId]; - gUnknown_0202499C.anims = gUnknown_08305D0C[trainerSpriteId]; - } - else - { - if (gMonSpritesGfxPtr != NULL) - gUnknown_0202499C = gMonSpritesGfxPtr->templates[bankIdentity]; - else - gUnknown_0202499C = gUnknown_08329D98[bankIdentity]; - gUnknown_0202499C.anims = gUnknown_0830536C[trainerSpriteId]; - } -} - -void sub_806A1C0(u16 arg0, u8 bankIdentity) -{ - if (gMonSpritesGfxPtr != NULL) - gUnknown_0202499C = gMonSpritesGfxPtr->templates[bankIdentity]; - else - gUnknown_0202499C = gUnknown_08329D98[bankIdentity]; - - gUnknown_0202499C.paletteTag = arg0; - gUnknown_0202499C.anims = gUnknown_0830536C[arg0]; -} - -void EncryptBoxMon(struct BoxPokemon *boxMon) -{ - u32 i; - for (i = 0; i < 12; i++) - { - boxMon->secure.raw[i] ^= boxMon->personality; - boxMon->secure.raw[i] ^= boxMon->otId; - } -} - -void DecryptBoxMon(struct BoxPokemon *boxMon) -{ - u32 i; - for (i = 0; i < 12; i++) - { - boxMon->secure.raw[i] ^= boxMon->otId; - boxMon->secure.raw[i] ^= boxMon->personality; - } -} - -#define SUBSTRUCT_CASE(n, v1, v2, v3, v4) \ -case n: \ - { \ - union PokemonSubstruct *substructs0 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs1 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs2 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs3 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs4 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs5 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs6 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs7 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs8 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs9 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs10 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs11 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs12 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs13 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs14 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs15 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs16 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs17 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs18 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs19 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs20 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs21 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs22 = boxMon->secure.substructs; \ - union PokemonSubstruct *substructs23 = boxMon->secure.substructs; \ - \ - switch (substructType) \ - { \ - case 0: \ - substruct = &substructs ## n [v1]; \ - break; \ - case 1: \ - substruct = &substructs ## n [v2]; \ - break; \ - case 2: \ - substruct = &substructs ## n [v3]; \ - break; \ - case 3: \ - substruct = &substructs ## n [v4]; \ - break; \ - } \ - break; \ - } \ - - -union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, u8 substructType) -{ - union PokemonSubstruct *substruct = NULL; - - switch (personality % 24) - { - SUBSTRUCT_CASE( 0,0,1,2,3) - SUBSTRUCT_CASE( 1,0,1,3,2) - SUBSTRUCT_CASE( 2,0,2,1,3) - SUBSTRUCT_CASE( 3,0,3,1,2) - SUBSTRUCT_CASE( 4,0,2,3,1) - SUBSTRUCT_CASE( 5,0,3,2,1) - SUBSTRUCT_CASE( 6,1,0,2,3) - SUBSTRUCT_CASE( 7,1,0,3,2) - SUBSTRUCT_CASE( 8,2,0,1,3) - SUBSTRUCT_CASE( 9,3,0,1,2) - SUBSTRUCT_CASE(10,2,0,3,1) - SUBSTRUCT_CASE(11,3,0,2,1) - SUBSTRUCT_CASE(12,1,2,0,3) - SUBSTRUCT_CASE(13,1,3,0,2) - SUBSTRUCT_CASE(14,2,1,0,3) - SUBSTRUCT_CASE(15,3,1,0,2) - SUBSTRUCT_CASE(16,2,3,0,1) - SUBSTRUCT_CASE(17,3,2,0,1) - SUBSTRUCT_CASE(18,1,2,3,0) - SUBSTRUCT_CASE(19,1,3,2,0) - SUBSTRUCT_CASE(20,2,1,3,0) - SUBSTRUCT_CASE(21,3,1,2,0) - SUBSTRUCT_CASE(22,2,3,1,0) - SUBSTRUCT_CASE(23,3,2,1,0) - } - - return substruct; -} - -extern u16 GetDeoxysStat(struct Pokemon *mon, s32 statId); - -u32 GetMonData(struct Pokemon *mon, s32 field, u8* data) -{ - u32 ret; - - switch (field) - { - case MON_DATA_STATUS: - ret = mon->status; - break; - case MON_DATA_LEVEL: - ret = mon->level; - break; - case MON_DATA_HP: - ret = mon->hp; - break; - case MON_DATA_MAX_HP: - ret = mon->maxHP; - break; - case MON_DATA_ATK: - ret = GetDeoxysStat(mon, STAT_ATK); - if (!ret) - ret = mon->attack; - break; - case MON_DATA_DEF: - ret = GetDeoxysStat(mon, STAT_DEF); - if (!ret) - ret = mon->defense; - break; - case MON_DATA_SPEED: - ret = GetDeoxysStat(mon, STAT_SPD); - if (!ret) - ret = mon->speed; - break; - case MON_DATA_SPATK: - ret = GetDeoxysStat(mon, STAT_SPATK); - if (!ret) - ret = mon->spAttack; - break; - case MON_DATA_SPDEF: - ret = GetDeoxysStat(mon, STAT_SPDEF); - if (!ret) - ret = mon->spDefense; - break; - case MON_DATA_ATK2: - ret = mon->attack; - break; - case MON_DATA_DEF2: - ret = mon->defense; - break; - case MON_DATA_SPEED2: - ret = mon->speed; - break; - case MON_DATA_SPATK2: - ret = mon->spAttack; - break; - case MON_DATA_SPDEF2: - ret = mon->spDefense; - break; - case MON_DATA_MAIL: - ret = mon->mail; - break; - default: - ret = GetBoxMonData(&mon->box, field, data); - break; - } - return ret; -} - -u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data) -{ - s32 i; - u32 retVal = 0; - struct PokemonSubstruct0 *substruct0 = NULL; - struct PokemonSubstruct1 *substruct1 = NULL; - struct PokemonSubstruct2 *substruct2 = NULL; - struct PokemonSubstruct3 *substruct3 = NULL; - - if (field > MON_DATA_10) - { - substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0); - substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1); - substruct2 = &(GetSubstruct(boxMon, boxMon->personality, 2)->type2); - substruct3 = &(GetSubstruct(boxMon, boxMon->personality, 3)->type3); - - DecryptBoxMon(boxMon); - - if (CalculateBoxMonChecksum(boxMon) != boxMon->checksum) - { - boxMon->isBadEgg = 1; - boxMon->isEgg = 1; - substruct3->isEgg = 1; - } - } - - switch (field) - { - case MON_DATA_PERSONALITY: - retVal = boxMon->personality; - break; - case MON_DATA_OT_ID: - retVal = boxMon->otId; - break; - case MON_DATA_NICKNAME: - { - if (boxMon->isBadEgg) - { - for (retVal = 0; - retVal < POKEMON_NAME_LENGTH && gText_BadEgg[retVal] != EOS; - data[retVal] = gText_BadEgg[retVal], retVal++) {} - - data[retVal] = EOS; - } - else if (boxMon->isEgg) - { - StringCopy(data, gText_EggNickname); - retVal = StringLength(data); - } - else if (boxMon->language == LANGUAGE_JAPANESE) - { - data[0] = EXT_CTRL_CODE_BEGIN; - data[1] = EXT_CTRL_CODE_JPN; - - for (retVal = 2, i = 0; - i < 5 && boxMon->nickname[i] != EOS; - data[retVal] = boxMon->nickname[i], retVal++, i++) {} - - data[retVal++] = EXT_CTRL_CODE_BEGIN; - data[retVal++] = EXT_CTRL_CODE_ENG; - data[retVal] = EOS; - } - else - { - for (retVal = 0; - retVal < POKEMON_NAME_LENGTH; - data[retVal] = boxMon->nickname[retVal], retVal++){} - - data[retVal] = EOS; - } - break; - } - case MON_DATA_LANGUAGE: - retVal = boxMon->language; - break; - case MON_DATA_SANITY_BIT1: - retVal = boxMon->isBadEgg; - break; - case MON_DATA_SANITY_BIT2: - retVal = boxMon->hasSpecies; - break; - case MON_DATA_SANITY_BIT3: - retVal = boxMon->isEgg; - break; - case MON_DATA_OT_NAME: - { - retVal = 0; - - while (retVal < OT_NAME_LENGTH) - { - data[retVal] = boxMon->otName[retVal]; - retVal++; - } - - data[retVal] = EOS; - break; - } - case MON_DATA_MARKINGS: - retVal = boxMon->markings; - break; - case MON_DATA_CHECKSUM: - retVal = boxMon->checksum; - break; - case MON_DATA_10: - retVal = boxMon->unknown; - break; - case MON_DATA_SPECIES: - retVal = boxMon->isBadEgg ? SPECIES_EGG : substruct0->species; - break; - case MON_DATA_HELD_ITEM: - retVal = substruct0->heldItem; - break; - case MON_DATA_EXP: - retVal = substruct0->experience; - break; - case MON_DATA_PP_BONUSES: - retVal = substruct0->ppBonuses; - break; - case MON_DATA_FRIENDSHIP: - retVal = substruct0->friendship; - break; - case MON_DATA_MOVE1: - case MON_DATA_MOVE2: - case MON_DATA_MOVE3: - case MON_DATA_MOVE4: - retVal = substruct1->moves[field - MON_DATA_MOVE1]; - break; - case MON_DATA_PP1: - case MON_DATA_PP2: - case MON_DATA_PP3: - case MON_DATA_PP4: - retVal = substruct1->pp[field - MON_DATA_PP1]; - break; - case MON_DATA_HP_EV: - retVal = substruct2->hpEV; - break; - case MON_DATA_ATK_EV: - retVal = substruct2->attackEV; - break; - case MON_DATA_DEF_EV: - retVal = substruct2->defenseEV; - break; - case MON_DATA_SPEED_EV: - retVal = substruct2->speedEV; - break; - case MON_DATA_SPATK_EV: - retVal = substruct2->spAttackEV; - break; - case MON_DATA_SPDEF_EV: - retVal = substruct2->spDefenseEV; - break; - case MON_DATA_COOL: - retVal = substruct2->cool; - break; - case MON_DATA_BEAUTY: - retVal = substruct2->beauty; - break; - case MON_DATA_CUTE: - retVal = substruct2->cute; - break; - case MON_DATA_SMART: - retVal = substruct2->smart; - break; - case MON_DATA_TOUGH: - retVal = substruct2->tough; - break; - case MON_DATA_SHEEN: - retVal = substruct2->sheen; - break; - case MON_DATA_POKERUS: - retVal = substruct3->pokerus; - break; - case MON_DATA_MET_LOCATION: - retVal = substruct3->metLocation; - break; - case MON_DATA_MET_LEVEL: - retVal = substruct3->metLevel; - break; - case MON_DATA_MET_GAME: - retVal = substruct3->metGame; - break; - case MON_DATA_POKEBALL: - retVal = substruct3->pokeball; - break; - case MON_DATA_OT_GENDER: - retVal = substruct3->otGender; - break; - case MON_DATA_HP_IV: - retVal = substruct3->hpIV; - break; - case MON_DATA_ATK_IV: - retVal = substruct3->attackIV; - break; - case MON_DATA_DEF_IV: - retVal = substruct3->defenseIV; - break; - case MON_DATA_SPEED_IV: - retVal = substruct3->speedIV; - break; - case MON_DATA_SPATK_IV: - retVal = substruct3->spAttackIV; - break; - case MON_DATA_SPDEF_IV: - retVal = substruct3->spDefenseIV; - break; - case MON_DATA_IS_EGG: - retVal = substruct3->isEgg; - break; - case MON_DATA_ALT_ABILITY: - retVal = substruct3->altAbility; - break; - case MON_DATA_COOL_RIBBON: - retVal = substruct3->coolRibbon; - break; - case MON_DATA_BEAUTY_RIBBON: - retVal = substruct3->beautyRibbon; - break; - case MON_DATA_CUTE_RIBBON: - retVal = substruct3->cuteRibbon; - break; - case MON_DATA_SMART_RIBBON: - retVal = substruct3->smartRibbon; - break; - case MON_DATA_TOUGH_RIBBON: - retVal = substruct3->toughRibbon; - break; - case MON_DATA_CHAMPION_RIBBON: - retVal = substruct3->championRibbon; - break; - case MON_DATA_WINNING_RIBBON: - retVal = substruct3->winningRibbon; - break; - case MON_DATA_VICTORY_RIBBON: - retVal = substruct3->victoryRibbon; - break; - case MON_DATA_ARTIST_RIBBON: - retVal = substruct3->artistRibbon; - break; - case MON_DATA_EFFORT_RIBBON: - retVal = substruct3->effortRibbon; - break; - case MON_DATA_GIFT_RIBBON_1: - retVal = substruct3->giftRibbon1; - break; - case MON_DATA_GIFT_RIBBON_2: - retVal = substruct3->giftRibbon2; - break; - case MON_DATA_GIFT_RIBBON_3: - retVal = substruct3->giftRibbon3; - break; - case MON_DATA_GIFT_RIBBON_4: - retVal = substruct3->giftRibbon4; - break; - case MON_DATA_GIFT_RIBBON_5: - retVal = substruct3->giftRibbon5; - break; - case MON_DATA_GIFT_RIBBON_6: - retVal = substruct3->giftRibbon6; - break; - case MON_DATA_GIFT_RIBBON_7: - retVal = substruct3->giftRibbon7; - break; - case MON_DATA_FATEFUL_ENCOUNTER: - retVal = substruct3->fatefulEncounter; - break; - case MON_DATA_OBEDIENCE: - retVal = substruct3->obedient; - break; - case MON_DATA_SPECIES2: - retVal = substruct0->species; - if (substruct0->species && (substruct3->isEgg || boxMon->isBadEgg)) - retVal = SPECIES_EGG; - break; - case MON_DATA_IVS: - retVal = substruct3->hpIV | (substruct3->attackIV << 5) | (substruct3->defenseIV << 10) | (substruct3->speedIV << 15) | (substruct3->spAttackIV << 20) | (substruct3->spDefenseIV << 25); - break; - case MON_DATA_KNOWN_MOVES: - if (substruct0->species && !substruct3->isEgg) - { - u16 *moves = (u16 *)data; - s32 i = 0; - - while (moves[i] != 355) - { - u16 move = moves[i]; - if (substruct1->moves[0] == move - || substruct1->moves[1] == move - || substruct1->moves[2] == move - || substruct1->moves[3] == move) - retVal |= gBitTable[i]; - i++; - } - } - break; - case MON_DATA_RIBBON_COUNT: - retVal = 0; - if (substruct0->species && !substruct3->isEgg) - { - retVal += substruct3->coolRibbon; - retVal += substruct3->beautyRibbon; - retVal += substruct3->cuteRibbon; - retVal += substruct3->smartRibbon; - retVal += substruct3->toughRibbon; - retVal += substruct3->championRibbon; - retVal += substruct3->winningRibbon; - retVal += substruct3->victoryRibbon; - retVal += substruct3->artistRibbon; - retVal += substruct3->effortRibbon; - retVal += substruct3->giftRibbon1; - retVal += substruct3->giftRibbon2; - retVal += substruct3->giftRibbon3; - retVal += substruct3->giftRibbon4; - retVal += substruct3->giftRibbon5; - retVal += substruct3->giftRibbon6; - retVal += substruct3->giftRibbon7; - } - break; - case MON_DATA_RIBBONS: - retVal = 0; - if (substruct0->species && !substruct3->isEgg) - { - retVal = substruct3->championRibbon - | (substruct3->coolRibbon << 1) - | (substruct3->beautyRibbon << 4) - | (substruct3->cuteRibbon << 7) - | (substruct3->smartRibbon << 10) - | (substruct3->toughRibbon << 13) - | (substruct3->winningRibbon << 16) - | (substruct3->victoryRibbon << 17) - | (substruct3->artistRibbon << 18) - | (substruct3->effortRibbon << 19) - | (substruct3->giftRibbon1 << 20) - | (substruct3->giftRibbon2 << 21) - | (substruct3->giftRibbon3 << 22) - | (substruct3->giftRibbon4 << 23) - | (substruct3->giftRibbon5 << 24) - | (substruct3->giftRibbon6 << 25) - | (substruct3->giftRibbon7 << 26); - } - break; - default: - break; - } - - if (field > MON_DATA_10) - EncryptBoxMon(boxMon); - - return retVal; -} - -#define SET8(lhs) (lhs) = *data -#define SET16(lhs) (lhs) = data[0] + (data[1] << 8) -#define SET32(lhs) (lhs) = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24) - -void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg) -{ - const u8* data = dataArg; - switch (field) - { - case MON_DATA_STATUS: - SET32(mon->status); - break; - case MON_DATA_LEVEL: - SET8(mon->level); - break; - case MON_DATA_HP: - SET16(mon->hp); - break; - case MON_DATA_MAX_HP: - SET16(mon->maxHP); - break; - case MON_DATA_ATK: - SET16(mon->attack); - break; - case MON_DATA_DEF: - SET16(mon->defense); - break; - case MON_DATA_SPEED: - SET16(mon->speed); - break; - case MON_DATA_SPATK: - SET16(mon->spAttack); - break; - case MON_DATA_SPDEF: - SET16(mon->spDefense); - break; - case MON_DATA_MAIL: - SET8(mon->mail); - break; - case MON_DATA_SPECIES2: - break; - default: - SetBoxMonData(&mon->box, field, data); - break; - } -} - -void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg) -{ - const u8* data = dataArg; - - struct PokemonSubstruct0 *substruct0 = NULL; - struct PokemonSubstruct1 *substruct1 = NULL; - struct PokemonSubstruct2 *substruct2 = NULL; - struct PokemonSubstruct3 *substruct3 = NULL; - - if (field > MON_DATA_10) - { - substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0); - substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1); - substruct2 = &(GetSubstruct(boxMon, boxMon->personality, 2)->type2); - substruct3 = &(GetSubstruct(boxMon, boxMon->personality, 3)->type3); - - DecryptBoxMon(boxMon); - - if (CalculateBoxMonChecksum(boxMon) != boxMon->checksum) - { - boxMon->isBadEgg = 1; - boxMon->isEgg = 1; - substruct3->isEgg = 1; - EncryptBoxMon(boxMon); - return; - } - } - - switch (field) - { - case MON_DATA_PERSONALITY: - SET32(boxMon->personality); - break; - case MON_DATA_OT_ID: - SET32(boxMon->otId); - break; - case MON_DATA_NICKNAME: - { - s32 i; - for (i = 0; i < POKEMON_NAME_LENGTH; i++) - boxMon->nickname[i] = data[i]; - break; - } - case MON_DATA_LANGUAGE: - SET8(boxMon->language); - break; - case MON_DATA_SANITY_BIT1: - SET8(boxMon->isBadEgg); - break; - case MON_DATA_SANITY_BIT2: - SET8(boxMon->hasSpecies); - break; - case MON_DATA_SANITY_BIT3: - SET8(boxMon->isEgg); - break; - case MON_DATA_OT_NAME: - { - s32 i; - for (i = 0; i < OT_NAME_LENGTH; i++) - boxMon->otName[i] = data[i]; - break; - } - case MON_DATA_MARKINGS: - SET8(boxMon->markings); - break; - case MON_DATA_CHECKSUM: - SET16(boxMon->checksum); - break; - case MON_DATA_10: - SET16(boxMon->unknown); - break; - case MON_DATA_SPECIES: - { - SET16(substruct0->species); - if (substruct0->species) - boxMon->hasSpecies = 1; - else - boxMon->hasSpecies = 0; - break; - } - case MON_DATA_HELD_ITEM: - SET16(substruct0->heldItem); - break; - case MON_DATA_EXP: - SET32(substruct0->experience); - break; - case MON_DATA_PP_BONUSES: - SET8(substruct0->ppBonuses); - break; - case MON_DATA_FRIENDSHIP: - SET8(substruct0->friendship); - break; - case MON_DATA_MOVE1: - case MON_DATA_MOVE2: - case MON_DATA_MOVE3: - case MON_DATA_MOVE4: - SET16(substruct1->moves[field - MON_DATA_MOVE1]); - break; - case MON_DATA_PP1: - case MON_DATA_PP2: - case MON_DATA_PP3: - case MON_DATA_PP4: - SET8(substruct1->pp[field - MON_DATA_PP1]); - break; - case MON_DATA_HP_EV: - SET8(substruct2->hpEV); - break; - case MON_DATA_ATK_EV: - SET8(substruct2->attackEV); - break; - case MON_DATA_DEF_EV: - SET8(substruct2->defenseEV); - break; - case MON_DATA_SPEED_EV: - SET8(substruct2->speedEV); - break; - case MON_DATA_SPATK_EV: - SET8(substruct2->spAttackEV); - break; - case MON_DATA_SPDEF_EV: - SET8(substruct2->spDefenseEV); - break; - case MON_DATA_COOL: - SET8(substruct2->cool); - break; - case MON_DATA_BEAUTY: - SET8(substruct2->beauty); - break; - case MON_DATA_CUTE: - SET8(substruct2->cute); - break; - case MON_DATA_SMART: - SET8(substruct2->smart); - break; - case MON_DATA_TOUGH: - SET8(substruct2->tough); - break; - case MON_DATA_SHEEN: - SET8(substruct2->sheen); - break; - case MON_DATA_POKERUS: - SET8(substruct3->pokerus); - break; - case MON_DATA_MET_LOCATION: - SET8(substruct3->metLocation); - break; - case MON_DATA_MET_LEVEL: - { - u8 metLevel = *data; - substruct3->metLevel = metLevel; - break; - } - case MON_DATA_MET_GAME: - SET8(substruct3->metGame); - break; - case MON_DATA_POKEBALL: - { - u8 pokeball = *data; - substruct3->pokeball = pokeball; - break; - } - case MON_DATA_OT_GENDER: - SET8(substruct3->otGender); - break; - case MON_DATA_HP_IV: - SET8(substruct3->hpIV); - break; - case MON_DATA_ATK_IV: - SET8(substruct3->attackIV); - break; - case MON_DATA_DEF_IV: - SET8(substruct3->defenseIV); - break; - case MON_DATA_SPEED_IV: - SET8(substruct3->speedIV); - break; - case MON_DATA_SPATK_IV: - SET8(substruct3->spAttackIV); - break; - case MON_DATA_SPDEF_IV: - SET8(substruct3->spDefenseIV); - break; - case MON_DATA_IS_EGG: - SET8(substruct3->isEgg); - if (substruct3->isEgg) - boxMon->isEgg = 1; - else - boxMon->isEgg = 0; - break; - case MON_DATA_ALT_ABILITY: - SET8(substruct3->altAbility); - break; - case MON_DATA_COOL_RIBBON: - SET8(substruct3->coolRibbon); - break; - case MON_DATA_BEAUTY_RIBBON: - SET8(substruct3->beautyRibbon); - break; - case MON_DATA_CUTE_RIBBON: - SET8(substruct3->cuteRibbon); - break; - case MON_DATA_SMART_RIBBON: - SET8(substruct3->smartRibbon); - break; - case MON_DATA_TOUGH_RIBBON: - SET8(substruct3->toughRibbon); - break; - case MON_DATA_CHAMPION_RIBBON: - SET8(substruct3->championRibbon); - break; - case MON_DATA_WINNING_RIBBON: - SET8(substruct3->winningRibbon); - break; - case MON_DATA_VICTORY_RIBBON: - SET8(substruct3->victoryRibbon); - break; - case MON_DATA_ARTIST_RIBBON: - SET8(substruct3->artistRibbon); - break; - case MON_DATA_EFFORT_RIBBON: - SET8(substruct3->effortRibbon); - break; - case MON_DATA_GIFT_RIBBON_1: - SET8(substruct3->giftRibbon1); - break; - case MON_DATA_GIFT_RIBBON_2: - SET8(substruct3->giftRibbon2); - break; - case MON_DATA_GIFT_RIBBON_3: - SET8(substruct3->giftRibbon3); - break; - case MON_DATA_GIFT_RIBBON_4: - SET8(substruct3->giftRibbon4); - break; - case MON_DATA_GIFT_RIBBON_5: - SET8(substruct3->giftRibbon5); - break; - case MON_DATA_GIFT_RIBBON_6: - SET8(substruct3->giftRibbon6); - break; - case MON_DATA_GIFT_RIBBON_7: - SET8(substruct3->giftRibbon7); - break; - case MON_DATA_FATEFUL_ENCOUNTER: - SET8(substruct3->fatefulEncounter); - break; - case MON_DATA_OBEDIENCE: - SET8(substruct3->obedient); - break; - case MON_DATA_IVS: - { - u32 ivs = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); - substruct3->hpIV = ivs & 0x1F; - substruct3->attackIV = (ivs >> 5) & 0x1F; - substruct3->defenseIV = (ivs >> 10) & 0x1F; - substruct3->speedIV = (ivs >> 15) & 0x1F; - substruct3->spAttackIV = (ivs >> 20) & 0x1F; - substruct3->spDefenseIV = (ivs >> 25) & 0x1F; - break; - } - default: - break; - } - - if (field > MON_DATA_10) - { - boxMon->checksum = CalculateBoxMonChecksum(boxMon); - EncryptBoxMon(boxMon); - } -} - -void CopyMon(void *dest, void *src, size_t size) -{ - memcpy(dest, src, size); -} - -u8 GiveMonToPlayer(struct Pokemon *mon) -{ - s32 i; - - SetMonData(mon, MON_DATA_OT_NAME, gSaveBlock2Ptr->playerName); - SetMonData(mon, MON_DATA_OT_GENDER, &gSaveBlock2Ptr->playerGender); - SetMonData(mon, MON_DATA_OT_ID, gSaveBlock2Ptr->playerTrainerId); - - i = 0; - - while (i < 6 && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL) != SPECIES_NONE) - i++; - - if (i >= 6) - return SendMonToPC(mon); - - CopyMon(&gPlayerParty[i], mon, sizeof(*mon)); - gPlayerPartyCount = i + 1; - return MON_GIVEN_TO_PARTY; -} - -extern u16 get_unknown_box_id(void); -extern u8 StorageGetCurrentBox(void); -extern void set_unknown_box_id(u8); -extern struct BoxPokemon* GetBoxedMonPtr(u8 boxNumber, u8 boxPosition); - -u8 SendMonToPC(struct Pokemon* mon) -{ - s32 boxNo, boxPos; - - set_unknown_box_id(VarGet(VAR_STORAGE_UNKNOWN)); - - boxNo = StorageGetCurrentBox(); - - do - { - for (boxPos = 0; boxPos < 30; boxPos++) - { - struct BoxPokemon* checkingMon = GetBoxedMonPtr(boxNo, boxPos); - if (GetBoxMonData(checkingMon, MON_DATA_SPECIES, NULL) == SPECIES_NONE) - { - MonRestorePP(mon); - CopyMon(checkingMon, &mon->box, sizeof(mon->box)); - gSpecialVar_MonBoxId = boxNo; - gSpecialVar_MonBoxPos = boxPos; - if (get_unknown_box_id() != boxNo) - FlagClear(FLAG_SYS_STORAGE_UNKNOWN_FLAG); - VarSet(VAR_STORAGE_UNKNOWN, boxNo); - return MON_GIVEN_TO_PC; - } - } - - boxNo++; - if (boxNo == 14) - boxNo = 0; - } while (boxNo != StorageGetCurrentBox()); - - return MON_CANT_GIVE; -} - -u8 CalculatePlayerPartyCount(void) -{ - gPlayerPartyCount = 0; - - while (gPlayerPartyCount < 6 - && GetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE) - { - gPlayerPartyCount++; - } - - return gPlayerPartyCount; -} - -u8 CalculateEnemyPartyCount(void) -{ - gEnemyPartyCount = 0; - - while (gEnemyPartyCount < 6 - && GetMonData(&gEnemyParty[gEnemyPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE) - { - gEnemyPartyCount++; - } - - return gEnemyPartyCount; -} - -u8 GetMonsStateToDoubles(void) -{ - s32 aliveCount = 0; - s32 i; - CalculatePlayerPartyCount(); - - if (gPlayerPartyCount == 1) - return gPlayerPartyCount; // PLAYER_HAS_ONE_MON - - for (i = 0; i < gPlayerPartyCount; i++) - { - if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_EGG - && GetMonData(&gPlayerParty[i], MON_DATA_HP, NULL) != 0 - && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_NONE) - aliveCount++; - } - - return (aliveCount > 1) ? PLAYER_HAS_TWO_USABLE_MONS : PLAYER_HAS_ONE_USABLE_MON; -} - -u8 GetMonsStateToDoubles_2(void) -{ - s32 aliveCount = 0; - s32 i; - - for (i = 0; i < PARTY_SIZE; i++) - { - u32 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL); - if (species != SPECIES_EGG && species != SPECIES_NONE - && GetMonData(&gPlayerParty[i], MON_DATA_HP, NULL) != 0) - aliveCount++; - } - - if (aliveCount == 1) - return PLAYER_HAS_ONE_MON; // may have more than one, but only one is alive - - return (aliveCount > 1) ? PLAYER_HAS_TWO_USABLE_MONS : PLAYER_HAS_ONE_USABLE_MON; -} - -u8 GetAbilityBySpecies(u16 species, bool8 altAbility) -{ - if (altAbility) - gLastUsedAbility = gBaseStats[species].ability2; - else - gLastUsedAbility = gBaseStats[species].ability1; - - return gLastUsedAbility; -} - -u8 GetMonAbility(struct Pokemon *mon) -{ - u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL); - u8 altAbility = GetMonData(mon, MON_DATA_ALT_ABILITY, NULL); - return GetAbilityBySpecies(species, altAbility); -} - -extern const struct BattleMove gBattleMoves[]; - -void CreateSecretBaseEnemyParty(struct SecretBaseRecord *secretBaseRecord) -{ - s32 i, j; - - ZeroEnemyPartyMons(); - *gBattleResources->secretBase = *secretBaseRecord; - - for (i = 0; i < PARTY_SIZE; i++) - { - if (gBattleResources->secretBase->party.species[i]) - { - CreateMon(&gEnemyParty[i], - gBattleResources->secretBase->party.species[i], - gBattleResources->secretBase->party.levels[i], - 15, - 1, - gBattleResources->secretBase->party.personality[i], - 2, - 0); - - SetMonData(&gEnemyParty[i], MON_DATA_HELD_ITEM, &gBattleResources->secretBase->party.heldItems[i]); - - for (j = 0; j < 6; j++) - SetMonData(&gEnemyParty[i], MON_DATA_HP_EV + j, &gBattleResources->secretBase->party.EVs[i]); - - for (j = 0; j < 4; j++) - { - SetMonData(&gEnemyParty[i], MON_DATA_MOVE1 + j, &gBattleResources->secretBase->party.moves[i * 4 + j]); - SetMonData(&gEnemyParty[i], MON_DATA_PP1 + j, &gBattleMoves[gBattleResources->secretBase->party.moves[i * 4 + j]].pp); - } - } - } -} - -extern const u8 gFacilityClassToPicIndex[]; -extern const u8 gFacilityClassToTrainerClass[]; -extern const u8 gSecretBaseTrainerClasses[][5]; - -u8 GetSecretBaseTrainerPicIndex(void) -{ - u8 trainerClass = gSecretBaseTrainerClasses[gBattleResources->secretBase->gender][gBattleResources->secretBase->trainerId[0] % 5]; - return gFacilityClassToPicIndex[trainerClass]; -} - -u8 GetSecretBaseTrainerNameIndex(void) -{ - u8 trainerClass = gSecretBaseTrainerClasses[gBattleResources->secretBase->gender][gBattleResources->secretBase->trainerId[0] % 5]; - return gFacilityClassToTrainerClass[trainerClass]; -} - -bool8 IsPlayerPartyAndPokemonStorageFull(void) -{ - s32 i; - - for (i = 0; i < 6; i++) - if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL) == SPECIES_NONE) - return FALSE; - - return IsPokemonStorageFull(); -} - -extern u32 GetBoxMonDataFromAnyBox(u8 boxNo, u8 boxPos, s32 field); - -bool8 IsPokemonStorageFull(void) -{ - s32 i, j; - - for (i = 0; i < 14; i++) - for (j = 0; j < 30; j++) - if (GetBoxMonDataFromAnyBox(i, j, MON_DATA_SPECIES) == SPECIES_NONE) - return FALSE; - - return TRUE; -} - -extern const u8 gSpeciesNames[][POKEMON_NAME_LENGTH + 1]; - -void GetSpeciesName(u8 *name, u16 species) -{ - s32 i; - - for (i = 0; i <= POKEMON_NAME_LENGTH; i++) - { - if (species > NUM_SPECIES) - name[i] = gSpeciesNames[0][i]; - else - name[i] = gSpeciesNames[species][i]; - - if (name[i] == EOS) - break; - } - - name[i] = EOS; -} - -extern const u8 gUnknown_08329D22[]; -extern const u8 gUnknown_08329D26[]; - -u8 CalculatePPWithBonus(u16 move, u8 ppBonuses, u8 moveIndex) -{ - u8 basePP = gBattleMoves[move].pp; - return basePP + ((basePP * 20 * ((gUnknown_08329D22[moveIndex] & ppBonuses) >> (2 * moveIndex))) / 100); -} - -void RemoveMonPPBonus(struct Pokemon *mon, u8 moveIndex) -{ - u8 ppBonuses = GetMonData(mon, MON_DATA_PP_BONUSES, NULL); - ppBonuses &= gUnknown_08329D26[moveIndex]; - SetMonData(mon, MON_DATA_PP_BONUSES, &ppBonuses); -} - -void RemoveBattleMonPPBonus(struct BattlePokemon *mon, u8 moveIndex) -{ - mon->ppBonuses &= gUnknown_08329D26[moveIndex]; -} - -void sub_803FA70(u8 bank); -void ClearTemporarySpeciesSpriteData(u8 bank, bool8); - -extern struct BattlePokemon gBattleMons[4]; - -void CopyPlayerPartyMonToBattleData(u8 bank, u8 partyIndex) -{ - u16* hpSwitchout; - s32 i; - u8 nickname[POKEMON_NAME_LENGTH * 2]; - - gBattleMons[bank].species = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES, NULL); - gBattleMons[bank].item = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HELD_ITEM, NULL); - - for (i = 0; i < 4; i++) - { - gBattleMons[bank].moves[i] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_MOVE1 + i, NULL); - gBattleMons[bank].pp[i] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_PP1 + i, NULL); - } - - gBattleMons[bank].ppBonuses = GetMonData(&gPlayerParty[partyIndex], MON_DATA_PP_BONUSES, NULL); - gBattleMons[bank].friendship = GetMonData(&gPlayerParty[partyIndex], MON_DATA_FRIENDSHIP, NULL); - gBattleMons[bank].experience = GetMonData(&gPlayerParty[partyIndex], MON_DATA_EXP, NULL); - gBattleMons[bank].hpIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HP_IV, NULL); - gBattleMons[bank].attackIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_ATK_IV, NULL); - gBattleMons[bank].defenseIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_DEF_IV, NULL); - gBattleMons[bank].speedIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPEED_IV, NULL); - gBattleMons[bank].spAttackIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPATK_IV, NULL); - gBattleMons[bank].spDefenseIV = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPDEF_IV, NULL); - gBattleMons[bank].personality = GetMonData(&gPlayerParty[partyIndex], MON_DATA_PERSONALITY, NULL); - gBattleMons[bank].status1 = GetMonData(&gPlayerParty[partyIndex], MON_DATA_STATUS, NULL); - gBattleMons[bank].level = GetMonData(&gPlayerParty[partyIndex], MON_DATA_LEVEL, NULL); - gBattleMons[bank].hp = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HP, NULL); - gBattleMons[bank].maxHP = GetMonData(&gPlayerParty[partyIndex], MON_DATA_MAX_HP, NULL); - gBattleMons[bank].attack = GetMonData(&gPlayerParty[partyIndex], MON_DATA_ATK, NULL); - gBattleMons[bank].defense = GetMonData(&gPlayerParty[partyIndex], MON_DATA_DEF, NULL); - gBattleMons[bank].speed = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPEED, NULL); - gBattleMons[bank].spAttack = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPATK, NULL); - gBattleMons[bank].spDefense = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPDEF, NULL); - gBattleMons[bank].isEgg = GetMonData(&gPlayerParty[partyIndex], MON_DATA_IS_EGG, NULL); - gBattleMons[bank].altAbility = GetMonData(&gPlayerParty[partyIndex], MON_DATA_ALT_ABILITY, NULL); - gBattleMons[bank].otId = GetMonData(&gPlayerParty[partyIndex], MON_DATA_OT_ID, NULL); - gBattleMons[bank].type1 = gBaseStats[gBattleMons[bank].species].type1; - gBattleMons[bank].type2 = gBaseStats[gBattleMons[bank].species].type2; - gBattleMons[bank].ability = GetAbilityBySpecies(gBattleMons[bank].species, gBattleMons[bank].altAbility); - GetMonData(&gPlayerParty[partyIndex], MON_DATA_NICKNAME, nickname); - StringCopy10(gBattleMons[bank].nickname, nickname); - GetMonData(&gPlayerParty[partyIndex], MON_DATA_OT_NAME, gBattleMons[bank].otName); - - hpSwitchout = &gBattleStruct->hpOnSwitchout[GetBattlerSide(bank)]; - *hpSwitchout = gBattleMons[bank].hp; - - for (i = 0; i < 8; i++) - gBattleMons[bank].statStages[i] = 6; - - gBattleMons[bank].status2 = 0; - sub_803FA70(bank); - ClearTemporarySpeciesSpriteData(bank, FALSE); -} diff --git a/src/pokemon_3.c b/src/pokemon_3.c index 790de0368..95d08d0c5 100644 --- a/src/pokemon_3.c +++ b/src/pokemon_3.c @@ -61,7 +61,18 @@ extern const struct CompressedSpritePalette gMonShinyPaletteTable[]; extern const u16 gHMMoves[]; extern const u8 gMonAnimationDelayTable[]; extern const u8 gMonFrontAnimIdsTable[]; +extern const u8 gFacilityClassToPicIndex[]; +extern const u8 gTrainerClassNames[][13]; +struct PokeItem +{ + u16 species; + u16 item; +}; + +extern const struct PokeItem gAlteringCaveWildMonHeldItems[9]; + +extern void SpriteCallbackDummy_2(struct Sprite*); extern bool8 InBattlePyramid(void); extern bool8 InBattlePike(void); extern bool8 sub_81D5C18(void); @@ -84,7 +95,7 @@ bool8 HealStatusConditions(struct Pokemon *mon, u32 battlePartyId, u32 healMask, if (status & healMask) { status &= ~healMask; - SetMonData(mon, MON_DATA_STATUS, (u8 *)&status); + SetMonData(mon, MON_DATA_STATUS, &status); if (gMain.inBattle && battleBank != 4) gBattleMons[battleBank].status1 &= ~healMask; return FALSE; @@ -1376,14 +1387,6 @@ void sub_806E994(void) BattleStringExpandPlaceholders(gText_PkmnsXPreventsSwitching, gStringVar4); } -struct PokeItem -{ - u16 species; - u16 item; -}; - -extern const struct PokeItem gAlteringCaveWildMonHeldItems[9]; - static s32 GetWildMonTableIdInAlteringCave(u16 species) { s32 i; @@ -1520,8 +1523,6 @@ void BattleAnimateFrontSprite(struct Sprite* sprite, u16 species, bool8 noCry, u DoMonFrontSpriteAnimation(sprite, species, noCry, arg3); } -extern void SpriteCallbackDummy_2(struct Sprite*); - void DoMonFrontSpriteAnimation(struct Sprite* sprite, u16 species, bool8 noCry, u8 arg3) { s8 pan; @@ -1652,8 +1653,6 @@ u8 sub_806EF84(u8 arg0, u8 arg1) return i; } -extern const u8 gFacilityClassToPicIndex[]; - u16 sub_806EFF0(u16 arg0) { return gFacilityClassToPicIndex[arg0]; @@ -1667,8 +1666,6 @@ u16 PlayerGenderToFrontTrainerPicId(u8 playerGender) return sub_806EFF0(0x3C); } -extern const u8 gTrainerClassNames[][13]; - void HandleSetPokedexFlag(u16 nationalNum, u8 caseId, u32 personality) { u8 getFlagCaseId = (caseId == FLAG_SET_SEEN) ? FLAG_GET_SEEN : FLAG_GET_CAUGHT;