mirror of
https://github.com/thornAvery/jep-hack.git
synced 2025-09-16 18:20:50 +12:00
120 lines
2.6 KiB
NASM
120 lines
2.6 KiB
NASM
CheckForHiddenItems:
|
|
; Checks to see if there are hidden items on the screen that have not yet been found. If it finds one, returns carry.
|
|
call GetMapScriptsBank
|
|
ld [wCurMapScriptBank], a
|
|
; Get the coordinate of the bottom right corner of the screen, and load it in wBottomRightYCoord/wBottomRightXCoord.
|
|
ld a, [wXCoord]
|
|
add SCREEN_WIDTH / 4
|
|
ld [wBottomRightXCoord], a
|
|
ld a, [wYCoord]
|
|
add SCREEN_HEIGHT / 4
|
|
ld [wBottomRightYCoord], a
|
|
; Get the pointer for the first bg_event in the map...
|
|
ld hl, wCurMapBGEventsPointer
|
|
ld a, [hli]
|
|
ld h, [hl]
|
|
ld l, a
|
|
; ... before even checking to see if there are any BG events on this map.
|
|
ld a, [wCurMapBGEventCount]
|
|
and a
|
|
jr z, .nobgeventitems
|
|
; For i = 1:wCurMapBGEventCount...
|
|
.loop
|
|
; Store the counter in wRemainingBGEventCount, and store the bg_event pointer in the stack.
|
|
ld [wRemainingBGEventCount], a
|
|
push hl
|
|
; Get the Y coordinate of the BG event.
|
|
call .GetFarByte
|
|
ld e, a
|
|
; Is the Y coordinate of the BG event on the screen? If not, go to the next BG event.
|
|
ld a, [wBottomRightYCoord]
|
|
sub e
|
|
jr c, .next
|
|
cp SCREEN_HEIGHT / 2
|
|
jr nc, .next
|
|
; Is the X coordinate of the BG event on the screen? If not, go to the next BG event.
|
|
call .GetFarByte
|
|
ld d, a
|
|
ld a, [wBottomRightXCoord]
|
|
sub d
|
|
jr c, .next
|
|
cp SCREEN_WIDTH / 2
|
|
jr nc, .next
|
|
; Is this BG event a hidden item? If not, go to the next BG event.
|
|
call .GetFarByte
|
|
cp BGEVENT_ITEM
|
|
jr nz, .next
|
|
; Has this item already been found? If not, set off the Itemfinder.
|
|
ld a, [wCurMapScriptBank]
|
|
call GetFarWord
|
|
ld a, [wCurMapScriptBank]
|
|
call GetFarWord
|
|
ld d, h
|
|
ld e, l
|
|
ld b, CHECK_FLAG
|
|
call EventFlagAction
|
|
ld a, c
|
|
and a
|
|
jr z, .itemnearby
|
|
|
|
.next
|
|
; Restore the bg_event pointer and increment it by the length of a bg_event.
|
|
pop hl
|
|
ld bc, BG_EVENT_SIZE
|
|
add hl, bc
|
|
; Restore the BG event counter and decrement it. If it hits zero, there are no hidden items in range.
|
|
ld a, [wRemainingBGEventCount]
|
|
dec a
|
|
jr nz, .loop
|
|
|
|
.nobgeventitems
|
|
xor a
|
|
ret
|
|
|
|
.itemnearby
|
|
pop hl
|
|
scf
|
|
ret
|
|
|
|
.GetFarByte:
|
|
ld a, [wCurMapScriptBank]
|
|
call GetFarByte
|
|
inc hl
|
|
ret
|
|
|
|
; from https://github.com/pret/pokecrystal/wiki/Smashing-rocks-has-a-chance-to-contain-items
|
|
RockItemEncounter:
|
|
ld hl, .RockItems
|
|
call Random
|
|
.loop
|
|
sub [hl]
|
|
jr c, .ok
|
|
inc hl
|
|
inc hl
|
|
jr .loop
|
|
|
|
.ok
|
|
ld a, [hli]
|
|
inc a
|
|
jr z, .done
|
|
ld a, [hli]
|
|
.done
|
|
ld [wScriptVar], a
|
|
ret
|
|
|
|
.RockItems:
|
|
db 1, MAX_REVIVE
|
|
db 2, DOME_FOSSIL
|
|
db 2, HELIX_FOSSIL
|
|
db 2, WING_FOSSIL
|
|
db 2, OLD_AMBER
|
|
db 2, CLUB_FOSSIL
|
|
db 4, STAR_PIECE
|
|
db 10, BIG_PEARL
|
|
db 18, ETHER
|
|
db 24, HARD_STONE
|
|
db 24, SOFT_SAND
|
|
db 48, PEARL
|
|
db 64, BRICK_PIECE
|
|
db -1
|