2017-06-17 16:14:55 -07:00
|
|
|
SECTION "Events", ROMX
|
2013-11-22 23:51:48 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
OverworldLoop::
|
2019-01-24 18:41:14 -08:00
|
|
|
xor a ; MAPSTATUS_START
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wMapStatus], a
|
2013-12-27 02:56:23 -08:00
|
|
|
.loop
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wMapStatus]
|
2021-03-17 08:38:01 -07:00
|
|
|
ld hl, .Jumptable
|
2013-11-22 02:04:32 -08:00
|
|
|
rst JumpTable
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wMapStatus]
|
2019-01-24 18:41:14 -08:00
|
|
|
cp MAPSTATUS_DONE
|
2013-12-27 02:56:23 -08:00
|
|
|
jr nz, .loop
|
2013-11-22 02:04:32 -08:00
|
|
|
.done
|
2023-09-22 14:12:05 -07:00
|
|
|
call DisableOverworldHUD
|
2023-10-07 10:08:54 -07:00
|
|
|
ld hl, wGameTimer
|
2023-09-30 15:10:44 -07:00
|
|
|
res GAME_TIMER_COUNTING_F, [hl] ; stop game timer counter
|
|
|
|
ld a, FALSE
|
|
|
|
ld [wText2bpp], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
.Jumptable:
|
2019-01-24 18:41:14 -08:00
|
|
|
; entries correspond to MAPSTATUS_* constants
|
2013-12-27 02:56:23 -08:00
|
|
|
dw StartMap
|
|
|
|
dw EnterMap
|
|
|
|
dw HandleMap
|
2013-11-22 02:04:32 -08:00
|
|
|
dw .done
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
DisableEvents:
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
2020-10-26 12:45:57 -07:00
|
|
|
ld [wScriptFlags2], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
EnableEvents::
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, $ff
|
2020-10-26 12:45:57 -07:00
|
|
|
ld [wScriptFlags2], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2023-10-17 07:24:04 -07:00
|
|
|
DisableTileEvents:
|
|
|
|
; DisableWarpsConnxns + DisableCoordEvents + DisableStepCount + DisableWildEncounters
|
|
|
|
push af
|
|
|
|
ld hl, wScriptFlags2
|
|
|
|
ld a, [hl]
|
|
|
|
and ~((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))
|
|
|
|
ld [hl], a
|
|
|
|
pop af
|
|
|
|
ret
|
|
|
|
|
2020-10-26 12:45:57 -07:00
|
|
|
DisableWarpsConnxns: ; unreferenced
|
|
|
|
ld hl, wScriptFlags2
|
2013-11-22 02:04:32 -08:00
|
|
|
res 2, [hl]
|
|
|
|
ret
|
|
|
|
|
2020-10-26 12:45:57 -07:00
|
|
|
DisableCoordEvents: ; unreferenced
|
|
|
|
ld hl, wScriptFlags2
|
2013-11-22 02:04:32 -08:00
|
|
|
res 1, [hl]
|
|
|
|
ret
|
|
|
|
|
2020-10-26 12:45:57 -07:00
|
|
|
DisableStepCount: ; unreferenced
|
|
|
|
ld hl, wScriptFlags2
|
2013-11-22 02:04:32 -08:00
|
|
|
res 0, [hl]
|
|
|
|
ret
|
|
|
|
|
2020-10-26 12:45:57 -07:00
|
|
|
DisableWildEncounters: ; unreferenced
|
|
|
|
ld hl, wScriptFlags2
|
2023-10-17 07:24:04 -07:00
|
|
|
res 3, [hl]
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2023-10-17 07:24:04 -07:00
|
|
|
DisableSpaceEffects:
|
2023-10-14 10:28:35 -07:00
|
|
|
ld hl, wScriptFlags2
|
2023-10-17 07:24:04 -07:00
|
|
|
res 4, [hl]
|
2023-10-14 10:28:35 -07:00
|
|
|
ret
|
|
|
|
|
2023-11-29 11:04:08 -08:00
|
|
|
DisableTrainerAndTalkerEvents: ; unreferenced
|
|
|
|
ld hl, wScriptFlags2
|
|
|
|
res 5, [hl]
|
|
|
|
ret
|
|
|
|
|
2020-10-26 12:45:57 -07:00
|
|
|
EnableWarpsConnxns: ; unreferenced
|
|
|
|
ld hl, wScriptFlags2
|
2013-11-22 02:04:32 -08:00
|
|
|
set 2, [hl]
|
|
|
|
ret
|
|
|
|
|
2020-10-26 12:45:57 -07:00
|
|
|
EnableCoordEvents: ; unreferenced
|
|
|
|
ld hl, wScriptFlags2
|
2013-11-22 02:04:32 -08:00
|
|
|
set 1, [hl]
|
|
|
|
ret
|
|
|
|
|
2020-10-26 12:45:57 -07:00
|
|
|
EnableStepCount: ; unreferenced
|
|
|
|
ld hl, wScriptFlags2
|
2013-11-22 02:04:32 -08:00
|
|
|
set 0, [hl]
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
EnableWildEncounters:
|
2020-10-26 12:45:57 -07:00
|
|
|
ld hl, wScriptFlags2
|
2023-10-17 07:24:04 -07:00
|
|
|
set 3, [hl]
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2023-10-14 10:28:35 -07:00
|
|
|
EnableSpaceEffects: ; unreferenced
|
|
|
|
ld hl, wScriptFlags2
|
2023-10-17 07:24:04 -07:00
|
|
|
set 4, [hl]
|
2023-10-14 10:28:35 -07:00
|
|
|
ret
|
|
|
|
|
2023-11-29 11:04:08 -08:00
|
|
|
EnableTrainerAndTalkerEvents: ; unreferenced
|
|
|
|
ld hl, wScriptFlags2
|
|
|
|
set 5, [hl]
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckWarpConnxnScriptFlag:
|
2020-10-26 12:45:57 -07:00
|
|
|
ld hl, wScriptFlags2
|
2013-11-22 02:04:32 -08:00
|
|
|
bit 2, [hl]
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckCoordEventScriptFlag:
|
2020-10-26 12:45:57 -07:00
|
|
|
ld hl, wScriptFlags2
|
2013-11-22 02:04:32 -08:00
|
|
|
bit 1, [hl]
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckStepCountScriptFlag:
|
2020-10-26 12:45:57 -07:00
|
|
|
ld hl, wScriptFlags2
|
2013-11-22 02:04:32 -08:00
|
|
|
bit 0, [hl]
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckWildEncountersScriptFlag:
|
2020-10-26 12:45:57 -07:00
|
|
|
ld hl, wScriptFlags2
|
2023-10-17 07:24:04 -07:00
|
|
|
bit 3, [hl]
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2023-10-17 07:24:04 -07:00
|
|
|
CheckSpaceEffectsScriptFlag:
|
2023-10-14 10:28:35 -07:00
|
|
|
ld hl, wScriptFlags2
|
2023-10-17 07:24:04 -07:00
|
|
|
bit 4, [hl]
|
2023-10-14 10:28:35 -07:00
|
|
|
ret
|
|
|
|
|
2023-11-29 11:04:08 -08:00
|
|
|
CheckTrainerAndTalkerEvents:
|
|
|
|
ld hl, wScriptFlags2
|
|
|
|
bit 5, [hl]
|
|
|
|
ret
|
|
|
|
|
2023-12-15 10:10:47 -08:00
|
|
|
; on enter overworld loop (MAPSETUP_ENTERLEVEL or MAPSETUP_CONTINUE)
|
2018-06-24 07:09:41 -07:00
|
|
|
StartMap:
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wScriptRunning], a
|
|
|
|
ld hl, wMapStatus
|
|
|
|
ld bc, wMapStatusEnd - wMapStatus
|
2013-11-22 02:04:32 -08:00
|
|
|
call ByteFill
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall InitCallReceiveDelay
|
2013-12-22 14:30:35 -08:00
|
|
|
call ClearJoypad
|
2023-10-18 09:07:46 -07:00
|
|
|
|
|
|
|
ld a, [hMapEntryMethod]
|
|
|
|
cp MAPSETUP_ENTERLEVEL
|
|
|
|
jr nz, .not_starting_level
|
2023-12-15 10:10:47 -08:00
|
|
|
|
|
|
|
; initialize board state
|
2023-10-14 11:52:09 -07:00
|
|
|
xor a
|
|
|
|
ld [wCurTurn], a
|
|
|
|
ld [wCurSpace], a
|
2023-12-15 10:10:47 -08:00
|
|
|
|
|
|
|
; initialize overworld state
|
|
|
|
ld hl, wNextWarp
|
|
|
|
xor a
|
|
|
|
ld [hli], a ; wNextWarp
|
|
|
|
ld [hli], a ; wNextMapGroup
|
|
|
|
ld [hli], a ; wNextMapNumber
|
|
|
|
ld [hli], a ; wPrevWarp
|
|
|
|
ld [hli], a ; wPrevMapGroup
|
|
|
|
ld [hl], a ; wPrevMapNumber
|
2023-12-20 10:14:28 -08:00
|
|
|
|
|
|
|
ld a, BANK(wDisabledSpacesBackups)
|
|
|
|
ld [rSVBK], a
|
|
|
|
ld hl, wDisabledSpacesBackups
|
|
|
|
ld bc, wDisabledSpacesBackupsEnd - wDisabledSpacesBackups
|
|
|
|
xor a
|
|
|
|
call ByteFill
|
|
|
|
ld e, NUM_DISABLED_SPACES_BACKUPS
|
|
|
|
ld hl, wDisabledSpacesBackups
|
|
|
|
ld bc, wMap2DisabledSpacesBackup - wMap1DisabledSpacesBackup
|
|
|
|
.loop1
|
|
|
|
ld a, GROUP_N_A
|
|
|
|
ld [hl], a
|
|
|
|
add hl, bc
|
|
|
|
dec e
|
|
|
|
jr nz, .loop1
|
|
|
|
ld [hl], $00 ; list terminator
|
|
|
|
|
2023-12-15 10:10:47 -08:00
|
|
|
ld a, BANK(wMapObjectsBackups)
|
|
|
|
ld [rSVBK], a
|
|
|
|
ld e, NUM_MAP_OBJECTS_BACKUPS
|
|
|
|
ld hl, wMapObjectsBackups
|
|
|
|
ld bc, wMap2ObjectsBackup - wMap1ObjectsBackup
|
2023-12-20 10:14:28 -08:00
|
|
|
.loop2
|
2023-12-15 10:10:47 -08:00
|
|
|
ld a, GROUP_N_A
|
|
|
|
ld [hl], a
|
|
|
|
add hl, bc
|
|
|
|
dec e
|
2023-12-20 10:14:28 -08:00
|
|
|
jr nz, .loop2
|
2023-12-15 10:10:47 -08:00
|
|
|
ld [hl], $00 ; list terminator
|
2023-12-20 10:14:28 -08:00
|
|
|
|
2023-12-15 10:10:47 -08:00
|
|
|
ld a, 1
|
|
|
|
ld [rSVBK], a
|
|
|
|
|
2023-10-18 09:07:46 -07:00
|
|
|
.not_starting_level
|
2023-09-22 14:12:05 -07:00
|
|
|
ld a, BOARDEVENT_DISPLAY_MENU
|
2023-10-14 10:28:35 -07:00
|
|
|
ldh [hCurBoardEvent], a
|
2023-10-14 11:52:09 -07:00
|
|
|
; fallthrough
|
|
|
|
|
|
|
|
; on map reload (e.g. after battle), warps and connections
|
2018-06-24 07:09:41 -07:00
|
|
|
EnterMap:
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
2016-01-12 09:46:18 -08:00
|
|
|
ld [wXYComparePointer], a
|
|
|
|
ld [wXYComparePointer + 1], a
|
2015-10-07 18:27:32 -07:00
|
|
|
call SetUpFiveStepWildEncounterCooldown
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall RunMapSetupScript
|
2015-11-13 15:59:49 -08:00
|
|
|
call DisableEvents
|
2013-12-27 02:56:23 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMapEntryMethod]
|
2015-11-11 20:38:57 -08:00
|
|
|
cp MAPSETUP_CONNECTION
|
2015-11-13 15:59:49 -08:00
|
|
|
jr nz, .dont_enable
|
|
|
|
call EnableEvents
|
|
|
|
.dont_enable
|
2013-12-27 02:56:23 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hMapEntryMethod]
|
2015-10-24 16:49:19 -07:00
|
|
|
cp MAPSETUP_RELOADMAP
|
2015-07-15 12:48:44 -07:00
|
|
|
jr nz, .dontresetpoison
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wPoisonStepCount], a
|
2015-07-15 12:48:44 -07:00
|
|
|
.dontresetpoison
|
2013-12-27 02:56:23 -08:00
|
|
|
|
2015-10-24 16:49:19 -07:00
|
|
|
xor a ; end map entry
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hMapEntryMethod], a
|
2019-01-24 18:41:14 -08:00
|
|
|
ld a, MAPSTATUS_HANDLE
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wMapStatus], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
HandleMap:
|
2013-11-22 02:04:32 -08:00
|
|
|
call ResetOverworldDelay
|
2015-12-17 12:14:51 -08:00
|
|
|
call HandleMapTimeAndJoypad
|
2023-09-15 11:04:16 -07:00
|
|
|
call HandleCmdQueue
|
2013-12-27 02:56:23 -08:00
|
|
|
call MapEvents
|
|
|
|
|
|
|
|
; Not immediately entering a connected map will cause problems.
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wMapStatus]
|
2019-01-24 18:41:14 -08:00
|
|
|
cp MAPSTATUS_HANDLE
|
2013-11-22 02:04:32 -08:00
|
|
|
ret nz
|
2013-12-27 02:56:23 -08:00
|
|
|
|
2016-05-17 05:40:42 -07:00
|
|
|
call HandleMapObjects
|
2013-11-22 02:04:32 -08:00
|
|
|
call NextOverworldFrame
|
2016-05-17 05:40:42 -07:00
|
|
|
call HandleMapBackground
|
|
|
|
call CheckPlayerState
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
MapEvents:
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wMapEventStatus]
|
2021-03-17 08:38:01 -07:00
|
|
|
ld hl, .Jumptable
|
2013-11-22 02:04:32 -08:00
|
|
|
rst JumpTable
|
|
|
|
ret
|
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
.Jumptable:
|
2019-01-24 18:41:14 -08:00
|
|
|
; entries correspond to MAPEVENTS_* constants
|
2013-12-27 02:56:23 -08:00
|
|
|
dw .events
|
|
|
|
dw .no_events
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
.events:
|
2013-11-22 02:04:32 -08:00
|
|
|
call PlayerEvents
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall ScriptEvents
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
.no_events:
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2023-11-01 03:48:12 -07:00
|
|
|
DEF MAX_OVERWORLD_DELAY EQU 2
|
|
|
|
DEF VIEW_MAP_OVERWORLD_DELAY EQU 1
|
2018-06-24 07:09:41 -07:00
|
|
|
ResetOverworldDelay:
|
2023-11-01 03:48:12 -07:00
|
|
|
ldh a, [hCurBoardEvent]
|
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
|
|
|
ld a, MAX_OVERWORLD_DELAY
|
|
|
|
jr nz, .set_delay
|
|
|
|
ld a, VIEW_MAP_OVERWORLD_DELAY
|
|
|
|
.set_delay
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hOverworldDelay], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
NextOverworldFrame:
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh a, [hOverworldDelay]
|
2013-11-22 02:04:32 -08:00
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
ld c, a
|
|
|
|
call DelayFrames
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
HandleMapTimeAndJoypad:
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wMapEventStatus]
|
2019-01-24 18:41:14 -08:00
|
|
|
cp MAPEVENTS_OFF
|
2013-11-22 02:04:32 -08:00
|
|
|
ret z
|
2013-12-27 02:56:23 -08:00
|
|
|
|
2013-12-22 14:30:35 -08:00
|
|
|
call GetJoypad
|
2013-11-22 02:04:32 -08:00
|
|
|
call TimeOfDayPals
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
HandleMapObjects:
|
2020-11-17 08:12:21 -08:00
|
|
|
farcall HandleNPCStep
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall _HandlePlayerStep
|
2015-12-24 19:58:42 -08:00
|
|
|
call _CheckObjectEnteringVisibleRange
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
HandleMapBackground:
|
2023-10-21 09:46:56 -07:00
|
|
|
call UpdateActiveSprites
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall ScrollScreen
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckPlayerState:
|
2015-11-14 20:02:38 -08:00
|
|
|
ld a, [wPlayerStepFlags]
|
2019-01-24 18:41:14 -08:00
|
|
|
bit PLAYERSTEP_CONTINUE_F, a
|
2023-10-18 11:04:11 -07:00
|
|
|
jr z, .events ; PLAYERSTEP_CONTINUE_F not set
|
2019-01-24 18:41:14 -08:00
|
|
|
bit PLAYERSTEP_STOP_F, a
|
2023-10-18 11:04:11 -07:00
|
|
|
jr z, .noevents ; PLAYERSTEP_CONTINUE_F set and PLAYERSTEP_STOP_F not set
|
2019-01-24 18:41:14 -08:00
|
|
|
bit PLAYERSTEP_MIDAIR_F, a
|
2023-10-18 11:04:11 -07:00
|
|
|
jr nz, .noevents ; PLAYERSTEP_CONTINUE_F, PLAYERSTEP_STOP_F, and PLAYERSTEP_MIDAIR_F all set
|
2015-11-13 15:59:49 -08:00
|
|
|
call EnableEvents
|
2015-07-15 12:48:44 -07:00
|
|
|
.events
|
2019-01-24 18:41:14 -08:00
|
|
|
ld a, MAPEVENTS_ON
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wMapEventStatus], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.noevents
|
2019-01-24 18:41:14 -08:00
|
|
|
ld a, MAPEVENTS_OFF
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wMapEventStatus], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
_CheckObjectEnteringVisibleRange:
|
2015-11-14 20:02:38 -08:00
|
|
|
ld hl, wPlayerStepFlags
|
2019-01-24 18:41:14 -08:00
|
|
|
bit PLAYERSTEP_STOP_F, [hl]
|
2013-11-22 02:04:32 -08:00
|
|
|
ret z
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall CheckObjectEnteringVisibleRange
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
PlayerEvents:
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
2015-10-24 07:34:19 -07:00
|
|
|
; If there's already a player event, don't interrupt it.
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wScriptRunning]
|
2013-11-22 02:04:32 -08:00
|
|
|
and a
|
|
|
|
ret nz
|
|
|
|
|
2023-09-22 14:12:05 -07:00
|
|
|
call CheckBoardEvent
|
2023-10-17 07:24:04 -07:00
|
|
|
call DisableSpaceEffects ; doesn't alter f
|
2023-09-22 14:12:05 -07:00
|
|
|
jr c, .ok
|
|
|
|
|
2023-11-28 04:59:36 -08:00
|
|
|
call CheckTrainerOrTalkerEvent
|
2015-07-15 12:48:44 -07:00
|
|
|
jr c, .ok
|
2013-11-22 02:04:32 -08:00
|
|
|
|
|
|
|
call CheckTileEvent
|
2023-10-17 07:24:04 -07:00
|
|
|
call DisableTileEvents ; preserves f
|
2015-07-15 12:48:44 -07:00
|
|
|
jr c, .ok
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
call RunMemScript
|
2015-07-15 12:48:44 -07:00
|
|
|
jr c, .ok
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2017-12-24 10:46:34 -08:00
|
|
|
call RunSceneScript
|
2015-07-15 12:48:44 -07:00
|
|
|
jr c, .ok
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
call CheckTimeEvents
|
2015-07-15 12:48:44 -07:00
|
|
|
jr c, .ok
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2023-10-14 12:45:48 -07:00
|
|
|
; BOARDEVENT_END_TURN is used as turn cleanup after BOARDEVENT_HANDLE_BOARD.
|
|
|
|
; when we make it here, it means there's finally nothing else to do (e.g. a trainer),
|
|
|
|
; so return with BOARDEVENT_DISPLAY_MENU for the next MapEvents iteration.
|
|
|
|
ldh a, [hCurBoardEvent]
|
|
|
|
cp BOARDEVENT_END_TURN
|
|
|
|
jr nz, .continue
|
|
|
|
ld a, BOARDEVENT_DISPLAY_MENU
|
|
|
|
ldh [hCurBoardEvent], a
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.continue
|
2013-11-22 02:04:32 -08:00
|
|
|
call OWPlayerInput
|
2015-07-15 12:48:44 -07:00
|
|
|
jr c, .ok
|
2013-11-22 02:04:32 -08:00
|
|
|
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.ok
|
2013-11-22 02:04:32 -08:00
|
|
|
push af
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall EnableScriptMode
|
2013-11-22 02:04:32 -08:00
|
|
|
pop af
|
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wScriptRunning], a
|
2015-10-24 16:49:19 -07:00
|
|
|
call DoPlayerEvent
|
2013-11-22 02:04:32 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2023-09-22 14:12:05 -07:00
|
|
|
CheckBoardEvent:
|
|
|
|
jumptable .Jumptable, hCurBoardEvent
|
|
|
|
|
|
|
|
.Jumptable:
|
|
|
|
table_width 2, .Jumptable
|
|
|
|
dw .none
|
2023-10-31 12:25:56 -07:00
|
|
|
dw .menu ; BOARDEVENT_DISPLAY_MENU
|
|
|
|
dw .board ; BOARDEVENT_HANDLE_BOARD
|
|
|
|
dw .none ; BOARDEVENT_END_TURN
|
2023-11-04 09:17:08 -07:00
|
|
|
dw .viewmap ; BOARDEVENT_VIEW_MAP_MODE
|
2023-10-31 12:25:56 -07:00
|
|
|
dw .menu ; BOARDEVENT_REDISPLAY_MENU
|
2023-11-04 09:17:08 -07:00
|
|
|
dw .branch ; BOARDEVENT_RESUME_BRANCH
|
2023-09-22 14:12:05 -07:00
|
|
|
assert_table_length NUM_BOARD_EVENTS + 1
|
|
|
|
|
|
|
|
.none
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.menu
|
|
|
|
ld a, BANK(BoardMenuScript)
|
|
|
|
ld hl, BoardMenuScript
|
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2023-10-14 10:28:35 -07:00
|
|
|
.board
|
2023-10-17 07:24:04 -07:00
|
|
|
call CheckSpaceEffectsScriptFlag
|
2023-10-14 10:28:35 -07:00
|
|
|
jr z, .no_space_effect
|
2023-11-16 08:20:13 -08:00
|
|
|
|
|
|
|
; anchor point handler
|
2023-11-17 05:22:28 -08:00
|
|
|
; if wCurSpaceNextSpace is not an anchor point, override any anchor point we pass through
|
2023-11-16 08:20:13 -08:00
|
|
|
ld a, [wCurSpaceNextSpace]
|
|
|
|
cp NEXT_SPACE_IS_ANCHOR_POINT
|
|
|
|
jr c, .next
|
|
|
|
ld a, [wCurMapAnchorEventCount]
|
|
|
|
and a
|
|
|
|
jr z, .next
|
|
|
|
; if we have arrived to an anchor point, load its associated next space to wCurSpaceNextSpace right now.
|
|
|
|
; don't queue a script so that it happens transparently from the point of view of the player's movement.
|
|
|
|
; note that the next space of an anchor point could be another anchor point.
|
|
|
|
ld c, a
|
|
|
|
ld hl, wCurMapAnchorEventsPointer
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
ld a, [wXCoord]
|
|
|
|
ld d, a
|
|
|
|
ld a, [wYCoord]
|
|
|
|
ld e, a
|
|
|
|
call CheckAndApplyAnchorPoint
|
|
|
|
ret nc ; if we applied an anchor point, we're done here (we're not in a space)
|
|
|
|
|
|
|
|
.next
|
|
|
|
; space handler
|
2023-10-14 10:28:35 -07:00
|
|
|
ld a, [wPlayerTile]
|
|
|
|
and $f0
|
|
|
|
cp HI_NYBBLE_SPACES
|
|
|
|
jr nz, .no_space_effect
|
|
|
|
ld a, [wPlayerTile]
|
|
|
|
and $0f
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
|
|
|
ld hl, .SpaceScripts
|
|
|
|
add hl, de
|
|
|
|
add hl, de
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
ld a, BANK(BoardSpaceScripts)
|
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2023-11-04 09:17:08 -07:00
|
|
|
.viewmap
|
2023-10-31 12:25:56 -07:00
|
|
|
; check if player pressed B and if so queue the script to exit View Map mode
|
|
|
|
ldh a, [hJoyDown]
|
|
|
|
and D_PAD
|
|
|
|
ret nz ; nc
|
|
|
|
ldh a, [hJoyPressed]
|
|
|
|
bit B_BUTTON_F, a
|
|
|
|
ret z ; nc
|
|
|
|
; B was pressed
|
2023-11-04 09:17:08 -07:00
|
|
|
ld a, BANK(.ExitViewMapModeScript)
|
|
|
|
ld hl, .ExitViewMapModeScript
|
2023-10-31 12:25:56 -07:00
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2023-11-04 09:17:08 -07:00
|
|
|
.ExitViewMapModeScript:
|
2023-10-31 12:25:56 -07:00
|
|
|
reloadmapafterviewmapmode
|
|
|
|
end
|
|
|
|
|
2023-11-04 09:17:08 -07:00
|
|
|
.branch
|
|
|
|
; special handler to resume branch space after returning from View Map mode.
|
|
|
|
; skip scall to .ArriveToBranchSpaceScript not to recompute branch struct.
|
|
|
|
ld a, BOARDEVENT_HANDLE_BOARD
|
|
|
|
ldh [hCurBoardEvent], a
|
|
|
|
ld a, BANK(BranchSpaceScript)
|
|
|
|
ld hl, BranchSpaceScript_PromptPlayer
|
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2023-10-14 10:28:35 -07:00
|
|
|
.no_space_effect
|
|
|
|
; continue moving in board
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.SpaceScripts:
|
|
|
|
table_width 2, .SpaceScripts
|
2023-10-19 11:38:54 -07:00
|
|
|
dw BlueSpaceScript ; COLL_BLUE_SPACE
|
|
|
|
dw RedSpaceScript ; COLL_RED_SPACE
|
|
|
|
dw GreenSpaceScript ; COLL_GREEN_SPACE
|
|
|
|
dw ItemSpaceScript ; COLL_ITEM_SPACE
|
|
|
|
dw PokemonSpaceScript ; COLL_POKEMON_SPACE
|
|
|
|
dw MinigameSpaceScript ; COLL_MINIGAME_SPACE
|
|
|
|
dw EndSpaceScript ; COLL_END_SPACE
|
|
|
|
dw GreySpaceScript ; COLL_GREY_SPACE
|
2023-10-24 11:36:23 -07:00
|
|
|
dw BranchSpaceScript ; COLL_BRANCH_SPACE
|
2023-10-28 10:09:58 -07:00
|
|
|
dw UnionSpaceScript ; COLL_UNION_SPACE
|
2023-10-14 10:28:35 -07:00
|
|
|
assert_table_length NUM_COLL_SPACES
|
|
|
|
|
2023-11-28 04:59:36 -08:00
|
|
|
CheckTrainerOrTalkerEvent:
|
2023-11-29 11:04:08 -08:00
|
|
|
call CheckTrainerAndTalkerEvents
|
|
|
|
jr z, .nope
|
2023-11-05 02:07:32 -08:00
|
|
|
ldh a, [hCurBoardEvent]
|
2023-10-31 12:25:56 -07:00
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
2023-11-29 11:04:08 -08:00
|
|
|
ret z ; nc
|
2023-10-31 12:25:56 -07:00
|
|
|
|
2023-11-28 04:59:36 -08:00
|
|
|
call CheckTrainerBattleOrTalkerPrompt
|
2015-07-15 12:48:44 -07:00
|
|
|
jr nc, .nope
|
2013-12-27 02:56:23 -08:00
|
|
|
|
2023-11-28 09:02:00 -08:00
|
|
|
ld a, [wSeenTrainerOrTalkerIsTalker]
|
2023-11-28 04:59:36 -08:00
|
|
|
and a ; cp FALSE
|
2015-11-12 08:10:19 -08:00
|
|
|
ld a, PLAYEREVENT_SEENBYTRAINER
|
2023-11-28 04:59:36 -08:00
|
|
|
jr z, .done
|
|
|
|
ld a, PLAYEREVENT_SEENBYTALKER
|
|
|
|
.done
|
2013-11-22 02:04:32 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.nope
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckTileEvent:
|
2017-12-24 10:46:34 -08:00
|
|
|
; Check for warps, coord events, or wild battles.
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-11-13 15:59:49 -08:00
|
|
|
call CheckWarpConnxnScriptFlag
|
|
|
|
jr z, .connections_disabled
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall CheckMovingOffEdgeOfMap
|
2015-11-12 08:10:19 -08:00
|
|
|
jr c, .map_connection
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2023-11-05 02:07:32 -08:00
|
|
|
ldh a, [hCurBoardEvent]
|
2023-10-31 12:25:56 -07:00
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
2023-11-29 11:04:08 -08:00
|
|
|
ret z ; nc
|
2023-10-31 12:25:56 -07:00
|
|
|
|
2015-10-24 16:49:19 -07:00
|
|
|
call CheckWarpTile
|
2015-11-12 08:10:19 -08:00
|
|
|
jr c, .warp_tile
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-11-13 15:59:49 -08:00
|
|
|
.connections_disabled
|
2023-11-05 02:07:32 -08:00
|
|
|
ldh a, [hCurBoardEvent]
|
2023-10-31 12:25:56 -07:00
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
2023-11-29 11:04:08 -08:00
|
|
|
ret z ; nc
|
2023-10-31 12:25:56 -07:00
|
|
|
|
2015-11-13 15:59:49 -08:00
|
|
|
call CheckCoordEventScriptFlag
|
|
|
|
jr z, .coord_events_disabled
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2017-12-24 10:46:34 -08:00
|
|
|
call CheckCurrentMapCoordEvents
|
2015-11-13 15:59:49 -08:00
|
|
|
jr c, .coord_event
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-11-13 15:59:49 -08:00
|
|
|
.coord_events_disabled
|
|
|
|
call CheckStepCountScriptFlag
|
|
|
|
jr z, .step_count_disabled
|
2013-11-22 02:04:32 -08:00
|
|
|
|
|
|
|
call CountStep
|
|
|
|
ret c
|
|
|
|
|
2015-11-13 15:59:49 -08:00
|
|
|
.step_count_disabled
|
|
|
|
call CheckWildEncountersScriptFlag
|
2015-07-15 12:48:44 -07:00
|
|
|
jr z, .ok
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-10-07 18:27:32 -07:00
|
|
|
call RandomEncounter
|
2013-11-22 02:04:32 -08:00
|
|
|
ret c
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.ok
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2015-11-12 08:10:19 -08:00
|
|
|
.map_connection
|
|
|
|
ld a, PLAYEREVENT_CONNECTION
|
2013-11-22 02:04:32 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2015-11-12 08:10:19 -08:00
|
|
|
.warp_tile
|
2022-09-12 06:15:44 -07:00
|
|
|
ld a, [wPlayerTile]
|
2013-11-22 02:04:32 -08:00
|
|
|
call CheckPitTile
|
2015-11-12 08:10:19 -08:00
|
|
|
jr nz, .not_pit
|
|
|
|
ld a, PLAYEREVENT_FALL
|
2013-11-22 02:04:32 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2015-11-12 08:10:19 -08:00
|
|
|
.not_pit
|
|
|
|
ld a, PLAYEREVENT_WARP
|
2013-11-22 02:04:32 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2015-11-13 15:59:49 -08:00
|
|
|
.coord_event
|
2016-01-06 04:44:50 -08:00
|
|
|
ld hl, wCurCoordEventScriptAddr
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2013-11-22 02:04:32 -08:00
|
|
|
call CallScript
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckWildEncounterCooldown::
|
2015-10-07 18:27:32 -07:00
|
|
|
ld hl, wWildEncounterCooldown
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
dec [hl]
|
|
|
|
ret z
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
SetUpFiveStepWildEncounterCooldown:
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, 5
|
2015-10-07 18:27:32 -07:00
|
|
|
ld [wWildEncounterCooldown], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2023-09-15 11:04:16 -07:00
|
|
|
SetMinTwoStepWildEncounterCooldown: ; unreferenced
|
2015-10-07 18:27:32 -07:00
|
|
|
ld a, [wWildEncounterCooldown]
|
2013-11-22 02:04:32 -08:00
|
|
|
cp 2
|
|
|
|
ret nc
|
|
|
|
ld a, 2
|
2015-10-07 18:27:32 -07:00
|
|
|
ld [wWildEncounterCooldown], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
RunSceneScript:
|
2023-11-05 02:07:32 -08:00
|
|
|
ldh a, [hCurBoardEvent]
|
2023-10-31 12:25:56 -07:00
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
2023-11-29 11:04:08 -08:00
|
|
|
ret z ; nc
|
2023-10-31 12:25:56 -07:00
|
|
|
|
2018-09-09 12:09:51 -07:00
|
|
|
ld a, [wCurMapSceneScriptCount]
|
2013-11-22 02:04:32 -08:00
|
|
|
and a
|
2015-07-15 12:48:44 -07:00
|
|
|
jr z, .nope
|
2013-11-22 02:04:32 -08:00
|
|
|
|
|
|
|
ld c, a
|
2017-12-24 10:46:34 -08:00
|
|
|
call CheckScenes
|
2013-11-22 02:04:32 -08:00
|
|
|
cp c
|
2015-07-15 12:48:44 -07:00
|
|
|
jr nc, .nope
|
2013-11-22 02:04:32 -08:00
|
|
|
|
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
2018-09-09 12:09:51 -07:00
|
|
|
ld hl, wCurMapSceneScriptsPointer
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2019-03-03 11:19:16 -08:00
|
|
|
rept SCENE_SCRIPT_SIZE
|
2016-01-10 14:44:09 -08:00
|
|
|
add hl, de
|
2015-07-20 08:28:05 -07:00
|
|
|
endr
|
2016-04-10 11:42:14 -07:00
|
|
|
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2021-01-09 12:16:05 -08:00
|
|
|
call GetFarWord
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2013-11-22 02:04:32 -08:00
|
|
|
call CallScript
|
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wScriptFlags
|
2013-11-22 02:04:32 -08:00
|
|
|
res 3, [hl]
|
|
|
|
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall EnableScriptMode
|
|
|
|
farcall ScriptEvents
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wScriptFlags
|
2013-11-22 02:04:32 -08:00
|
|
|
bit 3, [hl]
|
2015-07-15 12:48:44 -07:00
|
|
|
jr z, .nope
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2021-06-08 17:35:04 -07:00
|
|
|
ld hl, wDeferredScriptAddr
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2021-06-08 17:35:04 -07:00
|
|
|
ld a, [wDeferredScriptBank]
|
2013-11-22 02:04:32 -08:00
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.nope
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckTimeEvents:
|
2023-11-05 02:07:32 -08:00
|
|
|
ldh a, [hCurBoardEvent]
|
2023-10-31 12:25:56 -07:00
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
2023-11-29 11:04:08 -08:00
|
|
|
ret z ; nc
|
2023-10-31 12:25:56 -07:00
|
|
|
|
2015-10-19 07:23:58 -07:00
|
|
|
ld a, [wLinkMode]
|
2013-11-22 02:04:32 -08:00
|
|
|
and a
|
2014-07-24 20:19:56 -07:00
|
|
|
jr nz, .nothing
|
|
|
|
|
2017-12-28 04:15:46 -08:00
|
|
|
ld hl, wStatusFlags2
|
2018-01-22 12:40:43 -08:00
|
|
|
bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
|
2015-10-24 07:34:19 -07:00
|
|
|
jr z, .do_daily
|
2014-07-24 20:19:56 -07:00
|
|
|
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall CheckBugContestTimer
|
2015-10-24 07:34:19 -07:00
|
|
|
jr c, .end_bug_contest
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
.do_daily
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall CheckDailyResetTimer
|
|
|
|
farcall CheckPokerusTick
|
|
|
|
farcall CheckPhoneCall
|
2013-11-22 02:04:32 -08:00
|
|
|
ret c
|
|
|
|
|
2014-07-24 20:19:56 -07:00
|
|
|
.nothing
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
.end_bug_contest
|
2015-07-16 15:10:10 -07:00
|
|
|
ld a, BANK(BugCatchingContestOverScript)
|
|
|
|
ld hl, BugCatchingContestOverScript
|
2013-11-22 02:04:32 -08:00
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
OWPlayerInput:
|
2013-11-22 02:04:32 -08:00
|
|
|
call PlayerMovement
|
|
|
|
ret c
|
|
|
|
and a
|
|
|
|
jr nz, .NoAction
|
|
|
|
|
2023-10-31 12:25:56 -07:00
|
|
|
; Can't perform button actions while in BOARDEVENT_HANDLE_BOARD or BOARDEVENT_VIEW_MAP_MODE
|
2023-11-05 02:07:32 -08:00
|
|
|
ldh a, [hCurBoardEvent]
|
2023-10-18 11:29:49 -07:00
|
|
|
cp BOARDEVENT_HANDLE_BOARD
|
|
|
|
jr z, .NoAction
|
2023-10-31 12:25:56 -07:00
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
|
|
|
jr z, .NoAction
|
2023-10-18 11:29:49 -07:00
|
|
|
|
2013-11-22 02:04:32 -08:00
|
|
|
; Can't perform button actions while sliding on ice.
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall CheckStandingOnIce
|
2013-11-22 02:04:32 -08:00
|
|
|
jr c, .NoAction
|
|
|
|
|
|
|
|
call CheckAPressOW
|
|
|
|
jr c, .Action
|
|
|
|
|
|
|
|
call CheckMenuOW
|
|
|
|
jr c, .Action
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.NoAction:
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.Action:
|
2013-11-22 02:04:32 -08:00
|
|
|
push af
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall StopPlayerForEvent
|
2013-11-22 02:04:32 -08:00
|
|
|
pop af
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckAPressOW:
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hJoyPressed]
|
2013-11-22 02:04:32 -08:00
|
|
|
and A_BUTTON
|
|
|
|
ret z
|
|
|
|
call TryObjectEvent
|
|
|
|
ret c
|
2017-12-24 10:46:34 -08:00
|
|
|
call TryBGEvent
|
2013-11-22 02:04:32 -08:00
|
|
|
ret c
|
2017-12-24 10:46:34 -08:00
|
|
|
call TryTileCollisionEvent
|
2013-11-22 02:04:32 -08:00
|
|
|
ret c
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
PlayTalkObject:
|
2013-11-22 02:04:32 -08:00
|
|
|
push de
|
|
|
|
ld de, SFX_READ_TEXT_2
|
|
|
|
call PlaySFX
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
TryObjectEvent:
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall CheckFacingObject
|
2013-11-22 02:04:32 -08:00
|
|
|
jr c, .IsObject
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.IsObject:
|
2013-11-22 02:04:32 -08:00
|
|
|
call PlayTalkObject
|
2020-12-23 13:54:28 -08:00
|
|
|
ldh a, [hObjectStructIndex]
|
2015-07-15 12:48:44 -07:00
|
|
|
call GetObjectStruct
|
|
|
|
ld hl, OBJECT_MAP_OBJECT_INDEX
|
2013-11-22 02:04:32 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hLastTalked], a
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hLastTalked]
|
2013-11-22 02:04:32 -08:00
|
|
|
call GetMapObject
|
2023-01-03 19:16:08 -08:00
|
|
|
ld hl, MAPOBJECT_TYPE
|
2013-11-22 02:04:32 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hl]
|
2023-01-03 19:16:08 -08:00
|
|
|
and MAPOBJECT_TYPE_MASK
|
2013-11-22 02:04:32 -08:00
|
|
|
|
|
|
|
push bc
|
|
|
|
ld de, 3
|
2021-03-17 08:38:01 -07:00
|
|
|
ld hl, ObjectEventTypeArray
|
2013-11-22 02:04:32 -08:00
|
|
|
call IsInArray
|
|
|
|
pop bc
|
2023-07-27 04:01:32 -07:00
|
|
|
jr nc, .nope
|
2013-11-22 02:04:32 -08:00
|
|
|
|
|
|
|
inc hl
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2017-06-17 16:14:55 -07:00
|
|
|
jp hl
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2019-04-23 16:07:41 -07:00
|
|
|
.nope
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
ObjectEventTypeArray:
|
|
|
|
table_width 3, ObjectEventTypeArray
|
2017-12-24 10:46:34 -08:00
|
|
|
dbw OBJECTTYPE_SCRIPT, .script
|
|
|
|
dbw OBJECTTYPE_ITEMBALL, .itemball
|
|
|
|
dbw OBJECTTYPE_TRAINER, .trainer
|
2015-11-15 11:59:38 -08:00
|
|
|
; the remaining four are dummy events
|
2023-11-28 04:59:36 -08:00
|
|
|
dbw OBJECTTYPE_TALKER, .three
|
2017-12-24 10:46:34 -08:00
|
|
|
dbw OBJECTTYPE_4, .four
|
|
|
|
dbw OBJECTTYPE_5, .five
|
|
|
|
dbw OBJECTTYPE_6, .six
|
2021-03-17 08:38:01 -07:00
|
|
|
assert_table_length NUM_OBJECT_TYPES
|
|
|
|
db -1 ; end
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.script
|
2015-07-18 12:46:38 -07:00
|
|
|
ld hl, MAPOBJECT_SCRIPT_POINTER
|
2013-11-22 02:04:32 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2013-11-22 02:04:32 -08:00
|
|
|
call CallScript
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.itemball
|
2015-07-18 12:46:38 -07:00
|
|
|
ld hl, MAPOBJECT_SCRIPT_POINTER
|
2013-11-22 02:04:32 -08:00
|
|
|
add hl, bc
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2019-04-08 15:50:10 -07:00
|
|
|
ld de, wItemBallData
|
|
|
|
ld bc, wItemBallDataEnd - wItemBallData
|
2013-11-22 02:04:32 -08:00
|
|
|
call FarCopyBytes
|
2015-11-15 11:59:38 -08:00
|
|
|
ld a, PLAYEREVENT_ITEMBALL
|
2013-11-22 02:04:32 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.trainer
|
2015-11-15 11:59:38 -08:00
|
|
|
call TalkToTrainer
|
|
|
|
ld a, PLAYEREVENT_TALKTOTRAINER
|
2013-11-22 02:04:32 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.three
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.four
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.five
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.six
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
TryBGEvent:
|
2017-12-24 10:46:34 -08:00
|
|
|
call CheckFacingBGEvent
|
|
|
|
jr c, .is_bg_event
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2017-12-24 10:46:34 -08:00
|
|
|
.is_bg_event:
|
2019-04-08 15:50:10 -07:00
|
|
|
ld a, [wCurBGEventType]
|
2021-03-17 08:38:01 -07:00
|
|
|
ld hl, BGEventJumptable
|
2013-11-22 02:04:32 -08:00
|
|
|
rst JumpTable
|
|
|
|
ret
|
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
BGEventJumptable:
|
|
|
|
table_width 2, BGEventJumptable
|
2013-11-22 02:04:32 -08:00
|
|
|
dw .read
|
|
|
|
dw .up
|
|
|
|
dw .down
|
|
|
|
dw .right
|
|
|
|
dw .left
|
|
|
|
dw .ifset
|
|
|
|
dw .ifnotset
|
|
|
|
dw .itemifset
|
2015-07-15 12:48:44 -07:00
|
|
|
dw .copy
|
2021-03-17 08:38:01 -07:00
|
|
|
assert_table_length NUM_BGEVENTS
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
.up:
|
2015-11-15 11:59:38 -08:00
|
|
|
ld b, OW_UP
|
2013-11-22 02:04:32 -08:00
|
|
|
jr .checkdir
|
2021-03-17 08:38:01 -07:00
|
|
|
|
|
|
|
.down:
|
2015-11-15 11:59:38 -08:00
|
|
|
ld b, OW_DOWN
|
2013-11-22 02:04:32 -08:00
|
|
|
jr .checkdir
|
2021-03-17 08:38:01 -07:00
|
|
|
|
|
|
|
.right:
|
2015-11-15 11:59:38 -08:00
|
|
|
ld b, OW_RIGHT
|
2013-11-22 02:04:32 -08:00
|
|
|
jr .checkdir
|
2021-03-17 08:38:01 -07:00
|
|
|
|
|
|
|
.left:
|
2015-11-15 11:59:38 -08:00
|
|
|
ld b, OW_LEFT
|
2013-11-22 02:04:32 -08:00
|
|
|
jr .checkdir
|
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
.checkdir:
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPlayerDirection]
|
2013-11-22 02:04:32 -08:00
|
|
|
and %1100
|
|
|
|
cp b
|
|
|
|
jp nz, .dontread
|
2021-03-17 08:38:01 -07:00
|
|
|
.read:
|
2013-11-22 02:04:32 -08:00
|
|
|
call PlayTalkObject
|
2019-04-08 15:50:10 -07:00
|
|
|
ld hl, wCurBGEventScriptAddr
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2013-11-22 02:04:32 -08:00
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
.itemifset:
|
2017-12-24 10:46:34 -08:00
|
|
|
call CheckBGEventFlag
|
2013-11-22 02:04:32 -08:00
|
|
|
jp nz, .dontread
|
|
|
|
call PlayTalkObject
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2019-04-08 15:50:10 -07:00
|
|
|
ld de, wHiddenItemData
|
|
|
|
ld bc, wHiddenItemDataEnd - wHiddenItemData
|
2013-11-22 02:04:32 -08:00
|
|
|
call FarCopyBytes
|
2015-12-15 08:21:58 -08:00
|
|
|
ld a, BANK(HiddenItemScript)
|
|
|
|
ld hl, HiddenItemScript
|
2013-11-22 02:04:32 -08:00
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
.copy:
|
2017-12-24 10:46:34 -08:00
|
|
|
call CheckBGEventFlag
|
2013-11-22 02:04:32 -08:00
|
|
|
jr nz, .dontread
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2019-04-08 15:50:10 -07:00
|
|
|
ld de, wHiddenItemData
|
|
|
|
ld bc, wHiddenItemDataEnd - wHiddenItemData
|
2013-11-22 02:04:32 -08:00
|
|
|
call FarCopyBytes
|
|
|
|
jr .dontread
|
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
.ifset:
|
2017-12-24 10:46:34 -08:00
|
|
|
call CheckBGEventFlag
|
2013-11-22 02:04:32 -08:00
|
|
|
jr z, .dontread
|
2015-07-15 12:48:44 -07:00
|
|
|
jr .thenread
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
.ifnotset:
|
2017-12-24 10:46:34 -08:00
|
|
|
call CheckBGEventFlag
|
2013-11-22 02:04:32 -08:00
|
|
|
jr nz, .dontread
|
2021-03-17 08:38:01 -07:00
|
|
|
.thenread:
|
2013-11-22 02:04:32 -08:00
|
|
|
push hl
|
|
|
|
call PlayTalkObject
|
|
|
|
pop hl
|
|
|
|
inc hl
|
2015-12-26 18:59:03 -08:00
|
|
|
inc hl
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2021-01-09 12:16:05 -08:00
|
|
|
call GetFarWord
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2013-11-22 02:04:32 -08:00
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
.dontread:
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckBGEventFlag:
|
2019-04-08 15:50:10 -07:00
|
|
|
ld hl, wCurBGEventScriptAddr
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
push hl
|
2018-01-16 19:57:19 -08:00
|
|
|
call GetMapScriptsBank
|
2021-01-09 12:16:05 -08:00
|
|
|
call GetFarWord
|
2013-11-22 02:04:32 -08:00
|
|
|
ld e, l
|
|
|
|
ld d, h
|
2015-11-12 08:10:19 -08:00
|
|
|
ld b, CHECK_FLAG
|
2013-11-22 02:04:32 -08:00
|
|
|
call EventFlagAction
|
|
|
|
ld a, c
|
|
|
|
and a
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
PlayerMovement:
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall DoPlayerMovement
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, c
|
2021-03-17 08:38:01 -07:00
|
|
|
ld hl, PlayerMovementPointers
|
2013-11-22 02:04:32 -08:00
|
|
|
rst JumpTable
|
|
|
|
ld a, c
|
|
|
|
ret
|
|
|
|
|
2021-03-17 08:38:01 -07:00
|
|
|
PlayerMovementPointers:
|
2019-11-03 11:30:33 -08:00
|
|
|
; entries correspond to PLAYERMOVEMENT_* constants
|
2021-03-17 08:38:01 -07:00
|
|
|
table_width 2, PlayerMovementPointers
|
2019-11-03 11:30:33 -08:00
|
|
|
dw .normal
|
|
|
|
dw .warp
|
|
|
|
dw .turn
|
|
|
|
dw .force_turn
|
|
|
|
dw .finish
|
|
|
|
dw .continue
|
|
|
|
dw .exit_water
|
|
|
|
dw .jump
|
2021-03-17 08:38:01 -07:00
|
|
|
assert_table_length NUM_PLAYER_MOVEMENTS
|
2019-11-03 11:30:33 -08:00
|
|
|
|
|
|
|
.normal:
|
|
|
|
.finish:
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ld c, a
|
|
|
|
ret
|
|
|
|
|
2019-11-03 11:30:33 -08:00
|
|
|
.jump:
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ld c, a
|
|
|
|
ret
|
|
|
|
|
2019-11-03 11:30:33 -08:00
|
|
|
.warp:
|
|
|
|
ld a, PLAYEREVENT_WARP
|
2013-11-22 02:04:32 -08:00
|
|
|
ld c, a
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2019-11-03 11:30:33 -08:00
|
|
|
.turn:
|
|
|
|
ld a, PLAYEREVENT_JOYCHANGEFACING
|
2013-11-22 02:04:32 -08:00
|
|
|
ld c, a
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2019-11-03 11:30:33 -08:00
|
|
|
.force_turn:
|
2013-11-22 02:04:32 -08:00
|
|
|
; force the player to move in some direction
|
2015-07-15 12:48:44 -07:00
|
|
|
ld a, BANK(Script_ForcedMovement)
|
|
|
|
ld hl, Script_ForcedMovement
|
2013-11-22 02:04:32 -08:00
|
|
|
call CallScript
|
|
|
|
ld c, a
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2019-11-03 11:30:33 -08:00
|
|
|
.continue:
|
|
|
|
.exit_water:
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, -1
|
|
|
|
ld c, a
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CheckMenuOW:
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
2023-09-30 10:12:57 -07:00
|
|
|
ld [wMenuReturn], a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hJoyPressed]
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2017-12-30 09:35:50 -08:00
|
|
|
bit SELECT_F, a
|
2013-11-22 02:04:32 -08:00
|
|
|
jr nz, .Select
|
|
|
|
|
2017-12-30 09:35:50 -08:00
|
|
|
bit START_F, a
|
2013-11-22 02:04:32 -08:00
|
|
|
jr z, .NoMenu
|
|
|
|
|
|
|
|
ld a, BANK(StartMenuScript)
|
|
|
|
ld hl, StartMenuScript
|
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.NoMenu:
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.Select:
|
2013-11-22 02:04:32 -08:00
|
|
|
call PlayTalkObject
|
|
|
|
ld a, BANK(SelectMenuScript)
|
|
|
|
ld hl, SelectMenuScript
|
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
StartMenuScript:
|
2015-01-20 00:01:23 -08:00
|
|
|
callasm StartMenu
|
2019-03-10 13:39:31 -07:00
|
|
|
sjump StartMenuCallback
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
SelectMenuScript:
|
2015-01-20 00:01:23 -08:00
|
|
|
callasm SelectMenu
|
2019-03-10 13:39:31 -07:00
|
|
|
sjump SelectMenuCallback
|
2013-11-22 02:04:32 -08:00
|
|
|
|
|
|
|
StartMenuCallback:
|
2018-06-24 07:09:41 -07:00
|
|
|
SelectMenuCallback:
|
2023-09-30 10:12:57 -07:00
|
|
|
readmem wMenuReturn
|
|
|
|
ifequal MENURETURN_SCRIPT, .Script
|
|
|
|
ifequal MENURETURN_ASM, .Asm
|
2013-11-22 02:04:32 -08:00
|
|
|
end
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.Script:
|
2019-03-10 13:39:31 -07:00
|
|
|
memjump wQueuedScriptBank
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.Asm:
|
2019-03-10 13:39:31 -07:00
|
|
|
memcallasm wQueuedScriptBank
|
2013-11-22 02:04:32 -08:00
|
|
|
end
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
CountStep:
|
2015-10-24 07:34:19 -07:00
|
|
|
; Don't count steps in link communication rooms.
|
2015-10-19 07:23:58 -07:00
|
|
|
ld a, [wLinkMode]
|
2013-11-22 02:04:32 -08:00
|
|
|
and a
|
2015-07-15 12:48:44 -07:00
|
|
|
jr nz, .done
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
; If there is a special phone call, don't count the step.
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall CheckSpecialPhoneCall
|
2015-10-24 07:34:19 -07:00
|
|
|
jr c, .doscript
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
; If Repel wore off, don't count the step.
|
|
|
|
call DoRepelStep
|
|
|
|
jr c, .doscript
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
; Count the step for poison and total steps
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPoisonStepCount
|
2013-11-22 02:04:32 -08:00
|
|
|
inc [hl]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wStepCount
|
2013-11-22 02:04:32 -08:00
|
|
|
inc [hl]
|
2015-10-24 07:34:19 -07:00
|
|
|
; Every 256 steps, increase the happiness of all your Pokemon.
|
|
|
|
jr nz, .skip_happiness
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall StepHappiness
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
.skip_happiness
|
|
|
|
; Every 256 steps, offset from the happiness incrementor by 128 steps,
|
|
|
|
; decrease the hatch counter of all your eggs until you reach the first
|
|
|
|
; one that is ready to hatch.
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wStepCount]
|
2013-11-22 02:04:32 -08:00
|
|
|
cp $80
|
2015-10-24 07:34:19 -07:00
|
|
|
jr nz, .skip_egg
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall DoEggStep
|
2015-10-24 07:34:19 -07:00
|
|
|
jr nz, .hatch
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
.skip_egg
|
|
|
|
; Increase the EXP of (both) DayCare Pokemon by 1.
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall DayCareStep
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2020-11-17 08:09:02 -08:00
|
|
|
; Every 4 steps, deal damage to all poisoned Pokemon.
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPoisonStepCount
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, [hl]
|
|
|
|
cp 4
|
2015-10-24 07:34:19 -07:00
|
|
|
jr c, .skip_poison
|
2013-11-22 02:04:32 -08:00
|
|
|
ld [hl], 0
|
|
|
|
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall DoPoisonStep
|
2015-10-24 07:34:19 -07:00
|
|
|
jr c, .doscript
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
.skip_poison
|
2017-12-24 09:47:30 -08:00
|
|
|
farcall DoBikeStep
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2015-07-15 12:48:44 -07:00
|
|
|
.done
|
2013-11-22 02:04:32 -08:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
.doscript
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, -1
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2015-10-24 07:34:19 -07:00
|
|
|
.hatch
|
2019-11-03 11:30:33 -08:00
|
|
|
ld a, PLAYEREVENT_HATCH
|
2013-11-22 02:04:32 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2020-06-21 13:27:43 -07:00
|
|
|
.whiteout ; unreferenced
|
2019-11-03 11:30:33 -08:00
|
|
|
ld a, PLAYEREVENT_WHITEOUT
|
2013-11-22 02:04:32 -08:00
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
DoRepelStep:
|
2015-10-24 07:34:19 -07:00
|
|
|
ld a, [wRepelEffect]
|
2013-11-22 02:04:32 -08:00
|
|
|
and a
|
|
|
|
ret z
|
2015-09-09 16:27:07 -07:00
|
|
|
|
2013-11-22 02:04:32 -08:00
|
|
|
dec a
|
2015-10-24 07:34:19 -07:00
|
|
|
ld [wRepelEffect], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ret nz
|
2015-09-09 16:27:07 -07:00
|
|
|
|
2015-07-16 15:10:10 -07:00
|
|
|
ld a, BANK(RepelWoreOffScript)
|
|
|
|
ld hl, RepelWoreOffScript
|
2013-11-22 02:04:32 -08:00
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
DoPlayerEvent:
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wScriptRunning]
|
2013-11-22 02:04:32 -08:00
|
|
|
and a
|
|
|
|
ret z
|
2015-11-11 20:38:57 -08:00
|
|
|
|
2015-11-05 12:08:00 -08:00
|
|
|
cp PLAYEREVENT_MAPSCRIPT ; run script
|
2013-11-22 02:04:32 -08:00
|
|
|
ret z
|
2015-11-11 20:38:57 -08:00
|
|
|
|
2015-11-05 12:08:00 -08:00
|
|
|
cp NUM_PLAYER_EVENTS
|
2013-11-22 02:04:32 -08:00
|
|
|
ret nc
|
|
|
|
|
|
|
|
ld c, a
|
|
|
|
ld b, 0
|
2015-11-05 12:08:00 -08:00
|
|
|
ld hl, PlayerEventScriptPointers
|
2016-01-10 14:44:09 -08:00
|
|
|
add hl, bc
|
2016-05-10 09:31:49 -07:00
|
|
|
add hl, bc
|
|
|
|
add hl, bc
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, [hli]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wScriptBank], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, [hli]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wScriptPos], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ld a, [hl]
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wScriptPos + 1], a
|
2013-11-22 02:04:32 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
PlayerEventScriptPointers:
|
2018-07-28 21:57:28 -07:00
|
|
|
; entries correspond to PLAYEREVENT_* constants
|
2021-03-17 08:38:01 -07:00
|
|
|
table_width 3, PlayerEventScriptPointers
|
2020-10-04 16:43:28 -07:00
|
|
|
dba InvalidEventScript ; PLAYEREVENT_NONE
|
2020-07-17 05:37:03 -07:00
|
|
|
dba SeenByTrainerScript ; PLAYEREVENT_SEENBYTRAINER
|
|
|
|
dba TalkToTrainerScript ; PLAYEREVENT_TALKTOTRAINER
|
|
|
|
dba FindItemInBallScript ; PLAYEREVENT_ITEMBALL
|
|
|
|
dba EdgeWarpScript ; PLAYEREVENT_CONNECTION
|
|
|
|
dba WarpToNewMapScript ; PLAYEREVENT_WARP
|
|
|
|
dba FallIntoMapScript ; PLAYEREVENT_FALL
|
|
|
|
dba OverworldWhiteoutScript ; PLAYEREVENT_WHITEOUT
|
|
|
|
dba HatchEggScript ; PLAYEREVENT_HATCH
|
|
|
|
dba ChangeDirectionScript ; PLAYEREVENT_JOYCHANGEFACING
|
2023-11-28 04:59:36 -08:00
|
|
|
dba SeenByTalkerScript ; PLAYEREVENT_SEENBYTALKER
|
2020-10-04 16:43:28 -07:00
|
|
|
dba InvalidEventScript ; (NUM_PLAYER_EVENTS)
|
2021-03-17 08:38:01 -07:00
|
|
|
assert_table_length NUM_PLAYER_EVENTS + 1
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2020-10-04 16:43:28 -07:00
|
|
|
InvalidEventScript:
|
2013-11-22 02:04:32 -08:00
|
|
|
end
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
HatchEggScript:
|
2015-07-15 12:48:44 -07:00
|
|
|
callasm OverworldHatchEgg
|
2013-11-22 02:04:32 -08:00
|
|
|
end
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
WarpToNewMapScript:
|
2013-11-22 02:04:32 -08:00
|
|
|
warpsound
|
2015-11-11 20:38:57 -08:00
|
|
|
newloadmap MAPSETUP_DOOR
|
2013-11-22 02:04:32 -08:00
|
|
|
end
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
FallIntoMapScript:
|
2015-11-11 20:38:57 -08:00
|
|
|
newloadmap MAPSETUP_FALL
|
2013-11-22 02:04:32 -08:00
|
|
|
playsound SFX_KINESIS
|
2020-10-04 16:43:28 -07:00
|
|
|
applymovement PLAYER, .SkyfallMovement
|
2013-11-22 02:04:32 -08:00
|
|
|
playsound SFX_STRENGTH
|
2015-10-24 16:49:19 -07:00
|
|
|
scall LandAfterPitfallScript
|
2013-11-22 02:04:32 -08:00
|
|
|
end
|
|
|
|
|
2020-10-04 16:43:28 -07:00
|
|
|
.SkyfallMovement:
|
2013-11-22 02:04:32 -08:00
|
|
|
skyfall
|
|
|
|
step_end
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
LandAfterPitfallScript:
|
2013-11-22 02:04:32 -08:00
|
|
|
earthquake 16
|
|
|
|
end
|
|
|
|
|
2020-10-04 16:43:28 -07:00
|
|
|
EdgeWarpScript:
|
2020-07-17 05:37:03 -07:00
|
|
|
reloadend MAPSETUP_CONNECTION
|
2013-11-22 02:04:32 -08:00
|
|
|
|
2020-10-04 16:43:28 -07:00
|
|
|
ChangeDirectionScript:
|
2015-11-13 15:59:49 -08:00
|
|
|
deactivatefacing 3
|
|
|
|
callasm EnableWildEncounters
|
2013-11-22 02:04:32 -08:00
|
|
|
end
|
|
|
|
|
2018-03-13 05:07:16 -07:00
|
|
|
INCLUDE "engine/overworld/scripting.asm"
|
2018-01-11 20:50:44 -08:00
|
|
|
|
2018-06-25 10:48:16 -07:00
|
|
|
WarpToSpawnPoint::
|
|
|
|
ld hl, wStatusFlags2
|
|
|
|
res STATUSFLAGS2_SAFARI_GAME_F, [hl]
|
|
|
|
res STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
|
|
|
|
ret
|
|
|
|
|
|
|
|
RunMemScript::
|
2023-11-05 02:07:32 -08:00
|
|
|
ldh a, [hCurBoardEvent]
|
2023-10-31 12:25:56 -07:00
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
2023-11-29 11:04:08 -08:00
|
|
|
ret z ; nc
|
2018-06-25 10:48:16 -07:00
|
|
|
; If there is no script here, we don't need to be here.
|
|
|
|
ld a, [wMapReentryScriptQueueFlag]
|
|
|
|
and a
|
2023-11-29 11:04:08 -08:00
|
|
|
ret z ; nc
|
2018-06-25 10:48:16 -07:00
|
|
|
; Execute the script at (wMapReentryScriptBank):(wMapReentryScriptAddress).
|
|
|
|
ld hl, wMapReentryScriptAddress
|
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
|
|
|
ld a, [wMapReentryScriptBank]
|
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
; Clear the buffer for the next script.
|
|
|
|
push af
|
|
|
|
xor a
|
|
|
|
ld hl, wMapReentryScriptQueueFlag
|
|
|
|
ld bc, 8
|
|
|
|
call ByteFill
|
|
|
|
pop af
|
|
|
|
ret
|
|
|
|
|
2023-09-15 11:04:16 -07:00
|
|
|
LoadMemScript::
|
2018-06-25 10:48:16 -07:00
|
|
|
; If there's already a script here, don't overwrite.
|
|
|
|
ld hl, wMapReentryScriptQueueFlag
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
ret nz
|
|
|
|
; Set the flag
|
|
|
|
ld [hl], 1
|
|
|
|
inc hl
|
|
|
|
; Load the script pointer b:de into (wMapReentryScriptBank):(wMapReentryScriptAddress)
|
|
|
|
ld [hl], b
|
|
|
|
inc hl
|
|
|
|
ld [hl], e
|
|
|
|
inc hl
|
|
|
|
ld [hl], d
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
|
|
|
TryTileCollisionEvent::
|
|
|
|
call GetFacingTileCoord
|
2019-04-08 15:50:10 -07:00
|
|
|
ld [wFacingTileID], a
|
2018-06-25 10:48:16 -07:00
|
|
|
ld c, a
|
2022-06-17 19:30:53 -07:00
|
|
|
; CheckFacingTileForStdScript preserves c, and
|
|
|
|
; farcall copies c back into a.
|
2018-06-25 10:48:16 -07:00
|
|
|
farcall CheckFacingTileForStdScript
|
|
|
|
jr c, .done
|
|
|
|
|
2022-06-17 19:30:53 -07:00
|
|
|
; CheckCutTreeTile expects a == [wFacingTileID], which
|
|
|
|
; it still is after the previous farcall.
|
2018-06-25 10:48:16 -07:00
|
|
|
call CheckCutTreeTile
|
|
|
|
jr nz, .whirlpool
|
|
|
|
farcall TryCutOW
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
.whirlpool
|
2019-04-08 15:50:10 -07:00
|
|
|
ld a, [wFacingTileID]
|
2018-06-25 10:48:16 -07:00
|
|
|
call CheckWhirlpoolTile
|
|
|
|
jr nz, .waterfall
|
|
|
|
farcall TryWhirlpoolOW
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
.waterfall
|
2019-04-08 15:50:10 -07:00
|
|
|
ld a, [wFacingTileID]
|
2018-06-25 10:48:16 -07:00
|
|
|
call CheckWaterfallTile
|
|
|
|
jr nz, .headbutt
|
|
|
|
farcall TryWaterfallOW
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
.headbutt
|
2019-04-08 15:50:10 -07:00
|
|
|
ld a, [wFacingTileID]
|
2018-06-25 10:48:16 -07:00
|
|
|
call CheckHeadbuttTreeTile
|
|
|
|
jr nz, .surf
|
|
|
|
farcall TryHeadbuttOW
|
|
|
|
jr c, .done
|
|
|
|
jr .noevent
|
|
|
|
|
|
|
|
.surf
|
|
|
|
farcall TrySurfOW
|
|
|
|
jr nc, .noevent
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
.noevent
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.done
|
|
|
|
call PlayClickSFX
|
|
|
|
ld a, $ff
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
|
|
|
RandomEncounter::
|
|
|
|
; Random encounter
|
|
|
|
|
|
|
|
call CheckWildEncounterCooldown
|
|
|
|
jr c, .nope
|
2023-08-04 09:45:50 -07:00
|
|
|
call CanEncounterWildMonInThisTile
|
2018-06-25 10:48:16 -07:00
|
|
|
jr nc, .nope
|
|
|
|
ld hl, wStatusFlags2
|
|
|
|
bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, [hl]
|
|
|
|
jr nz, .bug_contest
|
|
|
|
farcall TryWildEncounter
|
|
|
|
jr nz, .nope
|
|
|
|
jr .ok
|
|
|
|
|
|
|
|
.bug_contest
|
|
|
|
call _TryWildEncounter_BugContest
|
|
|
|
jr nc, .nope
|
|
|
|
jr .ok_bug_contest
|
|
|
|
|
|
|
|
.nope
|
|
|
|
ld a, 1
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.ok
|
|
|
|
ld a, BANK(WildBattleScript)
|
|
|
|
ld hl, WildBattleScript
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
.ok_bug_contest
|
|
|
|
ld a, BANK(BugCatchingContestBattleScript)
|
|
|
|
ld hl, BugCatchingContestBattleScript
|
|
|
|
jr .done
|
|
|
|
|
|
|
|
.done
|
|
|
|
call CallScript
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
|
|
|
WildBattleScript:
|
|
|
|
randomwildmon
|
|
|
|
startbattle
|
|
|
|
reloadmapafterbattle
|
|
|
|
end
|
|
|
|
|
2023-08-04 09:45:50 -07:00
|
|
|
CanEncounterWildMonInThisTile::
|
2018-06-25 10:48:16 -07:00
|
|
|
ld hl, wStatusFlags
|
|
|
|
bit STATUSFLAGS_NO_WILD_ENCOUNTERS_F, [hl]
|
|
|
|
jr nz, .no
|
|
|
|
ld a, [wEnvironment]
|
2023-08-04 09:45:50 -07:00
|
|
|
cp INDOOR_ENVIRONMENT
|
|
|
|
jr nc, .ice_check
|
2018-06-25 10:48:16 -07:00
|
|
|
farcall CheckGrassCollision
|
|
|
|
jr nc, .no
|
|
|
|
|
|
|
|
.ice_check
|
2022-09-12 06:15:44 -07:00
|
|
|
ld a, [wPlayerTile]
|
2018-06-25 10:48:16 -07:00
|
|
|
call CheckIceTile
|
|
|
|
jr z, .no
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
|
|
|
.no
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
_TryWildEncounter_BugContest:
|
|
|
|
call TryWildEncounter_BugContest
|
|
|
|
ret nc
|
|
|
|
call ChooseWildEncounter_BugContest
|
|
|
|
farcall CheckRepelEffect
|
|
|
|
ret
|
|
|
|
|
|
|
|
ChooseWildEncounter_BugContest::
|
|
|
|
; Pick a random mon out of ContestMons.
|
|
|
|
|
|
|
|
.loop
|
|
|
|
call Random
|
|
|
|
cp 100 << 1
|
|
|
|
jr nc, .loop
|
|
|
|
srl a
|
|
|
|
|
|
|
|
ld hl, ContestMons
|
|
|
|
ld de, 4
|
|
|
|
.CheckMon:
|
|
|
|
sub [hl]
|
|
|
|
jr c, .GotMon
|
|
|
|
add hl, de
|
|
|
|
jr .CheckMon
|
|
|
|
|
|
|
|
.GotMon:
|
|
|
|
inc hl
|
|
|
|
|
|
|
|
; Species
|
|
|
|
ld a, [hli]
|
|
|
|
ld [wTempWildMonSpecies], a
|
|
|
|
|
|
|
|
; Min level
|
|
|
|
ld a, [hli]
|
|
|
|
ld d, a
|
|
|
|
|
|
|
|
; Max level
|
|
|
|
ld a, [hl]
|
|
|
|
|
|
|
|
sub d
|
|
|
|
jr nz, .RandomLevel
|
|
|
|
|
|
|
|
; If min and max are the same.
|
|
|
|
ld a, d
|
|
|
|
jr .GotLevel
|
|
|
|
|
|
|
|
.RandomLevel:
|
|
|
|
; Get a random level between the min and max.
|
|
|
|
ld c, a
|
|
|
|
inc c
|
|
|
|
call Random
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hRandomAdd]
|
2018-06-25 10:48:16 -07:00
|
|
|
call SimpleDivide
|
|
|
|
add d
|
|
|
|
|
|
|
|
.GotLevel:
|
|
|
|
ld [wCurPartyLevel], a
|
|
|
|
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
|
|
|
TryWildEncounter_BugContest:
|
2022-09-12 06:15:44 -07:00
|
|
|
ld a, [wPlayerTile]
|
2018-06-25 10:48:16 -07:00
|
|
|
call CheckSuperTallGrassTile
|
|
|
|
ld b, 40 percent
|
|
|
|
jr z, .ok
|
|
|
|
ld b, 20 percent
|
|
|
|
|
|
|
|
.ok
|
|
|
|
farcall ApplyMusicEffectOnEncounterRate
|
|
|
|
farcall ApplyCleanseTagEffectOnEncounterRate
|
|
|
|
call Random
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hRandomAdd]
|
2018-06-25 10:48:16 -07:00
|
|
|
cp b
|
|
|
|
ret c
|
|
|
|
ld a, 1
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
|
|
|
INCLUDE "data/wild/bug_contest_mons.asm"
|
|
|
|
|
|
|
|
DoBikeStep::
|
|
|
|
; If the bike shop owner doesn't have our number, or
|
|
|
|
; if we've already gotten the call, we don't have to
|
|
|
|
; be here.
|
|
|
|
ld hl, wStatusFlags2
|
|
|
|
bit STATUSFLAGS2_BIKE_SHOP_CALL_F, [hl]
|
2023-07-25 06:33:08 -07:00
|
|
|
jr z, .dont_increment
|
2018-06-25 10:48:16 -07:00
|
|
|
|
|
|
|
; If we're not on the bike, we don't have to be here.
|
|
|
|
ld a, [wPlayerState]
|
|
|
|
cp PLAYER_BIKE
|
2023-07-25 06:33:08 -07:00
|
|
|
jr nz, .dont_increment
|
2018-06-25 10:48:16 -07:00
|
|
|
|
|
|
|
; If we're not in an area of phone service, we don't
|
|
|
|
; have to be here.
|
|
|
|
call GetMapPhoneService
|
|
|
|
and a
|
2023-07-25 06:33:08 -07:00
|
|
|
jr nz, .dont_increment
|
2018-06-25 10:48:16 -07:00
|
|
|
|
|
|
|
; Check the bike step count and check whether we've
|
|
|
|
; taken 65536 of them yet.
|
|
|
|
ld hl, wBikeStep
|
|
|
|
ld a, [hli]
|
|
|
|
ld d, a
|
|
|
|
ld e, [hl]
|
|
|
|
cp 255
|
|
|
|
jr nz, .increment
|
|
|
|
ld a, e
|
|
|
|
cp 255
|
|
|
|
jr z, .dont_increment
|
|
|
|
|
|
|
|
.increment
|
|
|
|
inc de
|
|
|
|
ld [hl], e
|
|
|
|
dec hl
|
|
|
|
ld [hl], d
|
|
|
|
|
|
|
|
.dont_increment
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
|
2020-06-17 19:12:04 -07:00
|
|
|
INCLUDE "engine/overworld/cmd_queue.asm"
|