unit: Fixed unit switching interrupting the last move
authorLukas Krickl <lukas@krickl.dev>
Wed, 21 May 2025 03:41:26 +0000 (05:41 +0200)
committerLukas Krickl <lukas@krickl.dev>
Wed, 21 May 2025 03:41:26 +0000 (05:41 +0200)
Unit switching is now requrested by the idle state

src/map.s
src/unit.s
src/wram.s

index 780a5d335d061a579b57bfa38d801cbfc5b10d18..e4e12655793be0278ea016bb3b80015d0ba65c25 100644 (file)
--- 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
index e6e4953ace80d4999ec2873e8dd274f0e24fd30a..ca3d3886fe93431814014dc8d760df3d53b53562 100644 (file)
@@ -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 
index f598058c99fd8b393ecfb71f642a48cf153bbbf9..c7cc74b89f46a9c12c847ed030a89a1930f7648d 100644 (file)
@@ -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