ref: 1205fe5100c09624350b5e6822b4c063586afcaf
parent: adf2fe712d372bad8c68590ae77b1dde85290d8f
author: PikalaxALT <PikalaxALT@gmail.com>
date: Thu Nov 5 10:08:00 EST 2015
PLAYEREVENT_
--- a/constants/map_setup_constants.asm
+++ b/constants/map_setup_constants.asm
@@ -1,5 +1,4 @@
-const_value SET $f0
- const MAPSETUP_00
+const_value SET $f1
const MAPSETUP_WARP
const MAPSETUP_02
const MAPSETUP_RELOADMAP
@@ -11,6 +10,7 @@
const MAPSETUP_09
const MAPSETUP_10
const MAPSETUP_BADWARP
+ const MAPSETUP_12
; Command descriptions from Condensation water's scripting compendium. const_def
const_def
--- a/constants/script_constants.asm
+++ b/constants/script_constants.asm
@@ -35,3 +35,17 @@
RETVAR_STRBUF2 EQU (0 << 6)
RETVAR_ADDR_DE EQU (1 << 6)
RETVAR_EXECUTE EQU (2 << 6)
+
+const_value SET -1
+ const PLAYEREVENT_MAPSCRIPT
+ const PLAYEREVENT_NONE
+ const PLAYEREVENT_SEENBYTRAINER
+ const PLAYEREVENT_TALKTOTRAINER
+ const PLAYEREVENT_ITEMBALL
+ const PLAYEREVENT_4
+ const PLAYEREVENT_WARP
+ const PLAYEREVENT_FALL
+ const PLAYEREVENT_7
+ const PLAYEREVENT_HATCH
+ const PLAYEREVENT_9
+NUM_PLAYER_EVENTS EQU const_value
--- a/engine/events.asm
+++ b/engine/events.asm
@@ -322,9 +322,9 @@
ld [ScriptRunning], a
call DoPlayerEvent
ld a, [ScriptRunning]
- cp 4
+ cp PLAYEREVENT_4
jr z, .ok2
- cp 9
+ cp PLAYEREVENT_9
jr z, .ok2
xor a
@@ -1050,14 +1050,14 @@
ld a, [ScriptRunning]
and a
ret z
- cp -1 ; run script
+ cp PLAYEREVENT_MAPSCRIPT ; run script
ret z
- cp 10
+ cp NUM_PLAYER_EVENTS
ret nc
ld c, a
ld b, 0
- ld hl, ScriptPointers96c0c
+ ld hl, PlayerEventScriptPointers
rept 3
add hl,bc
endr
@@ -1070,18 +1070,18 @@
ret
; 96c0c
-ScriptPointers96c0c: ; 96c0c
- dba Invalid_0x96c2d
- dba SeenByTrainerScript
- dba TalkToTrainerScript
- dba FindItemInBallScript
- dba UnknownScript_0x96c4d
- dba WarpToNewMapScript
- dba FallIntoMapScript
- dba UnknownScript_0x124c8
- dba HatchEggScript
- dba UnknownScript_0x96c4f
- dba Invalid_0x96c2d
+PlayerEventScriptPointers: ; 96c0c
+ dba Invalid_0x96c2d ; 0
+ dba SeenByTrainerScript ; 1
+ dba TalkToTrainerScript ; 2
+ dba FindItemInBallScript ; 3
+ dba UnknownScript_0x96c4d ; 4
+ dba WarpToNewMapScript ; 5
+ dba FallIntoMapScript ; 6
+ dba UnknownScript_0x124c8 ; 7
+ dba HatchEggScript ; 8
+ dba UnknownScript_0x96c4f ; 9
+ dba Invalid_0x96c2d ; 10
; 96c2d
Invalid_0x96c2d: ; 96c2d
@@ -1122,11 +1122,11 @@
end
; 96c4d
-UnknownScript_0x96c4d: ; 96c4d
- reloadandreturn $f7
+UnknownScript_0x96c4d: ; 4
+ reloadandreturn MAPSETUP_07
; 96c4f
-UnknownScript_0x96c4f: ; 96c4f
+UnknownScript_0x96c4f: ; 9
deactivatefacing $3
callasm SetBit4_ScriptFlags3
end
--- a/engine/scripting.asm
+++ b/engine/scripting.asm
@@ -1664,7 +1664,7 @@
ret
; 0x974f3
-Function974f3:: ; 0x974f3
+CallCallback:: ; 0x974f3
ld a, [ScriptBank]
or $80
ld [ScriptBank], a
--- a/home.asm
+++ b/home.asm
@@ -1242,7 +1242,7 @@
ld e, l
call Function35de
jr nc, .asm_3597
- call Function2631
+ call CallMapScript
callba EnableScriptMode
scf
ret
--- a/home/map.asm
+++ b/home/map.asm
@@ -208,7 +208,7 @@
; 222a
Function222a:: ; 222a
- ld a, $fa
+ ld a, MAPSETUP_10
ld [hMapEntryMethod], a
callba RunMapSetupScript
xor a
@@ -967,7 +967,7 @@
ld a, h
ld [ScriptPos + 1], a
- ld a, $ff
+ ld a, PLAYEREVENT_MAPSCRIPT
ld [ScriptRunning], a
scf
@@ -974,7 +974,8 @@
ret
; 2631
-Function2631:: ; 2631
+CallMapScript:: ; 2631
+; Call a script at hl in the current bank if there isn't already a script running
ld a, [ScriptRunning]
and a
ret nz
@@ -988,7 +989,7 @@
ld a, [hROMBank]
push af
call SwitchToMapScriptHeaderBank
- call Function2653
+ call .FindCallback
jr nc, .done
call GetMapScriptHeaderBank
@@ -1003,7 +1004,7 @@
ret
; 2653
-Function2653:: ; 2653
+.FindCallback: ; 2653
ld a, [wCurrMapCallbackCount]
ld c, a
and a
@@ -1018,7 +1019,7 @@
.loop
ld a, [hl]
cp b
- jr z, .done
+ jr z, .found
add hl, de
dec c
jr nz, .loop
@@ -1025,7 +1026,7 @@
xor a
ret
-.done
+.found
inc hl
ld a, [hli]
ld h, [hl]
@@ -1035,7 +1036,8 @@
; 2674
ExecuteCallbackScript:: ; 2674
- callba Function974f3
+; Do map callback de and return to script bank b.
+ callba CallCallback
ld a, [ScriptMode]
push af
ld hl, ScriptFlags
--- a/main.asm
+++ b/main.asm
@@ -141,7 +141,7 @@
ld a, SPAWN_HOME
ld [wd001], a
- ld a, $f1
+ ld a, MAPSETUP_WARP
ld [hMapEntryMethod], a
jp FinishContinueFunction
; 5b8f
@@ -451,7 +451,7 @@
ld a, [wSpawnAfterChampion]
cp SPAWN_LANCE
jr z, .SpawnAfterE4
- ld a, $f2
+ ld a, MAPSETUP_02
ld [hMapEntryMethod], a
jp FinishContinueFunction
@@ -473,7 +473,7 @@
PostCreditsSpawn: ; 5de7
xor a
ld [wSpawnAfterChampion], a
- ld a, $f1
+ ld a, MAPSETUP_WARP
ld [hMapEntryMethod], a
ret
; 5df0
@@ -5248,7 +5248,7 @@
special WarpToSpawnPoint
callasm DelayLoadingNewSprites
writecode VAR_MOVEMENT, $0
- newloadmap -4
+ newloadmap MAPSETUP_12
callasm Function8cb33
special WaitSFX
callasm Functioncacb
@@ -5516,7 +5516,7 @@
farscall UnknownScript_0x122c1
special WarpToSpawnPoint
writecode VAR_MOVEMENT, $0
- newloadmap -11
+ newloadmap MAPSETUP_05
playsound SFX_WARP_FROM
applymovement PLAYER, MovementData_0xcc5d
end
@@ -5614,7 +5614,7 @@
farscall UnknownScript_0x122c1
special WarpToSpawnPoint
writecode VAR_MOVEMENT, $0
- newloadmap -12
+ newloadmap MAPSETUP_04
playsound SFX_WARP_FROM
applymovement PLAYER, MovementData_0xcce3
end
@@ -12257,7 +12257,7 @@
callasm Function12527
farscall UnknownScript_0x122c1
special WarpToSpawnPoint
- newloadmap $f1
+ newloadmap MAPSETUP_WARP
resetfuncs
.script_64f2
--- a/maps/Colosseum.asm
+++ b/maps/Colosseum.asm
@@ -49,7 +49,7 @@
MapColosseumSignpost1Script:
special Special_Colosseum
- newloadmap $f8
+ newloadmap MAPSETUP_08
end
ChrisScript_0x193499:
--- a/maps/GoldenrodMagnetTrainStation.asm
+++ b/maps/GoldenrodMagnetTrainStation.asm
@@ -35,7 +35,7 @@
writebyte $0
special Special_MagnetTrain
warpcheck
- newloadmap $f9
+ newloadmap MAPSETUP_09
applymovement PLAYER, .MovementBoardTheTrain
wait $14
end
--- a/maps/SaffronTrainStation.asm
+++ b/maps/SaffronTrainStation.asm
@@ -35,7 +35,7 @@
writebyte $1
special Special_MagnetTrain
warpcheck
- newloadmap $f9
+ newloadmap MAPSETUP_09
applymovement PLAYER, .MovementBoardTheTrain
wait $14
end
--- a/maps/TimeCapsule.asm
+++ b/maps/TimeCapsule.asm
@@ -39,7 +39,7 @@
MapTimeCapsuleSignpost1Script:
special Special_TimeCapsule
- newloadmap $f8
+ newloadmap MAPSETUP_08
end
ChrisScript_0x19351a:
--- a/maps/TradeCenter.asm
+++ b/maps/TradeCenter.asm
@@ -39,7 +39,7 @@
MapTradeCenterSignpost1Script:
special Special_TradeCenter
- newloadmap $f8
+ newloadmap MAPSETUP_08
end
ChrisScript_0x19340b:
--- a/misc/mobile_40.asm
+++ b/misc/mobile_40.asm
@@ -406,7 +406,7 @@
; 1002dc
Function1002dc: ; 1002dc
- ld a, $f8
+ ld a, MAPSETUP_08
ld [hMapEntryMethod], a
callba RunMapSetupScript
xor a