Add support for a level having more than one associated landmark, for levels with alternative starting points (#12)

This commit is contained in:
xCrystal 2024-01-18 14:06:10 +01:00
parent 0abe559e11
commit 8757112152
6 changed files with 44 additions and 10 deletions

View File

@ -1,21 +1,21 @@
; Landmarks indexes (see data/maps/landmarks.asm)
; Landmarks indexes (see data/level_selection_menu.asm)
const_def
const LANDMARK_LEVEL_1 ; 00
if DEF(_DEBUG)
const LANDMARK_DEBUGLEVEL_1 ; 00
const LANDMARK_DEBUGLEVEL_2 ; 01
const LANDMARK_DEBUGLEVEL_3 ; 02
const LANDMARK_DEBUGLEVEL_4 ; 03
const LANDMARK_DEBUGLEVEL_5 ; 04
const LANDMARK_DEBUGLEVEL_1 ; 01
const LANDMARK_DEBUGLEVEL_2 ; 02
const LANDMARK_DEBUGLEVEL_3 ; 03
const LANDMARK_DEBUGLEVEL_4 ; 04
const LANDMARK_DEBUGLEVEL_5 ; 05
endc
DEF NUM_LANDMARKS EQU const_value
; used in CaughtData
; used in CaughtData (legacy)
const_def $7f, -1
const LANDMARK_EVENT ; $7f
const LANDMARK_GIFT ; $7e
; Regions
; Regions (legacy)
const_def
const JOHTO_REGION ; 0
const KANTO_REGION ; 1

11
constants/level_constants.asm Executable file
View File

@ -0,0 +1,11 @@
; Level indexes (see data/level_selection_menu.asm)
const_def
const LEVEL_1 ; 00
if DEF(_DEBUG)
const DEBUGLEVEL_1 ; 01
const DEBUGLEVEL_2 ; 02
const DEBUGLEVEL_3 ; 03
const DEBUGLEVEL_4 ; 04
const DEBUGLEVEL_5 ; 05
endc
DEF NUM_LEVELS EQU const_value

View File

@ -17,6 +17,7 @@ MACRO level_selection_menu_landmark
ENDM
LevelSelectionMenu_Landmarks:
table_width 6, LevelSelectionMenu_Landmarks
.landmark1
level_selection_menu_landmark 0, 16, 12, .Level1LandmarkName, SPAWN_LEVEL_1 ; LANDMARK_LEVEL_1
.landmark2
@ -27,6 +28,7 @@ if DEF(_DEBUG)
level_selection_menu_landmark 1, 16, 11, .DebugLevel4LandmarkName, SPAWN_DEBUGLEVEL_4 ; LANDMARK_DEBUGLEVEL_4
level_selection_menu_landmark 2, 9, 5, .DebugLevel5LandmarkName, SPAWN_DEBUGLEVEL_5 ; LANDMARK_DEBUGLEVEL_5
endc
assert_table_length NUM_LANDMARKS
.Level1LandmarkName: db "LEVEL 1@"
if DEF(_DEBUG)
@ -108,3 +110,17 @@ LevelSelectionMenu_PageGrid:
DEF LEVELSELECTIONMENU_PAGE_GRID_WIDTH EQU 4
DEF LEVELSELECTIONMENU_PAGE_GRID_HEIGHT EQU 4
LandmarkToLevelTable:
; the usual level:landmark relation is expected to be 1:1, but 1:n is
; also supported, for levels that may have alternative starting points.
table_width 1, LandmarkToLevelTable
db LEVEL_1 ; LANDMARK_LEVEL_1
if DEF(_DEBUG)
db DEBUGLEVEL_1 ; LANDMARK_DEBUGLEVEL_1
db DEBUGLEVEL_2 ; LANDMARK_DEBUGLEVEL_2
db DEBUGLEVEL_3 ; LANDMARK_DEBUGLEVEL_3
db DEBUGLEVEL_4 ; LANDMARK_DEBUGLEVEL_4
db DEBUGLEVEL_5 ; LANDMARK_DEBUGLEVEL_5
endc
assert_table_length NUM_LANDMARKS

View File

@ -23,6 +23,8 @@ if DEF(_DEBUG)
ld a, 100
ld [wCurPartyLevel], a
predef TryAddMonToParty
ld a, -1
ld [wUnlockedLevels], a ; debug
endc
farcall AutoSaveGameOutsideOverworld
jp GameMenu

View File

@ -4,8 +4,6 @@ LevelSelectionMenu::
ldh [hMapAnims], a
ld a, 1 << 2 ; do not clear wShadowOAM during DoNextFrameForAllSprites
ld [wVramState], a
ld a, -1
ld [wUnlockedLevels], a ; debug
call ClearBGPalettes
call ClearTilemap
@ -598,6 +596,12 @@ LevelSelectionMenu_GetValidDirections:
; the landmark byte of this transition is two bytes back
dec hl
dec hl
; use LandmarkToLevelTable to find the level that this landmark belongs to
ld e, [hl]
ld d, 0
ld hl, LandmarkToLevelTable
add hl, de
; find if said level has been unlocked
ld e, [hl]
ld b, CHECK_FLAG
call UnlockedLevelsFlagAction

View File

@ -40,6 +40,7 @@ INCLUDE "constants/engine_flags.asm"
INCLUDE "constants/event_flags.asm"
INCLUDE "constants/icon_constants.asm"
INCLUDE "constants/landmark_constants.asm"
INCLUDE "constants/level_constants.asm"
INCLUDE "constants/map_constants.asm"
INCLUDE "constants/map_data_constants.asm"
INCLUDE "constants/map_object_constants.asm"