2018-06-24 17:10:37 -07:00
|
|
|
BeastsCheck:
|
2015-12-06 19:36:09 -08:00
|
|
|
; Check if the player owns all three legendary beasts.
|
|
|
|
; They must exist in either party or PC, and have the player's OT and ID.
|
2023-09-30 10:12:57 -07:00
|
|
|
; Return the result in hScriptVar.
|
2015-12-06 19:36:09 -08:00
|
|
|
|
|
|
|
ld a, RAIKOU
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-12-06 19:36:09 -08:00
|
|
|
call CheckOwnMonAnywhere
|
|
|
|
jr nc, .notexist
|
|
|
|
|
|
|
|
ld a, ENTEI
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-12-06 19:36:09 -08:00
|
|
|
call CheckOwnMonAnywhere
|
|
|
|
jr nc, .notexist
|
|
|
|
|
|
|
|
ld a, SUICUNE
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-12-06 19:36:09 -08:00
|
|
|
call CheckOwnMonAnywhere
|
|
|
|
jr nc, .notexist
|
|
|
|
|
|
|
|
; they exist
|
|
|
|
ld a, 1
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-12-06 19:36:09 -08:00
|
|
|
ret
|
|
|
|
|
|
|
|
.notexist
|
|
|
|
xor a
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-12-06 19:36:09 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 17:10:37 -07:00
|
|
|
MonCheck:
|
2023-09-30 10:12:57 -07:00
|
|
|
; Check if the player owns any Pokémon of the species in hScriptVar.
|
|
|
|
; Return the result in hScriptVar.
|
2015-12-06 19:36:09 -08:00
|
|
|
|
|
|
|
call CheckOwnMonAnywhere
|
|
|
|
jr c, .exists
|
|
|
|
|
|
|
|
; doesn't exist
|
|
|
|
xor a
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-12-06 19:36:09 -08:00
|
|
|
ret
|
|
|
|
|
|
|
|
.exists
|
|
|
|
ld a, 1
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2015-12-06 19:36:09 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 17:10:37 -07:00
|
|
|
CheckOwnMonAnywhere:
|
2023-09-30 10:12:57 -07:00
|
|
|
; Check if the player owns any monsters of the species in hScriptVar.
|
2015-12-06 19:36:09 -08:00
|
|
|
; It must exist in either party or PC, and have the player's OT and ID.
|
|
|
|
|
|
|
|
; If there are no monsters in the party,
|
|
|
|
; the player must not own any yet.
|
2022-06-17 20:21:08 -07:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPartyCount]
|
2015-12-06 19:36:09 -08:00
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
|
2022-07-09 14:12:02 -07:00
|
|
|
; BUG: CheckOwnMon does not check the Day-Care (see docs/bugs_and_glitches.md)
|
2015-12-06 19:36:09 -08:00
|
|
|
ld d, a
|
|
|
|
ld e, 0
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMon1Species
|
2021-03-17 13:16:02 -07:00
|
|
|
ld bc, wPartyMonOTs
|
2015-12-06 19:36:09 -08:00
|
|
|
|
|
|
|
; Run CheckOwnMon on each Pokémon in the party.
|
2022-06-17 20:21:08 -07:00
|
|
|
|
2015-12-06 19:36:09 -08:00
|
|
|
.partymon
|
|
|
|
call CheckOwnMon
|
2022-06-17 20:21:08 -07:00
|
|
|
ret c
|
2015-12-06 19:36:09 -08:00
|
|
|
|
|
|
|
push bc
|
|
|
|
ld bc, PARTYMON_STRUCT_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
call UpdateOTPointer
|
|
|
|
dec d
|
|
|
|
jr nz, .partymon
|
|
|
|
|
|
|
|
; Run CheckOwnMon on each Pokémon in the PC.
|
2022-06-17 20:21:08 -07:00
|
|
|
|
2015-12-06 19:36:09 -08:00
|
|
|
ld a, BANK(sBoxCount)
|
2020-06-17 14:03:38 -07:00
|
|
|
call OpenSRAM
|
2015-12-06 19:36:09 -08:00
|
|
|
ld a, [sBoxCount]
|
|
|
|
and a
|
|
|
|
jr z, .boxes
|
|
|
|
|
|
|
|
ld d, a
|
|
|
|
ld hl, sBoxMon1Species
|
2021-03-17 13:16:02 -07:00
|
|
|
ld bc, sBoxMonOTs
|
2015-12-06 19:36:09 -08:00
|
|
|
.openboxmon
|
|
|
|
call CheckOwnMon
|
|
|
|
jr nc, .loop
|
|
|
|
|
|
|
|
call CloseSRAM
|
|
|
|
ret
|
|
|
|
|
|
|
|
.loop
|
|
|
|
push bc
|
|
|
|
ld bc, BOXMON_STRUCT_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
call UpdateOTPointer
|
|
|
|
dec d
|
|
|
|
jr nz, .openboxmon
|
|
|
|
|
|
|
|
; Run CheckOwnMon on each monster in the other 13 PC boxes.
|
2022-06-17 20:21:08 -07:00
|
|
|
|
2015-12-06 19:36:09 -08:00
|
|
|
.boxes
|
|
|
|
call CloseSRAM
|
|
|
|
|
|
|
|
ld c, 0
|
|
|
|
.box
|
|
|
|
; Don't search the current box again.
|
|
|
|
ld a, [wCurBox]
|
|
|
|
and $f
|
|
|
|
cp c
|
|
|
|
jr z, .loopbox
|
|
|
|
|
|
|
|
; Load the box.
|
2022-06-17 20:21:08 -07:00
|
|
|
|
2021-03-21 14:47:53 -07:00
|
|
|
ld hl, SearchBoxAddressTable
|
2015-12-06 19:36:09 -08:00
|
|
|
ld b, 0
|
|
|
|
add hl, bc
|
2016-05-10 09:31:49 -07:00
|
|
|
add hl, bc
|
|
|
|
add hl, bc
|
2015-12-06 19:36:09 -08:00
|
|
|
ld a, [hli]
|
2020-06-17 14:03:38 -07:00
|
|
|
call OpenSRAM
|
2015-12-06 19:36:09 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
|
|
|
|
; Number of monsters in the box
|
2022-06-17 20:21:08 -07:00
|
|
|
|
2015-12-06 19:36:09 -08:00
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
jr z, .loopbox
|
|
|
|
|
|
|
|
push bc
|
|
|
|
|
|
|
|
push hl
|
|
|
|
ld de, sBoxMons - sBoxCount
|
|
|
|
add hl, de
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
|
|
|
pop hl
|
|
|
|
push de
|
2021-03-17 13:16:02 -07:00
|
|
|
ld de, sBoxMonOTs - sBoxCount
|
2015-12-06 19:36:09 -08:00
|
|
|
add hl, de
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
pop hl
|
|
|
|
|
|
|
|
ld d, a
|
|
|
|
|
|
|
|
.boxmon
|
|
|
|
call CheckOwnMon
|
|
|
|
jr nc, .loopboxmon
|
|
|
|
|
|
|
|
pop bc
|
|
|
|
call CloseSRAM
|
|
|
|
ret
|
|
|
|
|
|
|
|
.loopboxmon
|
|
|
|
push bc
|
|
|
|
ld bc, BOXMON_STRUCT_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
call UpdateOTPointer
|
|
|
|
dec d
|
|
|
|
jr nz, .boxmon
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
.loopbox
|
|
|
|
inc c
|
|
|
|
ld a, c
|
|
|
|
cp NUM_BOXES
|
|
|
|
jr c, .box
|
|
|
|
|
|
|
|
call CloseSRAM
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 17:10:37 -07:00
|
|
|
CheckOwnMon:
|
2015-12-06 19:36:09 -08:00
|
|
|
; Check if a Pokémon belongs to the player and is of a specific species.
|
2023-09-30 10:12:57 -07:00
|
|
|
; We compare the species we are looking for in [hScriptVar] to the species
|
2022-06-17 20:21:08 -07:00
|
|
|
; we have in [hl].
|
2015-12-06 19:36:09 -08:00
|
|
|
|
|
|
|
; inputs:
|
|
|
|
; hl, pointer to PartyMonNSpecies
|
|
|
|
; bc, pointer to PartyMonNOT
|
2023-09-30 10:12:57 -07:00
|
|
|
; hScriptVar should contain the species we're looking for
|
2015-12-06 19:36:09 -08:00
|
|
|
|
|
|
|
; outputs:
|
|
|
|
; sets carry if monster matches species, ID, and OT name.
|
|
|
|
|
|
|
|
push bc
|
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
ld d, b
|
|
|
|
ld e, c
|
|
|
|
|
2022-06-17 20:21:08 -07:00
|
|
|
; check species
|
|
|
|
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh a, [hScriptVar]
|
2022-06-17 20:21:08 -07:00
|
|
|
ld b, [hl]
|
2015-12-06 19:36:09 -08:00
|
|
|
cp b
|
2022-06-17 20:21:08 -07:00
|
|
|
jr nz, .notfound
|
|
|
|
|
|
|
|
; check ID number
|
2015-12-06 19:36:09 -08:00
|
|
|
|
|
|
|
ld bc, MON_ID
|
2022-06-17 20:21:08 -07:00
|
|
|
add hl, bc
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPlayerID]
|
2015-12-06 19:36:09 -08:00
|
|
|
cp [hl]
|
2022-06-17 20:21:08 -07:00
|
|
|
jr nz, .notfound
|
2015-12-06 19:36:09 -08:00
|
|
|
inc hl
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPlayerID + 1]
|
2015-12-06 19:36:09 -08:00
|
|
|
cp [hl]
|
2022-06-17 20:21:08 -07:00
|
|
|
jr nz, .notfound
|
2015-12-06 19:36:09 -08:00
|
|
|
|
2022-06-17 20:21:08 -07:00
|
|
|
; check OT
|
2015-12-06 19:36:09 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPlayerName
|
2015-12-06 19:36:09 -08:00
|
|
|
|
2022-07-09 14:12:02 -07:00
|
|
|
; BUG: CheckOwnMon only checks the first five letters of OT names (see docs/bugs_and_glitches.md)
|
|
|
|
rept NAME_LENGTH_JAPANESE - 2
|
2015-12-06 19:36:09 -08:00
|
|
|
ld a, [de]
|
|
|
|
cp [hl]
|
|
|
|
jr nz, .notfound
|
|
|
|
cp "@"
|
2022-06-17 20:21:08 -07:00
|
|
|
jr z, .found
|
2015-12-06 19:36:09 -08:00
|
|
|
inc hl
|
|
|
|
inc de
|
2017-12-12 17:15:07 -08:00
|
|
|
endr
|
2015-12-06 19:36:09 -08:00
|
|
|
|
|
|
|
ld a, [de]
|
|
|
|
cp [hl]
|
|
|
|
jr z, .found
|
|
|
|
|
|
|
|
.notfound
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
pop bc
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.found
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
pop bc
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2021-03-21 14:47:53 -07:00
|
|
|
SearchBoxAddressTable:
|
|
|
|
table_width 3, SearchBoxAddressTable
|
2022-08-31 15:03:49 -07:00
|
|
|
for n, 1, NUM_BOXES + 1
|
|
|
|
dba sBox{d:n}
|
|
|
|
endr
|
2021-03-21 14:47:53 -07:00
|
|
|
assert_table_length NUM_BOXES
|
2015-12-06 19:36:09 -08:00
|
|
|
|
2018-06-24 17:10:37 -07:00
|
|
|
UpdateOTPointer:
|
2015-12-06 19:36:09 -08:00
|
|
|
push hl
|
|
|
|
ld hl, NAME_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
pop hl
|
|
|
|
ret
|