pokecrystal-board/engine/events/treemons.asm

274 lines
3.2 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
TreeMonEncounter:
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
; 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
ldh [hDividend], a
2018-01-11 20:50:44 -08:00
ld a, l
ldh [hDividend + 1], a
2018-01-11 20:50:44 -08:00
ld a, 5
ldh [hDivisor], a
2018-01-11 20:50:44 -08:00
ld b, 2
call Divide
ldh a, [hQuotient + 2]
ldh [hDividend], a
ldh a, [hQuotient + 3]
ldh [hDividend + 1], a
2018-01-11 20:50:44 -08:00
ld a, 10
ldh [hDivisor], a
2018-01-11 20:50:44 -08:00
ld b, 2
call Divide
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]
ldh [hDividend], a
2018-01-23 14:39:09 -08:00
ld a, [wPlayerID + 1]
ldh [hDividend + 1], a
2018-01-11 20:50:44 -08:00
ld a, 10
ldh [hDivisor], a
2018-01-11 20:50:44 -08:00
ld b, 2
call Divide
ldh a, [hRemainder]
2018-01-11 20:50:44 -08:00
ret