pokecrystal-board/engine/events/treemons.asm

286 lines
3.4 KiB
NASM
Raw Normal View History

2018-01-11 20:50:44 -08:00
TreeMonEncounter: ; b81ea
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
; b8219
RockMonEncounter: ; b8219
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
; b823e
db $05 ; ????
GetTreeMonSet: ; b823f
; 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
; 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]
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
NoTreeMon: ; b843b
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
; b8443
GetTreeScore: ; b8443
call .CoordScore
2018-01-23 14:39:09 -08:00
ld [wBuffer1], a
2018-01-11 20:50:44 -08:00
call .OTIDScore
2018-01-23 14:39:09 -08:00
ld [wBuffer2], a
2018-01-11 20:50:44 -08:00
ld c, a
2018-01-23 14:39:09 -08:00
ld a, [wBuffer1]
2018-01-11 20:50:44 -08:00
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
2018-01-23 14:39:09 -08:00
ld a, [wPlayerID]
2018-01-11 20:50:44 -08:00
ld [hDividend], a
2018-01-23 14:39:09 -08:00
ld a, [wPlayerID + 1]
2018-01-11 20:50:44 -08:00
ld [hDividend + 1], a
ld a, 10
ld [hDivisor], a
ld b, 2
call Divide
ld a, [hQuotient + 3]
ret
; b84b3