-
Notifications
You must be signed in to change notification settings - Fork 817
/
start_battle.asm
199 lines (166 loc) · 3.15 KB
/
start_battle.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
ShowLinkBattleParticipants:
; If we're not in a communications room,
; we don't need to be here.
ld a, [wLinkMode]
and a
ret z
farcall _ShowLinkBattleParticipants
ld c, 150
call DelayFrames
call ClearTilemap
call ClearSprites
ret
FindFirstAliveMonAndStartBattle:
xor a
ldh [hMapAnims], a
call DelayFrame
ld b, PARTY_LENGTH
ld hl, wPartyMon1HP
ld de, PARTYMON_STRUCT_LENGTH - 1
.loop
ld a, [hli]
or [hl]
jr nz, .okay
add hl, de
dec b
jr nz, .loop
.okay
ld de, MON_LEVEL - MON_HP
add hl, de
ld a, [hl]
ld [wBattleMonLevel], a
predef DoBattleTransition
farcall _LoadBattleFontsHPBar
ld a, 1
ldh [hBGMapMode], a
call ClearSprites
call ClearTilemap
xor a
ldh [hBGMapMode], a
ldh [hWY], a
ldh [rWY], a
ldh [hMapAnims], a
ret
PlayBattleMusic:
push hl
push de
push bc
xor a
ld [wMusicFade], a
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
call MaxVolume
ld a, [wBattleType]
cp BATTLETYPE_SUICUNE
ld de, MUSIC_SUICUNE_BATTLE
jp z, .done
cp BATTLETYPE_ROAMING
jp z, .done
; Are we fighting a trainer?
ld a, [wOtherTrainerClass]
and a
jr nz, .trainermusic
farcall RegionCheck
ld a, e
and a
jr nz, .kantowild
ld de, MUSIC_JOHTO_WILD_BATTLE
ld a, [wTimeOfDay]
cp NITE_F
jr nz, .done
ld de, MUSIC_JOHTO_WILD_BATTLE_NIGHT
jr .done
.kantowild
ld de, MUSIC_KANTO_WILD_BATTLE
jr .done
.trainermusic
ld de, MUSIC_CHAMPION_BATTLE
cp CHAMPION
jr z, .done
cp RED
jr z, .done
; BUG: Team Rocket battle music is not used for Executives or Scientists (see docs/bugs_and_glitches.md)
ld de, MUSIC_ROCKET_BATTLE
cp GRUNTM
jr z, .done
cp GRUNTF
jr z, .done
ld de, MUSIC_KANTO_GYM_LEADER_BATTLE
farcall IsKantoGymLeader
jr c, .done
; IsGymLeader also counts CHAMPION, RED, and the Kanto gym leaders
; but they have been taken care of before this
ld de, MUSIC_JOHTO_GYM_LEADER_BATTLE
farcall IsGymLeader
jr c, .done
ld de, MUSIC_RIVAL_BATTLE
ld a, [wOtherTrainerClass]
cp RIVAL1
jr z, .done
cp RIVAL2
jr nz, .othertrainer
ld a, [wOtherTrainerID]
cp RIVAL2_2_CHIKORITA ; Rival in Indigo Plateau
jr c, .done
ld de, MUSIC_CHAMPION_BATTLE
jr .done
.othertrainer
ld a, [wLinkMode]
and a
jr nz, .johtotrainer
farcall RegionCheck
ld a, e
and a
jr nz, .kantotrainer
.johtotrainer
ld de, MUSIC_JOHTO_TRAINER_BATTLE
jr .done
.kantotrainer
ld de, MUSIC_KANTO_TRAINER_BATTLE
.done
call PlayMusic
pop bc
pop de
pop hl
ret
ClearBattleRAM:
xor a
ld [wBattlePlayerAction], a
ld [wBattleResult], a
ld hl, wPartyMenuCursor
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
ld [wMenuScrollPosition], a
ld [wCriticalHit], a
ld [wBattleMonSpecies], a
ld [wBattleParticipantsNotFainted], a
ld [wCurBattleMon], a
ld [wForcedSwitch], a
ld [wTimeOfDayPal], a
ld [wPlayerTurnsTaken], a
ld [wEnemyTurnsTaken], a
ld [wEvolvableFlags], a
ld hl, wPlayerHPPal
ld [hli], a
ld [hl], a
ld hl, wBattleMonDVs
ld [hli], a
ld [hl], a
ld hl, wEnemyMonDVs
ld [hli], a
ld [hl], a
; Clear the entire BattleMons area
ld hl, wBattle
ld bc, wBattleEnd - wBattle
xor a
call ByteFill
callfar ResetEnemyStatLevels
call ClearWindowData
ld hl, hBGMapAddress
xor a ; LOW(vBGMap0)
ld [hli], a
ld [hl], HIGH(vBGMap0)
ret