pokecrystal-board/engine/items/tmhm.asm

555 lines
8.1 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
TMHMPocket:
ld a, $1
ldh [hInMenu], a
call TMHM_PocketLoop
ld a, $0
ldh [hInMenu], a
ret nc
call PlaceHollowCursor
call WaitBGMap
ld a, [wCurItem]
dec a
ld [wCurItemQuantity], a
ld hl, wTMsHMs
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
ld [wItemQuantityBuffer], a
call .ConvertItemToTMHMNumber
scf
ret
2018-06-24 07:09:41 -07:00
.ConvertItemToTMHMNumber:
ld a, [wCurItem]
ld c, a
callfar GetNumberedTMHM
ld a, c
ld [wCurItem], a
ret
2018-06-24 07:09:41 -07:00
ConvertCurItemIntoCurTMHM:
ld a, [wCurItem]
ld c, a
callfar GetTMHMNumber
ld a, c
ld [wTempTMHM], a
ret
2018-06-24 07:09:41 -07:00
GetTMHMItemMove:
call ConvertCurItemIntoCurTMHM
predef GetTMHMMove
ret
2018-06-24 07:09:41 -07:00
AskTeachTMHM:
ld hl, wOptions
ld a, [hl]
push af
res NO_TEXT_SCROLL, [hl]
ld a, [wCurItem]
cp TM01
jr c, .NotTMHM
call GetTMHMItemMove
ld a, [wTempTMHM]
ld [wPutativeTMHMMove], a
call GetMoveName
call CopyName1
ld hl, BootedTMText ; Booted up a TM
ld a, [wCurItem]
cp HM01
jr c, .TM
ld hl, BootedHMText ; Booted up an HM
.TM:
call PrintText
ld hl, ContainedMoveText
call PrintText
call YesNoBox
.NotTMHM:
pop bc
ld a, b
ld [wOptions], a
ret
2018-06-24 07:09:41 -07:00
ChooseMonToLearnTMHM:
ld hl, wStringBuffer2
ld de, wTMHMMoveNameBackup
ld bc, MOVE_NAME_LENGTH - 1
call CopyBytes
call ClearBGPalettes
2018-06-24 07:09:41 -07:00
ChooseMonToLearnTMHM_NoRefresh:
farcall LoadPartyMenuGFX
farcall InitPartyMenuWithCancel
farcall InitPartyMenuGFX
ld a, PARTYMENUACTION_TEACH_TMHM
ld [wPartyMenuActionText], a
.loopback
farcall WritePartyMenuTilemap
farcall PrintPartyMenuText
call WaitBGMap
call SetPalettes
call DelayFrame
farcall PartyMenuSelect
push af
2018-01-23 14:39:09 -08:00
ld a, [wCurPartySpecies]
cp EGG
pop bc ; now contains the former contents of af
jr z, .egg
push bc
ld hl, wTMHMMoveNameBackup
ld de, wStringBuffer2
ld bc, MOVE_NAME_LENGTH - 1
call CopyBytes
pop af ; now contains the original contents of af
ret
.egg
2015-11-11 13:11:08 -08:00
push hl
push de
push bc
push af
ld de, SFX_WRONG
call PlaySFX
call WaitSFX
pop af
pop bc
pop de
pop hl
jr .loopback
2018-06-24 07:09:41 -07:00
TeachTMHM:
predef CanLearnTMHMMove
push bc
ld a, [wCurPartyMon]
ld hl, wPartyMonNicknames
call GetNick
pop bc
ld a, c
and a
jr nz, .compatible
push de
ld de, SFX_WRONG
call PlaySFX
pop de
ld hl, TMHMNotCompatibleText
call PrintText
jr .nope
.compatible
callfar KnowsMove
jr c, .nope
predef LearnMove
ld a, b
and a
jr z, .nope
farcall StubbedTrainerRankings_TMsHMsTaught
ld a, [wCurItem]
call IsHM
ret c
ld c, HAPPINESS_LEARNMOVE
callfar ChangeHappiness
call ConsumeTM
jr .learned_move
.nope
and a
ret
2015-11-11 13:11:08 -08:00
.didnt_use ; unreferenced
ld a, 2
ld [wItemEffectSucceeded], a
.learned_move
scf
ret
BootedTMText:
text_far _BootedTMText
text_end
BootedHMText:
text_far _BootedHMText
text_end
ContainedMoveText:
text_far _ContainedMoveText
text_end
TMHMNotCompatibleText:
text_far _TMHMNotCompatibleText
text_end
2018-06-24 07:09:41 -07:00
TMHM_PocketLoop:
xor a
ldh [hBGMapMode], a
call TMHM_DisplayPocketItems
ld a, 2
ld [w2DMenuCursorInitY], a
ld a, 7
ld [w2DMenuCursorInitX], a
ld a, 1
ld [w2DMenuNumCols], a
ld a, 5
sub d
inc a
cp 6
jr nz, .okay
dec a
.okay
ld [w2DMenuNumRows], a
ld a, $c
ld [w2DMenuFlags1], a
xor a
ld [w2DMenuFlags2], a
ld a, $20
ld [w2DMenuCursorOffsets], a
ld a, A_BUTTON | B_BUTTON | D_UP | D_DOWN | D_LEFT | D_RIGHT
ld [wMenuJoypadFilter], a
ld a, [wTMHMPocketCursor]
inc a
ld [wMenuCursorY], a
ld a, $1
ld [wMenuCursorX], a
jr TMHM_ShowTMMoveDescription
2018-06-24 07:09:41 -07:00
TMHM_JoypadLoop:
call TMHM_DisplayPocketItems
call StaticMenuJoypad
ld b, a
ld a, [wMenuCursorY]
dec a
ld [wTMHMPocketCursor], a
xor a
ldh [hBGMapMode], a
ld a, [w2DMenuFlags2]
bit 7, a
jp nz, TMHM_ScrollPocket
ld a, b
ld [wMenuJoypad], a
bit A_BUTTON_F, a
jp nz, TMHM_ChooseTMorHM
bit B_BUTTON_F, a
jp nz, TMHM_ExitPack
bit D_RIGHT_F, a
jp nz, TMHM_ExitPocket
bit D_LEFT_F, a
jp nz, TMHM_ExitPocket
2018-06-24 07:09:41 -07:00
TMHM_ShowTMMoveDescription:
call TMHM_CheckHoveringOverCancel
jp nc, TMHM_ExitPocket
hlcoord 0, 12
ld b, 4
ld c, SCREEN_WIDTH - 2
2019-04-08 05:15:10 -07:00
call Textbox
ld a, [wCurItem]
cp NUM_TMS + NUM_HMS + 1
jr nc, TMHM_JoypadLoop
ld [wTempTMHM], a
predef GetTMHMMove
ld a, [wTempTMHM]
ld [wCurSpecies], a
hlcoord 1, 14
call PrintMoveDescription
jp TMHM_JoypadLoop
2018-06-24 07:09:41 -07:00
TMHM_ChooseTMorHM:
call TMHM_PlaySFX_ReadText2
call CountTMsHMs ; This stores the count to wTempTMHM.
ld a, [wMenuCursorY]
dec a
ld b, a
ld a, [wTMHMPocketScrollPosition]
add b
ld b, a
ld a, [wTempTMHM]
cp b
jr z, _TMHM_ExitPack ; our cursor was hovering over CANCEL
2018-06-24 07:09:41 -07:00
TMHM_CheckHoveringOverCancel:
call TMHM_GetCurrentPocketPosition
ld a, [wMenuCursorY]
2015-11-11 13:11:08 -08:00
ld b, a
.loop
inc c
ld a, c
cp NUM_TMS + NUM_HMS + 1
jr nc, .okay
2015-11-11 13:11:08 -08:00
ld a, [hli]
and a
jr z, .loop
dec b
jr nz, .loop
ld a, c
.okay
ld [wCurItem], a
cp -1
ret
2018-06-24 07:09:41 -07:00
TMHM_ExitPack:
call TMHM_PlaySFX_ReadText2
2018-06-24 07:09:41 -07:00
_TMHM_ExitPack:
ld a, $2
ld [wMenuJoypad], a
and a
ret
2018-06-24 07:09:41 -07:00
TMHM_ExitPocket:
and a
ret
2018-06-24 07:09:41 -07:00
TMHM_ScrollPocket:
ld a, b
bit 7, a
jr nz, .skip
ld hl, wTMHMPocketScrollPosition
ld a, [hl]
and a
jp z, TMHM_JoypadLoop
dec [hl]
call TMHM_DisplayPocketItems
jp TMHM_ShowTMMoveDescription
.skip
call TMHM_GetCurrentPocketPosition
ld b, 5
.loop
inc c
ld a, c
cp NUM_TMS + NUM_HMS + 1
jp nc, TMHM_JoypadLoop
ld a, [hli]
and a
jr z, .loop
dec b
jr nz, .loop
ld hl, wTMHMPocketScrollPosition
inc [hl]
call TMHM_DisplayPocketItems
jp TMHM_ShowTMMoveDescription
2018-06-24 07:09:41 -07:00
TMHM_DisplayPocketItems:
ld a, [wBattleType]
cp BATTLETYPE_TUTORIAL
jp z, Tutorial_TMHMPocket
hlcoord 5, 2
lb bc, 10, 15
ld a, " "
call ClearBox
call TMHM_GetCurrentPocketPosition
ld d, $5
.loop2
2015-11-11 13:11:08 -08:00
inc c
ld a, c
cp NUM_TMS + NUM_HMS + 1
jr nc, .NotTMHM
ld a, [hli]
and a
jr z, .loop2
ld b, a
ld a, c
ld [wTempTMHM], a
push hl
push de
push bc
call TMHMPocket_GetCurrentLineCoord
push hl
ld a, [wTempTMHM]
cp NUM_TMS + 1
jr nc, .HM
ld de, wTempTMHM
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
call PrintNum
jr .okay
2015-11-11 13:11:08 -08:00
.HM:
push af
sub NUM_TMS
ld [wTempTMHM], a
ld [hl], "H"
inc hl
ld de, wTempTMHM
2019-11-03 17:17:04 -08:00
lb bc, PRINTNUM_LEFTALIGN | 1, 2
call PrintNum
pop af
ld [wTempTMHM], a
.okay
predef GetTMHMMove
ld a, [wNamedObjectIndexBuffer]
ld [wPutativeTMHMMove], a
call GetMoveName
pop hl
ld bc, 3
add hl, bc
push hl
call PlaceString
pop hl
pop bc
ld a, c
push bc
cp NUM_TMS + 1
jr nc, .hm2
ld bc, SCREEN_WIDTH + 9
add hl, bc
ld [hl], "×"
inc hl
ld a, "0" ; why are we doing this?
pop bc
push bc
ld a, b
ld [wTempTMHM], a
ld de, wTempTMHM
lb bc, 1, 2
call PrintNum
.hm2
pop bc
pop de
2015-11-11 13:11:08 -08:00
pop hl
dec d
jr nz, .loop2
jr .done
.NotTMHM:
call TMHMPocket_GetCurrentLineCoord
inc hl
inc hl
inc hl
2015-11-11 13:11:08 -08:00
push de
ld de, TMHM_CancelString
call PlaceString
2015-11-11 13:11:08 -08:00
pop de
.done
ret
2018-06-24 07:09:41 -07:00
TMHMPocket_GetCurrentLineCoord:
hlcoord 5, 0
ld bc, 2 * SCREEN_WIDTH
ld a, 6
sub d
ld e, a
; AddNTimes
.loop
add hl, bc
dec e
jr nz, .loop
2015-11-11 13:11:08 -08:00
ret
2020-10-05 17:10:01 -07:00
PlaceMoveNameAfterTMHMName: ; unreferenced
; Similar to a part of TMHM_DisplayPocketItems.
pop hl
ld bc, 3
add hl, bc
predef GetTMHMMove
ld a, [wTempTMHM]
ld [wPutativeTMHMMove], a
call GetMoveName
push hl
call PlaceString
2015-11-11 13:11:08 -08:00
pop hl
ret
TMHM_CancelString:
db "CANCEL@"
2018-06-24 07:09:41 -07:00
TMHM_GetCurrentPocketPosition:
ld hl, wTMsHMs
ld a, [wTMHMPocketScrollPosition]
ld b, a
inc b
2015-11-11 13:11:08 -08:00
ld c, 0
.loop
inc c
ld a, [hli]
and a
jr z, .loop
dec b
jr nz, .loop
dec hl
dec c
2015-11-11 13:11:08 -08:00
ret
2018-06-24 07:09:41 -07:00
Tutorial_TMHMPocket:
hlcoord 9, 3
push de
ld de, TMHM_CancelString
call PlaceString
pop de
ret
2018-06-24 07:09:41 -07:00
TMHM_PlaySFX_ReadText2:
push de
ld de, SFX_READ_TEXT_2
call PlaySFX
pop de
ret
2020-10-05 13:15:57 -07:00
VerboseReceiveTMHM: ; unreferenced
call ConvertCurItemIntoCurTMHM
call .CheckHaveRoomForTMHM
ld hl, .NoRoomTMHMText
jr nc, .print
ld hl, .ReceivedTMHMText
.print
jp PrintText
.NoRoomTMHMText:
text_far _NoRoomTMHMText
text_end
.ReceivedTMHMText:
text_far _ReceivedTMHMText
text_end
2018-06-24 07:09:41 -07:00
.CheckHaveRoomForTMHM:
ld a, [wTempTMHM]
2015-11-11 13:11:08 -08:00
dec a
ld hl, wTMsHMs
2015-11-11 13:11:08 -08:00
ld b, 0
ld c, a
add hl, bc
ld a, [hl]
inc a
2020-10-05 13:15:57 -07:00
cp MAX_ITEM_STACK + 1
ret nc
ld [hl], a
2015-11-11 13:11:08 -08:00
ret
2018-06-24 07:09:41 -07:00
ConsumeTM:
call ConvertCurItemIntoCurTMHM
ld a, [wTempTMHM]
dec a
ld hl, wTMsHMs
ld b, 0
ld c, a
add hl, bc
ld a, [hl]
and a
ret z
dec a
ld [hl], a
ret nz
ld a, [wTMHMPocketScrollPosition]
and a
ret z
dec a
ld [wTMHMPocketScrollPosition], a
ret
2018-06-24 07:09:41 -07:00
CountTMsHMs:
ld b, 0
ld c, NUM_TMS + NUM_HMS
ld hl, wTMsHMs
.loop
ld a, [hli]
and a
jr z, .skip
inc b
.skip
dec c
jr nz, .loop
ld a, b
ld [wTempTMHM], a
ret