shithub: pokecrystal

Download patch

ref: 66d84ff021bf22e607b766867a1a6ce7ce9855ed
parent: 4db344db89d8e36b0dd915cac570c9819f311146
author: vulcandth <[email protected]>
date: Fri Jun 17 18:21:08 EDT 2022

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

Co-authored-by: Rangi <[email protected]>

--- a/engine/pokemon/search.asm
+++ b/engine/pokemon/search.asm
@@ -51,6 +51,7 @@
 
 	; If there are no monsters in the party,
 	; the player must not own any yet.
+
 	ld a, [wPartyCount]
 	and a
 	ret z
@@ -61,9 +62,10 @@
 	ld bc, wPartyMonOTs
 
 	; Run CheckOwnMon on each Pokémon in the party.
+
 .partymon
 	call CheckOwnMon
-	ret c ; found!
+	ret c
 
 	push bc
 	ld bc, PARTYMON_STRUCT_LENGTH
@@ -74,6 +76,7 @@
 	jr nz, .partymon
 
 	; Run CheckOwnMon on each Pokémon in the PC.
+
 	ld a, BANK(sBoxCount)
 	call OpenSRAM
 	ld a, [sBoxCount]
@@ -87,7 +90,6 @@
 	call CheckOwnMon
 	jr nc, .loop
 
-	; found!
 	call CloseSRAM
 	ret
 
@@ -101,6 +103,7 @@
 	jr nz, .openboxmon
 
 	; Run CheckOwnMon on each monster in the other 13 PC boxes.
+
 .boxes
 	call CloseSRAM
 
@@ -113,6 +116,7 @@
 	jr z, .loopbox
 
 	; Load the box.
+
 	ld hl, SearchBoxAddressTable
 	ld b, 0
 	add hl, bc
@@ -125,6 +129,7 @@
 	ld l, a
 
 	; Number of monsters in the box
+
 	ld a, [hl]
 	and a
 	jr z, .loopbox
@@ -150,7 +155,6 @@
 	call CheckOwnMon
 	jr nc, .loopboxmon
 
-	; found!
 	pop bc
 	call CloseSRAM
 	ret
@@ -171,7 +175,6 @@
 	cp NUM_BOXES
 	jr c, .box
 
-	; not found
 	call CloseSRAM
 	and a
 	ret
@@ -178,6 +181,8 @@
 
 CheckOwnMon:
 ; 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:
 ; hl, pointer to PartyMonNSpecies
@@ -193,26 +198,26 @@
 	ld d, b
 	ld e, c
 
-; check species
-	ld a, [wScriptVar] ; species we're looking for
-	ld b, [hl] ; species we have
+	; check species
+
+	ld a, [wScriptVar]
+	ld b, [hl]
 	cp b
-	jr nz, .notfound ; species doesn't match
+	jr nz, .notfound
 
-; check ID number
+	; check ID number
+
 	ld bc, MON_ID
-	add hl, bc ; now hl points to ID number
+	add hl, bc
 	ld a, [wPlayerID]
 	cp [hl]
-	jr nz, .notfound ; ID doesn't match
+	jr nz, .notfound
 	inc hl
 	ld a, [wPlayerID + 1]
 	cp [hl]
-	jr nz, .notfound ; ID doesn't match
+	jr nz, .notfound
 
-; 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.
+	; check OT
 
 	ld hl, wPlayerName
 
@@ -221,7 +226,7 @@
 	cp [hl]
 	jr nz, .notfound
 	cp "@"
-	jr z, .found ; reached end of string
+	jr z, .found
 	inc hl
 	inc de
 endr
--- a/mobile/mobile_12_2.asm
+++ b/mobile/mobile_12_2.asm
@@ -1,7 +1,16 @@
 MobileCheckOwnMonAnywhere:
-; Like CheckOwnMonAnywhere, but only check for species.
+; Like CheckOwnMonAnywhere, but only checks for species.
 ; 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]
 	and a
 	ret z
@@ -10,9 +19,13 @@
 	ld e, 0
 	ld hl, wPartyMon1Species
 	ld bc, wPartyMonOTs
-.asm_4a851
+
+	; Run .CheckMatch on each Pokémon in the party.
+
+.partymon
 	call .CheckMatch
 	ret c
+
 	push bc
 	ld bc, PARTYMON_STRUCT_LENGTH
 	add hl, bc
@@ -19,22 +32,27 @@
 	pop bc
 	call .AdvanceOTName
 	dec d
-	jr nz, .asm_4a851
+	jr nz, .partymon
+
+	; Run .CheckMatch on each Pokémon in the PC.
+
 	ld a, BANK(sBoxCount)
 	call OpenSRAM
 	ld a, [sBoxCount]
 	and a
-	jr z, .asm_4a888
+	jr z, .boxes
+
 	ld d, a
 	ld hl, sBoxMon1Species
 	ld bc, sBoxMonOTs
-.asm_4a873
+.openboxmon
 	call .CheckMatch
-	jr nc, .asm_4a87c
+	jr nc, .loop
+
 	call CloseSRAM
 	ret
 
-.asm_4a87c
+.loop
 	push bc
 	ld bc, BOXMON_STRUCT_LENGTH
 	add hl, bc
@@ -41,16 +59,23 @@
 	pop bc
 	call .AdvanceOTName
 	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
+
 	ld c, 0
-.asm_4a88d
+.box
+	; Don't search the current box again.
 	ld a, [wCurBox]
 	and $f
 	cp c
-	jr z, .asm_4a8d1
+	jr z, .loopbox
+
+	; Load the box.
+
 	ld hl, .BoxAddresses
 	ld b, 0
 	add hl, bc
@@ -61,10 +86,15 @@
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
+
+	; Number of monsters in the box
+
 	ld a, [hl]
 	and a
-	jr z, .asm_4a8d1
+	jr z, .loopbox
+
 	push bc
+
 	push hl
 	ld de, sBoxMons - sBoxCount
 	add hl, de
@@ -77,15 +107,18 @@
 	ld b, h
 	ld c, l
 	pop hl
+
 	ld d, a
-.asm_4a8ba
+
+.boxmon
 	call .CheckMatch
-	jr nc, .asm_4a8c4
+	jr nc, .loopboxmon
+
 	pop bc
 	call CloseSRAM
 	ret
 
-.asm_4a8c4
+.loopboxmon
 	push bc
 	ld bc, BOXMON_STRUCT_LENGTH
 	add hl, bc
@@ -92,24 +125,33 @@
 	pop bc
 	call .AdvanceOTName
 	dec d
-	jr nz, .asm_4a8ba
+	jr nz, .boxmon
 	pop bc
 
-.asm_4a8d1
+.loopbox
 	inc c
 	ld a, c
 	cp NUM_BOXES
-	jr c, .asm_4a88d
+	jr c, .box
+
 	call CloseSRAM
 	and a
 	ret
 
 .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 hl
 	push de
 	ld d, b
 	ld e, c
+
+	; check species
+
 	ld a, [wScriptVar]
 	ld b, [hl]
 	cp b