diff --git a/engine/pokemon/search.asm b/engine/pokemon/search.asm index f74c11875..db426e00d 100644 --- a/engine/pokemon/search.asm +++ b/engine/pokemon/search.asm @@ -51,6 +51,7 @@ CheckOwnMonAnywhere: ; 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 @@ CheckOwnMonAnywhere: 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 @@ CheckOwnMonAnywhere: 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 @@ CheckOwnMonAnywhere: call CheckOwnMon jr nc, .loop - ; found! call CloseSRAM ret @@ -101,6 +103,7 @@ CheckOwnMonAnywhere: jr nz, .openboxmon ; Run CheckOwnMon on each monster in the other 13 PC boxes. + .boxes call CloseSRAM @@ -113,6 +116,7 @@ CheckOwnMonAnywhere: jr z, .loopbox ; Load the box. + ld hl, SearchBoxAddressTable ld b, 0 add hl, bc @@ -125,6 +129,7 @@ CheckOwnMonAnywhere: ld l, a ; Number of monsters in the box + ld a, [hl] and a jr z, .loopbox @@ -150,7 +155,6 @@ CheckOwnMonAnywhere: call CheckOwnMon jr nc, .loopboxmon - ; found! pop bc call CloseSRAM ret @@ -171,13 +175,14 @@ CheckOwnMonAnywhere: cp NUM_BOXES jr c, .box - ; not found call CloseSRAM and a ret 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 @@ CheckOwnMon: ld d, b ld e, c -; check species - ld a, [wScriptVar] ; species we're looking for - ld b, [hl] ; species we have - cp b - jr nz, .notfound ; species doesn't match + ; check species + + ld a, [wScriptVar] + ld b, [hl] + cp b + 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 @@ rept NAME_LENGTH_JAPANESE - 2 ; should be PLAYER_NAME_LENGTH - 2 cp [hl] jr nz, .notfound cp "@" - jr z, .found ; reached end of string + jr z, .found inc hl inc de endr diff --git a/mobile/mobile_12_2.asm b/mobile/mobile_12_2.asm index 51463718b..c57bc8a78 100644 --- 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,47 +19,63 @@ MobileCheckOwnMonAnywhere: 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 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 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 @@ MobileCheckOwnMonAnywhere: 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,39 +107,51 @@ MobileCheckOwnMonAnywhere: 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 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