From 6fb2aa5bbe9b33d0c9db423beebf2be4fcfef3d7 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Wed, 21 May 2025 05:41:26 +0200 Subject: [PATCH] unit: Fixed unit switching interrupting the last move Unit switching is now requrested by the idle state --- src/map.s | 2 +- src/unit.s | 27 ++++++++++++++++++++------- src/wram.s | 3 +++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/map.s b/src/map.s index 780a5d3..e4e1265 100644 --- a/src/map.s +++ b/src/map.s @@ -114,7 +114,7 @@ map_load_demo_actors: ld bc, act_size call memcpy - ld de, p0_units + ld de, p_empty_unit call unit_next_request ret diff --git a/src/unit.s b/src/unit.s index e6e4953..ca3d388 100644 --- a/src/unit.s +++ b/src/unit.s @@ -254,16 +254,14 @@ unit_use_move: pop de ; hl = act_moves ld a, [hl] ; current - cp a, 1 ; if 1 request next - - push_all - call z, unit_next_request - pop_all cp a, 0 ; if 0 exit ret z dec a ld [hl], a + ; we need the z flag to not be set ehre + ; so just do something that will always unset it + or a, 1 ret ; centers the current scroll on the selected unit @@ -549,6 +547,21 @@ unit_reset_all_moves: ret + ; called before switching to active + ; this call also checks if the unit may need to + ; hand over control to a new unit + ; this is done when moves are 0 + ; inputs: + ; de: unit +unit_delay_to_active: + ld hl, act_moves + add hl, de ; hl = moves + ld a, [hl] + cp a, 0 + call z, unit_next_request + ldnull bc + ret + unit_demo_1: st_def 0x00, unit_demo_1_init, st_unit_demo_1_idle @@ -558,7 +571,7 @@ unit_demo_1: unit_demo_2: st_def 0x00, unit_demo_1_init, st_unit_demo_1_idle - act_def ACT_T_DEMO_1, 0, 1, 2, 3, 4, 5, 3, 3, 0 + act_def ACT_T_DEMO_1, 0, 1, 2, 3, 0, 5, 3, 3, 0 act_st_def NULL, NULL, st_unit_demo_1_update, st_unit_demo_1_idle st_unit_demo_1_update: @@ -568,7 +581,7 @@ st_unit_demo_1_idle: st_def 0x00, unit_demo_1_idle, st_unit_demo_1_idle st_unit_delay_to_active: - st_def CURSOR_MOVE_TIMER, st_null_fn, st_unit_switch_to_active + st_def CURSOR_MOVE_TIMER, unit_delay_to_active, st_unit_switch_to_active st_unit_switch_to_active: st_def 0, unit_switch_to_active, st_unit_switch_to_active diff --git a/src/wram.s b/src/wram.s index f598058..c7cc74b 100644 --- a/src/wram.s +++ b/src/wram.s @@ -35,6 +35,9 @@ bg_update_queue: .adv bge_size * BGE_MAX draw_flags: .adv 1 gameplay_flags: .adv 1 +; a dummy unit +p_empty_unit: .adv act_size + ; the unit that requested unit_next gameplay_unit_current: .adv 2 -- 2.30.2