pokecrystal-board/engine/overworld/scripting.asm

2473 lines
41 KiB
NASM
Raw Permalink Normal View History

; Event scripting commands.
2017-02-22 20:49:44 -08:00
EnableScriptMode::
push af
ld a, SCRIPT_READ
2018-01-23 14:39:09 -08:00
ld [wScriptMode], a
pop af
ret
2017-02-22 20:49:44 -08:00
ScriptEvents::
call StartScript
.loop
2018-01-23 14:39:09 -08:00
ld a, [wScriptMode]
ld hl, .modes
rst JumpTable
call CheckScript
jr nz, .loop
ret
2017-02-22 20:49:44 -08:00
.modes
dw EndScript
dw RunScriptCommand
dw WaitScriptMovement
dw WaitScript
2017-02-22 20:49:44 -08:00
EndScript:
call StopScript
ret
2017-02-22 20:49:44 -08:00
WaitScript:
call StopScript
2018-01-23 14:39:09 -08:00
ld hl, wScriptDelay
dec [hl]
ret nz
2020-10-22 18:25:40 -07:00
farcall UnfreezeAllObjects
ld a, SCRIPT_READ
2018-01-23 14:39:09 -08:00
ld [wScriptMode], a
call StartScript
ret
2017-02-22 20:49:44 -08:00
WaitScriptMovement:
call StopScript
ld hl, wStateFlags
bit 7, [hl]
ret nz
2020-10-22 18:25:40 -07:00
farcall UnfreezeAllObjects
ld a, SCRIPT_READ
2018-01-23 14:39:09 -08:00
ld [wScriptMode], a
call StartScript
ret
2017-02-22 20:49:44 -08:00
RunScriptCommand:
call GetScriptByte
ld hl, ScriptCommandTable
rst JumpTable
ret
ScriptCommandTable:
; entries correspond to *_command constants (see macros/scripts/events.asm)
2021-03-11 13:28:52 -08:00
table_width 2, ScriptCommandTable
dw Script_scall ; 00
dw Script_farscall ; 01
dw Script_memcall ; 02
dw Script_sjump ; 03
dw Script_farsjump ; 04
dw Script_memjump ; 05
dw Script_ifequal ; 06
dw Script_ifnotequal ; 07
dw Script_iffalse ; 08
dw Script_iftrue ; 09
dw Script_ifgreater ; 0a
dw Script_ifless ; 0b
dw Script_jumpstd ; 0c
dw Script_callstd ; 0d
dw Script_callasm ; 0e
dw Script_special ; 0f
dw Script_memcallasm ; 10
dw Script_checkmapscene ; 11
dw Script_setmapscene ; 12
dw Script_checkscene ; 13
dw Script_setscene ; 14
dw Script_setval ; 15
dw Script_addval ; 16
dw Script_random ; 17
dw Script_checkver ; 18
dw Script_readmem ; 19
dw Script_writemem ; 1a
dw Script_loadmem ; 1b
dw Script_readvar ; 1c
dw Script_writevar ; 1d
dw Script_loadvar ; 1e
dw Script_giveitem ; 1f
dw Script_takeitem ; 20
dw Script_checkitem ; 21
dw Script_givecoins ; 22
dw Script_takecoins ; 23
dw Script_checkcoins ; 24
dw Script_givechips ; 25
dw Script_takechips ; 26
dw Script_checkchips ; 27
dw Script_addcellnum ; 28
dw Script_delcellnum ; 29
dw Script_checkcellnum ; 2a
dw Script_checktime ; 2b
dw Script_checkpoke ; 2c
dw Script_givepoke ; 2d
dw Script_giveegg ; 2e
dw Script_givepokemail ; 2f
dw Script_checkpokemail ; 30
dw Script_checkevent ; 31
dw Script_clearevent ; 32
dw Script_setevent ; 33
dw Script_checkflag ; 34
dw Script_clearflag ; 35
dw Script_setflag ; 36
dw Script_wildon ; 37
dw Script_wildoff ; 38
dw Script_xycompare ; 39
dw Script_warpmod ; 3a
dw Script_blackoutmod ; 3b
dw Script_warp ; 3c
dw Script_getcoins ; 3d
dw Script_getchips ; 3e
dw Script_getnum ; 3f
dw Script_getmonname ; 40
dw Script_getitemname ; 41
dw Script_getcurlandmarkname ; 42
dw Script_gettrainername ; 43
dw Script_getstring ; 44
dw Script_itemnotify ; 45
dw Script_pocketisfull ; 46
dw Script_opentext ; 47
2024-02-10 15:16:00 -08:00
dw Script_reanchormap ; 48
dw Script_closetext ; 49
dw Script_writeunusedbyte ; 4a
dw Script_farwritetext ; 4b
dw Script_writetext ; 4c
dw Script_repeattext ; 4d
dw Script_yesorno ; 4e
dw Script_loadmenu ; 4f
dw Script_closewindow ; 50
dw Script_jumptextfaceplayer ; 51
dw Script_farjumptext ; 52
dw Script_jumptext ; 53
dw Script_waitbutton ; 54
dw Script_promptbutton ; 55
dw Script_pokepic ; 56
dw Script_closepokepic ; 57
dw Script__2dmenu ; 58
dw Script_verticalmenu ; 59
dw Script_loadpikachudata ; 5a
dw Script_randomwildmon ; 5b
dw Script_loadtemptrainer ; 5c
dw Script_loadwildmon ; 5d
dw Script_loadtrainer ; 5e
dw Script_startbattle ; 5f
dw Script_reloadmapafterbattle ; 60
dw Script_catchtutorial ; 61
dw Script_trainerortalkertext ; 62
dw Script_trainerortalkerflagaction ; 63
dw Script_winlosstext ; 64
dw Script_jumptrainerafterbattlescript ; 65
dw Script_endifjustbattled ; 66
dw Script_checkjustbattled ; 67
dw Script_setlasttalked ; 68
dw Script_applymovement ; 69
dw Script_applymovementlasttalked ; 6a
dw Script_faceplayer ; 6b
dw Script_faceobject ; 6c
dw Script_variablesprite ; 6d
dw Script_disappear ; 6e
dw Script_appear ; 6f
dw Script_follow ; 70
dw Script_stopfollow ; 71
dw Script_moveobject ; 72
dw Script_writeobjectxy ; 73
dw Script_loademote ; 74
dw Script_showemote ; 75
dw Script_turnobject ; 76
dw Script_follownotexact ; 77
dw Script_earthquake ; 78
dw Script_changemapblocks ; 79
dw Script_changeblock ; 7a
dw Script_reloadmap ; 7b
2024-02-10 15:16:00 -08:00
dw Script_refreshmap ; 7c
dw Script_writecmdqueue ; 7d
dw Script_delcmdqueue ; 7e
dw Script_playmusic ; 7f
dw Script_encountermusic ; 80
dw Script_musicfadeout ; 81
dw Script_playmapmusic ; 82
dw Script_dontrestartmapmusic ; 83
dw Script_cry ; 84
dw Script_playsound ; 85
dw Script_waitsfx ; 86
dw Script_warpsound ; 87
dw Script_specialsound ; 88
dw Script_autoinput ; 89
dw Script_newloadmap ; 8a
dw Script_pause ; 8b
dw Script_deactivatefacing ; 8c
dw Script_sdefer ; 8d
dw Script_warpcheck ; 8e
dw Script_stopandsjump ; 8f
dw Script_endcallback ; 90
dw Script_end ; 91
dw Script_reloadend ; 92
dw Script_endall ; 93
dw Script_pokemart ; 94
dw Script_elevator ; 95
dw Script_trade ; 96
dw Script_askforphonenumber ; 97
dw Script_phonecall ; 98
dw Script_hangup ; 99
dw Script_describedecoration ; 9a
dw Script_fruittree ; 9b
dw Script_specialphonecall ; 9c
dw Script_checkphonecall ; 9d
dw Script_verbosegiveitem ; 9e
dw Script_verbosegiveitemvar ; 9f
dw Script_swarm ; a0
dw Script_halloffame ; a1
dw Script_credits ; a2
dw Script_warpfacing ; a3
dw Script_battletowertext ; a4
dw Script_getlandmarkname ; a5
dw Script_gettrainerclassname ; a6
dw Script_getname ; a7
dw Script_wait ; a8
dw Script_checksave ; a9
dw Script_exitoverworld ; aa
dw Script_reloadmapafterviewmapmode ; ab
dw Script_talkerscript ; ac
2021-03-11 13:28:52 -08:00
assert_table_length NUM_EVENT_COMMANDS
2017-02-22 20:49:44 -08:00
StartScript:
2018-01-23 14:39:09 -08:00
ld hl, wScriptFlags
2013-07-04 02:37:20 -07:00
set SCRIPT_RUNNING, [hl]
ret
2017-02-22 20:49:44 -08:00
CheckScript:
2018-01-23 14:39:09 -08:00
ld hl, wScriptFlags
2013-07-04 02:37:20 -07:00
bit SCRIPT_RUNNING, [hl]
ret
2017-02-22 20:49:44 -08:00
StopScript:
2018-01-23 14:39:09 -08:00
ld hl, wScriptFlags
2013-07-04 02:37:20 -07:00
res SCRIPT_RUNNING, [hl]
ret
2017-02-22 20:49:44 -08:00
Script_callasm:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld b, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
ld a, b
2013-10-01 18:55:40 -07:00
rst FarCall
ret
2017-02-22 20:49:44 -08:00
Script_special:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2017-12-24 09:47:30 -08:00
farcall Special
ret
Script_memcallasm:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
ld b, [hl]
inc hl
ld a, [hli]
ld h, [hl]
ld l, a
ld a, b
2013-10-01 18:55:40 -07:00
rst FarCall
ret
2017-02-22 20:49:44 -08:00
Script_jumptextfaceplayer:
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld [wScriptTextBank], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wScriptTextAddr], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wScriptTextAddr + 1], a
ld b, BANK(JumpTextFacePlayerScript)
ld hl, JumpTextFacePlayerScript
2013-05-03 11:27:24 -07:00
jp ScriptJump
2017-02-22 20:49:44 -08:00
Script_jumptext:
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld [wScriptTextBank], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wScriptTextAddr], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wScriptTextAddr + 1], a
ld b, BANK(JumpTextScript)
ld hl, JumpTextScript
2013-05-03 11:27:24 -07:00
jp ScriptJump
2017-02-22 20:49:44 -08:00
JumpTextFacePlayerScript:
faceplayer
2017-02-22 20:49:44 -08:00
JumpTextScript:
2015-12-09 15:25:44 -08:00
opentext
repeattext -1, -1
2015-11-25 07:16:29 -08:00
waitbutton
closetext
end
2017-02-22 20:49:44 -08:00
Script_farjumptext:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wScriptTextBank], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wScriptTextAddr], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wScriptTextAddr + 1], a
ld b, BANK(JumpTextScript)
ld hl, JumpTextScript
2013-05-03 11:27:24 -07:00
jp ScriptJump
2017-02-22 20:49:44 -08:00
Script_writetext:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld b, a
call MapTextbox
ret
2017-02-22 20:49:44 -08:00
Script_farwritetext:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld b, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
call MapTextbox
ret
2017-02-22 20:49:44 -08:00
Script_repeattext:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
cp -1
2015-11-16 08:53:26 -08:00
jr nz, .done
ld a, l
cp -1
2015-11-16 08:53:26 -08:00
jr nz, .done
ld hl, wScriptTextBank
ld a, [hli]
ld b, a
ld a, [hli]
ld h, [hl]
ld l, a
call MapTextbox
ret
.done
ret
2017-02-22 20:49:44 -08:00
Script_waitbutton:
2015-11-25 07:16:29 -08:00
jp WaitButton
2019-11-03 09:48:54 -08:00
Script_promptbutton:
ldh a, [hOAMUpdate]
push af
ld a, $1
ldh [hOAMUpdate], a
call WaitBGMap
2019-11-03 09:48:54 -08:00
call PromptButton
pop af
ldh [hOAMUpdate], a
ret
2017-02-22 20:49:44 -08:00
Script_yesorno:
2013-12-03 23:49:12 -08:00
call YesNoBox
2015-11-25 07:16:29 -08:00
ld a, FALSE
2015-11-16 08:53:26 -08:00
jr c, .no
2015-11-25 07:16:29 -08:00
ld a, TRUE
.no
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
vc_hook Unknown_yesorno_ret
ret
Script_loadmenu:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
ld de, LoadMenuHeader
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
call Call_a_de
call UpdateSprites
ret
2017-02-22 20:49:44 -08:00
Script_closewindow:
call CloseWindow
call UpdateSprites
ret
2017-02-22 20:49:44 -08:00
Script_pokepic:
2013-02-28 13:36:21 -08:00
call GetScriptByte
and a
2014-05-21 13:21:46 -07:00
jr nz, .ok
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
2014-05-21 13:21:46 -07:00
.ok
2018-01-23 14:39:09 -08:00
ld [wCurPartySpecies], a
2017-12-24 09:47:30 -08:00
farcall Pokepic
ret
2017-02-22 20:49:44 -08:00
Script_closepokepic:
2017-12-24 09:47:30 -08:00
farcall ClosePokepic
ret
2017-02-22 20:49:44 -08:00
Script_verticalmenu:
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
2015-12-15 15:59:49 -08:00
ld hl, VerticalMenu
2013-10-01 18:55:40 -07:00
rst FarCall
2015-12-15 15:59:49 -08:00
ld a, [wMenuCursorY]
2014-05-21 13:21:46 -07:00
jr nc, .ok
xor a
2014-05-21 13:21:46 -07:00
.ok
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script__2dmenu:
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
2015-12-15 15:59:49 -08:00
ld hl, _2DMenu
2013-10-01 18:55:40 -07:00
rst FarCall
ld a, [wMenuCursorPosition]
2014-05-21 13:21:46 -07:00
jr nc, .ok
xor a
2014-05-21 13:21:46 -07:00
.ok
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_battletowertext:
push hl
call SpeechTextbox2bpp
call UpdateSprites
call ApplyTilemap
pop hl
2013-02-28 13:36:21 -08:00
call GetScriptByte
ret
2017-02-22 20:49:44 -08:00
Script_verbosegiveitem:
call Script_giveitem
call CurItemName
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer1
ld a, STRING_BUFFER_4
call CopyConvertedText
ld b, BANK(GiveItemScript)
ld de, GiveItemScript
jp ScriptCall
2017-02-22 20:49:44 -08:00
GiveItemScript:
writetext .ReceivedItemText
iffalse .Full
2015-11-25 07:16:29 -08:00
waitsfx
specialsound
2015-11-25 07:16:29 -08:00
waitbutton
itemnotify
end
.Full:
2019-11-03 09:48:54 -08:00
promptbutton
pocketisfull
end
.ReceivedItemText:
text_far _ReceivedItemText
text_end
Script_verbosegiveitemvar:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2019-01-24 18:15:30 -08:00
cp ITEM_FROM_MEM
2014-05-21 13:21:46 -07:00
jr nz, .ok
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
2014-05-21 13:21:46 -07:00
.ok
2018-01-23 14:39:09 -08:00
ld [wCurItem], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetVarAction
ld a, [de]
ld [wItemQuantityChange], a
2018-01-23 14:39:09 -08:00
ld hl, wNumItems
call ReceiveItem
2015-11-25 07:16:29 -08:00
ld a, TRUE
2014-05-21 13:21:46 -07:00
jr c, .ok2
xor a
2014-05-21 13:21:46 -07:00
.ok2
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
call CurItemName
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer1
ld a, STRING_BUFFER_4
call CopyConvertedText
ld b, BANK(GiveItemScript)
ld de, GiveItemScript
jp ScriptCall
2017-02-22 20:49:44 -08:00
Script_itemnotify:
call GetPocketName
call CurItemName
ld b, BANK(PutItemInPocketText)
ld hl, PutItemInPocketText
call MapTextbox
ret
2017-02-22 20:49:44 -08:00
Script_pocketisfull:
call GetPocketName
call CurItemName
ld b, BANK(PocketIsFullText)
ld hl, PocketIsFullText
call MapTextbox
ret
2017-02-22 20:49:44 -08:00
Script_specialsound:
2017-12-24 09:47:30 -08:00
farcall CheckItemPocket
ld a, [wItemAttributeValue]
2013-05-02 17:27:39 -07:00
cp TM_HM
ld de, SFX_GET_TM
jr z, .play
ld de, SFX_ITEM
.play
2013-10-08 10:10:36 -07:00
call PlaySFX
2013-05-02 17:27:39 -07:00
call WaitSFX
ret
2017-02-22 20:49:44 -08:00
GetPocketName:
2017-12-24 09:47:30 -08:00
farcall CheckItemPocket
ld a, [wItemAttributeValue]
dec a
2018-02-27 05:24:29 -08:00
ld hl, ItemPocketNames
2018-01-16 14:27:50 -08:00
maskbits NUM_POCKETS
add a
ld e, a
ld d, 0
add hl, de
ld a, [hli]
ld d, [hl]
ld e, a
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer3
call CopyName2
ret
2018-02-27 05:24:29 -08:00
INCLUDE "data/items/pocket_names.asm"
2017-02-22 20:49:44 -08:00
CurItemName:
2018-01-23 14:39:09 -08:00
ld a, [wCurItem]
ld [wNamedObjectIndex], a
call GetItemName
ret
2017-02-22 20:49:44 -08:00
PutItemInPocketText:
text_far _PutItemInPocketText
text_end
2017-02-22 20:49:44 -08:00
PocketIsFullText:
text_far _PocketIsFullText
text_end
2017-02-22 20:49:44 -08:00
Script_pokemart:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld c, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld b, a
2017-12-24 09:47:30 -08:00
farcall OpenMartDialog
ret
2017-02-22 20:49:44 -08:00
Script_elevator:
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld b, a
2017-12-24 09:47:30 -08:00
farcall Elevator
ret c
2015-11-25 07:16:29 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_trade:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2017-12-24 09:47:30 -08:00
farcall NPCTrade
ret
2017-02-22 20:49:44 -08:00
Script_phonecall:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld b, a
2017-12-24 09:47:30 -08:00
farcall PhoneCall
ret
2017-02-22 20:49:44 -08:00
Script_hangup:
2017-12-24 09:47:30 -08:00
farcall HangUp
ret
2017-02-22 20:49:44 -08:00
Script_askforphonenumber:
2013-12-03 23:49:12 -08:00
call YesNoBox
2015-11-16 08:53:26 -08:00
jr c, .refused
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld c, a
2017-12-24 09:47:30 -08:00
farcall AddPhoneNumber
2015-11-16 08:53:26 -08:00
jr c, .phonefull
2018-01-11 22:40:20 -08:00
xor a ; PHONE_CONTACT_GOT
2015-11-16 08:53:26 -08:00
jr .done
.phonefull
2018-01-11 22:40:20 -08:00
ld a, PHONE_CONTACTS_FULL
2015-11-16 08:53:26 -08:00
jr .done
.refused
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-11 22:40:20 -08:00
ld a, PHONE_CONTACT_REFUSED
.done
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_describedecoration:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld b, a
2017-12-24 09:47:30 -08:00
farcall DescribeDecoration
ld h, d
ld l, e
2013-05-03 11:27:24 -07:00
jp ScriptJump
2017-02-22 20:49:44 -08:00
Script_fruittree:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wCurFruitTree], a
2013-05-03 12:40:45 -07:00
ld b, BANK(FruitTreeScript)
ld hl, FruitTreeScript
2013-05-03 11:27:24 -07:00
jp ScriptJump
2017-02-22 20:49:44 -08:00
Script_swarm:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld c, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2017-12-24 09:47:30 -08:00
farcall StoreSwarmMapIndices
ret
Script_trainerortalkertext:
2013-02-28 13:36:21 -08:00
call GetScriptByte
cp TRAINERORTALKERTEXT_TALKER
ld hl, wTempTalkerTextOrScriptPointer
jr z, .next
ld c, a
ld b, 0
ld hl, wSeenTextPointer
add hl, bc
2015-12-26 18:59:03 -08:00
add hl, bc
.next
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wSeenTrainerOrTalkerBank]
ld b, a
call MapTextbox
ret
Script_talkerscript:
ld hl, wTempTalkerTextOrScriptPointer
ld a, [hli]
ld d, [hl]
ld e, a
ld a, [wSeenTrainerOrTalkerBank]
ld b, a
jp ScriptCall
Script_jumptrainerafterbattlescript:
2015-12-18 17:07:09 -08:00
ld hl, wScriptAfterPointer
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wSeenTrainerOrTalkerBank]
ld b, a
2013-05-03 11:27:24 -07:00
jp ScriptJump
Script_trainerortalkerflagaction:
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ld hl, wTempTrainerEventFlag ; wTempTalkerEventFlag
ld e, [hl]
inc hl
ld d, [hl]
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld b, a
2013-08-23 12:48:26 -07:00
call EventFlagAction
ld a, c
and a
ret z
2015-11-25 07:16:29 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_winlosstext:
ld hl, wWinTextPointer
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [hli], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [hli], a
2017-02-22 20:49:44 -08:00
ld hl, wLossTextPointer
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [hli], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [hli], a
ret
2018-02-02 18:09:17 -08:00
Script_endifjustbattled:
2015-11-25 07:16:29 -08:00
ld a, [wRunningTrainerBattleScript]
and a
ret z
2013-07-04 02:37:20 -07:00
jp Script_end
2018-02-02 18:09:17 -08:00
Script_checkjustbattled:
2015-11-25 07:16:29 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2015-11-25 07:16:29 -08:00
ld a, [wRunningTrainerBattleScript]
and a
ret nz
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_encountermusic:
2018-01-23 14:39:09 -08:00
ld a, [wOtherTrainerClass]
ld e, a
2017-12-24 09:47:30 -08:00
farcall PlayTrainerEncounterMusic
ret
2017-02-22 20:49:44 -08:00
Script_playmapmusic:
2014-05-21 13:21:46 -07:00
call PlayMapMusic
ret
2017-02-22 20:49:44 -08:00
Script_playmusic:
2014-05-21 13:21:46 -07:00
ld de, MUSIC_NONE
2013-10-08 10:21:15 -07:00
call PlayMusic
xor a
2018-01-23 14:39:09 -08:00
ld [wMusicFade], a
call MaxVolume
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2013-10-08 10:21:15 -07:00
call PlayMusic
ret
2017-02-22 20:49:44 -08:00
Script_musicfadeout:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wMusicFadeID], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wMusicFadeID + 1], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2021-11-23 17:37:18 -08:00
and ~(1 << MUSIC_FADE_IN_F)
2018-01-23 14:39:09 -08:00
ld [wMusicFade], a
ret
2017-02-22 20:49:44 -08:00
Script_playsound:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2013-10-08 10:10:36 -07:00
call PlaySFX
ret
2017-02-22 20:49:44 -08:00
Script_waitsfx:
2013-05-02 17:27:39 -07:00
call WaitSFX
ret
2017-02-22 20:49:44 -08:00
Script_warpsound:
2017-12-24 09:47:30 -08:00
farcall GetWarpSFX
2013-10-08 10:10:36 -07:00
call PlaySFX
ret
2017-02-22 20:49:44 -08:00
Script_cry:
2013-02-28 13:36:21 -08:00
call GetScriptByte
push af
2013-02-28 13:36:21 -08:00
call GetScriptByte
pop af
and a
2014-07-18 10:25:03 -07:00
jr nz, .ok
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
2014-07-18 10:25:03 -07:00
.ok
call PlayMonCry
ret
GetScriptObject:
and a ; PLAYER?
ret z
cp LAST_TALKED
ret z
dec a
ret
2017-02-22 20:49:44 -08:00
Script_setlasttalked:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
ldh [hLastTalked], a
ret
2017-02-22 20:49:44 -08:00
Script_applymovement:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
ld c, a
2017-02-22 20:49:44 -08:00
ApplyMovement:
push bc
ld a, c
2020-10-22 18:25:40 -07:00
farcall FreezeAllOtherObjects
pop bc
2015-11-11 20:38:57 -08:00
push bc
2020-10-22 18:25:40 -07:00
call UnfreezeFollowerObject
pop bc
2015-11-11 20:38:57 -08:00
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld b, a
call GetMovementData
ret c
2015-11-11 20:38:57 -08:00
2013-07-04 02:37:20 -07:00
ld a, SCRIPT_WAIT_MOVEMENT
2018-01-23 14:39:09 -08:00
ld [wScriptMode], a
2013-07-04 02:37:20 -07:00
call StopScript
ret
2020-10-22 18:25:40 -07:00
UnfreezeFollowerObject:
farcall _UnfreezeFollowerObject
ret
Script_applymovementlasttalked:
; apply movement to last talked
ldh a, [hLastTalked]
ld c, a
jp ApplyMovement
2017-02-22 20:49:44 -08:00
Script_faceplayer:
ldh a, [hLastTalked]
and a
ret z
ld d, $0
ldh a, [hLastTalked]
ld e, a
2017-12-24 09:47:30 -08:00
farcall GetRelativeFacing
ld a, d
add a
2015-12-26 18:59:03 -08:00
add a
ld e, a
ldh a, [hLastTalked]
ld d, a
call ApplyObjectFacing
ret
Script_faceobject:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
cp LAST_TALKED
jr c, .ok
ldh a, [hLastTalked]
.ok
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
cp LAST_TALKED
jr nz, .ok2
ldh a, [hLastTalked]
.ok2
ld d, a
push de
2017-12-24 09:47:30 -08:00
farcall GetRelativeFacing
pop bc
ret c
ld a, d
add a
2015-12-26 18:59:03 -08:00
add a
ld e, a
ld d, c
call ApplyObjectFacing
ret
Script_turnobject:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
cp LAST_TALKED
jr nz, .ok
ldh a, [hLastTalked]
.ok
ld d, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
add a
2015-12-26 18:59:03 -08:00
add a
ld e, a
call ApplyObjectFacing
ret
ApplyObjectFacing:
ld a, d
push de
2015-11-02 08:15:32 -08:00
call CheckObjectVisibility
2015-11-16 08:53:26 -08:00
jr c, .not_visible
ld hl, OBJECT_SPRITE
add hl, bc
ld a, [hl]
push bc
2015-11-04 17:20:14 -08:00
call DoesSpriteHaveFacings
pop bc
2015-11-04 17:20:14 -08:00
jr c, .not_visible ; STILL_SPRITE
ld hl, OBJECT_FLAGS1
add hl, bc
bit FIXED_FACING_F, [hl]
2015-11-16 08:53:26 -08:00
jr nz, .not_visible
pop de
ld a, e
call SetSpriteDirection
ld hl, wStateFlags
bit 6, [hl]
2015-11-16 08:53:26 -08:00
jr nz, .text_state
2015-11-02 09:54:27 -08:00
call .DisableTextTiles
.text_state
call UpdateSprites
ret
2015-11-02 09:54:27 -08:00
.not_visible
pop de
scf
ret
2017-02-22 20:49:44 -08:00
.DisableTextTiles:
2024-02-10 15:16:00 -08:00
call LoadOverworldTilemap
hlcoord 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
2015-11-02 09:54:27 -08:00
.loop
res 7, [hl]
inc hl
dec bc
ld a, b
or c
2015-11-16 08:53:26 -08:00
jr nz, .loop
ret
2017-02-22 20:49:44 -08:00
Script_variablesprite:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
ld d, 0
2018-01-23 14:39:09 -08:00
ld hl, wVariableSprites
add hl, de
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [hl], a
ret
2017-02-22 20:49:44 -08:00
Script_appear:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
2020-06-22 13:30:13 -07:00
call UnmaskCopyMapObjectStruct
ldh a, [hMapObjectIndex]
ld b, 0 ; clear
call ApplyEventActionAppearDisappear
ret
2017-02-22 20:49:44 -08:00
Script_disappear:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
cp LAST_TALKED
jr nz, .ok
ldh a, [hLastTalked]
.ok
call DeleteObjectStruct
ldh a, [hMapObjectIndex]
ld b, 1 ; set
call ApplyEventActionAppearDisappear
call UpdateActiveSprites
ret
2017-02-22 20:49:44 -08:00
ApplyEventActionAppearDisappear:
push bc
call GetMapObject
ld hl, MAPOBJECT_EVENT_FLAG
add hl, bc
pop bc
ld e, [hl]
inc hl
ld d, [hl]
2023-12-28 10:53:34 -08:00
ld a, HIGH(ALWAYS_SHOWN) ; HIGH(ALWAYS_HIDDEN)
cp d
2023-12-28 10:53:34 -08:00
jr z, .not_a_flag
2013-08-23 12:48:26 -07:00
call EventFlagAction
ret
2023-12-28 10:53:34 -08:00
.not_a_flag
xor a
ret
2017-02-22 20:49:44 -08:00
Script_follow:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
ld b, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
ld c, a
2017-12-24 09:47:30 -08:00
farcall StartFollow
ret
2017-02-22 20:49:44 -08:00
Script_stopfollow:
2017-12-24 09:47:30 -08:00
farcall StopFollow
ret
Script_moveobject:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
ld b, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2015-10-24 07:34:19 -07:00
add 4
ld d, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2015-10-24 07:34:19 -07:00
add 4
ld e, a
2017-12-24 09:47:30 -08:00
farcall CopyDECoordsToMapObject
ret
Script_writeobjectxy:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
cp LAST_TALKED
jr nz, .ok
ldh a, [hLastTalked]
.ok
ld b, a
farcall WriteObjectXY
ret
2017-02-22 20:49:44 -08:00
Script_follownotexact:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
ld b, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
ld c, a
2017-12-24 09:47:30 -08:00
farcall FollowNotExact
ret
2017-02-22 20:49:44 -08:00
Script_loademote:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2019-01-24 18:15:30 -08:00
cp EMOTE_FROM_MEM
2015-11-16 08:53:26 -08:00
jr nz, .not_var_emote
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
2015-10-24 07:34:19 -07:00
.not_var_emote
ld c, a
2017-12-24 09:47:30 -08:00
farcall LoadEmote
ret
2017-02-22 20:49:44 -08:00
Script_showemote:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptObject
cp LAST_TALKED
jr z, .ok
ldh [hLastTalked], a
.ok
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wScriptDelay], a
ld b, BANK(ShowEmoteScript)
ld de, ShowEmoteScript
jp ScriptCall
2017-02-22 20:49:44 -08:00
ShowEmoteScript:
2019-01-24 18:15:30 -08:00
loademote EMOTE_FROM_MEM
applymovementlasttalked .Show
pause 0
applymovementlasttalked .Hide
end
.Show:
show_emote
2016-05-14 09:28:00 -07:00
step_sleep 1
step_end
.Hide:
hide_emote
2016-05-14 09:28:00 -07:00
step_sleep 1
step_end
2017-02-22 20:49:44 -08:00
Script_earthquake:
ld hl, EarthquakeMovement
2017-12-09 16:41:03 -08:00
ld de, wEarthquakeMovementDataBuffer
ld bc, EarthquakeMovement.End - EarthquakeMovement
call CopyBytes
2013-02-28 13:36:21 -08:00
call GetScriptByte
2017-12-09 16:41:03 -08:00
ld [wEarthquakeMovementDataBuffer + 1], a
and %00111111
ld [wEarthquakeMovementDataBuffer + 3], a
2015-10-24 07:34:19 -07:00
ld b, BANK(.script)
ld de, .script
jp ScriptCall
2017-02-22 20:49:44 -08:00
.script
2017-12-09 16:41:03 -08:00
applymovement PLAYER, wEarthquakeMovementDataBuffer
end
2017-02-22 20:49:44 -08:00
EarthquakeMovement:
2015-11-11 20:38:57 -08:00
step_shake 16 ; the 16 gets overwritten with the script byte
step_sleep 16 ; the 16 gets overwritten with the lower 6 bits of the script byte
step_end
.End
2017-02-22 20:49:44 -08:00
Script_loadpikachudata:
ld a, PIKACHU
2018-01-23 14:39:09 -08:00
ld [wTempWildMonSpecies], a
ld a, 5
2018-01-23 14:39:09 -08:00
ld [wCurPartyLevel], a
ret
2017-02-22 20:49:44 -08:00
Script_randomwildmon:
xor a
2015-11-25 07:16:29 -08:00
ld [wBattleScriptFlags], a
ret
Script_loadtemptrainer:
2015-10-24 07:34:19 -07:00
ld a, (1 << 7) | 1
2015-11-25 07:16:29 -08:00
ld [wBattleScriptFlags], a
ld a, [wTempTrainerClass]
2018-01-23 14:39:09 -08:00
ld [wOtherTrainerClass], a
ld a, [wTempTrainerID]
2018-01-23 14:39:09 -08:00
ld [wOtherTrainerID], a
ret
2017-02-22 20:49:44 -08:00
Script_loadwildmon:
2015-10-24 07:34:19 -07:00
ld a, (1 << 7)
2015-11-25 07:16:29 -08:00
ld [wBattleScriptFlags], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wTempWildMonSpecies], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wCurPartyLevel], a
ret
2017-02-22 20:49:44 -08:00
Script_loadtrainer:
2015-10-24 07:34:19 -07:00
ld a, (1 << 7) | 1
2015-11-25 07:16:29 -08:00
ld [wBattleScriptFlags], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wOtherTrainerClass], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wOtherTrainerID], a
ret
2017-02-22 20:49:44 -08:00
Script_startbattle:
2023-08-29 09:33:20 -07:00
call DisableOverworldHUD
ld a, FALSE
ld [wText2bpp], a
ld hl, wDisplaySecondarySprites
res SECONDARYSPRITES_SPACES_LEFT_F, [hl]
call BufferScreen
predef StartBattle
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
2021-11-23 17:37:18 -08:00
and ~BATTLERESULT_BITMASK
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_catchtutorial:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wBattleType], a
call BufferScreen
2017-12-24 09:47:30 -08:00
farcall CatchTutorial
jp Script_reloadmap
2017-02-22 20:49:44 -08:00
Script_reloadmapafterbattle:
2015-11-25 07:16:29 -08:00
ld hl, wBattleScriptFlags
ld d, [hl]
2018-04-05 08:44:02 -07:00
ld [hl], 0
ld a, TRUE
ld [wText2bpp], a
2015-10-24 07:34:19 -07:00
ld a, [wBattleResult]
2021-11-23 17:37:18 -08:00
and ~BATTLERESULT_BITMASK
2018-04-05 08:44:02 -07:00
cp LOSE
2015-11-16 08:53:26 -08:00
jr nz, .notblackedout
2015-11-11 13:11:08 -08:00
ld b, BANK(Script_BattleWhiteout)
ld hl, Script_BattleWhiteout
2013-05-03 11:27:24 -07:00
jp ScriptJump
2015-10-19 13:49:29 -07:00
.notblackedout
bit 0, d
2015-11-16 08:53:26 -08:00
jr z, .was_wild
jr .next
2015-10-19 13:49:29 -07:00
2015-10-24 07:34:19 -07:00
.was_wild
ld a, [wBattleResult]
2018-04-05 08:44:02 -07:00
bit BATTLERESULT_BOX_FULL, a
jr z, .next
2015-10-19 13:49:29 -07:00
ld b, BANK(Script_SpecialBillCall)
ld de, Script_SpecialBillCall
2023-09-15 11:04:16 -07:00
farcall LoadMemScript
.next
ld a, [wSpacesLeft]
and a
jr z, .done
farcall LoadBoardMenuDieNumbersGFX
ld hl, wDisplaySecondarySprites
set SECONDARYSPRITES_SPACES_LEFT_F, [hl]
call ConstructOverworldHUDTilemap ; refresh coins just won
2015-10-19 13:49:29 -07:00
.done
jp Script_reloadmap
Script_reloadmapafterviewmapmode:
xor a
ld [wBattleScriptFlags], a
ld a, MAPSETUP_EXITVIEWMAP
ldh [hMapEntryMethod], a
ld a, SPAWN_FROM_RAM
ld [wDefaultSpawnpoint], a
ld a, [wSpacesLeft]
and a
ld a, BOARDEVENT_REDISPLAY_MENU
jr z, .in_board_menu
; .in_branch_space
; load branch space gfx (overwritten by view map mode gfx)
; refresh sprites first without view map mode objects to avoid visual glitch
ld hl, wDisplaySecondarySprites
res SECONDARYSPRITES_VIEW_MAP_MODE_F, [hl]
call UpdateActiveSprites
farcall LoadBranchSpaceGFX
ld hl, wDisplaySecondarySprites
set SECONDARYSPRITES_SPACES_LEFT_F, [hl]
set SECONDARYSPRITES_BRANCH_SPACE_F, [hl]
; load the saved facing direction to wPlayerSpriteSetupFlags
ld hl, wPlayerSpriteSetupFlags
ld a, [wBeforeViewMapDirection]
srl a
srl a
maskbits NUM_DIRECTIONS
ld [hl], a
set PLAYERSPRITESETUP_CUSTOM_FACING_F, [hl]
ld a, BOARDEVENT_RESUME_BRANCH
.in_board_menu
ldh [hCurBoardEvent], a
ld hl, wDisplaySecondarySprites
res SECONDARYSPRITES_VIEW_MAP_MODE_F, [hl]
ld a, MAPSTATUS_ENTER
call LoadMapStatus
ld hl, wPlayerFlags
res INVISIBLE_F, [hl]
call StopScript
ret
2017-02-22 20:49:44 -08:00
Script_reloadmap:
xor a
2015-11-25 07:16:29 -08:00
ld [wBattleScriptFlags], a
2015-10-24 16:49:19 -07:00
ld a, MAPSETUP_RELOADMAP
ldh [hMapEntryMethod], a
2019-01-24 18:41:14 -08:00
ld a, MAPSTATUS_ENTER
call LoadMapStatus
2013-07-04 02:37:20 -07:00
call StopScript
ret
2017-02-22 20:49:44 -08:00
Script_scall:
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld b, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
jr ScriptCall
2017-02-22 20:49:44 -08:00
Script_farscall:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld b, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
jr ScriptCall
Script_memcall:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
ld b, [hl]
inc hl
ld e, [hl]
inc hl
ld d, [hl]
; fallthrough
2017-02-22 20:49:44 -08:00
ScriptCall:
2015-11-16 08:53:26 -08:00
ld hl, wScriptStackSize
ld a, [hl]
cp 5
ret nc
push de
inc [hl]
ld e, a
ld d, 0
ld hl, wScriptStack
add hl, de
add hl, de
add hl, de
pop de
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld [hli], a
2018-01-23 14:39:09 -08:00
ld a, [wScriptPos]
ld [hli], a
2018-01-23 14:39:09 -08:00
ld a, [wScriptPos + 1]
ld [hl], a
ld a, b
2018-01-23 14:39:09 -08:00
ld [wScriptBank], a
ld a, e
2018-01-23 14:39:09 -08:00
ld [wScriptPos], a
ld a, d
2018-01-23 14:39:09 -08:00
ld [wScriptPos + 1], a
ret
2017-02-22 20:49:44 -08:00
CallCallback::
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
or $80
2018-01-23 14:39:09 -08:00
ld [wScriptBank], a
jp ScriptCall
Script_sjump:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld b, a
2013-05-03 11:27:24 -07:00
jp ScriptJump
Script_farsjump:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld b, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
2013-05-03 11:27:24 -07:00
jp ScriptJump
Script_memjump:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
ld b, [hl]
inc hl
ld a, [hli]
ld h, [hl]
ld l, a
2013-05-03 11:27:24 -07:00
jp ScriptJump
2017-02-22 20:49:44 -08:00
Script_iffalse:
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
and a
jp nz, SkipTwoScriptBytes
jp Script_sjump
2017-02-22 20:49:44 -08:00
Script_iftrue:
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
and a
jp nz, Script_sjump
jp SkipTwoScriptBytes
2018-02-02 18:09:17 -08:00
Script_ifequal:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2023-09-30 10:12:57 -07:00
ld hl, hScriptVar
cp [hl]
jr z, Script_sjump
2015-11-16 08:53:26 -08:00
jr SkipTwoScriptBytes
2018-02-02 18:09:17 -08:00
Script_ifnotequal:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2023-09-30 10:12:57 -07:00
ld hl, hScriptVar
cp [hl]
jr nz, Script_sjump
2015-11-16 08:53:26 -08:00
jr SkipTwoScriptBytes
2018-02-02 18:09:17 -08:00
Script_ifgreater:
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
ld b, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
cp b
jr c, Script_sjump
2015-11-16 08:53:26 -08:00
jr SkipTwoScriptBytes
2018-02-02 18:09:17 -08:00
Script_ifless:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld b, a
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
cp b
jr c, Script_sjump
2015-11-16 08:53:26 -08:00
jr SkipTwoScriptBytes
2017-02-22 20:49:44 -08:00
Script_jumpstd:
call StdScript
2015-11-16 08:53:26 -08:00
jr ScriptJump
2017-02-22 20:49:44 -08:00
Script_callstd:
call StdScript
ld d, h
ld e, l
jp ScriptCall
2017-02-22 20:49:44 -08:00
StdScript:
call GetScriptByte
ld e, a
call GetScriptByte
ld d, a
ld hl, StdScripts
add hl, de
add hl, de
add hl, de
ld a, BANK(StdScripts)
call GetFarByte
ld b, a
inc hl
ld a, BANK(StdScripts)
call GetFarWord
ret
2017-02-22 20:49:44 -08:00
SkipTwoScriptBytes:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptByte
2013-02-28 13:04:26 -08:00
ret
2017-02-22 20:49:44 -08:00
ScriptJump:
2013-02-28 13:04:26 -08:00
ld a, b
2018-01-23 14:39:09 -08:00
ld [wScriptBank], a
2013-02-28 13:04:26 -08:00
ld a, l
2018-01-23 14:39:09 -08:00
ld [wScriptPos], a
2013-02-28 13:04:26 -08:00
ld a, h
2018-01-23 14:39:09 -08:00
ld [wScriptPos + 1], a
2013-02-28 13:04:26 -08:00
ret
2021-06-08 17:35:04 -07:00
Script_sdefer:
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
2021-06-08 17:35:04 -07:00
ld [wDeferredScriptBank], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2021-06-08 17:35:04 -07:00
ld [wDeferredScriptAddr], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2021-06-08 17:35:04 -07:00
ld [wDeferredScriptAddr + 1], a
2018-01-23 14:39:09 -08:00
ld hl, wScriptFlags
set 3, [hl]
ret
Script_checkscene:
call CheckScenes
jr z, .no_scene
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2015-11-16 09:49:42 -08:00
.no_scene
ld a, $ff
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
Script_checkmapscene:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld b, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld c, a
call GetMapSceneID
ld a, d
or e
jr z, .no_scene
ld a, [de]
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2015-11-16 09:49:42 -08:00
.no_scene
ld a, $ff
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
Script_setscene:
2018-01-23 14:39:09 -08:00
ld a, [wMapGroup]
ld b, a
2018-01-23 14:39:09 -08:00
ld a, [wMapNumber]
ld c, a
jr DoScene
Script_setmapscene:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld b, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld c, a
DoScene:
call GetMapSceneID
ld a, d
or e
jr z, .no_scene
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [de], a
.no_scene
ret
Script_readmem:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
ld a, [hl]
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
Script_writemem:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
ld [hl], a
ret
Script_loadmem:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [hl], a
ret
Script_setval:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
Script_addval:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2023-09-30 10:12:57 -07:00
ld hl, hScriptVar
add [hl]
ld [hl], a
ret
2017-02-22 20:49:44 -08:00
Script_random:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
and a
ret z
2015-11-16 08:53:26 -08:00
ld c, a
2015-11-16 08:53:26 -08:00
call .Divide256byC
and a
2015-11-16 08:53:26 -08:00
jr z, .no_restriction ; 256 % b == 0
ld b, a
xor a
sub b
ld b, a
2015-11-16 08:53:26 -08:00
.loop
push bc
call Random
pop bc
ldh a, [hRandomAdd]
cp b
2015-11-16 08:53:26 -08:00
jr nc, .loop
jr .finish
.no_restriction
push bc
call Random
pop bc
ldh a, [hRandomAdd]
2015-11-16 08:53:26 -08:00
.finish
push af
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
ld c, a
pop af
call SimpleDivide
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
.Divide256byC:
xor a
ld b, a
sub c
2015-11-16 08:53:26 -08:00
.mod_loop
inc b
sub c
2015-11-16 08:53:26 -08:00
jr nc, .mod_loop
dec b
add c
ret
Script_readvar:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetVarAction
ld a, [de]
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
Script_writevar:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetVarAction
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
ld [de], a
ret
Script_loadvar:
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetVarAction
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [de], a
ret
2017-02-22 20:49:44 -08:00
GetVarAction:
ld c, a
2017-12-24 09:47:30 -08:00
farcall _GetVarAction
ret
2017-02-22 20:49:44 -08:00
Script_checkver:
2018-01-08 21:51:53 -08:00
ld a, [.gs_version]
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2018-01-08 21:51:53 -08:00
.gs_version:
db GS_VERSION
Script_getmonname:
2013-02-28 13:36:21 -08:00
call GetScriptByte
and a
2015-11-16 08:53:26 -08:00
jr nz, .gotit
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
.gotit
ld [wNamedObjectIndex], a
call GetPokemonName
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer1
GetStringBuffer:
2013-02-28 13:36:21 -08:00
call GetScriptByte
cp NUM_STRING_BUFFERS
2014-09-30 11:19:33 -07:00
jr c, .ok
xor a
2014-09-30 11:19:33 -07:00
.ok
2017-02-22 20:49:44 -08:00
CopyConvertedText:
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer3
ld bc, STRING_BUFFER_LENGTH
call AddNTimes
call CopyName2
ret
Script_getitemname:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-11 22:40:20 -08:00
and a ; USE_SCRIPT_VAR
2015-11-16 08:53:26 -08:00
jr nz, .ok
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
.ok
ld [wNamedObjectIndex], a
call GetItemName
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer1
jr GetStringBuffer
Script_getcurlandmarkname:
2018-01-23 14:39:09 -08:00
ld a, [wMapGroup]
ld b, a
2018-01-23 14:39:09 -08:00
ld a, [wMapNumber]
ld c, a
call GetWorldMapLocation
2017-02-22 20:49:44 -08:00
ConvertLandmarkToText:
ld e, a
farcall LevelSelectionMenu_GetLandmarkName
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer1
jp GetStringBuffer
Script_getlandmarkname:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2015-11-16 08:53:26 -08:00
jr ConvertLandmarkToText
Script_gettrainername:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld c, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld b, a
2017-12-24 09:47:30 -08:00
farcall GetTrainerName
jr GetStringBuffer
Script_getname:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wNamedObjectType], a
2017-02-22 20:49:44 -08:00
ContinueToGetName:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wCurSpecies], a
call GetName
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer1
jp GetStringBuffer
Script_gettrainerclassname:
ld a, TRAINER_NAME
ld [wNamedObjectType], a
2015-11-16 08:53:26 -08:00
jr ContinueToGetName
Script_getcoins:
call ResetStringBuffer1
call GetCoinsAccount
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer1
2019-11-03 17:17:04 -08:00
lb bc, PRINTNUM_LEFTALIGN | 3, 6
call PrintNum
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer1
jp GetStringBuffer
Script_getchips:
call ResetStringBuffer1
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer1
ld de, wChips
2019-11-03 17:17:04 -08:00
lb bc, PRINTNUM_LEFTALIGN | 2, 6
call PrintNum
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer1
jp GetStringBuffer
Script_getnum:
call ResetStringBuffer1
2023-09-30 10:12:57 -07:00
ld de, hScriptVar
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer1
2019-11-03 17:17:04 -08:00
lb bc, PRINTNUM_LEFTALIGN | 1, 3
call PrintNum
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer1
jp GetStringBuffer
2017-02-22 20:49:44 -08:00
ResetStringBuffer1:
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer1
ld bc, NAME_LENGTH
ld a, "@"
call ByteFill
ret
Script_getstring:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld hl, CopyName1
2013-10-01 18:55:40 -07:00
rst FarCall
2018-01-23 14:39:09 -08:00
ld de, wStringBuffer2
jp GetStringBuffer
Script_givepokemail:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
call GetFarByte
ld b, a
push bc
inc hl
ld bc, MAIL_MSG_LENGTH
ld de, wMonMailMessageBuffer
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
call FarCopyBytes
pop bc
farcall GivePokeMail
ret
Script_checkpokemail:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld b, a
farcall CheckPokeMail
ret
2017-02-22 20:49:44 -08:00
Script_giveitem:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2015-11-03 12:05:19 -08:00
cp ITEM_FROM_MEM
2015-11-16 08:53:26 -08:00
jr nz, .ok
2023-09-30 10:12:57 -07:00
ldh a, [hScriptVar]
.ok
2018-01-23 14:39:09 -08:00
ld [wCurItem], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wItemQuantityChange], a
2018-01-23 14:39:09 -08:00
ld hl, wNumItems
call ReceiveItem
2015-11-16 08:53:26 -08:00
jr nc, .full
2015-11-25 07:16:29 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
.full
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_takeitem:
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wCurItem], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wItemQuantityChange], a
2015-11-03 19:35:36 -08:00
ld a, -1
2018-01-23 14:39:09 -08:00
ld [wCurItemQuantity], a
ld hl, wNumItems
call TossItem
ret nc
2015-11-25 07:16:29 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_checkitem:
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wCurItem], a
ld hl, wNumItems
call CheckItem
ret nc
2015-11-25 07:16:29 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
Script_givecoins:
call GetCoinsAccount
call LoadCoinsAmountToMem
farcall GiveCoins
ret
Script_takecoins:
call GetCoinsAccount
call LoadCoinsAmountToMem
farcall TakeCoins
ret
Script_checkcoins:
call GetCoinsAccount
call LoadCoinsAmountToMem
farcall CompareCoins
CompareCoinsAction:
2018-01-11 22:40:20 -08:00
jr c, .less
jr z, .exact
ld a, HAVE_MORE
2014-05-21 13:21:46 -07:00
jr .done
2018-01-11 22:40:20 -08:00
.exact
ld a, HAVE_AMOUNT
2014-05-21 13:21:46 -07:00
jr .done
2018-01-11 22:40:20 -08:00
.less
ld a, HAVE_LESS
2014-05-21 13:21:46 -07:00
.done
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
GetCoinsAccount:
call GetScriptByte
and a
ld de, wCoins ; YOUR_COINS
ret z
ld de, wCurLevelCoins ; CUR_LEVEL_COINS
ret
LoadCoinsAmountToMem:
ld bc, hCoinsTemp
call GetScriptByte
cp COINS_FROM_RAM >> 16
jr z, .coins_from_ram
cp BLUE_RED_SPACE_COINS >> 16
jr z, .blue_red_space_coins
push bc
ld [bc], a
inc bc
call GetScriptByte
ld [bc], a
inc bc
call GetScriptByte
ld [bc], a
pop bc
ret
.coins_from_ram
; if the highest byte was COINS_FROM_RAM, the lowest two bytes are a RAM address.
; but the script argument is dt, which is big endian rather than little endian like dw.
call GetScriptByte
ld h, a
call GetScriptByte
ld l, a
push bc
ld a, [hli]
ld [bc], a
inc bc
ld a, [hli]
ld [bc], a
inc bc
ld a, [hl]
ld [bc], a
pop bc
ret
.blue_red_space_coins
push de
call GetScriptByte
call GetScriptByte
; return [hCoinsTemp] = MAP_BASECOINS * [wDieRoll]
ld de, MAP_BASECOINS
call GetMapField
ld a, [wDieRoll]
dec a
ld e, a
ld a, c
ld b, 0 ; c = ba = MAP_BASECOINS
jr z, .go
.loop
add c
jr nc, .ok
inc b
.ok
dec e
jr nz, .loop
.go
; ba = MAP_BASECOINS * [wDieRoll]
ld hl, hCoinsTemp + 2
ld [hld], a
ld a, b
ld [hld], a
xor a
ld [hl], a
ld bc, hCoinsTemp
pop de
ret
Script_givechips:
call LoadChipAmountToMem
farcall GiveChips
ret
Script_takechips:
call LoadChipAmountToMem
farcall TakeChips
ret
Script_checkchips:
call LoadChipAmountToMem
farcall CheckChips
jp CompareCoinsAction
LoadChipAmountToMem:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ldh [hCoinsTemp + 1], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ldh [hCoinsTemp], a
ld bc, hCoinsTemp
ret
2017-02-22 20:49:44 -08:00
Script_checktime:
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2017-12-24 09:47:30 -08:00
farcall CheckTime
2013-02-28 13:36:21 -08:00
call GetScriptByte
and c
ret z
2015-11-25 07:16:29 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_checkpoke:
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld hl, wPartySpecies
2014-05-21 13:21:46 -07:00
ld de, 1
call IsInArray
ret nc
2015-11-25 07:16:29 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_addcellnum:
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld c, a
2017-12-24 09:47:30 -08:00
farcall AddPhoneNumber
ret nc
2015-11-25 07:16:29 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_delcellnum:
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld c, a
2017-12-24 09:47:30 -08:00
farcall DelCellNum
ret nc
2015-11-25 07:16:29 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_checkcellnum:
; returns false if the cell number is not in your phone
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld c, a
2017-12-24 09:47:30 -08:00
farcall CheckCellNum
ret nc
2015-11-25 07:16:29 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_specialphonecall:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wSpecialPhoneCallID], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [wSpecialPhoneCallID + 1], a
ret
2017-02-22 20:49:44 -08:00
Script_checkphonecall:
; returns false if no special phone call is stored
ld a, [wSpecialPhoneCallID]
and a
2014-05-21 13:21:46 -07:00
jr z, .ok
2015-11-25 07:16:29 -08:00
ld a, TRUE
2014-05-21 13:21:46 -07:00
.ok
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_givepoke:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wCurPartySpecies], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wCurPartyLevel], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wCurItem], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
and a
ld b, a
2014-05-21 13:21:46 -07:00
jr z, .ok
2018-01-23 14:39:09 -08:00
ld hl, wScriptPos
ld e, [hl]
inc hl
ld d, [hl]
2013-02-28 13:36:21 -08:00
call GetScriptByte
call GetScriptByte
call GetScriptByte
call GetScriptByte
2014-05-21 13:21:46 -07:00
.ok
2017-12-24 09:47:30 -08:00
farcall GivePoke
ld a, b
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_giveegg:
2023-09-30 10:12:57 -07:00
; if no room in the party, return 0 in hScriptVar; else, return 2
xor a ; PARTYMON
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2018-01-23 14:39:09 -08:00
ld [wMonType], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wCurPartySpecies], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wCurPartyLevel], a
farcall GiveEgg
ret nc
ld a, 2
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_setevent:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
ld b, SET_FLAG
2013-08-23 12:48:26 -07:00
call EventFlagAction
ret
2017-02-22 20:49:44 -08:00
Script_clearevent:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
ld b, RESET_FLAG
2013-08-23 12:48:26 -07:00
call EventFlagAction
ret
2017-02-22 20:49:44 -08:00
Script_checkevent:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
ld b, CHECK_FLAG
2013-08-23 12:48:26 -07:00
call EventFlagAction
ld a, c
and a
2015-11-16 08:53:26 -08:00
jr z, .false
2015-11-25 07:16:29 -08:00
ld a, TRUE
.false
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
Script_setflag:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2015-11-25 07:16:29 -08:00
ld b, SET_FLAG
call _EngineFlagAction
ret
2017-02-22 20:49:44 -08:00
Script_clearflag:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2015-11-25 07:16:29 -08:00
ld b, RESET_FLAG
call _EngineFlagAction
ret
2017-02-22 20:49:44 -08:00
Script_checkflag:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2018-01-11 22:40:20 -08:00
ld b, CHECK_FLAG
call _EngineFlagAction
ld a, c
and a
2015-11-16 08:53:26 -08:00
jr z, .false
2015-11-25 07:16:29 -08:00
ld a, TRUE
.false
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2017-02-22 20:49:44 -08:00
_EngineFlagAction:
2017-12-24 09:47:30 -08:00
farcall EngineFlagAction
ret
2017-02-22 20:49:44 -08:00
Script_wildoff:
ld hl, wStatusFlags
2018-01-22 12:40:43 -08:00
set STATUSFLAGS_NO_WILD_ENCOUNTERS_F, [hl]
ret
2017-02-22 20:49:44 -08:00
Script_wildon:
ld hl, wStatusFlags
2018-01-22 12:40:43 -08:00
res STATUSFLAGS_NO_WILD_ENCOUNTERS_F, [hl]
ret
2017-02-22 20:49:44 -08:00
Script_xycompare:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2016-01-12 09:46:18 -08:00
ld [wXYComparePointer], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2016-01-12 09:46:18 -08:00
ld [wXYComparePointer + 1], a
ret
2017-02-22 20:49:44 -08:00
Script_warpfacing:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-16 14:27:50 -08:00
maskbits NUM_DIRECTIONS
ld c, a
2015-10-24 07:34:19 -07:00
ld a, [wPlayerSpriteSetupFlags]
2018-01-22 11:34:55 -08:00
set PLAYERSPRITESETUP_CUSTOM_FACING_F, a
or c
2015-10-24 07:34:19 -07:00
ld [wPlayerSpriteSetupFlags], a
; fallthrough
2017-02-22 20:49:44 -08:00
Script_warp:
2018-01-23 14:39:09 -08:00
ld [wMapGroup], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wMapNumber], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wXCoord], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wYCoord], a
2019-01-24 18:41:14 -08:00
ld a, SPAWN_N_A
2018-01-23 14:39:09 -08:00
ld [wDefaultSpawnpoint], a
2015-10-24 16:49:19 -07:00
ld a, MAPSETUP_WARP
ldh [hMapEntryMethod], a
2019-01-24 18:41:14 -08:00
ld a, MAPSTATUS_ENTER
call LoadMapStatus
2013-07-04 02:37:20 -07:00
call StopScript
ret
2015-11-11 20:38:57 -08:00
2017-02-22 20:49:44 -08:00
Script_warpmod:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wBackupWarpNumber], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wBackupMapGroup], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wBackupMapNumber], a
ret
2017-02-22 20:49:44 -08:00
Script_blackoutmod:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2015-11-11 13:11:08 -08:00
ld [wLastSpawnMapGroup], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2015-11-11 13:11:08 -08:00
ld [wLastSpawnMapNumber], a
ret
2017-02-22 20:49:44 -08:00
Script_dontrestartmapmusic:
2019-01-24 18:15:30 -08:00
ld a, TRUE
ld [wDontPlayMapMusicOnReload], a
ret
2017-02-22 20:49:44 -08:00
Script_writecmdqueue:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld e, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld d, a
2018-01-23 14:39:09 -08:00
ld a, [wScriptBank]
ld b, a
2017-12-24 09:47:30 -08:00
farcall WriteCmdQueue ; no need to farcall
ret
2017-02-22 20:49:44 -08:00
Script_delcmdqueue:
xor a
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld b, a
2017-12-24 09:47:30 -08:00
farcall DelCmdQueue ; no need to farcall
ret c
2019-01-24 18:15:30 -08:00
ld a, TRUE
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
Script_changemapblocks:
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wMapBlocksBank], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wMapBlocksPointer], a
2013-02-28 13:36:21 -08:00
call GetScriptByte
2018-01-23 14:39:09 -08:00
ld [wMapBlocksPointer + 1], a
call ChangeMap
call BufferScreen
ret
2017-02-22 20:49:44 -08:00
Script_changeblock:
2013-02-28 13:36:21 -08:00
call GetScriptByte
add 4
ld d, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
add 4
ld e, a
call GetBlockLocation
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld [hl], a
call BufferScreen
ret
2024-02-10 15:16:00 -08:00
Script_refreshmap::
xor a
ldh [hBGMapMode], a
2024-02-10 15:16:00 -08:00
call LoadOverworldTilemapAndAttrmapPals
2015-11-19 15:07:20 -08:00
call GetMovementPermissions
2024-02-10 15:16:00 -08:00
farcall HDMATransferTilemapAndAttrmap_Overworld
call UpdateSprites
ret
2017-02-22 20:49:44 -08:00
Script_warpcheck:
2015-11-12 08:10:19 -08:00
call WarpCheck
ret nc
2017-12-24 09:47:30 -08:00
farcall EnableEvents
ret
Script_enableevents: ; unreferenced
2017-12-24 09:47:30 -08:00
farcall EnableEvents
ret
2017-02-22 20:49:44 -08:00
Script_newloadmap:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ldh [hMapEntryMethod], a
2019-01-24 18:41:14 -08:00
ld a, MAPSTATUS_ENTER
call LoadMapStatus
2013-07-04 02:37:20 -07:00
call StopScript
ret
Script_reloadend:
call Script_newloadmap
2013-07-04 02:37:20 -07:00
jp Script_end
2018-02-02 18:09:17 -08:00
Script_opentext:
call OpenText2bpp
ret
2024-02-10 15:16:00 -08:00
Script_reanchormap:
call RefreshScreen
2013-02-28 13:36:21 -08:00
call GetScriptByte
ret
Script_writeunusedbyte:
2013-02-28 13:36:21 -08:00
call GetScriptByte
ret
2017-02-22 20:49:44 -08:00
Script_closetext:
2024-02-10 15:16:00 -08:00
call HDMATransferTilemapAndAttrmap_Menu
2015-11-25 07:16:29 -08:00
call CloseText
ret
2019-02-16 13:06:11 -08:00
Script_autoinput:
2013-02-28 13:36:21 -08:00
call GetScriptByte
push af
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld l, a
2013-02-28 13:36:21 -08:00
call GetScriptByte
ld h, a
pop af
call StartAutoInput
ret
2017-02-22 20:49:44 -08:00
Script_pause:
2013-02-28 13:36:21 -08:00
call GetScriptByte
and a
2015-11-16 08:53:26 -08:00
jr z, .loop
2018-01-23 14:39:09 -08:00
ld [wScriptDelay], a
.loop
2013-07-04 02:37:20 -07:00
ld c, 2
call DelayFrames
2018-01-23 14:39:09 -08:00
ld hl, wScriptDelay
dec [hl]
2015-11-16 08:53:26 -08:00
jr nz, .loop
ret
2017-02-22 20:49:44 -08:00
Script_deactivatefacing:
2013-02-28 13:36:21 -08:00
call GetScriptByte
and a
2015-11-16 08:53:26 -08:00
jr z, .no_time
2018-01-23 14:39:09 -08:00
ld [wScriptDelay], a
.no_time
2013-07-04 02:37:20 -07:00
ld a, SCRIPT_WAIT
2018-01-23 14:39:09 -08:00
ld [wScriptMode], a
2013-07-04 02:37:20 -07:00
call StopScript
ret
Script_stopandsjump:
2013-07-04 02:37:20 -07:00
call StopScript
jp Script_sjump
2017-02-22 20:49:44 -08:00
Script_end:
2013-07-04 02:37:20 -07:00
call ExitScriptSubroutine
jr c, .resume
ret
2015-11-11 20:38:57 -08:00
.resume
xor a
2018-01-23 14:39:09 -08:00
ld [wScriptRunning], a
2013-07-04 02:37:20 -07:00
ld a, SCRIPT_OFF
2018-01-23 14:39:09 -08:00
ld [wScriptMode], a
ld hl, wScriptFlags
res 0, [hl]
2013-07-04 02:37:20 -07:00
call StopScript
ret
Script_endcallback:
2013-07-04 02:37:20 -07:00
call ExitScriptSubroutine
2018-01-23 14:39:09 -08:00
ld hl, wScriptFlags
res 0, [hl]
2013-07-04 02:37:20 -07:00
call StopScript
ret
2017-02-22 20:49:44 -08:00
ExitScriptSubroutine:
2013-07-04 02:37:20 -07:00
; Return carry if there's no parent to return to.
2015-11-16 08:53:26 -08:00
ld hl, wScriptStackSize
ld a, [hl]
and a
2015-11-16 08:53:26 -08:00
jr z, .done
dec [hl]
ld e, [hl]
ld d, $0
ld hl, wScriptStack
add hl, de
add hl, de
add hl, de
ld a, [hli]
ld b, a
2020-07-21 08:12:56 -07:00
and $7f
2018-01-23 14:39:09 -08:00
ld [wScriptBank], a
ld a, [hli]
ld e, a
2018-01-23 14:39:09 -08:00
ld [wScriptPos], a
ld a, [hl]
ld d, a
2018-01-23 14:39:09 -08:00
ld [wScriptPos + 1], a
and a
ret
.done
scf
ret
2018-02-02 18:09:17 -08:00
Script_endall:
xor a
2015-11-16 08:53:26 -08:00
ld [wScriptStackSize], a
2018-01-23 14:39:09 -08:00
ld [wScriptRunning], a
2013-07-04 02:37:20 -07:00
ld a, SCRIPT_OFF
2018-01-23 14:39:09 -08:00
ld [wScriptMode], a
ld hl, wScriptFlags
res 0, [hl]
2013-07-04 02:37:20 -07:00
call StopScript
ret
2017-02-22 20:49:44 -08:00
Script_halloffame:
ld hl, wGameTimer
res GAME_TIMER_COUNTING_F, [hl]
2017-12-24 09:47:30 -08:00
farcall HallOfFame
ld hl, wGameTimer
set GAME_TIMER_COUNTING_F, [hl]
2015-12-14 17:06:41 -08:00
jr ReturnFromCredits
2017-02-22 20:49:44 -08:00
Script_credits:
2017-12-24 09:47:30 -08:00
farcall RedCredits
2015-12-14 17:06:41 -08:00
ReturnFromCredits:
2018-02-02 18:09:17 -08:00
call Script_endall
2019-01-24 18:41:14 -08:00
ld a, MAPSTATUS_DONE
call LoadMapStatus
2013-07-04 02:37:20 -07:00
call StopScript
ret
Script_exitoverworld:
call GetScriptByte
ld [wExitOverworldReason], a
call Script_endall
ld a, MAPSTATUS_DONE
call LoadMapStatus
call StopScript
ret
2017-02-22 20:49:44 -08:00
Script_wait:
push bc
2013-02-28 13:36:21 -08:00
call GetScriptByte
.loop
push af
2013-07-04 02:37:20 -07:00
ld c, 6
call DelayFrames
pop af
dec a
2015-11-16 08:53:26 -08:00
jr nz, .loop
pop bc
ret
2018-02-02 18:09:17 -08:00
Script_checksave:
2017-12-24 09:47:30 -08:00
farcall CheckSave
ld a, c
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
Script_checkver_duplicate: ; unreferenced
ld a, [.gs_version]
2023-09-30 10:12:57 -07:00
ldh [hScriptVar], a
ret
2021-03-24 07:24:52 -07:00
.gs_version:
db GS_VERSION