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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
TreeMonEncounter: ; b81ea
farcall StubbedTrainerRankings_TreeEncounters
xor a
ld [wTempWildMonSpecies], a
ld [wCurPartyLevel], a
ld hl, TreeMonMaps
call GetTreeMonSet
jr nc, .no_battle
call GetTreeMons
jr nc, .no_battle
call GetTreeMon
jr nc, .no_battle
ld a, BATTLETYPE_TREE
ld [wBattleType], a
ld a, 1
ld [wScriptVar], a
ret
.no_battle
xor a
ld [wScriptVar], a
ret
; b8219
RockMonEncounter: ; b8219
xor a
ld [wTempWildMonSpecies], a
ld [wCurPartyLevel], a
ld hl, RockMonMaps
call GetTreeMonSet
jr nc, .no_battle
call GetTreeMons
jr nc, .no_battle
; 40% chance of an encounter
ld a, 10
call RandomRange
cp 4
jr nc, .no_battle
call SelectTreeMon
jr nc, .no_battle
ret
.no_battle
xor a
ret
; b823e
db $05 ; ????
GetTreeMonSet: ; b823f
; Return carry and treemon set in a
; if the current map is in table hl.
ld a, [wMapNumber]
ld e, a
ld a, [wMapGroup]
ld d, a
.loop
ld a, [hli]
cp -1
jr z, .not_in_table
cp d
jr nz, .skip2
ld a, [hli]
cp e
jr nz, .skip1
jr .in_table
.skip2
inc hl
.skip1
inc hl
jr .loop
.not_in_table
xor a
ret
.in_table
ld a, [hl]
scf
ret
; b825e
INCLUDE "data/wild/treemon_maps.asm"
GetTreeMons: ; b82d2
; Return the address of TreeMon table a in hl.
; Return nc if table a doesn't exist.
cp NUM_TREEMON_SETS
jr nc, .quit
and a
jr z, .quit
ld e, a
ld d, 0
ld hl, TreeMons
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
scf
ret
.quit
xor a
ret
; b82e8
INCLUDE "data/wild/treemons.asm"
GetTreeMon: ; b83e5
push hl
call GetTreeScore
pop hl
and a ; TREEMON_SCORE_BAD
jr z, .bad
cp TREEMON_SCORE_GOOD
jr z, .good
cp TREEMON_SCORE_RARE
jr z, .rare
ret
.bad
; 10% chance of an encounter
ld a, 10
call RandomRange
and a
jr nz, NoTreeMon
jr SelectTreeMon
.good
; 50% chance of an encounter
ld a, 10
call RandomRange
cp 5
jr nc, NoTreeMon
jr SelectTreeMon
.rare
; 80% chance of an encounter
ld a, 10
call RandomRange
cp 8
jr nc, NoTreeMon
jr .skip
.skip
ld a, [hli]
cp -1
jr nz, .skip
call SelectTreeMon
ret
; b841f
SelectTreeMon: ; b841f
; Read a TreeMons table and pick one monster at random.
ld a, 100
call RandomRange
.loop
sub [hl]
jr c, .ok
inc hl
inc hl
inc hl
jr .loop
.ok
ld a, [hli]
cp -1
jr z, NoTreeMon
ld a, [hli]
ld [wTempWildMonSpecies], a
ld a, [hl]
ld [wCurPartyLevel], a
scf
ret
NoTreeMon: ; b843b
xor a
ld [wTempWildMonSpecies], a
ld [wCurPartyLevel], a
ret
; b8443
GetTreeScore: ; b8443
call .CoordScore
ld [wBuffer1], a
call .OTIDScore
ld [wBuffer2], a
ld c, a
ld a, [wBuffer1]
sub c
jr z, .rare
jr nc, .ok
add 10
.ok
cp 5
jr c, .good
.bad
xor a ; TREEMON_SCORE_BAD
ret
.good
ld a, TREEMON_SCORE_GOOD
ret
.rare
ld a, TREEMON_SCORE_RARE
ret
; b8466
.CoordScore: ; b8466
call GetFacingTileCoord
ld hl, 0
ld c, e
ld b, 0
ld a, d
and a
jr z, .next
.loop
add hl, bc
dec a
jr nz, .loop
.next
add hl, bc
ld c, d
add hl, bc
ld a, h
ld [hDividend], a
ld a, l
ld [hDividend + 1], a
ld a, 5
ld [hDivisor], a
ld b, 2
call Divide
ld a, [hQuotient + 1]
ld [hDividend], a
ld a, [hQuotient + 2]
ld [hDividend + 1], a
ld a, 10
ld [hDivisor], a
ld b, 2
call Divide
ld a, [hQuotient + 3]
ret
; b849d
.OTIDScore: ; b849d
ld a, [wPlayerID]
ld [hDividend], a
ld a, [wPlayerID + 1]
ld [hDividend + 1], a
ld a, 10
ld [hDivisor], a
ld b, 2
call Divide
ld a, [hQuotient + 3]
ret
; b84b3
|