pokered/engine/events/hidden_items.asm

162 lines
2.9 KiB
NASM
Raw Normal View History

2016-06-12 00:24:04 +00:00
HiddenItems:
2014-05-22 22:13:20 +00:00
ld hl, HiddenItemCoords
2015-07-19 03:49:52 +00:00
call FindHiddenItemOrCoinsIndex
ld [wHiddenItemOrCoinsIndex], a
ld hl, wObtainedHiddenItemsFlags
ld a, [wHiddenItemOrCoinsIndex]
2014-05-22 22:13:20 +00:00
ld c, a
2015-07-20 03:45:34 +00:00
ld b, FLAG_TEST
predef FlagActionPredef
2014-05-22 22:13:20 +00:00
ld a, c
and a
ret nz
call EnableAutoTextBoxDrawing
2015-07-19 03:49:52 +00:00
ld a, 1
2014-09-13 07:50:56 +00:00
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
2015-07-19 03:49:52 +00:00
ld a, [wHiddenObjectFunctionArgument] ; item ID
ld [wd11e], a
2014-05-22 22:13:20 +00:00
call GetItemName
tx_pre_jump FoundHiddenItemText
2014-05-22 22:13:20 +00:00
INCLUDE "data/events/hidden_item_coords.asm"
2014-05-22 22:13:20 +00:00
FoundHiddenItemText::
text_far _FoundHiddenItemText
text_asm
2015-07-19 03:49:52 +00:00
ld a, [wHiddenObjectFunctionArgument] ; item ID
2014-05-22 22:13:20 +00:00
ld b, a
ld c, 1
call GiveItem
2016-06-12 04:30:05 +00:00
jr nc, .bagFull
2015-07-19 03:49:52 +00:00
ld hl, wObtainedHiddenItemsFlags
2015-07-23 13:07:12 +00:00
ld a, [wHiddenItemOrCoinsIndex]
2014-05-22 22:13:20 +00:00
ld c, a
2015-07-20 03:45:34 +00:00
ld b, FLAG_SET
predef FlagActionPredef
2015-07-19 08:46:12 +00:00
ld a, SFX_GET_ITEM_2
call PlaySoundWaitForCurrent
call WaitForSoundToFinish
2014-05-22 22:13:20 +00:00
jp TextScriptEnd
2016-06-12 04:30:05 +00:00
.bagFull
2014-05-22 22:13:20 +00:00
call WaitForTextScrollButtonPress ; wait for button press
xor a
2014-09-13 07:50:56 +00:00
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
2014-05-22 22:13:20 +00:00
ld hl, HiddenItemBagFullText
call PrintText
jp TextScriptEnd
HiddenItemBagFullText::
text_far _HiddenItemBagFullText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
HiddenCoins:
2014-05-22 22:13:20 +00:00
ld b, COIN_CASE
2015-08-13 05:14:31 +00:00
predef GetQuantityOfItemInBag
2014-05-22 22:13:20 +00:00
ld a, b
and a
ret z
ld hl, HiddenCoinCoords
2015-07-19 03:49:52 +00:00
call FindHiddenItemOrCoinsIndex
ld [wHiddenItemOrCoinsIndex], a
ld hl, wObtainedHiddenCoinsFlags
ld a, [wHiddenItemOrCoinsIndex]
2014-05-22 22:13:20 +00:00
ld c, a
2015-07-20 03:45:34 +00:00
ld b, FLAG_TEST
predef FlagActionPredef
2014-05-22 22:13:20 +00:00
ld a, c
and a
ret nz
xor a
ldh [hUnusedCoinsByte], a
ldh [hCoins], a
ldh [hCoins + 1], a
2015-07-19 03:49:52 +00:00
ld a, [wHiddenObjectFunctionArgument]
2014-05-22 22:13:20 +00:00
sub COIN
cp 10
jr z, .bcd10
cp 20
jr z, .bcd20
cp 40
2016-06-12 04:30:05 +00:00
jr z, .bcd20 ; should be bcd40
2014-05-22 22:13:20 +00:00
jr .bcd100
.bcd10
ld a, $10
ldh [hCoins + 1], a
2016-06-12 04:30:05 +00:00
jr .bcdDone
2014-05-22 22:13:20 +00:00
.bcd20
ld a, $20
ldh [hCoins + 1], a
2016-06-12 04:30:05 +00:00
jr .bcdDone
2014-05-22 22:13:20 +00:00
.bcd40 ; due to a typo, this is never used
ld a, $40
ldh [hCoins + 1], a
2016-06-12 04:30:05 +00:00
jr .bcdDone
2014-05-22 22:13:20 +00:00
.bcd100
ld a, $1
ldh [hCoins], a
2016-06-12 04:30:05 +00:00
.bcdDone
ld de, wPlayerCoins + 1
2015-07-17 08:21:40 +00:00
ld hl, hCoins + 1
2014-05-22 22:13:20 +00:00
ld c, $2
predef AddBCDPredef
2015-07-19 03:49:52 +00:00
ld hl, wObtainedHiddenCoinsFlags
2015-07-23 13:07:12 +00:00
ld a, [wHiddenItemOrCoinsIndex]
2014-05-22 22:13:20 +00:00
ld c, a
2015-07-20 03:45:34 +00:00
ld b, FLAG_SET
predef FlagActionPredef
2014-05-22 22:13:20 +00:00
call EnableAutoTextBoxDrawing
ld a, [wPlayerCoins]
cp $99
2016-06-12 04:30:05 +00:00
jr nz, .roomInCoinCase
2014-05-22 22:13:20 +00:00
ld a, [wPlayerCoins + 1]
cp $99
2016-06-12 04:30:05 +00:00
jr nz, .roomInCoinCase
tx_pre_id DroppedHiddenCoinsText
2014-05-22 22:13:20 +00:00
jr .done
2016-06-12 04:30:05 +00:00
.roomInCoinCase
tx_pre_id FoundHiddenCoinsText
2014-05-22 22:13:20 +00:00
.done
jp PrintPredefTextID
INCLUDE "data/events/hidden_coins.asm"
2014-05-22 22:13:20 +00:00
FoundHiddenCoinsText::
text_far _FoundHiddenCoinsText
sound_get_item_2
text_end
2014-05-22 22:13:20 +00:00
DroppedHiddenCoinsText::
text_far _FoundHiddenCoins2Text
sound_get_item_2
text_far _DroppedHiddenCoinsText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
FindHiddenItemOrCoinsIndex:
2015-07-19 03:49:52 +00:00
ld a, [wHiddenObjectY]
2014-05-22 22:13:20 +00:00
ld d, a
2015-07-19 03:49:52 +00:00
ld a, [wHiddenObjectX]
2014-05-22 22:13:20 +00:00
ld e, a
2015-08-31 02:38:41 +00:00
ld a, [wCurMap]
2014-05-22 22:13:20 +00:00
ld b, a
2015-07-19 03:49:52 +00:00
ld c, -1
2014-05-22 22:13:20 +00:00
.loop
inc c
ld a, [hli]
cp -1 ; end of the list?
2014-05-22 22:13:20 +00:00
ret z ; if so, we're done here
cp b
2015-07-19 03:49:52 +00:00
jr nz, .next1
2014-05-22 22:13:20 +00:00
ld a, [hli]
cp d
2015-07-19 03:49:52 +00:00
jr nz, .next2
2014-05-22 22:13:20 +00:00
ld a, [hli]
cp e
jr nz, .loop
ld a, c
ret
2015-07-19 03:49:52 +00:00
.next1
2014-05-22 22:13:20 +00:00
inc hl
2015-07-19 03:49:52 +00:00
.next2
2014-05-22 22:13:20 +00:00
inc hl
jr .loop