aboutsummaryrefslogtreecommitdiffstats
path: root/engine/overworld/hidden_events.asm
diff options
context:
space:
mode:
authordannye <33dannye@gmail.com>2026-01-17 22:38:33 -0600
committerdannye <33dannye@gmail.com>2026-01-17 22:38:33 -0600
commitbc2354dd6626ce28bb9561547ed2107cfa56c18e (patch)
tree5902d4c3389253c76b7c3351e0d7dfecb551c28d /engine/overworld/hidden_events.asm
parentIdentify characters in `_OakSpeechText2B` and `Printer_GetMonStats.IDNo` (#144) (diff)
parentUse macros for `WildMonEncounterSlotChances` (#562) (diff)
downloadpokeyellow-bc2354dd6626ce28bb9561547ed2107cfa56c18e.tar.gz
pokeyellow-bc2354dd6626ce28bb9561547ed2107cfa56c18e.tar.xz
pokeyellow-bc2354dd6626ce28bb9561547ed2107cfa56c18e.zip
Merge branch 'master' of https://github.com/pret/pokered
Diffstat (limited to 'engine/overworld/hidden_events.asm')
-rw-r--r--engine/overworld/hidden_events.asm107
1 files changed, 107 insertions, 0 deletions
diff --git a/engine/overworld/hidden_events.asm b/engine/overworld/hidden_events.asm
new file mode 100644
index 00000000..b7c803e5
--- /dev/null
+++ b/engine/overworld/hidden_events.asm
@@ -0,0 +1,107 @@
+; if a hidden event was found, stores $00 in [hDidntFindAnyHiddenEvent], else stores $ff
+CheckForHiddenEvent::
+ ld hl, hItemAlreadyFound
+ xor a
+ ld [hli], a ; [hItemAlreadyFound]
+ ld [hli], a ; [hSavedMapTextPtr]
+ ld [hli], a ; [hSavedMapTextPtr + 1]
+ ld [hl], a ; [hDidntFindAnyHiddenEvent]
+ ld hl, HiddenEventMaps
+ ld de, 3
+ ld a, [wCurMap]
+ call IsInArray
+ jr nc, .noMatch
+ inc hl
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ push hl
+ ld hl, wHiddenEventFunctionArgument
+ xor a
+ ld [hli], a
+ ld [hli], a
+ ld [hl], a
+ pop hl
+.hiddenEventLoop
+ ld a, [hli]
+ cp $ff
+ jr z, .noMatch
+ ld [wHiddenEventY], a
+ ld b, a
+ ld a, [hli]
+ ld [wHiddenEventX], a
+ ld c, a
+ call CheckIfCoordsInFrontOfPlayerMatch
+ ldh a, [hCoordsInFrontOfPlayerMatch]
+ and a
+ jr z, .foundMatchingEvent
+ inc hl
+ inc hl
+ inc hl
+ inc hl
+ push hl
+ ld hl, wHiddenEventIndex
+ inc [hl]
+ pop hl
+ jr .hiddenEventLoop
+.foundMatchingEvent
+ ld a, [hli]
+ ld [wHiddenEventFunctionArgument], a
+ ld a, [hli]
+ ld [wHiddenEventFunctionRomBank], a
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ret
+.noMatch
+ ld a, $ff
+ ldh [hDidntFindAnyHiddenEvent], a
+ ret
+
+; checks if the coordinates in front of the player's sprite match Y in b and X in c
+; [hCoordsInFrontOfPlayerMatch] = $00 if they match, $ff if they don't match
+CheckIfCoordsInFrontOfPlayerMatch:
+ ld a, [wSpritePlayerStateData1FacingDirection]
+ cp SPRITE_FACING_UP
+ jr z, .facingUp
+ cp SPRITE_FACING_LEFT
+ jr z, .facingLeft
+ cp SPRITE_FACING_RIGHT
+ jr z, .facingRight
+; facing down
+ ld a, [wYCoord]
+ inc a
+ jr .upDownCommon
+.facingUp
+ ld a, [wYCoord]
+ dec a
+.upDownCommon
+ cp b
+ jr nz, .didNotMatch
+ ld a, [wXCoord]
+ cp c
+ jr nz, .didNotMatch
+ jr .matched
+.facingLeft
+ ld a, [wXCoord]
+ dec a
+ jr .leftRightCommon
+.facingRight
+ ld a, [wXCoord]
+ inc a
+.leftRightCommon
+ cp c
+ jr nz, .didNotMatch
+ ld a, [wYCoord]
+ cp b
+ jr nz, .didNotMatch
+.matched
+ xor a
+ jr .done
+.didNotMatch
+ ld a, $ff
+.done
+ ldh [hCoordsInFrontOfPlayerMatch], a
+ ret
+
+INCLUDE "data/events/hidden_events.asm"