`MobileCheckOwnMonAnywhere` & `CheckOwnMonAnywhere` Label, comments, formatting (#927)

Co-authored-by: Rangi <35663410+Rangi42@users.noreply.github.com>
This commit is contained in:
vulcandth 2022-06-17 22:21:08 -05:00 committed by GitHub
parent 4db344db89
commit 66d84ff021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 35 deletions

View File

@ -51,6 +51,7 @@ CheckOwnMonAnywhere:
; If there are no monsters in the party, ; If there are no monsters in the party,
; the player must not own any yet. ; the player must not own any yet.
ld a, [wPartyCount] ld a, [wPartyCount]
and a and a
ret z ret z
@ -61,9 +62,10 @@ CheckOwnMonAnywhere:
ld bc, wPartyMonOTs ld bc, wPartyMonOTs
; Run CheckOwnMon on each Pokémon in the party. ; Run CheckOwnMon on each Pokémon in the party.
.partymon .partymon
call CheckOwnMon call CheckOwnMon
ret c ; found! ret c
push bc push bc
ld bc, PARTYMON_STRUCT_LENGTH ld bc, PARTYMON_STRUCT_LENGTH
@ -74,6 +76,7 @@ CheckOwnMonAnywhere:
jr nz, .partymon jr nz, .partymon
; Run CheckOwnMon on each Pokémon in the PC. ; Run CheckOwnMon on each Pokémon in the PC.
ld a, BANK(sBoxCount) ld a, BANK(sBoxCount)
call OpenSRAM call OpenSRAM
ld a, [sBoxCount] ld a, [sBoxCount]
@ -87,7 +90,6 @@ CheckOwnMonAnywhere:
call CheckOwnMon call CheckOwnMon
jr nc, .loop jr nc, .loop
; found!
call CloseSRAM call CloseSRAM
ret ret
@ -101,6 +103,7 @@ CheckOwnMonAnywhere:
jr nz, .openboxmon jr nz, .openboxmon
; Run CheckOwnMon on each monster in the other 13 PC boxes. ; Run CheckOwnMon on each monster in the other 13 PC boxes.
.boxes .boxes
call CloseSRAM call CloseSRAM
@ -113,6 +116,7 @@ CheckOwnMonAnywhere:
jr z, .loopbox jr z, .loopbox
; Load the box. ; Load the box.
ld hl, SearchBoxAddressTable ld hl, SearchBoxAddressTable
ld b, 0 ld b, 0
add hl, bc add hl, bc
@ -125,6 +129,7 @@ CheckOwnMonAnywhere:
ld l, a ld l, a
; Number of monsters in the box ; Number of monsters in the box
ld a, [hl] ld a, [hl]
and a and a
jr z, .loopbox jr z, .loopbox
@ -150,7 +155,6 @@ CheckOwnMonAnywhere:
call CheckOwnMon call CheckOwnMon
jr nc, .loopboxmon jr nc, .loopboxmon
; found!
pop bc pop bc
call CloseSRAM call CloseSRAM
ret ret
@ -171,13 +175,14 @@ CheckOwnMonAnywhere:
cp NUM_BOXES cp NUM_BOXES
jr c, .box jr c, .box
; not found
call CloseSRAM call CloseSRAM
and a and a
ret ret
CheckOwnMon: CheckOwnMon:
; Check if a Pokémon belongs to the player and is of a specific species. ; Check if a Pokémon belongs to the player and is of a specific species.
; We compare the species we are looking for in [wScriptVar] to the species
; we have in [hl].
; inputs: ; inputs:
; hl, pointer to PartyMonNSpecies ; hl, pointer to PartyMonNSpecies
@ -193,26 +198,26 @@ CheckOwnMon:
ld d, b ld d, b
ld e, c ld e, c
; check species ; check species
ld a, [wScriptVar] ; species we're looking for
ld b, [hl] ; species we have ld a, [wScriptVar]
cp b ld b, [hl]
jr nz, .notfound ; species doesn't match cp b
jr nz, .notfound
; check ID number
; check ID number
ld bc, MON_ID ld bc, MON_ID
add hl, bc ; now hl points to ID number add hl, bc
ld a, [wPlayerID] ld a, [wPlayerID]
cp [hl] cp [hl]
jr nz, .notfound ; ID doesn't match jr nz, .notfound
inc hl inc hl
ld a, [wPlayerID + 1] ld a, [wPlayerID + 1]
cp [hl] cp [hl]
jr nz, .notfound ; ID doesn't match jr nz, .notfound
; check OT ; check OT
; This only checks five characters, which is fine for the Japanese version,
; but in the English version the player name is 7 characters, so this is wrong.
ld hl, wPlayerName ld hl, wPlayerName
@ -221,7 +226,7 @@ rept NAME_LENGTH_JAPANESE - 2 ; should be PLAYER_NAME_LENGTH - 2
cp [hl] cp [hl]
jr nz, .notfound jr nz, .notfound
cp "@" cp "@"
jr z, .found ; reached end of string jr z, .found
inc hl inc hl
inc de inc de
endr endr

View File

@ -1,7 +1,16 @@
MobileCheckOwnMonAnywhere: MobileCheckOwnMonAnywhere:
; Like CheckOwnMonAnywhere, but only check for species. ; Like CheckOwnMonAnywhere, but only checks for species.
; OT/ID don't matter. ; OT/ID don't matter.
; inputs:
; [wScriptVar] should contain the species we're looking for.
; outputs:
; sets carry if monster matches species.
; If there are no monsters in the party,
; the player must not own any yet.
ld a, [wPartyCount] ld a, [wPartyCount]
and a and a
ret z ret z
@ -10,47 +19,63 @@ MobileCheckOwnMonAnywhere:
ld e, 0 ld e, 0
ld hl, wPartyMon1Species ld hl, wPartyMon1Species
ld bc, wPartyMonOTs ld bc, wPartyMonOTs
.asm_4a851
; Run .CheckMatch on each Pokémon in the party.
.partymon
call .CheckMatch call .CheckMatch
ret c ret c
push bc push bc
ld bc, PARTYMON_STRUCT_LENGTH ld bc, PARTYMON_STRUCT_LENGTH
add hl, bc add hl, bc
pop bc pop bc
call .AdvanceOTName call .AdvanceOTName
dec d dec d
jr nz, .asm_4a851 jr nz, .partymon
; Run .CheckMatch on each Pokémon in the PC.
ld a, BANK(sBoxCount) ld a, BANK(sBoxCount)
call OpenSRAM call OpenSRAM
ld a, [sBoxCount] ld a, [sBoxCount]
and a and a
jr z, .asm_4a888 jr z, .boxes
ld d, a ld d, a
ld hl, sBoxMon1Species ld hl, sBoxMon1Species
ld bc, sBoxMonOTs ld bc, sBoxMonOTs
.asm_4a873 .openboxmon
call .CheckMatch call .CheckMatch
jr nc, .asm_4a87c jr nc, .loop
call CloseSRAM call CloseSRAM
ret ret
.asm_4a87c .loop
push bc push bc
ld bc, BOXMON_STRUCT_LENGTH ld bc, BOXMON_STRUCT_LENGTH
add hl, bc add hl, bc
pop bc pop bc
call .AdvanceOTName call .AdvanceOTName
dec d dec d
jr nz, .asm_4a873 jr nz, .openboxmon
.asm_4a888 ; Run .CheckMatch on each monster in the other 13 PC boxes.
.boxes
call CloseSRAM call CloseSRAM
ld c, 0 ld c, 0
.asm_4a88d .box
; Don't search the current box again.
ld a, [wCurBox] ld a, [wCurBox]
and $f and $f
cp c cp c
jr z, .asm_4a8d1 jr z, .loopbox
; Load the box.
ld hl, .BoxAddresses ld hl, .BoxAddresses
ld b, 0 ld b, 0
add hl, bc add hl, bc
@ -61,10 +86,15 @@ MobileCheckOwnMonAnywhere:
ld a, [hli] ld a, [hli]
ld h, [hl] ld h, [hl]
ld l, a ld l, a
; Number of monsters in the box
ld a, [hl] ld a, [hl]
and a and a
jr z, .asm_4a8d1 jr z, .loopbox
push bc push bc
push hl push hl
ld de, sBoxMons - sBoxCount ld de, sBoxMons - sBoxCount
add hl, de add hl, de
@ -77,39 +107,51 @@ MobileCheckOwnMonAnywhere:
ld b, h ld b, h
ld c, l ld c, l
pop hl pop hl
ld d, a ld d, a
.asm_4a8ba
.boxmon
call .CheckMatch call .CheckMatch
jr nc, .asm_4a8c4 jr nc, .loopboxmon
pop bc pop bc
call CloseSRAM call CloseSRAM
ret ret
.asm_4a8c4 .loopboxmon
push bc push bc
ld bc, BOXMON_STRUCT_LENGTH ld bc, BOXMON_STRUCT_LENGTH
add hl, bc add hl, bc
pop bc pop bc
call .AdvanceOTName call .AdvanceOTName
dec d dec d
jr nz, .asm_4a8ba jr nz, .boxmon
pop bc pop bc
.asm_4a8d1 .loopbox
inc c inc c
ld a, c ld a, c
cp NUM_BOXES cp NUM_BOXES
jr c, .asm_4a88d jr c, .box
call CloseSRAM call CloseSRAM
and a and a
ret ret
.CheckMatch: .CheckMatch:
; Check if a Pokémon is of a specific species.
; We compare the species we are looking for in
; [wScriptVar] to the species we have in [hl].
; Sets carry flag if species matches.
push bc push bc
push hl push hl
push de push de
ld d, b ld d, b
ld e, c ld e, c
; check species
ld a, [wScriptVar] ld a, [wScriptVar]
ld b, [hl] ld b, [hl]
cp b cp b