diff --git a/constants/space_constants.asm b/constants/space_constants.asm new file mode 100755 index 000000000..fb110e9f2 --- /dev/null +++ b/constants/space_constants.asm @@ -0,0 +1,8 @@ +; metatile layout constants +DEF FIRST_SPACE_METATILE EQU $80 +DEF FIRST_GREY_SPACE_METATILE EQU $e0 +DEF UNIQUE_SPACE_METATILES_MASK EQU %11111 + +; Branch Space special direction values +DEF BRANCH_DIRECTION_INVALID EQU -1 +DEF BRANCH_DIRECTION_UNAVAILABLE EQU -2 \ No newline at end of file diff --git a/constants/tileset_constants.asm b/constants/tileset_constants.asm index fb9db00d9..94ccd1f19 100644 --- a/constants/tileset_constants.asm +++ b/constants/tileset_constants.asm @@ -68,8 +68,3 @@ DEF NUM_VARIABLE_SPACES_SETS EQU const_value ; number of tiles of the tileset occupied by space tiles (see LoadTilesetGFX) DEF TILESET_FIXED_SPACES_NUM_TILES EQU $20 DEF TILESET_VARIABLE_SPACES_NUM_TILES EQU $20 - -; metatile layout constants -DEF FIRST_SPACE_METATILE EQU $80 -DEF FIRST_GREY_SPACE_METATILE EQU $e0 -DEF UNIQUE_SPACE_METATILES_MASK EQU %11111 diff --git a/engine/board/spaces.asm b/engine/board/spaces.asm index 36c909e8f..94a2e8ff8 100755 --- a/engine/board/spaces.asm +++ b/engine/board/spaces.asm @@ -127,10 +127,24 @@ LandedInRegularSpace: BranchSpaceScript:: scall .ArriveToBranchSpaceScript +.prompt_player callasm .PromptPlayerToChooseDirection + iffalse .print_technique_required wait 200 end +.print_technique_required + opentext + writetext .TechniqueRequiredText + waitbutton + closetext + sjump .prompt_player + +.TechniqueRequiredText: + text "A new TECHNIQUE is" + line "required!" + done + .ArriveToBranchSpaceScript: playsound SFX_TWINKLE wait 400 @@ -141,8 +155,11 @@ BranchSpaceScript:: ; load new space ld a, [wCurSpaceNextSpace] ld [wCurSpace], a +; unlike in other cases, wCurSpaceNextSpace will not yet +; contain the next space after calling LoadCurSpaceData. +; it will be defined after the player has chosen which direction to take. call LoadCurSpaceData -; load its branch data +; load the space's branch data call LoadTempSpaceBranchData call .DisableDirectionsRequiringLockedTechniques ; draw arrows for valid directions @@ -153,55 +170,86 @@ BranchSpaceScript:: jp UpdateActiveSprites .DisableDirectionsRequiringLockedTechniques: +; set to BRANCH_DIRECTION_UNAVAILABLE each next space byte of the branch struct +; that has an unavailable direction due to required techniques not yet unlocked. + ld hl, wTempSpaceBranchStruct + NUM_DIRECTIONS + ld de, wTempSpaceBranchStruct + ld bc, wUnlockedTechniques +rept NUM_DIRECTIONS + ld a, [bc] + and [hl] + cp [hl] + jr z, .next\@ + ld a, BRANCH_DIRECTION_UNAVAILABLE + ld [de], a +.next\@ + inc hl + inc de +endr ret .PromptPlayerToChooseDirection: -; compute available directions in b as joypad dpad flags +; sample a dpad press ld hl, wTempSpaceBranchStruct - ld b, 0 - ld a, [hli] - cp -1 - jr z, .not_right - set D_RIGHT_F, b -.not_right - ld a, [hli] - cp -1 - jr z, .not_left - set D_LEFT_F, b -.not_left - ld a, [hli] - cp -1 - jr z, .not_up - set D_UP_F, b -.not_up - ld a, [hli] - cp -1 - jr z, .joypad_loop - set D_DOWN_F, b - -; sample input of an available direction -.joypad_loop call GetJoypad ldh a, [hJoyPressed] - and b - jr z, .joypad_loop + and D_PAD + jr z, .PromptPlayerToChooseDirection -; load the next space for the chosen direction - ld hl, wTempSpaceBranchStruct +; determine the status (ok/invalid/unavailable) of the chosen direction bit D_RIGHT_F, a - jr nz, .ok + jr z, .not_right + ld a, [hl] + inc a ; cp BRANCH_DIRECTION_INVALID + jr z, .PromptPlayerToChooseDirection + inc a ; cp BRANCH_DIRECTION_UNAVAILABLE + jr z, .technique_required + jr .direction_chosen +.not_right + inc hl bit D_LEFT_F, a - jr nz, .ok + jr z, .not_left + ld a, [hl] + inc a ; cp BRANCH_DIRECTION_INVALID + jr z, .PromptPlayerToChooseDirection + inc a ; cp BRANCH_DIRECTION_UNAVAILABLE + jr z, .technique_required + jr .direction_chosen +.not_left + inc hl bit D_UP_F, a - jr nz, .ok + jr z, .not_up + ld a, [hl] + inc a ; cp BRANCH_DIRECTION_INVALID + jr z, .PromptPlayerToChooseDirection + inc a ; cp BRANCH_DIRECTION_UNAVAILABLE + jr z, .technique_required + jr .direction_chosen +.not_up + inc hl -.ok + ld a, [hl] + inc a ; cp BRANCH_DIRECTION_INVALID + jr z, .PromptPlayerToChooseDirection + inc a ; cp BRANCH_DIRECTION_UNAVAILABLE + jr z, .technique_required + ; fallthrough + +.direction_chosen +; save the next space of the chosen direction to wCurSpaceNextSpace ld a, [hl] ld [wCurSpaceNextSpace], a ld hl, wDisplaySecondarySprites res SECONDARYSPRITES_BRANCH_ARROWS_F, [hl] + ld a, TRUE + ldh [hScriptVar], a + jp PlayClickSFX + +.technique_required + xor a ; FALSE + ldh [hScriptVar], a jp PlayClickSFX UnionSpaceScript:: diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm index a8f4492b5..6b6d18d0a 100644 --- a/engine/overworld/map_objects.asm +++ b/engine/overworld/map_objects.asm @@ -3212,9 +3212,15 @@ InitBranchArrowsSprites: ld c, NUM_DIRECTIONS .loop ld a, [de] - cp -1 ; - jr z, .next1 ; skip this arrow if this direction is not available + cp BRANCH_DIRECTION_INVALID + jr z, .next1 ; skip this arrow if this direction is not valid + cp BRANCH_DIRECTION_UNAVAILABLE + gender_to_pal + ld b, a + jr nz, .available + ld b, PAL_OW_EMOTE ; draw grey arrow if this direction is unavailable +.available ; draw this arrow and advance hUsedSpriteIndex ; preserve loop variables d, e, c push de @@ -3222,11 +3228,13 @@ InitBranchArrowsSprites: ldh a, [hUsedSpriteIndex] ld e, a ld d, HIGH(wShadowOAM) -; copy all bytes minus the attributes one -; the palette matches the player's color palette +; copy all bytes minus the attributes one. the palette matches the +; player's color palette, or is PAL_OW_EMOTE if direction is unavailable + push bc ld bc, SPRITEOAMSTRUCT_LENGTH - 1 call CopyBytes - gender_to_pal + pop bc + ld a, b ; palette ld [de], a inc de ld a, e diff --git a/includes.asm b/includes.asm index a691fd9b9..fc5b99b45 100644 --- a/includes.asm +++ b/includes.asm @@ -60,6 +60,7 @@ INCLUDE "constants/radio_constants.asm" INCLUDE "constants/script_constants.asm" INCLUDE "constants/serial_constants.asm" INCLUDE "constants/sfx_constants.asm" +INCLUDE "constants/space_constants.asm" INCLUDE "constants/sprite_anim_constants.asm" INCLUDE "constants/sprite_constants.asm" INCLUDE "constants/sprite_data_constants.asm" diff --git a/maps/DebugLevel5_Map1.asm b/maps/DebugLevel5_Map1.asm index 76bcae626..d32658937 100755 --- a/maps/DebugLevel5_Map1.asm +++ b/maps/DebugLevel5_Map1.asm @@ -66,6 +66,6 @@ DebugLevel5_Map1_MapSpaces: space 16, 4, $0, 8 ; 43 .BS2: - branchdir RIGHT, 3, 0 + branchdir RIGHT, 3, TECHNIQUE_SURF branchdir UP, 35, 0 endbranch