mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-11-16 11:37:40 +01:00
battle5 decompiled and renamed
This commit is contained in:
parent
558bf2f7d0
commit
47a8c6c432
582
asm/battle_5.s
582
asm/battle_5.s
@ -1,582 +0,0 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "constants/constants.inc"
|
||||
|
||||
.syntax unified
|
||||
|
||||
.text
|
||||
|
||||
|
||||
thumb_func_start AllocateBattleResrouces
|
||||
AllocateBattleResrouces: @ 8056F28
|
||||
push {r4-r6,lr}
|
||||
ldr r5, =gBattleResources
|
||||
ldr r6, =gBattleTypeFlags
|
||||
ldr r0, [r6]
|
||||
movs r1, 0x80
|
||||
lsls r1, 19
|
||||
ands r0, r1
|
||||
cmp r0, 0
|
||||
beq _08056F3E
|
||||
bl sub_81D55D0
|
||||
_08056F3E:
|
||||
ldr r4, =gBattleStruct
|
||||
movs r0, 0xA9
|
||||
lsls r0, 2
|
||||
bl AllocZeroed
|
||||
str r0, [r4]
|
||||
movs r0, 0x20
|
||||
bl AllocZeroed
|
||||
str r0, [r5]
|
||||
movs r0, 0xA0
|
||||
bl AllocZeroed
|
||||
ldr r1, [r5]
|
||||
str r0, [r1]
|
||||
movs r0, 0x10
|
||||
bl AllocZeroed
|
||||
ldr r1, [r5]
|
||||
str r0, [r1, 0x4]
|
||||
movs r0, 0x24
|
||||
bl AllocZeroed
|
||||
ldr r1, [r5]
|
||||
str r0, [r1, 0x8]
|
||||
movs r0, 0x24
|
||||
bl AllocZeroed
|
||||
ldr r1, [r5]
|
||||
str r0, [r1, 0xC]
|
||||
movs r0, 0xC
|
||||
bl AllocZeroed
|
||||
ldr r1, [r5]
|
||||
str r0, [r1, 0x10]
|
||||
movs r0, 0x1C
|
||||
bl AllocZeroed
|
||||
ldr r1, [r5]
|
||||
str r0, [r1, 0x14]
|
||||
movs r0, 0x54
|
||||
bl AllocZeroed
|
||||
ldr r1, [r5]
|
||||
str r0, [r1, 0x18]
|
||||
movs r0, 0x24
|
||||
bl AllocZeroed
|
||||
ldr r1, [r5]
|
||||
str r0, [r1, 0x1C]
|
||||
ldr r4, =gLinkBattleSendBuffer
|
||||
movs r5, 0x80
|
||||
lsls r5, 5
|
||||
adds r0, r5, 0
|
||||
bl AllocZeroed
|
||||
str r0, [r4]
|
||||
ldr r4, =gLinkBattleRecvBuffer
|
||||
adds r0, r5, 0
|
||||
bl AllocZeroed
|
||||
str r0, [r4]
|
||||
ldr r4, =gUnknown_0202305C
|
||||
movs r0, 0x80
|
||||
lsls r0, 6
|
||||
bl AllocZeroed
|
||||
str r0, [r4]
|
||||
ldr r4, =gUnknown_02023060
|
||||
adds r0, r5, 0
|
||||
bl AllocZeroed
|
||||
str r0, [r4]
|
||||
ldr r0, [r6]
|
||||
movs r1, 0x80
|
||||
lsls r1, 20
|
||||
ands r0, r1
|
||||
cmp r0, 0
|
||||
beq _08056FFA
|
||||
ldr r0, =0x00004054
|
||||
bl VarGet
|
||||
lsls r0, 16
|
||||
lsrs r0, 16
|
||||
ldr r2, =gSaveBlock1Ptr
|
||||
lsls r1, r0, 2
|
||||
adds r1, r0
|
||||
lsls r1, 5
|
||||
ldr r0, =0x00001a9c
|
||||
adds r1, r0
|
||||
ldr r0, [r2]
|
||||
adds r0, r1
|
||||
bl CreateSecretBaseEnemyParty
|
||||
_08056FFA:
|
||||
pop {r4-r6}
|
||||
pop {r0}
|
||||
bx r0
|
||||
.pool
|
||||
thumb_func_end AllocateBattleResrouces
|
||||
|
||||
thumb_func_start FreeBattleResources
|
||||
FreeBattleResources: @ 8057028
|
||||
push {r4-r6,lr}
|
||||
ldr r0, =gBattleTypeFlags
|
||||
ldr r0, [r0]
|
||||
movs r1, 0x80
|
||||
lsls r1, 19
|
||||
ands r0, r1
|
||||
cmp r0, 0
|
||||
beq _0805703C
|
||||
bl sub_81D5694
|
||||
_0805703C:
|
||||
ldr r6, =gBattleResources
|
||||
ldr r0, [r6]
|
||||
cmp r0, 0
|
||||
beq _080570D0
|
||||
ldr r4, =gBattleStruct
|
||||
ldr r0, [r4]
|
||||
bl Free
|
||||
movs r5, 0
|
||||
str r5, [r4]
|
||||
ldr r0, [r6]
|
||||
ldr r0, [r0]
|
||||
bl Free
|
||||
ldr r0, [r6]
|
||||
str r5, [r0]
|
||||
ldr r0, [r0, 0x4]
|
||||
bl Free
|
||||
ldr r0, [r6]
|
||||
str r5, [r0, 0x4]
|
||||
ldr r0, [r0, 0x8]
|
||||
bl Free
|
||||
ldr r0, [r6]
|
||||
str r5, [r0, 0x8]
|
||||
ldr r0, [r0, 0xC]
|
||||
bl Free
|
||||
ldr r0, [r6]
|
||||
str r5, [r0, 0xC]
|
||||
ldr r0, [r0, 0x10]
|
||||
bl Free
|
||||
ldr r0, [r6]
|
||||
str r5, [r0, 0x10]
|
||||
ldr r0, [r0, 0x14]
|
||||
bl Free
|
||||
ldr r0, [r6]
|
||||
str r5, [r0, 0x14]
|
||||
ldr r0, [r0, 0x18]
|
||||
bl Free
|
||||
ldr r0, [r6]
|
||||
str r5, [r0, 0x18]
|
||||
ldr r0, [r0, 0x1C]
|
||||
bl Free
|
||||
ldr r0, [r6]
|
||||
str r5, [r0, 0x1C]
|
||||
bl Free
|
||||
str r5, [r6]
|
||||
ldr r4, =gLinkBattleSendBuffer
|
||||
ldr r0, [r4]
|
||||
bl Free
|
||||
str r5, [r4]
|
||||
ldr r4, =gLinkBattleRecvBuffer
|
||||
ldr r0, [r4]
|
||||
bl Free
|
||||
str r5, [r4]
|
||||
ldr r4, =gUnknown_0202305C
|
||||
ldr r0, [r4]
|
||||
bl Free
|
||||
str r5, [r4]
|
||||
ldr r4, =gUnknown_02023060
|
||||
ldr r0, [r4]
|
||||
bl Free
|
||||
str r5, [r4]
|
||||
_080570D0:
|
||||
pop {r4-r6}
|
||||
pop {r0}
|
||||
bx r0
|
||||
.pool
|
||||
thumb_func_end FreeBattleResources
|
||||
|
||||
thumb_func_start AdjustFriendshipOnBattleFaint
|
||||
AdjustFriendshipOnBattleFaint: @ 80570F4
|
||||
push {r4,r5,lr}
|
||||
lsls r0, 24
|
||||
lsrs r5, r0, 24
|
||||
ldr r0, =gBattleTypeFlags
|
||||
ldr r0, [r0]
|
||||
movs r1, 0x1
|
||||
ands r0, r1
|
||||
cmp r0, 0
|
||||
beq _08057140
|
||||
movs r0, 0x1
|
||||
bl GetBankByIdentity
|
||||
lsls r0, 24
|
||||
lsrs r4, r0, 24
|
||||
movs r0, 0x3
|
||||
bl GetBankByIdentity
|
||||
lsls r0, 24
|
||||
lsrs r3, r0, 24
|
||||
ldr r2, =gBattleMons
|
||||
movs r0, 0x58
|
||||
adds r1, r3, 0
|
||||
muls r1, r0
|
||||
adds r1, r2
|
||||
adds r1, 0x2A
|
||||
muls r0, r4
|
||||
adds r0, r2
|
||||
adds r0, 0x2A
|
||||
ldrb r1, [r1]
|
||||
ldrb r0, [r0]
|
||||
cmp r1, r0
|
||||
bls _0805714A
|
||||
adds r4, r3, 0
|
||||
b _0805714A
|
||||
.pool
|
||||
_08057140:
|
||||
movs r0, 0x1
|
||||
bl GetBankByIdentity
|
||||
lsls r0, 24
|
||||
lsrs r4, r0, 24
|
||||
_0805714A:
|
||||
ldr r2, =gBattleMons
|
||||
movs r1, 0x58
|
||||
adds r0, r4, 0
|
||||
muls r0, r1
|
||||
adds r0, r2
|
||||
adds r3, r0, 0
|
||||
adds r3, 0x2A
|
||||
adds r0, r5, 0
|
||||
muls r0, r1
|
||||
adds r0, r2
|
||||
adds r1, r0, 0
|
||||
adds r1, 0x2A
|
||||
ldrb r0, [r3]
|
||||
ldrb r2, [r1]
|
||||
cmp r0, r2
|
||||
bls _080571B8
|
||||
ldrb r1, [r1]
|
||||
subs r0, r1
|
||||
cmp r0, 0x1D
|
||||
ble _08057198
|
||||
ldr r1, =gBattlePartyID
|
||||
lsls r0, r5, 1
|
||||
adds r0, r1
|
||||
ldrh r1, [r0]
|
||||
movs r0, 0x64
|
||||
muls r0, r1
|
||||
ldr r1, =gPlayerParty
|
||||
adds r0, r1
|
||||
movs r1, 0x8
|
||||
bl AdjustFriendship
|
||||
b _080571CE
|
||||
.pool
|
||||
_08057198:
|
||||
ldr r1, =gBattlePartyID
|
||||
lsls r0, r5, 1
|
||||
adds r0, r1
|
||||
ldrh r1, [r0]
|
||||
movs r0, 0x64
|
||||
muls r0, r1
|
||||
ldr r1, =gPlayerParty
|
||||
adds r0, r1
|
||||
movs r1, 0x6
|
||||
bl AdjustFriendship
|
||||
b _080571CE
|
||||
.pool
|
||||
_080571B8:
|
||||
ldr r1, =gBattlePartyID
|
||||
lsls r0, r5, 1
|
||||
adds r0, r1
|
||||
ldrh r1, [r0]
|
||||
movs r0, 0x64
|
||||
muls r0, r1
|
||||
ldr r1, =gPlayerParty
|
||||
adds r0, r1
|
||||
movs r1, 0x6
|
||||
bl AdjustFriendship
|
||||
_080571CE:
|
||||
pop {r4,r5}
|
||||
pop {r0}
|
||||
bx r0
|
||||
.pool
|
||||
thumb_func_end AdjustFriendshipOnBattleFaint
|
||||
|
||||
thumb_func_start sub_80571DC
|
||||
sub_80571DC: @ 80571DC
|
||||
push {r4-r7,lr}
|
||||
lsls r0, 24
|
||||
lsrs r4, r0, 24
|
||||
lsls r1, 24
|
||||
lsrs r7, r1, 24
|
||||
adds r0, r4, 0
|
||||
bl GetBankSide
|
||||
lsls r0, 24
|
||||
lsrs r0, 24
|
||||
cmp r0, 0x1
|
||||
beq _08057248
|
||||
movs r2, 0
|
||||
ldr r6, =gBattlePartyID
|
||||
lsls r3, r4, 1
|
||||
ldr r5, =gUnknown_0203CF00
|
||||
ldr r4, =gBattleStruct
|
||||
_080571FE:
|
||||
adds r0, r2, r5
|
||||
ldr r1, [r4]
|
||||
adds r1, r2, r1
|
||||
adds r1, 0x60
|
||||
ldrb r1, [r1]
|
||||
strb r1, [r0]
|
||||
adds r2, 0x1
|
||||
cmp r2, 0x2
|
||||
ble _080571FE
|
||||
adds r0, r3, r6
|
||||
ldrb r0, [r0]
|
||||
bl pokemon_order_func
|
||||
adds r4, r0, 0
|
||||
lsls r4, 24
|
||||
lsrs r4, 24
|
||||
adds r0, r7, 0
|
||||
bl pokemon_order_func
|
||||
adds r1, r0, 0
|
||||
lsls r1, 24
|
||||
lsrs r1, 24
|
||||
adds r0, r4, 0
|
||||
bl sub_81B8FB0
|
||||
movs r2, 0
|
||||
ldr r4, =gBattleStruct
|
||||
ldr r3, =gUnknown_0203CF00
|
||||
_08057236:
|
||||
ldr r0, [r4]
|
||||
adds r0, r2, r0
|
||||
adds r0, 0x60
|
||||
adds r1, r2, r3
|
||||
ldrb r1, [r1]
|
||||
strb r1, [r0]
|
||||
adds r2, 0x1
|
||||
cmp r2, 0x2
|
||||
ble _08057236
|
||||
_08057248:
|
||||
pop {r4-r7}
|
||||
pop {r0}
|
||||
bx r0
|
||||
.pool
|
||||
thumb_func_end sub_80571DC
|
||||
|
||||
thumb_func_start sub_805725C
|
||||
sub_805725C: @ 805725C
|
||||
push {r4-r7,lr}
|
||||
mov r7, r10
|
||||
mov r6, r9
|
||||
mov r5, r8
|
||||
push {r5-r7}
|
||||
sub sp, 0x4
|
||||
lsls r0, 24
|
||||
lsrs r0, 24
|
||||
mov r9, r0
|
||||
movs r0, 0
|
||||
mov r8, r0
|
||||
ldr r1, =gBattleCommunication
|
||||
mov r10, r1
|
||||
b _08057284
|
||||
.pool
|
||||
_0805727C:
|
||||
mov r2, r8
|
||||
cmp r2, 0
|
||||
beq _08057284
|
||||
b _08057406
|
||||
_08057284:
|
||||
mov r1, r10
|
||||
ldrb r0, [r1]
|
||||
cmp r0, 0x1
|
||||
bne _0805728E
|
||||
b _08057390
|
||||
_0805728E:
|
||||
cmp r0, 0x1
|
||||
ble _08057294
|
||||
b _080573FC
|
||||
_08057294:
|
||||
cmp r0, 0
|
||||
beq _0805729A
|
||||
b _080573FC
|
||||
_0805729A:
|
||||
ldr r6, =gBattleMons
|
||||
movs r0, 0x58
|
||||
mov r5, r9
|
||||
muls r5, r0
|
||||
adds r0, r6, 0
|
||||
adds r0, 0x4C
|
||||
adds r4, r5, r0
|
||||
ldr r0, [r4]
|
||||
movs r7, 0x7
|
||||
ands r0, r7
|
||||
cmp r0, 0
|
||||
beq _08057372
|
||||
mov r0, r9
|
||||
bl UproarWakeUpCheck
|
||||
lsls r0, 24
|
||||
cmp r0, 0
|
||||
beq _080572FC
|
||||
ldr r0, [r4]
|
||||
movs r1, 0x8
|
||||
negs r1, r1
|
||||
ands r0, r1
|
||||
str r0, [r4]
|
||||
adds r2, r6, 0
|
||||
adds r2, 0x50
|
||||
adds r2, r5, r2
|
||||
ldr r0, [r2]
|
||||
ldr r1, =0xf7ffffff
|
||||
ands r0, r1
|
||||
str r0, [r2]
|
||||
bl BattleScriptPushCursor
|
||||
movs r0, 0x1
|
||||
mov r2, r10
|
||||
strb r0, [r2, 0x5]
|
||||
ldr r1, =gBattlescriptCurrInstr
|
||||
ldr r0, =BattleScript_MoveUsedWokeUp
|
||||
str r0, [r1]
|
||||
movs r0, 0x2
|
||||
mov r8, r0
|
||||
b _08057372
|
||||
.pool
|
||||
_080572FC:
|
||||
adds r0, r5, r6
|
||||
adds r0, 0x20
|
||||
ldrb r0, [r0]
|
||||
movs r2, 0x1
|
||||
cmp r0, 0x30
|
||||
bne _0805730A
|
||||
movs r2, 0x2
|
||||
_0805730A:
|
||||
ldr r1, [r4]
|
||||
adds r0, r1, 0
|
||||
ands r0, r7
|
||||
cmp r0, r2
|
||||
bcs _0805731E
|
||||
movs r0, 0x8
|
||||
negs r0, r0
|
||||
ands r1, r0
|
||||
str r1, [r4]
|
||||
b _08057322
|
||||
_0805731E:
|
||||
subs r0, r1, r2
|
||||
str r0, [r4]
|
||||
_08057322:
|
||||
ldr r2, =gBattleMons
|
||||
movs r0, 0x58
|
||||
mov r1, r9
|
||||
muls r1, r0
|
||||
adds r0, r2, 0
|
||||
adds r0, 0x4C
|
||||
adds r0, r1, r0
|
||||
ldr r4, [r0]
|
||||
movs r0, 0x7
|
||||
ands r4, r0
|
||||
cmp r4, 0
|
||||
beq _08057354
|
||||
ldr r1, =gBattlescriptCurrInstr
|
||||
ldr r0, =BattleScript_MoveUsedIsAsleep
|
||||
str r0, [r1]
|
||||
movs r1, 0x2
|
||||
mov r8, r1
|
||||
b _08057372
|
||||
.pool
|
||||
_08057354:
|
||||
adds r2, 0x50
|
||||
adds r2, r1, r2
|
||||
ldr r0, [r2]
|
||||
ldr r1, =0xf7ffffff
|
||||
ands r0, r1
|
||||
str r0, [r2]
|
||||
bl BattleScriptPushCursor
|
||||
ldr r0, =gBattleCommunication
|
||||
strb r4, [r0, 0x5]
|
||||
ldr r1, =gBattlescriptCurrInstr
|
||||
ldr r0, =BattleScript_MoveUsedWokeUp
|
||||
str r0, [r1]
|
||||
movs r2, 0x2
|
||||
mov r8, r2
|
||||
_08057372:
|
||||
ldr r1, =gBattleCommunication
|
||||
ldrb r0, [r1]
|
||||
adds r0, 0x1
|
||||
strb r0, [r1]
|
||||
mov r10, r1
|
||||
b _080573FC
|
||||
.pool
|
||||
_08057390:
|
||||
ldr r1, =gBattleMons
|
||||
movs r0, 0x58
|
||||
mov r2, r9
|
||||
muls r2, r0
|
||||
adds r0, r2, 0
|
||||
adds r1, 0x4C
|
||||
adds r4, r0, r1
|
||||
ldr r0, [r4]
|
||||
movs r1, 0x20
|
||||
ands r0, r1
|
||||
cmp r0, 0
|
||||
beq _080573F4
|
||||
bl Random
|
||||
lsls r0, 16
|
||||
lsrs r0, 16
|
||||
movs r1, 0x5
|
||||
bl __umodsi3
|
||||
lsls r0, 16
|
||||
lsrs r5, r0, 16
|
||||
cmp r5, 0
|
||||
beq _080573D4
|
||||
ldr r1, =gBattlescriptCurrInstr
|
||||
ldr r0, =BattleScript_MoveUsedIsFrozen
|
||||
str r0, [r1]
|
||||
b _080573EC
|
||||
.pool
|
||||
_080573D4:
|
||||
ldr r0, [r4]
|
||||
movs r1, 0x21
|
||||
negs r1, r1
|
||||
ands r0, r1
|
||||
str r0, [r4]
|
||||
bl BattleScriptPushCursor
|
||||
ldr r1, =gBattlescriptCurrInstr
|
||||
ldr r0, =BattleScript_MoveUsedUnfroze
|
||||
str r0, [r1]
|
||||
mov r0, r10
|
||||
strb r5, [r0, 0x5]
|
||||
_080573EC:
|
||||
movs r1, 0x2
|
||||
mov r8, r1
|
||||
ldr r2, =gBattleCommunication
|
||||
mov r10, r2
|
||||
_080573F4:
|
||||
mov r1, r10
|
||||
ldrb r0, [r1]
|
||||
adds r0, 0x1
|
||||
strb r0, [r1]
|
||||
_080573FC:
|
||||
mov r2, r10
|
||||
ldrb r0, [r2]
|
||||
cmp r0, 0x2
|
||||
beq _08057406
|
||||
b _0805727C
|
||||
_08057406:
|
||||
mov r0, r8
|
||||
cmp r0, 0x2
|
||||
bne _08057430
|
||||
ldr r4, =gActiveBank
|
||||
mov r1, r9
|
||||
strb r1, [r4]
|
||||
ldrb r1, [r4]
|
||||
movs r0, 0x58
|
||||
muls r0, r1
|
||||
ldr r1, =gBattleMons + 0x4C
|
||||
adds r0, r1
|
||||
str r0, [sp]
|
||||
movs r0, 0
|
||||
movs r1, 0x28
|
||||
movs r2, 0
|
||||
movs r3, 0x4
|
||||
bl EmitSetMonData
|
||||
ldrb r0, [r4]
|
||||
bl MarkBufferBankForExecution
|
||||
_08057430:
|
||||
mov r0, r8
|
||||
add sp, 0x4
|
||||
pop {r3-r5}
|
||||
mov r8, r3
|
||||
mov r9, r4
|
||||
mov r10, r5
|
||||
pop {r4-r7}
|
||||
pop {r1}
|
||||
bx r1
|
||||
.pool
|
||||
thumb_func_end sub_805725C
|
||||
|
||||
|
||||
.align 2, 0 @ Don't pad with nop.
|
@ -7,6 +7,7 @@
|
||||
#include "battle_2.h"
|
||||
#include "battle_ai_switch_items.h"
|
||||
#include "battle_gfx_sfx_util.h"
|
||||
#include "battle_util2.h"
|
||||
|
||||
/*
|
||||
Banks are a name given to what could be called a 'battlerId' or 'monControllerId'.
|
||||
@ -870,13 +871,6 @@ bool8 LoadChosenBattleElement(u8 caseId);
|
||||
void DrawMainBattleBackground(void);
|
||||
void task00_0800F6FC(u8 taskId);
|
||||
|
||||
// battle_5
|
||||
void AllocateBattleResrouces(void);
|
||||
void FreeBattleResources(void);
|
||||
void AdjustFriendshipOnBattleFaint(u8 bank);
|
||||
void sub_80571DC(u8 bank, u8 arg1);
|
||||
u32 sub_805725C(u8 bank);
|
||||
|
||||
enum
|
||||
{
|
||||
BACK_PIC_BRENDAN,
|
||||
@ -979,6 +973,9 @@ extern struct BattleSpriteData *gBattleSpritesDataPtr;
|
||||
extern u8 *gLinkBattleSendBuffer;
|
||||
extern u8 *gLinkBattleRecvBuffer;
|
||||
|
||||
extern u8 *gUnknown_0202305C;
|
||||
extern u8 *gUnknown_02023060;
|
||||
|
||||
// Move this somewhere else
|
||||
|
||||
#include "sprite.h"
|
||||
|
10
include/battle_util2.h
Normal file
10
include/battle_util2.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef GUARD_BATTLE_UTIL2_H
|
||||
#define GUARD_BATTLE_UTIL2_H
|
||||
|
||||
void AllocateBattleResources(void);
|
||||
void FreeBattleResources(void);
|
||||
void AdjustFriendshipOnBattleFaint(u8 bank);
|
||||
void sub_80571DC(u8 bank, u8 arg1);
|
||||
u32 sub_805725C(u8 bank);
|
||||
|
||||
#endif // GUARD_BATTLE_UTIL_H
|
@ -60,7 +60,7 @@ SECTIONS {
|
||||
src/battle_2.o(.text);
|
||||
src/battle_util.o(.text);
|
||||
src/battle_script_commands.o(.text);
|
||||
asm/battle_5.o(.text);
|
||||
src/battle_util2.o(.text);
|
||||
src/battle_controller_player.o(.text);
|
||||
src/battle_gfx_sfx_util.o(.text);
|
||||
src/battle_controller_opponent.o(.text);
|
||||
|
@ -353,7 +353,7 @@ static const u8 sUnknown_0831BCF3[] = {4, 4, 4, 4};
|
||||
void CB2_InitBattle(void)
|
||||
{
|
||||
MoveSaveBlocks_ResetHeap();
|
||||
AllocateBattleResrouces();
|
||||
AllocateBattleResources();
|
||||
AllocateBattleSpritesData();
|
||||
AllocateMonSpritesGfx();
|
||||
sub_8185F84();
|
||||
|
219
src/battle_util2.c
Normal file
219
src/battle_util2.c
Normal file
@ -0,0 +1,219 @@
|
||||
#include "global.h"
|
||||
#include "battle.h"
|
||||
#include "battle_controllers.h"
|
||||
#include "malloc.h"
|
||||
#include "pokemon.h"
|
||||
#include "event_data.h"
|
||||
#include "abilities.h"
|
||||
#include "rng.h"
|
||||
|
||||
extern struct BattlePokemon gBattleMons[BATTLE_BANKS_COUNT];
|
||||
extern u16 gBattlePartyID[BATTLE_BANKS_COUNT];
|
||||
extern u8 gUnknown_0203CF00[];
|
||||
extern const u8* gBattlescriptCurrInstr;
|
||||
extern u8 gBattleCommunication[];
|
||||
extern u8 gActiveBank;
|
||||
|
||||
extern const u8 BattleScript_MoveUsedWokeUp[];
|
||||
extern const u8 BattleScript_MoveUsedIsFrozen[];
|
||||
extern const u8 BattleScript_MoveUsedUnfroze[];
|
||||
extern const u8 BattleScript_MoveUsedIsAsleep[];
|
||||
|
||||
extern void sub_81D55D0(void);
|
||||
extern void sub_81D5694(void);
|
||||
extern u8 pokemon_order_func(u8);
|
||||
extern void sub_81B8FB0(u8, u8);
|
||||
|
||||
void AllocateBattleResources(void)
|
||||
{
|
||||
gBattleResources = gBattleResources; // something dumb needed to match
|
||||
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_x4000000)
|
||||
sub_81D55D0();
|
||||
|
||||
gBattleStruct = AllocZeroed(sizeof(*gBattleStruct));
|
||||
|
||||
gBattleResources = AllocZeroed(sizeof(*gBattleResources));
|
||||
gBattleResources->secretBase = AllocZeroed(sizeof(*gBattleResources->secretBase));
|
||||
gBattleResources->flags = AllocZeroed(sizeof(*gBattleResources->flags));
|
||||
gBattleResources->battleScriptsStack = AllocZeroed(sizeof(*gBattleResources->battleScriptsStack));
|
||||
gBattleResources->battleCallbackStack = AllocZeroed(sizeof(*gBattleResources->battleCallbackStack));
|
||||
gBattleResources->statsBeforeLvlUp = AllocZeroed(sizeof(*gBattleResources->statsBeforeLvlUp));
|
||||
gBattleResources->ai = AllocZeroed(sizeof(*gBattleResources->ai));
|
||||
gBattleResources->battleHistory = AllocZeroed(sizeof(*gBattleResources->battleHistory));
|
||||
gBattleResources->AI_ScriptsStack = AllocZeroed(sizeof(*gBattleResources->AI_ScriptsStack));
|
||||
|
||||
gLinkBattleSendBuffer = AllocZeroed(BATTLE_BUFFER_LINK_SIZE);
|
||||
gLinkBattleRecvBuffer = AllocZeroed(BATTLE_BUFFER_LINK_SIZE);
|
||||
|
||||
gUnknown_0202305C = AllocZeroed(0x2000);
|
||||
gUnknown_02023060 = AllocZeroed(0x1000);
|
||||
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_SECRET_BASE)
|
||||
{
|
||||
u16 currSecretBaseId = VarGet(VAR_0x4054);
|
||||
CreateSecretBaseEnemyParty(&gSaveBlock1Ptr->secretBases[currSecretBaseId]);
|
||||
}
|
||||
}
|
||||
|
||||
void FreeBattleResources(void)
|
||||
{
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_x4000000)
|
||||
sub_81D5694();
|
||||
|
||||
if (gBattleResources != NULL)
|
||||
{
|
||||
FREE_AND_SET_NULL(gBattleStruct);
|
||||
|
||||
FREE_AND_SET_NULL(gBattleResources->secretBase);
|
||||
FREE_AND_SET_NULL(gBattleResources->flags);
|
||||
FREE_AND_SET_NULL(gBattleResources->battleScriptsStack);
|
||||
FREE_AND_SET_NULL(gBattleResources->battleCallbackStack);
|
||||
FREE_AND_SET_NULL(gBattleResources->statsBeforeLvlUp);
|
||||
FREE_AND_SET_NULL(gBattleResources->ai);
|
||||
FREE_AND_SET_NULL(gBattleResources->battleHistory);
|
||||
FREE_AND_SET_NULL(gBattleResources->AI_ScriptsStack);
|
||||
FREE_AND_SET_NULL(gBattleResources);
|
||||
|
||||
FREE_AND_SET_NULL(gLinkBattleSendBuffer);
|
||||
FREE_AND_SET_NULL(gLinkBattleRecvBuffer);
|
||||
|
||||
FREE_AND_SET_NULL(gUnknown_0202305C);
|
||||
FREE_AND_SET_NULL(gUnknown_02023060);
|
||||
}
|
||||
}
|
||||
|
||||
void AdjustFriendshipOnBattleFaint(u8 bank)
|
||||
{
|
||||
u8 opposingBank;
|
||||
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
|
||||
{
|
||||
u8 opposingBank2;
|
||||
|
||||
opposingBank = GetBankByIdentity(IDENTITY_OPPONENT_MON1);
|
||||
opposingBank2 = GetBankByIdentity(IDENTITY_OPPONENT_MON2);
|
||||
|
||||
if (gBattleMons[opposingBank2].level > gBattleMons[opposingBank].level)
|
||||
opposingBank = opposingBank2;
|
||||
}
|
||||
else
|
||||
{
|
||||
opposingBank = GetBankByIdentity(IDENTITY_OPPONENT_MON1);
|
||||
}
|
||||
|
||||
if (gBattleMons[opposingBank].level > gBattleMons[bank].level)
|
||||
{
|
||||
if (gBattleMons[opposingBank].level - gBattleMons[bank].level > 29)
|
||||
AdjustFriendship(&gPlayerParty[gBattlePartyID[bank]], 8);
|
||||
else
|
||||
AdjustFriendship(&gPlayerParty[gBattlePartyID[bank]], 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
AdjustFriendship(&gPlayerParty[gBattlePartyID[bank]], 6);
|
||||
}
|
||||
}
|
||||
|
||||
void sub_80571DC(u8 bank, u8 arg1)
|
||||
{
|
||||
if (GetBankSide(bank) != SIDE_OPPONENT)
|
||||
{
|
||||
s32 i;
|
||||
|
||||
// gBattleStruct->field_60[0][i]
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
gUnknown_0203CF00[i] = *(0 * 3 + i + (u8*)(gBattleStruct->field_60));
|
||||
|
||||
sub_81B8FB0(pokemon_order_func(gBattlePartyID[bank]), pokemon_order_func(arg1));
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
*(0 * 3 + i + (u8*)(gBattleStruct->field_60)) = gUnknown_0203CF00[i];
|
||||
}
|
||||
}
|
||||
|
||||
u32 sub_805725C(u8 bank)
|
||||
{
|
||||
u32 effect = 0;
|
||||
|
||||
do
|
||||
{
|
||||
switch (gBattleCommunication[MULTIUSE_STATE])
|
||||
{
|
||||
case 0:
|
||||
if (gBattleMons[bank].status1 & STATUS_SLEEP)
|
||||
{
|
||||
if (UproarWakeUpCheck(bank))
|
||||
{
|
||||
gBattleMons[bank].status1 &= ~(STATUS_SLEEP);
|
||||
gBattleMons[bank].status2 &= ~(STATUS2_NIGHTMARE);
|
||||
BattleScriptPushCursor();
|
||||
gBattleCommunication[MULTISTRING_CHOOSER] = 1;
|
||||
gBattlescriptCurrInstr = BattleScript_MoveUsedWokeUp;
|
||||
effect = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 toSub;
|
||||
|
||||
if (gBattleMons[bank].ability == ABILITY_EARLY_BIRD)
|
||||
toSub = 2;
|
||||
else
|
||||
toSub = 1;
|
||||
|
||||
if ((gBattleMons[bank].status1 & STATUS_SLEEP) < toSub)
|
||||
gBattleMons[bank].status1 &= ~(STATUS_SLEEP);
|
||||
else
|
||||
gBattleMons[bank].status1 -= toSub;
|
||||
|
||||
if (gBattleMons[bank].status1 & STATUS_SLEEP)
|
||||
{
|
||||
gBattlescriptCurrInstr = BattleScript_MoveUsedIsAsleep;
|
||||
effect = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
gBattleMons[bank].status2 &= ~(STATUS2_NIGHTMARE);
|
||||
BattleScriptPushCursor();
|
||||
gBattleCommunication[MULTISTRING_CHOOSER] = 0;
|
||||
gBattlescriptCurrInstr = BattleScript_MoveUsedWokeUp;
|
||||
effect = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
gBattleCommunication[MULTIUSE_STATE]++;
|
||||
break;
|
||||
case 1:
|
||||
if (gBattleMons[bank].status1 & STATUS_FREEZE)
|
||||
{
|
||||
if (Random() % 5 != 0)
|
||||
{
|
||||
gBattlescriptCurrInstr = BattleScript_MoveUsedIsFrozen;
|
||||
}
|
||||
else
|
||||
{
|
||||
gBattleMons[bank].status1 &= ~(STATUS_FREEZE);
|
||||
BattleScriptPushCursor();
|
||||
gBattlescriptCurrInstr = BattleScript_MoveUsedUnfroze;
|
||||
gBattleCommunication[MULTISTRING_CHOOSER] = 0;
|
||||
}
|
||||
effect = 2;
|
||||
}
|
||||
gBattleCommunication[MULTIUSE_STATE]++;
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
}
|
||||
|
||||
} while (gBattleCommunication[MULTIUSE_STATE] != 2 && effect == 0);
|
||||
|
||||
if (effect == 2)
|
||||
{
|
||||
gActiveBank = bank;
|
||||
EmitSetMonData(0, REQUEST_STATUS_BATTLE, 0, 4, &gBattleMons[gActiveBank].status1);
|
||||
MarkBufferBankForExecution(gActiveBank);
|
||||
}
|
||||
|
||||
return effect;
|
||||
}
|
Loading…
Reference in New Issue
Block a user