pokecrystal-board/engine/events/kurt.asm

397 lines
5.5 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
Kurt_PrintTextWhichApricorn:
2015-12-18 17:07:09 -08:00
ld hl, .Text
2015-10-16 10:35:43 -07:00
call PrintText
ret
.Text:
2015-10-16 10:35:43 -07:00
; Which APRICORN should I use?
text_far _WhichApricornText
text_end
2015-10-16 10:35:43 -07:00
2018-06-24 07:09:41 -07:00
Kurt_PrintTextHowMany:
2015-12-18 17:07:09 -08:00
ld hl, .Text
2015-10-16 10:35:43 -07:00
call PrintText
ret
.Text:
2015-10-16 10:35:43 -07:00
; How many should I make?
text_far _HowManyShouldIMakeText
text_end
2015-10-16 10:35:43 -07:00
2018-06-24 07:09:41 -07:00
SelectApricornForKurt:
call LoadStandardMenuHeader
2015-10-16 10:35:43 -07:00
ld c, $1
xor a
2015-11-23 13:04:53 -08:00
ld [wMenuScrollPosition], a
2015-10-24 07:34:19 -07:00
ld [wKurtApricornQuantity], a
2015-10-16 10:35:43 -07:00
.loop
push bc
call Kurt_PrintTextWhichApricorn
pop bc
ld a, c
2018-01-23 14:39:09 -08:00
ld [wMenuSelection], a
2015-10-16 10:35:43 -07:00
call Kurt_SelectApricorn
ld a, c
2018-01-23 14:39:09 -08:00
ld [wScriptVar], a
2015-10-16 10:35:43 -07:00
and a
jr z, .done
2018-01-23 14:39:09 -08:00
ld [wCurItem], a
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
2015-10-16 10:35:43 -07:00
ld c, a
push bc
call Kurt_PrintTextHowMany
call Kurt_SelectQuantity
pop bc
jr nc, .loop
2015-11-01 15:13:31 -08:00
ld a, [wItemQuantityChangeBuffer]
2015-10-24 07:34:19 -07:00
ld [wKurtApricornQuantity], a
2015-10-16 10:35:43 -07:00
call Kurt_GiveUpSelectedQuantityOfSelectedApricorn
.done
2015-10-25 19:26:53 -07:00
call Call_ExitMenu
2015-10-16 10:35:43 -07:00
ret
2018-06-24 07:09:41 -07:00
Kurt_SelectApricorn:
2017-12-24 09:47:30 -08:00
farcall FindApricornsInBag
2015-10-16 10:35:43 -07:00
jr c, .nope
ld hl, .MenuHeader
call CopyMenuHeader
2018-01-23 14:39:09 -08:00
ld a, [wMenuSelection]
2015-11-01 09:44:30 -08:00
ld [wMenuCursorBuffer], a
2015-10-16 10:35:43 -07:00
xor a
ldh [hBGMapMode], a
2015-11-17 12:54:03 -08:00
call InitScrollingMenu
2015-10-16 10:35:43 -07:00
call UpdateSprites
2015-12-17 19:31:16 -08:00
call ScrollingMenu
2015-12-15 15:59:49 -08:00
ld a, [wMenuJoypad]
2015-12-18 17:07:09 -08:00
cp B_BUTTON
2015-10-16 10:35:43 -07:00
jr z, .nope
2018-01-23 14:39:09 -08:00
ld a, [wMenuSelection]
2015-10-16 10:35:43 -07:00
cp -1
jr nz, .done
.nope
2018-01-11 22:40:20 -08:00
xor a ; FALSE
2015-10-16 10:35:43 -07:00
.done
ld c, a
ret
.MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 1, 1, 13, 10
dw .MenuData
2015-10-16 10:35:43 -07:00
db 1 ; default option
db 0 ; XXX
2015-10-16 10:35:43 -07:00
.MenuData:
db SCROLLINGMENU_DISPLAY_ARROWS ; flags
2015-10-16 10:35:43 -07:00
db 4, 7
db 1
2018-01-23 14:39:09 -08:00
dbw 0, wBuffer1
2015-11-03 16:43:47 -08:00
dba .Name
dba .Quantity
dba NULL
2015-10-16 10:35:43 -07:00
2018-06-24 07:09:41 -07:00
.Name:
2018-01-23 14:39:09 -08:00
ld a, [wMenuSelection]
2015-10-16 10:35:43 -07:00
and a
ret z
2017-12-24 09:47:30 -08:00
farcall PlaceMenuItemName
2015-10-16 10:35:43 -07:00
ret
2018-06-24 07:09:41 -07:00
.Quantity:
2018-01-23 14:39:09 -08:00
ld a, [wMenuSelection]
ld [wCurItem], a
2015-10-16 10:35:43 -07:00
call Kurt_GetQuantityOfApricorn
ret z
2015-11-01 15:13:31 -08:00
ld a, [wItemQuantityChangeBuffer]
2018-01-23 14:39:09 -08:00
ld [wMenuSelectionQuantity], a
2017-12-24 09:47:30 -08:00
farcall PlaceMenuItemQuantity
2015-10-16 10:35:43 -07:00
ret
2018-06-24 07:09:41 -07:00
Kurt_SelectQuantity:
2018-01-23 14:39:09 -08:00
ld a, [wCurItem]
ld [wMenuSelection], a
2015-10-16 10:35:43 -07:00
call Kurt_GetQuantityOfApricorn
jr z, .done
2015-11-01 15:13:31 -08:00
ld a, [wItemQuantityChangeBuffer]
ld [wItemQuantityBuffer], a
2015-10-16 10:35:43 -07:00
ld a, $1
2015-11-01 15:13:31 -08:00
ld [wItemQuantityChangeBuffer], a
ld hl, .MenuHeader
call LoadMenuHeader
2015-10-16 10:35:43 -07:00
.loop
xor a
ldh [hBGMapMode], a
2015-11-04 11:02:11 -08:00
call MenuBox
2015-10-16 10:35:43 -07:00
call UpdateSprites
call .PlaceApricornName
call PlaceApricornQuantity
2015-11-25 07:16:29 -08:00
call ApplyTilemap
2017-12-24 09:47:30 -08:00
farcall Kurt_SelectQuantity_InterpretJoypad
2015-10-16 10:35:43 -07:00
jr nc, .loop
push bc
call PlayClickSFX
pop bc
ld a, b
cp -1
jr z, .done
2015-11-01 15:13:31 -08:00
ld a, [wItemQuantityChangeBuffer]
ld [wItemQuantityChangeBuffer], a ; What is the point of this operation?
2015-10-16 10:35:43 -07:00
scf
.done
call CloseWindow
2015-10-16 10:35:43 -07:00
ret
.MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 6, 9, SCREEN_WIDTH - 1, 12
dw NULL
db -1 ; default option
db 0
2015-10-16 10:35:43 -07:00
2018-06-24 07:09:41 -07:00
.PlaceApricornName:
call MenuBoxCoord2Tile
2015-12-18 17:07:09 -08:00
ld de, SCREEN_WIDTH + 1
2015-10-16 10:35:43 -07:00
add hl, de
ld d, h
ld e, l
2017-12-24 09:47:30 -08:00
farcall PlaceMenuItemName
2015-10-16 10:35:43 -07:00
ret
2018-06-24 07:09:41 -07:00
PlaceApricornQuantity:
call MenuBoxCoord2Tile
2015-12-18 17:07:09 -08:00
ld de, 2 * SCREEN_WIDTH + 10
2015-10-16 10:35:43 -07:00
add hl, de
ld [hl], "×"
inc hl
2015-11-01 15:13:31 -08:00
ld de, wItemQuantityChangeBuffer
2015-10-16 10:35:43 -07:00
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
jp PrintNum
2018-06-24 07:09:41 -07:00
Kurt_GetQuantityOfApricorn:
2015-10-16 10:35:43 -07:00
push bc
2018-01-23 14:39:09 -08:00
ld hl, wNumItems
ld a, [wCurItem]
2015-10-16 10:35:43 -07:00
ld c, a
ld b, $0
.loop
inc hl
ld a, [hli]
cp -1
jr z, .done
cp c
jr nz, .loop
ld a, [hl]
add b
ld b, a
jr nc, .loop
ld b, -1
.done
ld a, b
sub 99
jr c, .done2
ld b, 99
.done2
ld a, b
2015-11-01 15:13:31 -08:00
ld [wItemQuantityChangeBuffer], a
2015-10-16 10:35:43 -07:00
and a
pop bc
ret
2018-06-24 07:09:41 -07:00
Kurt_GiveUpSelectedQuantityOfSelectedApricorn:
2018-01-23 14:39:09 -08:00
; Get the quantity of Apricorns of type [wCurItem]
2015-10-16 10:35:43 -07:00
; in the bag. Compatible with multiple stacks.
; Initialize the search.
push de
push bc
2018-01-23 14:39:09 -08:00
ld hl, wNumItems
ld a, [wCurItem]
2015-10-16 10:35:43 -07:00
ld c, a
ld e, $0
xor a
2018-01-23 14:39:09 -08:00
ld [wCurItemQuantity], a
2015-10-16 10:35:43 -07:00
ld a, -1
2015-12-18 17:07:09 -08:00
ld [wApricorns], a
2015-10-16 10:35:43 -07:00
2018-01-23 14:39:09 -08:00
; Search for [wCurItem] in the bag.
2015-10-16 10:35:43 -07:00
.loop1
; Increase the total count.
2018-01-23 14:39:09 -08:00
ld a, [wCurItemQuantity]
2015-10-16 10:35:43 -07:00
inc a
2018-01-23 14:39:09 -08:00
ld [wCurItemQuantity], a
2015-10-16 10:35:43 -07:00
; Get the index of the next item.
inc hl
ld a, [hli]
; If we've reached the end of the pocket, break.
cp -1
jr z, .okay1
; If we haven't found what we're looking for, continue.
cp c
jr nz, .loop1
; Increment the result counter and store the bag index of the match.
ld d, $0
push hl
2015-12-18 17:07:09 -08:00
ld hl, wApricorns
2015-10-16 10:35:43 -07:00
add hl, de
inc e
2018-01-23 14:39:09 -08:00
ld a, [wCurItemQuantity]
2015-10-16 10:35:43 -07:00
dec a
ld [hli], a
ld a, -1
ld [hl], a
pop hl
jr .loop1
.okay1
; How many stacks have we found?
ld a, e
and a
jr z, .done
dec a
jr z, .OnlyOne
2015-12-18 17:07:09 -08:00
ld hl, wApricorns
2015-10-16 10:35:43 -07:00
.loop2
ld a, [hl]
ld c, a
push hl
.loop3
inc hl
ld a, [hl]
cp -1
jr z, .okay2
ld b, a
ld a, c
call Kurt_GetAddressOfApricornQuantity
ld e, a
ld a, b
call Kurt_GetAddressOfApricornQuantity
sub e
jr z, .equal
jr c, .less
jr .loop3
.equal
ld a, c
sub b
jr nc, .loop3
.less
ld a, c
ld c, b
ld [hl], a
ld a, c
pop hl
ld [hl], a
push hl
jr .loop3
.okay2
pop hl
inc hl
ld a, [hl]
cp -1
jr nz, .loop2
.OnlyOne:
2015-12-18 17:07:09 -08:00
ld hl, wApricorns
2015-10-16 10:35:43 -07:00
.loop4
ld a, [hl]
cp -1
jr z, .done
push hl
2018-01-23 14:39:09 -08:00
ld [wCurItemQuantity], a
2015-10-16 10:35:43 -07:00
call Kurt_GetRidOfItem
pop hl
2015-11-01 15:13:31 -08:00
ld a, [wItemQuantityChangeBuffer]
2015-10-16 10:35:43 -07:00
and a
jr z, .done
push hl
ld a, [hli]
ld c, a
.loop5
ld a, [hli]
cp -1
jr z, .okay3
cp c
jr c, .loop5
dec a
dec hl
ld [hli], a
jr .loop5
.okay3
pop hl
inc hl
jr .loop4
.done
2015-11-01 15:13:31 -08:00
ld a, [wItemQuantityChangeBuffer]
2015-10-16 10:35:43 -07:00
and a
pop bc
pop de
ret
2018-06-24 07:09:41 -07:00
Kurt_GetAddressOfApricornQuantity:
2015-10-16 10:35:43 -07:00
push hl
push bc
2018-01-23 14:39:09 -08:00
ld hl, wNumItems
2015-10-16 10:35:43 -07:00
inc hl
ld c, a
ld b, $0
add hl, bc
add hl, bc
2015-10-16 10:35:43 -07:00
inc hl
ld a, [hl]
pop bc
pop hl
ret
2018-06-24 07:09:41 -07:00
Kurt_GetRidOfItem:
2015-10-16 10:35:43 -07:00
push bc
2018-01-23 14:39:09 -08:00
ld hl, wNumItems
ld a, [wCurItemQuantity]
2015-10-16 10:35:43 -07:00
ld c, a
ld b, $0
inc hl
add hl, bc
add hl, bc
2018-01-23 14:39:09 -08:00
ld a, [wCurItem]
2015-10-16 10:35:43 -07:00
ld c, a
ld a, [hli]
cp -1
jr z, .done
cp c
jr nz, .done
2015-11-01 15:13:31 -08:00
ld a, [wItemQuantityChangeBuffer]
2015-10-16 10:35:43 -07:00
ld c, a
ld a, [hl]
sub c
ld b, c
jr nc, .okay
add c
ld b, a
.okay
push bc
2018-01-23 14:39:09 -08:00
ld hl, wNumItems
2015-10-16 10:35:43 -07:00
ld a, b
2015-11-01 15:13:31 -08:00
ld [wItemQuantityChangeBuffer], a
2015-10-16 10:35:43 -07:00
call TossItem
pop bc
ld a, c
sub b
.done
2015-11-01 15:13:31 -08:00
ld [wItemQuantityChangeBuffer], a
2015-10-16 10:35:43 -07:00
pop bc
ret