summaryrefslogtreecommitdiff
path: root/engine/events/checkforhiddenitems.asm
diff options
context:
space:
mode:
authorentrpntr <entrpntr@gmail.com>2020-03-14 15:12:13 -0400
committerentrpntr <entrpntr@gmail.com>2020-03-17 11:03:16 -0400
commit1e0807e4bfd5ca3e710c284cbbd4c0a50131baf3 (patch)
tree30c3108612fa8196fee6241070e21515ed111867 /engine/events/checkforhiddenitems.asm
parent6231351906960364a5ad2f34efefd809cceb0eb8 (diff)
Itemfinder routines and labels.
Diffstat (limited to 'engine/events/checkforhiddenitems.asm')
-rw-r--r--engine/events/checkforhiddenitems.asm83
1 files changed, 83 insertions, 0 deletions
diff --git a/engine/events/checkforhiddenitems.asm b/engine/events/checkforhiddenitems.asm
new file mode 100644
index 00000000..c71bd290
--- /dev/null
+++ b/engine/events/checkforhiddenitems.asm
@@ -0,0 +1,83 @@
+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 [wBuffer1], a
+; Get the coordinate of the bottom right corner of the screen, and load it in wBuffer3/wBuffer4.
+ ld a, [wXCoord]
+ add SCREEN_WIDTH / 4
+ ld [wBuffer4], a
+ ld a, [wYCoord]
+ add SCREEN_HEIGHT / 4
+ ld [wBuffer3], 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 wBuffer2, and store the bg_event pointer in the stack.
+ ld [wBuffer2], 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, [wBuffer3]
+ 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, [wBuffer4]
+ 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, [wBuffer1]
+ call GetFarHalfword
+ ld a, [wBuffer1]
+ call GetFarHalfword
+ 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, [wBuffer2]
+ dec a
+ jr nz, .loop
+
+.nobgeventitems
+ xor a
+ ret
+
+.itemnearby
+ pop hl
+ scf
+ ret
+
+.GetFarByte:
+ ld a, [wBuffer1]
+ call GetFarByte
+ inc hl
+ ret