summaryrefslogtreecommitdiff
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
parent6231351906960364a5ad2f34efefd809cceb0eb8 (diff)
Itemfinder routines and labels.
-rw-r--r--.gitignore4
-rw-r--r--data/text/common_2.asm4
-rw-r--r--engine/events/checkforhiddenitems.asm83
-rw-r--r--engine/events/itemfinder.asm50
-rw-r--r--home/map.asm10
-rwxr-xr-xitems/item_effects.asm6
-rw-r--r--main.asm9
-rw-r--r--wram.asm11
8 files changed, 160 insertions, 17 deletions
diff --git a/.gitignore b/.gitignore
index 5843a8f1..f1d1b6ed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,10 @@ pokesilver.txt
.*.swp
# swap files for gedit
*~
+# for vscode
+.vscode
+# osx files
+.DS_STORE
# compiled graphics
*.2bpp
diff --git a/data/text/common_2.asm b/data/text/common_2.asm
index c8b243be..9f6c9413 100644
--- a/data/text/common_2.asm
+++ b/data/text/common_2.asm
@@ -217,13 +217,13 @@ UnknownText_0x1c0a4e::
line "out!"
done
-UnknownText_0x1c0a77::
+_ItemfinderItemNearbyText::
text "Yes! ITEMFINDER"
line "indicates there's"
cont "an item nearby."
prompt
-UnknownText_0x1c0aa9::
+_ItemfinderNopeText::
text "Nope! ITEMFINDER"
line "isn't responding."
prompt
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
diff --git a/engine/events/itemfinder.asm b/engine/events/itemfinder.asm
new file mode 100644
index 00000000..3665187c
--- /dev/null
+++ b/engine/events/itemfinder.asm
@@ -0,0 +1,50 @@
+ItemFinder:
+ farcall CheckForHiddenItems
+ jr c, .found_something
+ ld hl, .Script_FoundNothing
+ jr .resume
+
+.found_something
+ ld hl, .Script_FoundSomething
+
+.resume
+ call QueueScript
+ ld a, $1
+ ld [wItemEffectSucceeded], a
+ ret
+
+.ItemfinderSound:
+ ld c, 4
+.sfx_loop
+ push bc
+ ld de, SFX_SECOND_PART_OF_ITEMFINDER
+ call WaitPlaySFX
+ ld de, SFX_TRANSACTION
+ call WaitPlaySFX
+ pop bc
+ dec c
+ jr nz, .sfx_loop
+ ret
+
+.Script_FoundSomething:
+ reloadmappart
+ special UpdateTimePals
+ callasm .ItemfinderSound
+ writetext .ItemfinderItemNearbyText
+ closetext
+ end
+
+.Script_FoundNothing:
+ reloadmappart
+ special UpdateTimePals
+ writetext .ItemfinderNopeText
+ closetext
+ end
+
+.ItemfinderItemNearbyText:
+ text_far _ItemfinderItemNearbyText
+ text_end
+
+.ItemfinderNopeText:
+ text_far _ItemfinderNopeText
+ text_end
diff --git a/home/map.asm b/home/map.asm
index 036969e1..cf60545b 100644
--- a/home/map.asm
+++ b/home/map.asm
@@ -859,11 +859,11 @@ ReadCoordEvents:: ; 24d0 (0:24d0)
ReadSignposts:: ; 24e7 (0:24e7)
ld a, [hli]
ld c, a
- ld [wd94b], a
+ ld [wCurMapBGEventCount], a
ld a, l
- ld [wd94c], a
+ ld [wCurMapBGEventsPointer], a
ld a, h
- ld [wd94d], a
+ ld [wCurMapBGEventsPointer + 1], a
ld a, c
and a
ret z
@@ -1981,7 +1981,7 @@ CheckFacingSign::
ld a, e
sub $4
ld e, a
- ld a, [wd94b]
+ ld a, [wCurMapBGEventCount]
and a
ret z
ld c, a
@@ -1995,7 +1995,7 @@ CheckFacingSign::
ret
CheckIfFacingTileCoordIsSign:: ; 2b8f (0:2b8f)
- ld hl, wd94c
+ ld hl, wCurMapBGEventsPointer
ld a, [hli]
ld h, [hl]
ld l, a
diff --git a/items/item_effects.asm b/items/item_effects.asm
index 9c494885..cdbaacc2 100755
--- a/items/item_effects.asm
+++ b/items/item_effects.asm
@@ -66,7 +66,7 @@ _DoItemEffect:: ; e7a6 (3:67a6)
dw XSpeed
dw XSpecial
dw CoinCase
- dw Itemfinder
+ dw ItemfinderEffect
dw PokeFlute
dw ExpShare
dw OldRod
@@ -2138,8 +2138,8 @@ UseRod:
farcall FishingRodFunction ; same bank
ret
-Itemfinder: ; f5ff (3:75ff)
- farcall ItemfinderFunction
+ItemfinderEffect: ; f5ff (3:75ff)
+ farcall ItemFinder
ret
Elixer: ; f606
diff --git a/main.asm b/main.asm
index 2366a2e4..12787429 100644
--- a/main.asm
+++ b/main.asm
@@ -626,8 +626,9 @@ INCLUDE "engine/events/misc_scripts.asm"
INCLUDE "engine/events/heal_machine_anim.asm"
INCLUDE "engine/events/whiteout.asm"
INCLUDE "engine/events/forced_movement.asm"
-ItemfinderFunction:
- dr $12947, $12e33
+INCLUDE "engine/events/itemfinder.asm"
+StartMenu:
+ dr $12994, $12e33
PartyMonItemName::
dr $12e33, $12fa0
@@ -1313,7 +1314,9 @@ SECTION "bank2d", ROMX, BANK[$2d]
dr $b4000, $b8000
SECTION "bank2e", ROMX, BANK[$2e]
- dr $b8000, $ba378
+ dr $b8000, $ba300
+
+INCLUDE "engine/events/checkforhiddenitems.asm"
TreeMonEncounter:
dr $ba378, $ba3a1
diff --git a/wram.asm b/wram.asm
index 203a78fa..de20b3b9 100644
--- a/wram.asm
+++ b/wram.asm
@@ -2437,7 +2437,11 @@ wPredefAddress:: dw ; cfde
wFarCallBCBuffer:: dw ; cfe0
wcfe2:: ds 1 ; cfe2
wcfe3:: ds 1 ; cfe3
-wFieldMoveSucceeded:: ds 1 ; cfe4
+
+wFieldMoveSucceeded::
+wItemEffectSucceeded::
+ db ; cfe4
+
wVramState:: ds 1
wcfe6:: ds 1 ; cfe6
wcfe7:: ds 1 ; cfe7
@@ -3394,9 +3398,8 @@ wCurMapWarpsPointer:: dw ; d946
wd948:: ds 1 ; d948
wd949:: ds 1 ; d949
wd94a:: ds 1 ; d94a
-wd94b:: ds 1 ; d94b
-wd94c:: ds 1 ; d94c
-wd94d:: ds 1 ; d94d
+wCurMapBGEventCount:: db ; d94b
+wCurMapBGEventsPointer:: dw ; d94c
wd94e:: ds 1 ; d94e
wd94f:: ds 1 ; d94f
wd950:: ds 1 ; d950