pokecrystal-board/engine/pokemon/search.asm

271 lines
3.9 KiB
NASM
Raw Normal View History

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.
2018-01-23 14:39:09 -08:00
; Return the result in wScriptVar.
2015-12-06 19:36:09 -08:00
ld a, RAIKOU
2018-01-23 14:39:09 -08:00
ld [wScriptVar], a
2015-12-06 19:36:09 -08:00
call CheckOwnMonAnywhere
jr nc, .notexist
ld a, ENTEI
2018-01-23 14:39:09 -08:00
ld [wScriptVar], a
2015-12-06 19:36:09 -08:00
call CheckOwnMonAnywhere
jr nc, .notexist
ld a, SUICUNE
2018-01-23 14:39:09 -08:00
ld [wScriptVar], a
2015-12-06 19:36:09 -08:00
call CheckOwnMonAnywhere
jr nc, .notexist
; they exist
ld a, 1
2018-01-23 14:39:09 -08:00
ld [wScriptVar], a
2015-12-06 19:36:09 -08:00
ret
.notexist
xor a
2018-01-23 14:39:09 -08:00
ld [wScriptVar], a
2015-12-06 19:36:09 -08:00
ret
MonCheck:
Merge branch 'master' of https://github.com/pret/pokecrystal # Conflicts: # audio/engine.asm # constants/gfx_constants.asm # constants/map_data_constants.asm # constants/pokemon_data_constants.asm # constants/sprite_constants.asm # constants/wram_constants.asm # data/maps/data.asm # engine/battle/ai/scoring.asm # engine/battle/core.asm # engine/battle/effect_commands.asm # engine/battle/misc.asm # engine/battle_anims/getpokeballwobble.asm # engine/breeding.asm # engine/buy_sell_toss.asm # engine/decorations.asm # engine/events/battle_tower/battle_tower.asm # engine/events/battle_tower/rules.asm # engine/events/buena.asm # engine/events/bug_contest/contest_2.asm # engine/events/daycare.asm # engine/events/dratini.asm # engine/events/halloffame.asm # engine/events/happiness_egg.asm # engine/events/kurt.asm # engine/events/lucky_number.asm # engine/events/magnet_train.asm # engine/events/overworld.asm # engine/events/pokerus/pokerus.asm # engine/events/print_unown.asm # engine/events/print_unown_2.asm # engine/events/unown_walls.asm # engine/item_effects.asm # engine/link.asm # engine/mon_menu.asm # engine/player_object.asm # engine/routines/playslowcry.asm # engine/scripting.asm # engine/search.asm # engine/search2.asm # engine/specials.asm # engine/start_menu.asm # engine/timeset.asm # home/battle_vars.asm # home/map.asm # maps/GoldenrodUndergroundSwitchRoomEntrances.asm # maps/IlexForest.asm # maps/KrissHouse2F.asm # maps/Route39Barn.asm # mobile/mobile_12_2.asm # mobile/mobile_40.asm # mobile/mobile_5f.asm # wram.asm
2018-02-03 15:21:53 -08:00
; Check if the player owns any Pokémon of the species in wScriptVar.
2018-01-23 14:39:09 -08:00
; Return the result in wScriptVar.
2015-12-06 19:36:09 -08:00
call CheckOwnMonAnywhere
jr c, .exists
; doesn't exist
xor a
2018-01-23 14:39:09 -08:00
ld [wScriptVar], a
2015-12-06 19:36:09 -08:00
ret
.exists
ld a, 1
2018-01-23 14:39:09 -08:00
ld [wScriptVar], a
2015-12-06 19:36:09 -08:00
ret
CheckOwnMonAnywhere:
2018-01-23 14:39:09 -08:00
; Check if the player owns any monsters of the species in wScriptVar.
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.
2018-01-23 14:39:09 -08:00
ld a, [wPartyCount]
2015-12-06 19:36:09 -08:00
and a
ret z
ld d, a
ld e, 0
2018-01-23 14:39:09 -08:00
ld hl, wPartyMon1Species
ld bc, wPartyMonOT
2015-12-06 19:36:09 -08:00
; Run CheckOwnMon on each Pokémon in the party.
.partymon
call CheckOwnMon
ret c ; found!
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.
ld a, BANK(sBoxCount)
call GetSRAMBank
ld a, [sBoxCount]
and a
jr z, .boxes
ld d, a
ld hl, sBoxMon1Species
ld bc, sBoxMonOT
.openboxmon
call CheckOwnMon
jr nc, .loop
; found!
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.
.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.
2019-11-23 17:56:22 -08:00
ld hl, BoxAddressTable
2015-12-06 19:36:09 -08:00
ld b, 0
add hl, bc
add hl, bc
add hl, bc
2015-12-06 19:36:09 -08:00
ld a, [hli]
call GetSRAMBank
ld a, [hli]
ld h, [hl]
ld l, a
; Number of monsters in the box
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
ld de, sBoxMonOT - sBoxCount
add hl, de
ld b, h
ld c, l
pop hl
ld d, a
.boxmon
call CheckOwnMon
jr nc, .loopboxmon
; found!
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
; not found
call CloseSRAM
and a
ret
CheckOwnMon:
2015-12-06 19:36:09 -08:00
; Check if a Pokémon belongs to the player and is of a specific species.
; inputs:
; hl, pointer to PartyMonNSpecies
; bc, pointer to PartyMonNOT
2018-01-23 14:39:09 -08:00
; wScriptVar 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
; check species
2018-01-23 14:39:09 -08:00
ld a, [wScriptVar] ; species we're looking for
2015-12-06 19:36:09 -08:00
ld b, [hl] ; species we have
cp b
jr nz, .notfound ; species doesn't match
; check ID number
ld bc, MON_ID
add hl, bc ; now hl points to ID number
2018-01-23 14:39:09 -08:00
ld a, [wPlayerID]
2015-12-06 19:36:09 -08:00
cp [hl]
jr nz, .notfound ; ID doesn't match
inc hl
2018-01-23 14:39:09 -08:00
ld a, [wPlayerID + 1]
2015-12-06 19:36:09 -08:00
cp [hl]
jr nz, .notfound ; ID doesn't match
; 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.
2018-01-23 14:39:09 -08:00
ld hl, wPlayerName
2015-12-06 19:36:09 -08:00
rept NAME_LENGTH_JAPANESE + -2 ; should be PLAYER_NAME_LENGTH + -2
2015-12-06 19:36:09 -08:00
ld a, [de]
cp [hl]
jr nz, .notfound
cp "@"
jr z, .found ; reached end of string
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
2019-11-23 17:56:22 -08:00
BoxAddressTable:
2015-12-06 19:36:09 -08:00
dba sBox1
dba sBox2
dba sBox3
dba sBox4
dba sBox5
dba sBox6
dba sBox7
dba sBox8
dba sBox9
dba sBox10
dba sBox11
dba sBox12
dba sBox13
dba sBox14
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