From 7448da83805cf20a4fbe8807a3185c1a7a3b4e24 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Sat, 14 Oct 2023 21:45:48 +0200 Subject: [PATCH] Create BOARDEVENT_END_TURN as a transition between turns after landing on space (#25) --- constants/script_constants.asm | 1 + engine/board/spaces.asm | 24 ++++++++++++++++++------ engine/overworld/events.asm | 17 +++++++++++++++-- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/constants/script_constants.asm b/constants/script_constants.asm index 94458c781..f8b94a63a 100644 --- a/constants/script_constants.asm +++ b/constants/script_constants.asm @@ -328,4 +328,5 @@ DEF NUM_UNOWN_PUZZLES EQU const_value const_def 1 const BOARDEVENT_DISPLAY_MENU ; 1 const BOARDEVENT_HANDLE_BOARD ; 2 + const BOARDEVENT_END_TURN ; 3 DEF NUM_BOARD_EVENTS EQU const_value - 1 diff --git a/engine/board/spaces.asm b/engine/board/spaces.asm index 59c785bbc..efd3cb2d2 100755 --- a/engine/board/spaces.asm +++ b/engine/board/spaces.asm @@ -2,20 +2,23 @@ BoardSpaceScripts:: ; used only for BANK(BoardSpaceScripts) BlueSpaceScript:: scall ArriveToRegularSpaceScript - iftrue .done -.done + iftrue .not_landed + scall LandedInRegularSpaceScript +.not_landed end RedSpaceScript:: scall ArriveToRegularSpaceScript - iftrue .done -.done + iftrue .not_landed + scall LandedInRegularSpaceScript +.not_landed end GreySpaceScript:: scall ArriveToRegularSpaceScript - iftrue .done -.done + iftrue .not_landed + scall LandedInRegularSpaceScript +.not_landed end ArriveToRegularSpaceScript: @@ -33,3 +36,12 @@ ArriveToRegularSpace: ld hl, wDisplaySecondarySprites res SECONDARYSPRITES_SPACES_LEFT_F, [hl] ret + +LandedInRegularSpaceScript: + callasm LandedInRegularSpace + end + +LandedInRegularSpace: + ld a, BOARDEVENT_END_TURN + ldh [hCurBoardEvent], a + ret diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index 8b77ae72e..bf59ddb46 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -266,7 +266,7 @@ PlayerEvents: call CheckBoardEvent jr c, .ok - call CheckTrainerBattle_GetPlayerEvent + call CheckTrainerEvent jr c, .ok call CheckTileEvent @@ -281,6 +281,18 @@ PlayerEvents: call CheckTimeEvents jr c, .ok +; 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 call OWPlayerInput jr c, .ok @@ -305,6 +317,7 @@ CheckBoardEvent: dw .none dw .menu ; BOARDEVENT_DISPLAY_MENU dw .board ; BOARDEVENT_HANDLE_BOARD + dw .none ; BOARDEVENT_END_TURN assert_table_length NUM_BOARD_EVENTS + 1 .none @@ -352,7 +365,7 @@ CheckBoardEvent: dw GreySpaceScript ; COLL_GREY_SPACE assert_table_length NUM_COLL_SPACES -CheckTrainerBattle_GetPlayerEvent: +CheckTrainerEvent: call CheckTrainerBattle jr nc, .nope