2018-06-24 07:09:41 -07:00
|
|
|
TreeMonEncounter:
|
2018-01-14 19:56:36 -08:00
|
|
|
farcall StubbedTrainerRankings_TreeEncounters
|
2018-01-11 20:50:44 -08:00
|
|
|
|
|
|
|
xor a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wTempWildMonSpecies], a
|
|
|
|
ld [wCurPartyLevel], a
|
2018-01-11 20:50:44 -08:00
|
|
|
|
|
|
|
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
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wBattleType], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ld a, 1
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wScriptVar], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ret
|
|
|
|
|
|
|
|
.no_battle
|
|
|
|
xor a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wScriptVar], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
RockMonEncounter:
|
2018-01-11 20:50:44 -08:00
|
|
|
xor a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wTempWildMonSpecies], a
|
|
|
|
ld [wCurPartyLevel], a
|
2018-01-11 20:50:44 -08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
db $05 ; ????
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetTreeMonSet:
|
2018-01-11 20:50:44 -08:00
|
|
|
; Return carry and treemon set in a
|
|
|
|
; if the current map is in table hl.
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wMapNumber]
|
2018-01-11 20:50:44 -08:00
|
|
|
ld e, a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wMapGroup]
|
2018-01-11 20:50:44 -08:00
|
|
|
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
|
|
|
|
|
|
|
|
INCLUDE "data/wild/treemon_maps.asm"
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetTreeMons:
|
2018-01-11 20:50:44 -08:00
|
|
|
; 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
|
|
|
|
|
|
|
|
INCLUDE "data/wild/treemons.asm"
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetTreeMon:
|
2018-01-11 20:50:44 -08:00
|
|
|
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
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
SelectTreeMon:
|
2018-01-11 20:50:44 -08:00
|
|
|
; 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]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wTempWildMonSpecies], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ld a, [hl]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wCurPartyLevel], a
|
2018-01-11 20:50:44 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
NoTreeMon:
|
2018-01-11 20:50:44 -08:00
|
|
|
xor a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wTempWildMonSpecies], a
|
|
|
|
ld [wCurPartyLevel], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetTreeScore:
|
2018-01-11 20:50:44 -08:00
|
|
|
call .CoordScore
|
2020-11-03 16:53:07 -08:00
|
|
|
ld [wTreeMonCoordScore], a
|
2018-01-11 20:50:44 -08:00
|
|
|
call .OTIDScore
|
2020-11-03 16:53:07 -08:00
|
|
|
ld [wTreeMonOTIDScore], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ld c, a
|
2020-11-03 16:53:07 -08:00
|
|
|
ld a, [wTreeMonCoordScore]
|
2018-01-11 20:50:44 -08:00
|
|
|
sub c
|
|
|
|
jr z, .rare
|
|
|
|
jr nc, .ok
|
|
|
|
add 10
|
|
|
|
.ok
|
|
|
|
cp 5
|
|
|
|
jr c, .good
|
|
|
|
|
2020-10-26 12:45:57 -07:00
|
|
|
; bad
|
2018-01-11 20:50:44 -08:00
|
|
|
xor a ; TREEMON_SCORE_BAD
|
|
|
|
ret
|
|
|
|
|
|
|
|
.good
|
|
|
|
ld a, TREEMON_SCORE_GOOD
|
|
|
|
ret
|
|
|
|
|
|
|
|
.rare
|
|
|
|
ld a, TREEMON_SCORE_RARE
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.CoordScore:
|
2018-01-11 20:50:44 -08:00
|
|
|
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
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDividend], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ld a, l
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDividend + 1], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ld a, 5
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDivisor], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ld b, 2
|
|
|
|
call Divide
|
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hQuotient + 2]
|
2018-08-26 10:49:38 -07:00
|
|
|
ldh [hDividend], a
|
|
|
|
ldh a, [hQuotient + 3]
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDividend + 1], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ld a, 10
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDivisor], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ld b, 2
|
|
|
|
call Divide
|
|
|
|
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hRemainder]
|
2018-01-11 20:50:44 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.OTIDScore:
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPlayerID]
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDividend], a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPlayerID + 1]
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDividend + 1], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ld a, 10
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hDivisor], a
|
2018-01-11 20:50:44 -08:00
|
|
|
ld b, 2
|
|
|
|
call Divide
|
2018-08-25 18:49:26 -07:00
|
|
|
ldh a, [hRemainder]
|
2018-01-11 20:50:44 -08:00
|
|
|
ret
|