2018-06-24 14:09:41 +00:00
|
|
|
CheckForHiddenItems:
|
2018-01-12 04:50:44 +00:00
|
|
|
; Checks to see if there are hidden items on the screen that have not yet been found. If it finds one, returns carry.
|
2018-01-17 03:57:19 +00:00
|
|
|
call GetMapScriptsBank
|
2020-11-04 03:45:12 +00:00
|
|
|
ld [wCurMapScriptBank], a
|
|
|
|
; Get the coordinate of the bottom right corner of the screen, and load it in wBottomRightYCoord/wBottomRightXCoord.
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wXCoord]
|
2018-01-12 04:50:44 +00:00
|
|
|
add SCREEN_WIDTH / 4
|
2020-11-04 03:45:12 +00:00
|
|
|
ld [wBottomRightXCoord], a
|
2018-01-23 22:39:09 +00:00
|
|
|
ld a, [wYCoord]
|
2018-01-12 04:50:44 +00:00
|
|
|
add SCREEN_HEIGHT / 4
|
2020-11-04 03:45:12 +00:00
|
|
|
ld [wBottomRightYCoord], a
|
2018-01-17 03:57:19 +00:00
|
|
|
; Get the pointer for the first bg_event in the map...
|
2018-09-09 19:09:51 +00:00
|
|
|
ld hl, wCurMapBGEventsPointer
|
2018-01-12 04:50:44 +00:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
; ... before even checking to see if there are any BG events on this map.
|
2018-09-09 19:09:51 +00:00
|
|
|
ld a, [wCurMapBGEventCount]
|
2018-01-12 04:50:44 +00:00
|
|
|
and a
|
|
|
|
jr z, .nobgeventitems
|
2018-09-09 19:09:51 +00:00
|
|
|
; For i = 1:wCurMapBGEventCount...
|
2018-01-12 04:50:44 +00:00
|
|
|
.loop
|
2020-11-04 03:45:12 +00:00
|
|
|
; Store the counter in wRemainingBGEventCount, and store the bg_event pointer in the stack.
|
|
|
|
ld [wRemainingBGEventCount], a
|
2018-01-12 04:50:44 +00:00
|
|
|
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.
|
2020-11-04 03:45:12 +00:00
|
|
|
ld a, [wBottomRightYCoord]
|
2018-01-12 04:50:44 +00:00
|
|
|
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
|
2020-11-04 03:45:12 +00:00
|
|
|
ld a, [wBottomRightXCoord]
|
2018-01-12 04:50:44 +00:00
|
|
|
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.
|
2020-11-04 03:45:12 +00:00
|
|
|
ld a, [wCurMapScriptBank]
|
2021-01-09 20:16:05 +00:00
|
|
|
call GetFarWord
|
2020-11-04 03:45:12 +00:00
|
|
|
ld a, [wCurMapScriptBank]
|
2021-01-09 20:16:05 +00:00
|
|
|
call GetFarWord
|
2018-01-12 04:50:44 +00:00
|
|
|
ld d, h
|
|
|
|
ld e, l
|
|
|
|
ld b, CHECK_FLAG
|
|
|
|
call EventFlagAction
|
|
|
|
ld a, c
|
|
|
|
and a
|
|
|
|
jr z, .itemnearby
|
|
|
|
|
|
|
|
.next
|
2018-01-17 03:57:19 +00:00
|
|
|
; Restore the bg_event pointer and increment it by the length of a bg_event.
|
2018-01-12 04:50:44 +00:00
|
|
|
pop hl
|
2019-03-03 19:19:16 +00:00
|
|
|
ld bc, BG_EVENT_SIZE
|
2018-01-12 04:50:44 +00:00
|
|
|
add hl, bc
|
|
|
|
; Restore the BG event counter and decrement it. If it hits zero, there are no hidden items in range.
|
2020-11-04 03:45:12 +00:00
|
|
|
ld a, [wRemainingBGEventCount]
|
2018-01-12 04:50:44 +00:00
|
|
|
dec a
|
|
|
|
jr nz, .loop
|
|
|
|
|
|
|
|
.nobgeventitems
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.itemnearby
|
|
|
|
pop hl
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 14:09:41 +00:00
|
|
|
.GetFarByte:
|
2020-11-04 03:45:12 +00:00
|
|
|
ld a, [wCurMapScriptBank]
|
2018-01-12 04:50:44 +00:00
|
|
|
call GetFarByte
|
|
|
|
inc hl
|
|
|
|
ret
|